|
|
Re: Perl Quiz-of-the-Week Suggestion: msg#00055
|
Subject: |
Re: Perl Quiz-of-the-Week Suggestion |
Hi;
I've enjoyed reading the quizzes, although I confess I've been too busy to tackle any of them myself - given my hack level of perl expertise. I had to write a quick utility yesterday to compare the contents of two directories and come up with identically named files. What I came up with is listed below. It's quick and dirty, taking two directories names as input parameters and putting out a list of names. I thought you might like this as an example for your Quiz of the Week, because I know that there has to be a more elegant way to do this. I'd also like the report to have more info on the files - showing their file dates and sizes in each directory - which is what I'm working on.
If this turns out to be something handled completely by a module that already exists, sorry to have bothered you.
Thanks,
John
@temp = sort glob($dir1 . "*.*");
foreach (@temp) {
if (-f $_) {
s(^.*\\)();
push(@dir1,$_);
}
}
@temp = sort glob($dir2 . "*.*");
foreach (@temp) {
if (-f $_) {
s(^.*\\)();
push(@dir2,$_);
}
}
foreach $outerstr (@dir1) {
foreach $innerstr (@dir2) {
if ($outerstr =~ $innerstr) {
push(@dirboth,$outerstr);
}
}
}
if (@dirboth) {
print("Found matching filenames. They will be stored in DIRBOTH.TXT\n");
open(TMPWORK, "> DIRBOTH.TXT");
printf TMPWORK ("Filenames found in both $dir1 and $dir2\n\n");
foreach (@dirboth) { printf TMPWORK ("$_\n"); }
close TMPWORK;
} else {
print("No matching filenames found in $dir1 and $dir2\n");
}
**********************************************************************
This e-mail and any files transmitted with it are considered
confidential and are intended solely for the use of the
individual or entity to whom they are addressed (intended).
This communication is subject to agent/client privilege.
If you are not the intended recipient (received in error) or
the person responsible for delivering the e-mail to the
intended recipient, be advised that you have received this
e-mail in error and that any use, dissemination, forwarding,
printing or copying of this e-mail is strictly prohibited. If
you have received this e-mail in error please notify the
sender immediately.
**********************************************************************
|
| |