Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by Trimbach (Curate)
on Jan 01, 2003 at 23:53 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others studying the Monastery: (9)
As of 2024-03-28 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found