如何取出数组中的不同元素并存入一个数组里

不管怎样都是使用hash啦,我弄了个总结:
#!/usr/bin/perl

my @list = ("0101", "0101", "0102", "0101", "0103", "0102");
# my %seen = map {$_=> 1} @list;
my %seen = map {$_, 1} @list;
my @uniq = keys %seen;
print "@uniq","\n";

%seen = ();
@uniq = ();
foreach $item (@list){
        push(@uniq, $item) unless $seen{$item}++;
}
print "@uniq","\n";

%seen = ();
foreach $item (@list) {
        $seen{$item}++;
}
@uniq = keys %seen;
print "@uniq","\n";

%seen = ();
@uniqu = grep { ! $seen{$_} ++ } @list;
print "@uniq","\n";




QUOTE:
原帖由 andyhau791010 于 2008-8-27 14:10 发表
以下的数组:@read={"0101","0101","0102","0101","0103","0102"}
我如何得到这样的数组:@read={"0101","0102","0103"}
急用,谢谢大家。

用grep的解决方案:
@uniq_array = grep { ++$counts{$_} < 2 } @read;