Normally - I would not code this way - this is written to help you get past initial roadblocks.my $CurrentDir="."; # Or "Sanjay"; opendir DH, "." or die "failed to readdir $CurrentDir: $!"; while($temp = readdir(DH)) { print "$temp\n"; if ($temp eq "." or $temp eq ".." or -d $temp){ next; # Do not open . or .. } open FILE, "$CurrentDir/$temp" or die "failed to open file $temp:$! +\n"; print "pass"; while(<FILE>) { print "sucess: $_"; } }
UPDATE: Changed while(<$temp>) to while(<FILE>).
This makes more sense, and is probably what you were trying to do.
Also, as merlyn says, the "opendir" and "while($temp=readdir..." can be replaced with :
while (glob "$CurrentDir/*"){ $temp = $_; # Remainder of the code is the same.
"For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken
In reply to Re: How do I read the contents of each file in a directory?
by NetWallah
in thread How do I read the contents of each file in a directory?
by sanjaysingh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |