Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by Trimbach (Curate)
on Jan 01, 2003 at 18: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?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2021-10-25 05:33 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (89 votes). Check out past polls.