Here is probably what you are looking for.
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: $_";
}
}
Normally - I would not code this way - this is written to help you get past initial roadblocks.
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
|