Re: fun with hashes!

[email protected] (Uri Guttman) Fri, 23 Nov 2007 17:40:13 -0500
Newsgroups perl.fwp
Message-ID <[email protected]>
>>>>> "SW" == Scott Wiersdorf <[email protected]> writes:

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

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

very old and i covered it in my hash slice tutorial:

	http://sysarch.com/Perl/hash_slice.txt

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

even faster is

	@is_a_foo{@foos} = () ;

and then use exists() to test instead of truth.

uri

-- 
Uri Guttman  ------  [email protected]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org