Chinaunix
标题:
一个数组中有重复的元素怎么把这些重复的元素只保留一个
[打印本页]
作者:
赛萌
时间:
2015-09-28 14:52
标题:
一个数组中有重复的元素怎么把这些重复的元素只保留一个
如:@w=qw(3 5 6 7 5 3);怎么得到@m=(3 5 6 7)
作者:
yybmsrs
时间:
2015-09-28 15:57
你先用最笨的方法实现一个
作者:
jason680
时间:
2015-09-28 16:19
本帖最后由 jason680 于 2015-09-28 16:19 编辑
回复
1#
赛萌
my %_;
my @m = grep{!$_{$_}++}@w;
作者:
104359176
时间:
2015-09-28 18:56
use List::MoreUtils qw(uniq);
my @list = (1,2,2,3);
uniq(@list) eq (1,2,3)
复制代码
作者:
bikong0411
时间:
2015-09-29 10:57
perl -e '@w=qw(3 5 6 7 5 3);%h; map {$h{$_}=1} @w;@w = keys %h;print "@w";'
复制代码
perl -MList::MoreUtils=uniq -e '@w=qw(3 5 6 7 5 3);@w=uniq @w;print "@w";'
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2