All assuming that the key value is unique! Sorry about the long lines ...
#! # Just For A Lark use strict; use warnings; use Digest::MD5; # Hash for X my %X_h; { open(my $IN,'<','X') or die "Can't open 'X'! $!"; # Populate hash with third field and SizeAndMD5 while (<$IN>) { chomp; $X_h{(split('|'))[2]}=SizeAndMD5($_); }; close($IN) or die "Can't close 'X'! $!"; }; ### %X_h # Processing Y # Hash for Y my %Y_h; { open(my $IN,'<','Y') or die "Can't open 'Y'! $!"; open(my $OUT,'>','Y.new') or die "Can't open 'Y.new'! $!"; # Populate hash with third field and SizeAndMD5 while (<$IN>) { chomp; $Y_h{my $key=(split('|'))[2]}=SizeAndMD5($_); unless (exists $X_h{$key}) { # No key in X so append a "D" print $OUT "$_|D\n"; } elsif ($Y_h{$key} ne $X_h{$key}) { # The corresponding record +in X is different print $OUT "$_|U\n"; } else { # The corresponding record in X is the same print $OUT "$_|\n"; }; }; close($OUT) or die "Can't close 'Y.new'! $!"; close($IN) or die "Can't close 'Y'! $!"; }; ### %Y_h # Re-processing X { open(my $IN,'<','X') or die "Can't open 'X'! $!"; open(my $OUT,'>','X.new') or die "Can't open 'X.new'! $!"; # Populate hash with third field and SizeAndMD5 while (<$IN>) { chomp; my $key=(split('|'))[2]; unless (exists $Y_h{$key}) { # No key in X so append a "I" print $OUT "$_|I\n"; } elsif ($X_h{$key} ne $Y_h{$key}) { # The corresponding record +in Y is different print $OUT "$_|U\n"; } else { # The corresponding record in Y is the same print $OUT "$_|\n"; }; }; close($OUT) or die "Can't close 'X.new'! $!"; close($IN) or die "Can't close 'X'! $!"; }; exit; # Returns Size and MD5 of the string as "%8.8lx%32.32s" sub SizeAndMD5 { return sprintf("%8.8lx%32.32s",length($_[0]),Digest::MD5::md5_ +hex($_[0])); };

In reply to Re: file delta detection by clueless newbie
in thread file delta detection by Anonymous Monk

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.