cipher has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl chdir("c:/perl/logs") or die "$!"; opendir (DIR, ".") or die "$!"; my @files = grep {/2010*/} readdir DIR; close DIR; { local @ARGV = @files; foreach my $file (@files) { open(FILE,"c:/perl/logs/$file") or die "No file !"; while (@logs = <FILE>) { foreach $odate (@logs) { if ($odate =~/\bdate=(\d{1,4}-\d{1,2}-\d{1,2})/i) { $date = $1; print "$date\n"; ### prints all dates from all files } } print "$date\n"; ### Only prints last date from each f +ile } } } close FILE; exit(0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Scalar looses values outside foreach loop
by Corion (Patriarch) on Dec 02, 2010 at 09:20 UTC | |
by cipher (Acolyte) on Dec 02, 2010 at 09:41 UTC | |
by Corion (Patriarch) on Dec 02, 2010 at 10:08 UTC | |
|
Re: Scalar looses values outside foreach loop
by locked_user sundialsvc4 (Abbot) on Dec 02, 2010 at 13:41 UTC | |
by cipher (Acolyte) on Dec 03, 2010 at 02:57 UTC | |
|
Re: Scalar looses values outside foreach loop
by choroba (Cardinal) on Dec 02, 2010 at 12:50 UTC | |
by ww (Archbishop) on Dec 02, 2010 at 14:59 UTC | |
|
Re: Scalar looses values outside foreach loop
by Anonymous Monk on Dec 02, 2010 at 14:57 UTC |