In case you want to compare files with the same name (that exist in both lists/directories), you could compute the intersection of both lists, and then iterate over the resulting list of files names, simply prepending the appropriate paths... Something like:

my %seen; $seen{$_}++ for @return, @remoteFilelist; my @files_in_both_lists = grep $seen{$_} > 1, keys %seen; for my $fname (@files_in_both_lists) { if (compare_text("$path1/$fname", "$path2/$fname") == 0) { #... } }

Otherwise (if you want to compare every file in list 1 with every file in list 2), I would compute checksums (e.g. MD5) for all files, and use the checksums as keys in a hash, with a list of filenames as the associated value. Those entries with more than one file in that list will indicate identical files...

Update: sample code for the latter approach:

#!/usr/bin/perl use strict; use warnings; use Digest::MD5; my @allfiles = ...; # your file lists merged (including paths) my %by_md5; for my $file (@allfiles) { open my $fh, "<", $file or die "Couldn't open '$file': $!"; binmode $fh; my $md5 = Digest::MD5->new(); $md5->addfile($fh); my $digest = $md5->hexdigest(); # or ->digest() -- hexdigest is j +ust more "dumping-friendly"... push @{ $by_md5{$digest} }, $file; } for my $digest (grep @{$by_md5{$_}} > 1, keys %by_md5) { print "duplicates: @{ $by_md5{$digest} }\n"; }

(In case you're paranoid (and worry about the very unlikely case of a digest collision), you can always do a byte-for-byte comparison of the files with the same digest...(those reported as duplicates with the above snippet))


In reply to Re: Assistance with file compare by almut
in thread Assistance with file compare by Karger78

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.