Skip Menu |

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

Report information
The Basics
Id: 63211
Status: resolved
Priority: 0/
Queue: Scalar-List-Utils

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

Bug Information
Severity: Normal
Broken in: 1.23_03
Fixed in: 1.41



Subject: aliases inside reduce give strange results usder utf8
test.txt: __BE bb bbbbbbbbbbbbbbb aaaaaa program: #!/usr/bin/env perl use 5.010; use warnings; #use open ':encoding(UTF-8)'; use List::Util qw(reduce); use Encode; my( @list, $longest, $len ); open my $fh, '<:utf8', 'test.txt' or die $!; while( my $line = readline( $fh ) ) { chomp $line; push @list, split( /\s+/, $line ); } close $fh; $longest = reduce{ my $c=length($a) > length($b) ? $a : $b;say "'$a' l=".length($a).' - '."'$b' l=".length($b)." => '$c'";$c } @list; foreach $el (@list) { say "$el - ".length($el); } $len = length $longest; say $longest; # aaaaaa say $len; # 6 Result from inside reduce are very strange. Use of uninitialized value $a in concatenation (.) or string at a.pl line 16. Use of uninitialized value $a in length at a.pl line 16. '' l=0 - 'bb' l=2 => '__BE' '__BE' l=4 - 'bbbbbbbbbbbbbbb' l=15 => 'bbbbbbbbbbbbbbb' 'bbbbbbbbbbbbbbb' l=4 - 'aaaaaa' l=6 => 'aaaaaa' __BE - 4 bb - 2 bbbbbbbbbbbbbbb - 15 aaaaaa - 6 aaaaaa 6 With ":utf8" removed from open (operator not pragma), results are better, but first line still prints $a as empty. perl 5.10.1 and 5.12.1 , List::Util 1.23_03 -- Alexandr Ciornii, http://chorny.net
Subject: Re: [rt.cpan.org #63211] aliases inside reduce give strange results usder utf8
Date: Mon, 22 Nov 2010 08:36:12 -0600
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
I think this is more likely a bug in the perl core. If you change the statement my $c=length($a) > length($b) ? $a : $b; to be my $c=length($a) > length($b) ? $a . "" : $b; then the warning goes away. Also adding some debug shows that $a holds the correct value before that statement, but is undefined after. Graham.
On Mon Nov 22 09:36:27 2010, gbarr@pobox.com wrote: Show quoted text
> I think this is more likely a bug in the perl core. If you change the > statement > > my $c=length($a) > length($b) ? $a : $b; > > to be > > my $c=length($a) > length($b) ? $a . "" : $b; > > then the warning goes away. Also adding some debug shows that $a holds > the correct value before that statement, but is undefined after.
This has also been reported against perl as: https://rt.perl.org/Ticket/Display.html?id=121992 and appears to be a bug in List::Util::reduce() as described in that ticket. Tony
On Mon Jun 16 21:41:10 2014, TONYC wrote: Show quoted text
> On Mon Nov 22 09:36:27 2010, gbarr@pobox.com wrote:
> > I think this is more likely a bug in the perl core. If you change the > > statement > > > > my $c=length($a) > length($b) ? $a : $b; > > > > to be > > > > my $c=length($a) > length($b) ? $a . "" : $b; > > > > then the warning goes away. Also adding some debug shows that $a holds > > the correct value before that statement, but is undefined after.
> > This has also been reported against perl as: > > https://rt.perl.org/Ticket/Display.html?id=121992 > > and appears to be a bug in List::Util::reduce() as described in that ticket.
Thanks for the analysis and fix by TonyC and davem. pull request with testcase at https://github.com/Scalar-List-Utils/Scalar-List-Utils/pull/16 -- Reini Urban
Merged; will be in 1.41 -- Paul Evans
Released -- Paul Evans