On Jun 7, Sara Campbell Meeks said:
>$edgar = "/home/Campbell/perl/edgar"
>
>opendir (EDGAR, $edgar) or die "Can't find $edgar!\n";
>
>while ($file = readdir EDGAR) {
> open (FILE, ">$file");
> print FILE;
>}
Problems of all sorts here. First, you're opening $file to bet WRITTEN
to. You need "< $file", or perhaps just $file.
open FILE, "< $file" or die "can't read $file: $!";
Second, you're doing 'print FILE', which tries to print TO the file, not
read the lines from it and print them.
print <FILE>;
Third, $file is just the NAME of the file -- you need to prepend the path
to file, $edgar, to it yourself.
open FILE, "< $edgar/$file" or die "can't read $edgar/$file: $!";
Fourth, you're going to try and print directories -- at least . and .. in
this case.
next if -d "$edgar/$file"; # skip directories
Finally, the while loop is kinda incomplete, since 0 is a valid name for a
file.
Perhaps you want to do:
opendir DIR, $edgar or die "can't read dir $edgar: $!";
while (defined (my $file = readdir DIR)) {
next if -d "$edgar/$file";
open FILE, "< $edgar/$file" or die "can't read $edgar/$file: $!";
print <FILE>;
close FILE; # it's nice to do this, you know...
}
closedir DIR;
There are other, more crafty solutions:
{
opendir DIR, $edgar or die "can't read dir $edgar: $!";
local @ARGV = grep !-d, map "$edgar/$_", readdir DIR;
closedir DIR;
print <>;
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **