Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Learning about hashes

by DamianKaelGreen (Acolyte)
on Oct 22, 2009 at 16:58 UTC ( #802771=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Learning about hashes
in thread Learning about hashes

OK, I think I see what you are trying to do, but a hash may not be what you want. A list might be better for your needs. List ex:

use List::MoreUtils qw(any); #instead of using: # "if (grep( m/whatever/, @list)){}" #use: "if (any { m/whatever/} @list){}" #this exits on the first occurrence. if (!any {m/^\Q$record[3]\E$} @esList){ #the \Q\E guarantees that the value held in the $record[3] #is not interpreted as a regular expression push (@esList = $record[3]); } ### @esList is now a unique list of the values you want...
But if you really want to use a hash, this is how you might do it:
my %esList = (); $esList{$record[3]) = 1; ### then to recall all the found records: foreach my $result {sort(keys(%esList))){ print "found record: $result \n"; }
Also, if you're interested, I started a discussion recently about how to best implement multidimensional hashes, they have some unique characterictics that you might not expect when trying to extending principals of a one dimensional hash. But there are some very good references listed there. It can be found at: Best Multidimensional Hash Practices? Good luck...


Comment on Re^3: Learning about hashes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2015-07-04 16:40 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 (60 votes), past polls