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

Re: Re^6: Set Operators

by Notromda (Pilgrim)
on Oct 28, 2002 at 21:18 UTC ( [id://208610]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Set Operators
in thread Set Operators

This doesn't mean grep is the be-all end-all solution: if you need to check many values against the same set, then constructing the hash will quickly pay off as all subsequent lookups run in nearly constant time. Esp when the set is large and even more so when the values are typically absent more often than not, the overhead of building the hash will pay off rapidly.

Indeed, this was the case I had in mind. I guess it comes down to which is more readable,

 my %items = map {$_ => 1} qw (one two three);

or:

my %hash; @hash{qw(one two three)} = ();

I'm still not clear on why that last one works...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-26 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found