perl 怎样合并两个数组,并除去相同的元素?
my@array1=('aa','bb');my@array2=('cc','aa');怎样得到@array3=('aa','bb','cc')???...
my @array1 = ('aa', 'bb');
my @array2 = ('cc', 'aa');
怎样得到 @array3 = ('aa', 'bb', 'cc') ??? 展开
my @array2 = ('cc', 'aa');
怎样得到 @array3 = ('aa', 'bb', 'cc') ??? 展开
3个回答
2013-10-18
展开全部
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;
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;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
my %h = ();
++$h{$_} foreach ( @array1, @array2 );
my @array3 = sort keys %h;
++$h{$_} foreach ( @array1, @array2 );
my @array3 = sort keys %h;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
my %hash;
@hash{@array1,@array2}++;
my @array3 = sort keys %hash;
@hash{@array1,@array2}++;
my @array3 = sort keys %hash;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询