[sf-perl] reduce-like function in Perl?

Chris Palmer chris at noncombatant.org
Tue Apr 26 16:15:36 PDT 2005


Sorry to bug you all. I found a fun thread on perlmonks.org that answers 
my question:

http://perlmonks.org/index.pl?node_id=20447

If you can live with the limitations of a signed ling, the somewhat
freaky last method given beats the mdillon method soundly:

    use Benchmark;
    sub a1 { my $sum; $sum += $_ for @_; $sum }
    sub a2 { unpack"l",pack"l",unpack"%32d*",pack"d*", at _ }
    timethese(1000000, {
                       'mdillon' => sub { a1(1,2,3,4,5,6,7,8,9,10); }
                       'pack' => sub { a2(1,2,3,4,5,6,7,8,9,10); },
                      }
              );


More information about the SanFrancisco-pm mailing list