in reply to how to use foreach loop to do comparison between two arrays of hashes

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

Replies are listed 'Best First'.
Re^2: how to use foreach loop to do comparison between two arrays of hashes
by BillKSmith (Monsignor) on Oct 27, 2018 at 18:51 UTC
    Amazing! But note that if two (or more) lines in the same brand fail to match, There is no spec on how to pair them in the report.
    Bill
      I think tybalt89 needs a new category on PM for his amazing contributions.

      Something like "regex is the new assembler" or "the last maintainer committed suicide" or "NSFW" ... ;-)))

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice