Rob E McCormick wrote: > > Bear with me, I'm trying to test chunks of code I understand (+/-?) to get > to the problem I need to solve. > > Would like to munge some old_logs in a directory into 'new' logs that have a > portion of the old logs and put those new logs into a 'processed' directory. > I'm struggling with arrays, FILEHANDLES, opendir, readdir, variables, ... > despite patient advice from some list members. > > Below is a crude regex, but this part seems to be working from the command > line (accept filenames input on the command line @ARGV)
If your file names are in @ARGV you can use the special input file handle <> to open and read the files. Your program could be written as (where /regex/ would be your regular expression): while ( <> ) { /regex/ and print; } > 1 #!/usr/bin/perl -w > 2 use strict; > 3 > 4 my $line; > 5 foreach my $original_log ( @ARGV ) { > 6 open ( LOG, $original_log ) || die "Can't open file: $!\n"; > 7 while ( defined ( $line = <LOG> ) ) { > 8 > 9 # match lines that fit (4) different conditions: those that start > with '#', those that contain 'CommunityID=399', > 10 # or those that contain '/developersupport/testfiles', or > '/remotegadgets/marks' > 11 > 12 if ( $line =~ > m/^#|CommunityID\=399|\/developersupport\/testfiles|\/remotegadgets\/marks\/ > gadget/ ) { > 13 print $line; > 14 } > 15 } > 16 close LOG; > 17 } > 18 > > Now, looking at Learning Perl (Ch. 10.4 Using Filehandles), there's an > example, of " copying data from a file specified in $a into a file specified > in $b. > > open(IN,$a) || die "cannot open $a for reading: $!"; > open(OUT,">$b") || die "cannot create $b: $!"; > while (<IN>) { # read a line from file $a into $_ > print OUT $_; # print that line to file $b > } > close(IN) || die "can't close $a: $!"; > close(OUT) || die "can't close $b: $!"; > > It's a semi-related example, but not quite.... How do I munge each old file > into $newdir/$with_new_filename? I've read that think of @arrays as "these" > $files I'm not getting it as rapidly as I'd like.... How are the new file names defined? Are they based on the old file names or something else? open IN, $old_filename or die "cannot open $old_filename for reading: $!"; open OUT,">$newdir/$with_new_filename" or die "cannot create $newdir/$with_new_filename: $!"; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]