How can I compare arrays in Perl?

后端 未结 12 2122
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  旧时难觅i
    2020-12-06 19:22

    my @a = qw' abc def efg ghy klm ghn ';
    my @b = qw' def ghy jgk lom com klm ';
    
    my $flag;
    
    foreach  my $item(@a) {
      $flag = @b~~$item ? 0 : 1;
      last if !$flag;
    }
    

    Note that you will need Perl 5.10, or later, to use the smart match operator (~~) .

提交回复
热议问题