Am Dienstag, 10. Mai 2005 13.54 schrieb Randal L. Schwartz:
> >>>>> "John" == John Doe <[EMAIL PROTECTED]> writes:
>
> John> Something like (untested):
>
> John> # build hashes with pairs (filename=>0)
> John> #
> John> my %first=map {$_=>1} find (sub {}, $dir1);
> John> my %second=map {$_=>1} find (sub {}, $dir2);
>
> Good thing that "untested" is in there, because find() doesn't return
> *anything* at all.  At least, nothing useful.  The wanted() routine
> is where all the action must take place.

Thanks a lot for the correction, shame on me :-(

And: Sorry "arkster" for misleading you.

> Or, you could do almost what you've written using my File::Finder:
>
>     my %files;
>     for my $dir ($dir1, $dir2) {
>       $files{$dir} = {map { $_ => 1 } File::Finder->type('f')->in($dir)};
>     }

> Or, you could get even trickier, save the next step, and build a
> single hash:
>
>     my %files;
>     for my $index (0..1) {
>       $files{$_} .= $index
>         for File::Finder->type('f')->in(($dir1, $dir2)[$index]);
>     }
>
>     while (my($file, $where) = each %files) {
>       print "$file only in $dir1\n" if $where eq "0";
>       print "$file only in $dir2\n" if $where eq "1";
>       print "$file in both\n" if $where eq "01";
>     }

This is very nice :-)

>
> This can easily be extended to multiple directories.
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
> training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to