Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Creating lists using a hash with the same key/values

by Trimbach (Curate)
on Jan 01, 2003 at 23:53 UTC ( #223645=note: print w/replies, xml ) Need Help??


in reply to Creating lists using a hash with the same key/values

The idiom of using hashes as a fast and easy lookup table is a common one in Perl. Hashes are quick, easy to setup and lend themselves well to a boolean-type comparisons like what you're talking about.

The only thing is your example of

%SampleHash ( 'whatever' => 'whatever', 'whoever' => 'whoever', )
is more commonly coded as
%SampleHash ( 'whatever' => 1, 'whoever' => 1, )
...simply because if you ain't gonna be using the values of the hash, there's no reason to make the value any longer than absolutely necessary. Making the value a "1" does the trick, and it doesn't waste memory. Of course, you're probably not likely to have a hash of values that's so big for the memory cost to matter much, but hey, waste not want not. :-)

Gary Blackburn
Trained Killer

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2023-06-10 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (36 votes). Check out past polls.

    Notices?