perl read multiple file -
in perl,
how read multiple file @ once,
am genrating report @ end of month,
per day 1 log file create,
i want read entire month files ,
my file somthing t.log.mmddyyy
the glob
function allow retrieve list of files names match pattern. if load list @argv
, can process files--even in order single loop:
use strict; use warnings; use getopt::long; sub usage ($) { $msg = shift; die <<"end_msg"; *** $msg usage: $0 --month=nn --year=nn path end_msg } getoptions( 'month=i' => \my $month, 'year=i' => \my $year ); usage "month not specified!" unless $month; usage "year not specified!" unless $year; usage "invalid month specified: $month" unless $month > 0 , $month < 13; usage "invalid year specified: $year" unless $year > 0; $directory_path = shift; die "'$directory_path' not exist!" unless -d $directory_path; @argv = sort glob( sprintf( "$directory_path/t.log.%02d??%02d", $month, $year )); while ( <> ) { # process files ... }
Comments
Post a Comment