Re: Comparing two directories
From: Vladimir Lemberg (lemba_at_sbcglobal.net)
Date: 10/28/04
- Next message: Franklin: "how to parse this xml file"
- Previous message: Vladimir Lemberg: "Comparing two directories"
- In reply to: Vladimir Lemberg: "Comparing two directories"
- Next in thread: Mark Goland: "Re: Comparing two directories"
- Reply: Mark Goland: "Re: Comparing two directories"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: "Vladimir Lemberg" <lemba@sbcglobal.net>, <beginners@perl.org> Date: Wed, 27 Oct 2004 17:16:58 -0700
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" <lemba@sbcglobal.net>
To: <beginners@perl.org>
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
- Next message: Franklin: "how to parse this xml file"
- Previous message: Vladimir Lemberg: "Comparing two directories"
- In reply to: Vladimir Lemberg: "Comparing two directories"
- Next in thread: Mark Goland: "Re: Comparing two directories"
- Reply: Mark Goland: "Re: Comparing two directories"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|