Skip Menu |
 

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 49366
Status: rejected
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: frequency [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: reduce/pairwise combo doesn't work
Download (untitled) / with headers
text/plain 898b
Hi there: I'm forwarding this bug on behalf of a Debian user. It was originally filed as: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=487262 The following is from the original bug report: Package: liblist-moreutils-perl Version: 0.21-1 Severity: normal File: /usr/lib/perl5/List/MoreUtils.pm It'd be nice if this worked: use List::Util qw/reduce/; use List::MoreUtils qw/pairwise/; use strict; my $data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; my $total = reduce { [ pairwise { $a + $b } @$a, @$b ] } @$data; print join(", ", @$total), "\n"; expected: 12, 15, 18 got: Can't use string ("3") as an ARRAY ref while "strict refs" in use at /tmp/foo.pl line 5. It looks like the localization of $a and $b isn't working correctly, and reduce's $a and $b are being messed up. I tried RTFS, but I don't understand why it's happening. I tried with perl 5.10.0-10 (debian testing), and same error.
Download (untitled) / with headers
text/plain 1.3k
On Wed Sep 02 09:47:15 2009, FREQUENCY wrote: Show quoted text
> Hi there: > > I'm forwarding this bug on behalf of a Debian user. It was originally > filed as: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=487262 > > The following is from the original bug report: > > Package: liblist-moreutils-perl > Version: 0.21-1 > Severity: normal > File: /usr/lib/perl5/List/MoreUtils.pm > > It'd be nice if this worked: > > use List::Util qw/reduce/; > use List::MoreUtils qw/pairwise/; > use strict; > my $data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; > my $total = reduce { [ pairwise { $a + $b } @$a, @$b ] } @$data; > print join(", ", @$total), "\n"; > > expected: > 12, 15, 18 > > got: > Can't use string ("3") as an ARRAY ref while "strict refs" in use at > /tmp/foo.pl line 5. > > It looks like the localization of $a and $b isn't working correctly, and > reduce's $a and $b are being messed up. I tried RTFS, but I don't > understand why it's happening. > > I tried with perl 5.10.0-10 (debian testing), and same error.
The problem there is that pairwise modifies $a and $b, and what is much more important - the return value of the BLOCK passed to reduce is put in next invocations $a. Concluding - out of the box for this algorithm, it will not work. I suggest some tuple_wise loop, arrayify - or similar. Unfortunately - this concrete wish is impossible to be solved.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.