in reply to Processing all files in a directory
You have a couple of problems.
foreach my $name (readdir DIR) { next if /^\./;
You want next if $name =~ /^\./; instead. The match operator works on $_ by default.
sub process_file { my $file = @_;
That doesn't do what you expect; it assigns the number of elements in @_ to $file. You want either my ($file) = @_; or my $file = shift; or maybe even my $file = $_[0]; (though I don't recommend that last.)
open (FILE, $file) or die "Could not open file: $!";
Unless your CWD is $dir, you'll need to prepend it to your filename... otherwise it will try to open $file in the current directory.
Oh, you might very well want split ' ', $line instead. That's a special case. Use /\s+/ only if you want to generate a leading null field on lines that begin with space.
Addendum: There are very good (security) reasons to use the three argument form of open() or to, at least, explicitly specify the mode.
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Processing all files in a directory
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 |