in reply to Compare two arrays of simple numbers
you might not actually want to do it this way, but:
use strict; use warnings; my @array_1 = (1, 12, 34, 50); my @array_2 = (1, 1234, 50); my @array_3 = (34, 12, 1, 50); for ([\@array_1, \@array_2], [\@array_1, \@array_3]) { if ("@{[sort @{$_->[0]}]}" eq "@{[sort @{$_->[1]}]}") { print "match: [@{$_->[0]}], [@{$_->[1]}]\n"; } else { print "mismatch: [@{$_->[0]}], [@{$_->[1]}]\n"; } }
Prints:
mismatch: [1 12 34 50], [1 1234 50] match: [1 12 34 50], [34 12 1 50]
where the magic of interest is "@{[sort @array_1]}" eq "@{[sort @array_2]}".
|
|---|