How can I compare arrays in Perl?

后端 未结 12 2119
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 18:54

I have two arrays, @a and @b. I want to do a compare among the elements of the two arrays.

my @a = qw\"abc def efg ghy klm ghn\";
m         


        
12条回答
  •  孤城傲影
    2020-12-06 19:14

    my @a1 = qw|a b c d|;
    my @a2 = qw|b c d e|;
    
    for my $i (0..$#a1) {
        say "element $i of array 1 was not found in array 2" 
            unless grep {$_ eq $a1[$i]} @a2
    }
    

提交回复
热议问题