Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: removing duplicates from an array of hashes

by vinoth.ree (Monsignor)
on Apr 17, 2014 at 07:26 UTC ( [id://1082604]=note: print w/replies, xml ) Need Help??


in reply to removing duplicates from an array of hashes

Hi,

Here is another way of removing duplicate elements from array of hash.

use strict; use warnings; use Data::Dumper; my $ref = []; $ref->[0] = { id => 'a' }; $ref->[1] = { id => 'b' }; $ref->[2] = { id => 'c' }; $ref->[3] = { id => 'b' }; #But using temp hash my $temp_hash={}; my @Uniqe_Array_Of_Hash = grep { $_ && ++$temp_hash->{$_->{id}}< 2 } + @$ref; print Dumper \@Uniqe_Array_Of_Hash;

All is well

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1082604]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-20 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found