Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Unique key/value pair in Multiple key values pair in Hash

by choroba (Canon)
on Feb 18, 2013 at 10:24 UTC ( #1019317=note: print w/ replies, xml ) Need Help??


in reply to Unique key/value pair in Multiple key values pair in Hash

When you need something unique, think a hash:

#!/usr/bin/perl use warnings; use strict; use feature qw(say); my %hash; push(@{$hash{Lemon}}, 'Juice'); push(@{$hash{Lemon}}, 'Cake'); push(@{$hash{Lemon}}, 'Juice'); push(@{$hash{Lemon}}, 'Cake'); my %uniq; undef @uniq{@{$hash{Lemon}}}; say for keys %uniq;

Do you really need the array? If not, you can use HoH instead of HoA:

undef $hash{Orange}{Cake}; undef $hash{Orange}{Juice}; undef $hash{Orange}{Cake}; undef $hash{Orange}{Juice}; say for keys %{ $hash{Orange} };
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Unique key/value pair in Multiple key values pair in Hash
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (16)
As of 2015-07-29 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls