billie_t has asked for the wisdom of the Perl Monks concerning the following question:
my $dir = "e:\\work\\testlogs"; opendir DIR, $dir or die "opendir: $!"; foreach my $name (readdir DIR) { next if /^\./; print "$name \n"; process_file ($name); } closedir DIR; sub process_file { my $file = @_; my @date = split(/-/, $file); print "@date \n"; open (FILE, $file) or die "Could not open file: $!"; while (defined(my $line = <FILE>)) { my @fields = split(/\s+/, $line); my $machine = $fields[0]; close FILE; } }
At the "foreach", I want each file in the directory to be opened, skipping files beginning with a ".". This is not working, with an error saying "use of unintialized value in pattern match".
More importantly, none of the files in the directory are being opened, with a "no such file or directory" being returned. Printing "$name", which I would hope contained the currently open file name, seems to produce ".", which is obviously what I'm trying to skip.
All wisdom much appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Processing all files in a directory
by sauoq (Abbot) on May 26, 2003 at 04:59 UTC | |
by billie_t (Sexton) on May 26, 2003 at 05:32 UTC | |
by Abigail-II (Bishop) on May 26, 2003 at 12:26 UTC | |
by billie_t (Sexton) on May 27, 2003 at 01:30 UTC | |
|
Re: Processing all files in a directory
by Zaxo (Archbishop) on May 26, 2003 at 04:56 UTC | |
by sauoq (Abbot) on May 26, 2003 at 05:14 UTC | |
|
Re: Processing all files in a directory
by vek (Prior) on May 27, 2003 at 00:04 UTC |