In Perl, is there a built in way to compare two arrays for equality?

后端 未结 13 2322
无人及你
无人及你 2020-11-27 17:08

I have two arrays of strings that I would like to compare for equality:

my @array1 = (\"part1\", \"part2\", \"part3\", \"part4\");
my @array2 = (\"part1\", \         


        
13条回答
  •  执笔经年
    2020-11-27 17:19

    One could use grep function in scalar context (http://perldoc.perl.org/functions/grep.html#grep-BLOCK-LIST)

    (0 eq (grep { $array1[ $_ ] ne $array2[ $_ ] } 0..$#array1)) if $#array1 eq $#array2;

    HIH.

提交回复
热议问题