如何在Perl中获得唯一的哈希数组?
我想得到唯一的散列数组,但我没有任何想法,并尝试了许多方法。请帮我解决这个问题: 注意:我不想使用任何Perl模块 我的尝试:如何在Perl中获得唯一的哈希数组?,perl,Perl,我想得到唯一的散列数组,但我没有任何想法,并尝试了许多方法。请帮我解决这个问题: 注意:我不想使用任何Perl模块 我的尝试: @AoH = ( { name => "susheel", college => "MRITS", }, { name => "sunil", college => "MRITS", }, { name => "susheel", college => "MRITS", }, ); @uni
@AoH = (
{
name => "susheel",
college => "MRITS",
},
{
name => "sunil",
college => "MRITS",
},
{
name => "susheel",
college => "MRITS",
},
);
@unique仍然没有唯一哈希
例如:
发件人:
@AoH = (
{
name => "susheel",
college => "MRITS",
},
{
name => "sunil",
college => "MRITS",
},
{
name => "susheel",
college => "MRITS",
},
);
至
@AoH = (
{
name => "susheel",
college => "MRITS",
},
{
name => "sunil",
college => "MRITS",
}
);
要通过
name
键过滤唯一的哈希值
my %seen;
my @unique = grep { ! $seen{$_->{name}}++ } @AoH;
请不要写所有的大写字母标题。试着自己写一些东西,如果不起作用,具体告诉我们你做了什么,这样我们可以帮助你。你开始,我们帮助。我们不是为你写的。向我们展示您尝试过的实际代码,然后描述发生了什么和什么不正确,然后我们可以从那里帮助您。如果你先亲自尝试,很可能你会非常接近答案。我有点困惑——第一个数组中的三个散列都是不同的。为什么第二个数组中只有两个哈希?