in reply to Re^2: Read Directory and getlines in .csv
in thread Read Directory and getlines in .csv
Not sure what part you are having trouble with but try this
poj#!/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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Read Directory and getlines in .csv
by Dipepper (Novice) on Apr 27, 2016 at 17:22 UTC | |
by Laurent_R (Canon) on Apr 27, 2016 at 20:13 UTC |