develooper Front page | perl.perl5.porters | Postings from September 2003

List::Util reduce strangeness

Thread Next
From:
Tony Bowden
Date:
September 26, 2003 07:49
Subject:
List::Util reduce strangeness
Message ID:
20030926144836.GA16971@soto.kasei.com

This works as expected:

my $reduce = reduce { $a + $b } map $_, (1 ..  10);

This doesn't:

my $reduce = reduce { [@$a + @$b] } map [$_], (1 ..  10);

Adding some debugging prints:

my $reduce = reduce { warn "$a -> $b\n"; [@$a + @$b] } map [$_], (1..10);

This shows that $a isn't being passed through.

It seems that reduce doesn't like the result of the expression being a
listref ...

Using the perl version (rather than XS) from the module works fine for
all versions, btw...

Tony


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About