Re: fun with hashes!

Scott Wiersdorf <[email protected]> Fri, 23 Nov 2007 11:23:37 -0700
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
On Fri, Nov 23, 2007 at 01:12:37PM -0500, Uri Guttman wrote:
> 	isa
> 		is a key valid? (not same as in a set). isa usually works on
> 		fixed sets of keys
> 
> 		my @foos = qw( axxj djdj whwh ) ;
> 		my %is_a_foo = map { $_ => 1 } @foos

I don't have any additional uses for hashes to add, but I do have a
great hash initializer I picked up from Damian when he was in town a
few years ago (borrowing from your example):

  my @foos = qw( axxj djdj whwh ) ;
  my %is_a_foo;
  @is_a_foo{@foos} = (1) x @foos;

It runs *way* faster than the $_ aliasing does in the map (at least by
my benches). I thought that was fun when I saw it.

Scott
-- 
Scott Wiersdorf
[email protected]