All it takes is a couple of regexes :)

#!/usr/bin/perl # https://perlmonks.org/?node_id=1224689 use strict; use warnings; my $newdata = <<END; Puma 77777 33333 44444 55555 Adidas 99999 88888 55555 77777 22222 11111 33333 44444 Brooks 11111 22222 33333 44444 33333 44444 55555 66666 END my $olddata = <<END; Puma 77777 33333 44444 55555 Adidas 11111 11111 33333 44444 99999 88888 55555 77777 Brooks 11111 22222 33333 44444 33333 44444 55555 66666 END local $_ = $newdata . $olddata; my $label = "\t\t\t New\t\t\t\t Old\n\t\t" . " x1 y1 x2 y2\t\t x1 y1 x2 y2"; print "Matching\n$label\n"; 1 while s/^ ([a-z]+)\n \K ( (?:\d\V*\n)*?) (\d\V*)\n ( .* ^\1\n (?:\d\V*\n)*? ) \3\n / print "$1\t\t$3\t\t$3\n"; "$2$4" /gmixes; print "\n\nNot matching\n$label\n"; 1 while s/^ ([a-z]+)\n \K (\d\V*)\n ( .* ^\1\n) (\d\V*)\n / print "$1\t\t$2\t\t$4\n"; $3 /gmixes;

Outputs :

Matching New Old x1 y1 x2 y2 x1 y1 x2 y2 Puma 77777 33333 44444 55555 77777 33333 44444 5555 +5 Adidas 99999 88888 55555 77777 99999 88888 55555 7777 +7 Brooks 11111 22222 33333 44444 11111 22222 33333 4444 +4 Brooks 33333 44444 55555 66666 33333 44444 55555 6666 +6 Not matching New Old x1 y1 x2 y2 x1 y1 x2 y2 Adidas 22222 11111 33333 44444 11111 11111 33333 4444 +4

In reply to Re: how to use foreach loop to do comparison between two arrays of hashes by tybalt89
in thread how to use foreach loop to do comparison between two arrays of hashes by darkmoon

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.