P is for Practical | |
PerlMonks |
Re: Comparedirs.plby rob_au (Abbot) |
on Feb 13, 2002 at 10:09 UTC ( [id://145120]=note: print w/replies, xml ) | Need Help?? |
A couple of comments on your code ... The readdir function iterates through each directory entry opened by opendir - Your code doesn't test whether the returned entry is either a file or directory and fails to iterate through any sub-directories present within the test directories. While not a problem per se, it does mean that great differences can exist between directories without being reported by your script. Another issue lies with the order of code when calling stat on the returned directory entry, specifically the following code segment:
While a warning is generated when the file stat fails, your code continues through and still assigns return values from the failed stat to the directory hash. An alternate (more defensive) way to write this code would be:
If you want to build a more robust file comparison tool that incorporates directory checking, you may want to look at the source to File::Find::Duplicates which builds an intermediate array of stat values for files found through File::Find. On a much smaller and less significant note ... "This script will compare the same directory on two different machines for content, size and mtime" ... Where is the code comparing file content? :-)
perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'
In Section
Code Catacombs
|
|