my @array1 = ('aa', 'bb');my @array2 = ('cc', 'aa');怎样得到 @array3 = ('aa', 'bb', 'cc') ???
2 回答
HUH函数
TA贡献1836条经验 获得超4个赞
my %h = ();
++$h{$_} foreach ( @array1, @array2 );
my @array3 = sort keys %h;
陪伴而非守候
TA贡献1757条经验 获得超8个赞
my @array1 = ('aa', 'bb');
my @array2 = ('cc', 'aa');
@array3 = (@array1, @array2);
my %count;
my @array3_new = grep { ++$count{ $_ } < 2; } @array3;
print @array3_new;
或者
@array3 = (@array1, @array2);
foreach my $item ( @array3 ){
if ( ! grep( /$item/, @array3_new ) ){
push( @array3_new, $item );}}
print @array3_new;
- 2 回答
- 0 关注
- 614 浏览
添加回答
举报
0/150
提交
取消