Actually, this is my script: foreach $filename(readdir DIR1) { next if $filename =~/^\./; while (readdir DIR2){ print "$filename\n" if (-e $filename); last; } }
----- Original Message ----- From: "Vladimir Lemberg" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, October 27, 2004 5:14 PM Subject: Comparing two directories Hi, Could you help me to find what's wrong in my script? I need to compare two directories and if file exists in both - print it. die "Usage: 2 arguments must be passed i.e. file1 file2\n" if @ARGV != 2; opendir DIR1, $ARGV[0] or die "couldn't open $ARGV[0] for reading.\n"; opendir DIR2, $ARGV[1] or die "couldn't open $ARGV[1] for reading.\n"; foreach $filename(readdir DIR1) { next if $filename =~/^\./; while (readdir DIR2){ if (-e $filename){ print "$filename\n"} } } closedir(DIR1); closedir(DIR2); Looks like I'm checking "if exists" in first directory but not in second. -Vladimir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>