Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Need help with removing duplicate hash keys from array of hashes

by jbrugger (Parson)
on Sep 25, 2006 at 05:20 UTC ( #574672=note: print w/replies, xml ) Need Help??


in reply to Re^2: Need help with removing duplicate hash keys from array of hashes
in thread Need help with removing duplicate hash keys from array of hashes

Just to explain what chargrill does here :
# Create a lookuptable to store found items my %hash = (); # Iterate over the data-array (thats what grep does here), and add the + item to newdata, and set the found item in the lookup table. When th +e new item is in the lookup table, don't add it again. my @newdata = grep { ! $hash{ $_->{operation} . $_->{machine} }++ } @$ +data; # more readable than grep (to my opinion,probably not to all others :) + ), but basically the same: my %hash = (); my @newdata; foreach my $item (@{$data}) { if (! $hash{ $item->{operation} . $item->{machine} } ) { $hash{ $item->{operation} . $item->{machine} } = 1 ; push @newdata, $item; } }
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
  • Comment on Re^3: Need help with removing duplicate hash keys from array of hashes
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://574672]
help
Chatterbox?
[holli]: how do you update a different window without javascript?
[holli]: ah, chatterbox right
[marto]: it's a normal HTML form, with some hidden input fields
[holli]: forgot that thing exists for a moment.
LanX welcome to the twilight zone ...
[Eily]: LanX well since the onion is your eye you should see it everywhere
[marto]: sounds eye watering
[LanX]: oh your talking about my pic?
[Eily]: marto #SoSad

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2017-12-14 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (398 votes). Check out past polls.

    Notices?