[perl] 数组去重

use strict;
use warnings;
use 5.010;


use Data::Dumper qw(Dumper);


my @words = qw(foo bar baz foo zorg baz);


my @unique = uniq( @words );


say Dumper \@unique_words;


sub uniq {
  my %seen;
  return grep { !$seen{$_}++ } @_;

}


http://cn.perlmaven.com/unique-values-in-an-array-in-perl 

猜你喜欢

转载自blog.csdn.net/lieberstraum/article/details/51862881
今日推荐