Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello. I am new to Perl and programming. I have written a perl program to get the names of .csv files in a different directory which were uploaded to the server today only, by modified date. These files are 13+ MB so I don't want to copy and move them to my new directory. I also wrote another perl program which will read a file and get only the lines with what I want and place those lines in a .csv with the criteria I need for my final report. My question is: How do I integrate these two programs into one program without moving these large files from the directory they are housed in. Is this possible?
#This is the program to get the .csv file names from the directory: #!/usr/bin/perl use strict; use warnings; use File::stat; use Text::CSV_XS; use IO::File; my $dirname = "Daily_QoS_CPD_link"; opendir(DIR, $dirname) or die "Not able to open $dirname $!"; # Create an array, Open the directory, get only .csv's modified in the + last 24 hours my @dir = sort { -M "$dirname/$a" <=> -M "$dirname/$b"} grep /\.csv/, $dirname ne '.' && $dirname ne '..', readdir + DIR; rewinddir(DIR); # create a list of csv's for today into a text file. my $One_day = 86400; foreach my $list (@dir){ my $diff = time()-stat("$dirname/$list")->mtime; if( $One_day > $diff){ open FILE, ">>CPD_Files.txt" or die "Not able to open f +ile $!"; print FILE "$list\n"; } } closedir DIR; close FILE; # This is the code for getting the lines from the .csv's that I need #!/usr/bin/perl use strict; use warnings; use Text::CSV_XS; my $Finput = "cpd_link_ABC_cpddrops_50_300300000.csv"; my $Foutput = "data0426-2.csv"; open my $FH, "<", $Finput; open my $out, ">", $Foutput; my $csv = Text::CSV_XS->new({binary => 1, eol => $/ }); while(my $row = $csv->getline($FH)) { my @fields = @$row; if ($fields[2] eq "DROPPED-10" || $fields[2] eq "CALL_START" | +| $fields[2] eq "CALL_END") { $csv->print($out, $row); } } close $FH; if (not $csv->eof){ $csv->error_diag(); }
|
|---|