如何使用写perl脚本,将在数组a里面的字符在数组b里面的数据选出来

use strict;
my @a={"a","b","c"};
my @b={"a","d","e","f"};
foreach my $a(@a)
{
foreach my $b(@b)
{
if($a=~ m/$b/)
{
print "$a\n";
}

}
}
这个程序该怎么改
最新回答
贫尼想借色

2024-04-26 06:49:25

少侠,你的数组定义有问题,应该是y @a=("a","b","c");和@b=("a","d","e","f");

其他的好像没什么问题

望采纳

具体代码如下:
use strict;
my @a=("a","b","c");
my @b=("a","d","e","f");
print "@a\n";
foreach my $a(@a)
{
foreach my $b(@b)
{
if($a eq $b)
{
print "$a\n";
}

}
}