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

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

    For checking equality of two arrays try this. In given code, if %eq_or_not has any value then both arrays are not equal otherwise they are equal.

    my @array1 = ("part1", "part2", "part3", "part4");
    my @array2 = ("part1", "PART2", "part3", "part4");
    
    my %eq_or_not;
    
    @eq_or_not{ @array1 } = undef;
    delete @eq_or_not{ @array2 };
    
    0 讨论(0)
提交回复
热议问题