在Perl中减去两个数组

时间:2014-05-15 12:00:14

标签: perl

在Perl中减去两个数组的惯用方法是什么?我不经常写Perl,我不明白为什么这不起作用:

my @arr1 = ("a", "b","c",);
my @arr2 = ("a", "b","c", "d", "E");
my @rs;
foreach my $e (@arr2) {
    if(grep(!/^$e$/, @arr1)) { # if $e is not in @arr1
        push(@rs, $e);
    }
}

0 个答案:

没有答案