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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |