If I am reading this correctly (which I am probably not!) you need another foreach loop in there somewhere. When you compare $file with $lines, you are trying to compare the contents of @temp. I think you need to wrap your comparison with a foreach loop:
foreach $file (sort readdir (DH)) { foreach $lines(@temp) { if ($file eq $lines) { etc etc } } }
This should work, you might want to have a look at the 'grep' function.
perldoc -f grep rather than using a double loop, though sometimes not: perldoc -q grep ....
As another completely opposite way to go about this, what about iterating over the list of files rather than the contents of the directory, then just check for the existence of the file specified in your list. Something similar to:
foreach my $file (@temp) { if (-e $file) { # file exists } else { # file does not exist } }
Depending on the length of the two lists this could be significantly faster since you don't have so many false checks, same reason a hash *can* be faster than an array when the index is not known.
Ah the beauty of TMTOWTDI,
http://danconia.org
, On Tuesday, July 8, 2003, at 11:22 pm, Sara wrote:
I m trying to read the files in a directory and match them with a same file names in text list.
Below given are the couple of lines, but I am unable to get the results, rather getting the same line repeated
This fileno1 does NOT found in directory but its in the list This fileno2 does NOT found in directory but its in the list This fileno3 does NOT found in directory but its in the list
and so on....
So its matching the file names but not giving the desired results?
Any idea?
###################################
open (NO, "list.txt"); # A list that contains the file numbers in a txt file, one per line
@temp = <NO>;
foreach $lines(@temp){
chomp $lines;
}
$dir = "Test"; #Directory we are opening to match the files in the directory with the above given list.
opendir (DH, $dir) || die ("could not open directory $dir\n"); foreach $file (sort readdir (DH)) { if ($file eq $lines) {
print "<br>This $file exists and found in the list too $lines";
}
else { print "<br>This $file does NOT found in directory but its in the list"; }
} close (DH);
#######################################
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]