25.6.2013

compare 2 arrays in perl 5.10

Filed under: perl — nax @ 11:22

Ever needed to compare 2 arrays in perl? Ultimate way is to use Array::Compare module, but for some reasons I was getting following error:

Argument 1 is not an array

Even thou I was casting both array pointers to array.

if ($comp->compare(@{$array1}, @{$array2})) {

Solution (because I was using 5.10 perl) is to use smart match operator:


if ( @{$array1} ~~ @{$array2}) {

Comments are closed.

Powered by WordPress