Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by choroba (Abbot)
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 rifling through the Monastery: (8)
As of 2014-12-20 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls