Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Most elegant way to dispose of duplicates using map

by Anonymous Monk
on Oct 31, 2006 at 15:58 UTC ( [id://581520]=note: print w/replies, xml ) Need Help??


in reply to Most elegant way to dispose of duplicates using map

Assuming that What I need to do is get rid of the duplicates bassed on "id" means that you should not have two items with the same id, and also assuming that the returned order doesn't matter, I'd use:
sub extractPartTuplesFromURL { my $cgi = shift; my %partTuples; foreach my $tuple ($cgi->param('partID')) { my($id, $version, $classificiation) = split(/,/, $tuple); next if $partTuples{$id}; # Keeps the first entry. Remove it i +f you want to keep the last. $partTuples{$id} = [$version,$classificiation]; } map {{id => $_, version => $partTuples{$id}->[0], classification = +> $partTuples{$id}->[1]}} keys %partTuples; }
Or just return \%partTuples and change the caller.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found