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...