compare 2 arrays in perl 5.10

Written in

by

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}) {

Tags