You can compare the sizes of both arrays ( @a1 == @a2
in a scalar context), and then compare the size of the @a1
array with the size of the list of indexes that correspond to the same rows in both arrays ( grep $a1[$_] eq $a2[$_], 0..$#a1
),
if (@a1 == @a2 and @a1 == grep $a1[$_] eq $a2[$_], 0..$#a1) { print "equal arrays\n" }
A more performance-oriented version (does not go through all the elements if necessary),
use List::Util 'all'; if (@a1 == @a2 and all{ $a1[$_] eq $a2[$_] } 0..$#a1) { print "equal arrays\n" }
Dry27 source share