in reply to Read Directory and getlines in .csv

You can open a file in any directory where you have access by specifying the path and the name of the file to open, for example:
my $file = "$path/$bare_file_name"; open my $IN, "<", $file or die "... $!";

Replies are listed 'Best First'.
Re^2: Read Directory and getlines in .csv
by Dipepper (Novice) on Apr 27, 2016 at 17:06 UTC

    I apologize, please be patient with me. I do not really understand your response. These files are on a server and all are not uploaded daily, depends on the activity (no set pattern). Sometimes 2 other times 14 csv files. Therefore, I do not know the filenames/unknown_path_in_that_case of the files which were modified that day (today) until I run the program I created. But, I do want to read each filename/unknown_path.. to getlines from that .csv place result in one document (a .csv) then go to next file, recursively going through files until end of today's modified files.

      Not sure what part you are having trouble with but try this

      #!/usr/bin/perl use strict; use warnings; use File::stat; use Text::CSV_XS; my $csv = Text::CSV_XS->new( { binary => 1, eol => $/ } ); my $ONE_DAY = 86400; my $Foutput = "data0426-2.csv"; open my $out, ">", $Foutput or die "$!"; # create array of csv filenames in directory my $dirname = "Daily_QoS_CPD_link"; unless (-d $dirname) { die "Not able to open $dirname"; } my @dir = glob "$dirname/*.csv"; # parse files modifed in past 24 hours foreach my $infile (@dir){ my $age = time()-stat($infile)->mtime; if( $age < $ONE_DAY ){ open my $FH, "<", $infile or die "Could not open $infile : $!"; while (my $row = $csv->getline($FH)) { if ( $row->[2] =~ /^(DROPPED-10|CALL_START|CALL_END)$/ ) { $csv->print($out, $row); } } close $FH; } }
      poj

        Works beautifully. I think I need to look up a few things to see how/why/what of them like using "glob" and "unless. Whew! Most of the components you have in your code are what I had in mine. I was close, but, alas...no cigar. (sad face) BUT->I'm learning!! Thank you so much for your assistance. I kinda like Perl, its very powerful.