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

后端 未结 13 2386
无人及你
无人及你 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:21

    Perl 5.10 gives you the smart match operator.

    use 5.010;
    
    if( @array1 ~~ @array2 )
    {
        say "The arrays are the same";
    }
    

    Otherwise, as you said, you'll have top roll your own.

提交回复
热议问题