如何在Perl中获得独特的哈希数组?

时间:2014-03-06 14:09:31

标签: perl

我想得到一系列独特的哈希,但我没有任何想法,并尝试了很多方法。请帮我解决这个问题:

注意:我不想使用任何Perl模块。

我尝试了什么:

%seen=();
@unique = grep { ! $seen{$_} ++ } @AoH;

@unique仍然没有独特的哈希值?

例如:

发件人:

@AoH = (
{
   name  => "susheel",
   college => "MRITS",
},
{
   name  => "sunil",
   college => "MRITS",
},
{
   name  => "susheel",
   college => "MRITS",
},
);

@AoH = (
{
   name  => "susheel",
   college => "MRITS",
},
{
   name  => "sunil",
   college => "MRITS",
}
);

1 个答案:

答案 0 :(得分:7)

name

过滤唯一的哈希值
my %seen;
my @unique = grep { ! $seen{$_->{name}}++ } @AoH;