>>>>> "J" == Juerd  <[EMAIL PROTECTED]> writes:

  J> John Williams skribis 2004-05-18 16:07 (-0600):
  >> >    $a{$_}++ for @a;
  >> [EMAIL PROTECTED];

  J> That's not a bad idea, even in Perl 5:

  J>     1;0 [EMAIL PROTECTED]:~$ perl -MBenchmark=cmpthese -e'my @foo = (1..16,
  J>     1..10); cmpthese -1, { a => sub { my %foo; $foo{$_}++ for @foo; }, i
  J>     b => sub { my %foo; $_++ for @[EMAIL PROTECTED]; } }'
  J>          Rate   a   b
  J>     a 51121/s  -- -9%
  J>     b 56220/s 10%  --

but those are setting the empty hash to values of 1's. you can do that
with a slice or map:

        @[EMAIL PROTECTED] = (1) x @foo ;
        my %foo = map { $_ => 1 } @foo ;

add those to the benchmark.

now if you wanted to increment the values of a hash already stuffed,
then values is cool:

        $_++ for values %foo ;

but i do like the hyper version in p6.

i assume that this is ok since >> is not a logical shift anymore.

        [EMAIL PROTECTED]>>++;

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

Reply via email to