Skip Menu |
 

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

Report information
The Basics
Id: 79949
Status: rejected
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: mcdave [...] stanford.edu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.23
Fixed in: (no value)



Subject: Using "first" within a block for "first" causes a strange return value
Download (untitled) / with headers
text/plain 427b
In the attached test, @l is ( [qw/a b c/], [qw/d e f/] ). The way I read the docs, first BLOCK @l should return either [qw/a b c/], [qw/d e f/], or undef, regardless of what BLOCK is. If I call first BLOCK @l from a list context, I can make it return [undef]. One could call this a bug in the implementation or in the documentation: "don't do that!" is probably a reasonable response to first { first { ... } @$_ } @l ;
Subject: list_first_bug.t
Download list_first_bug.t
text/x-perl 672b
#!/usr/bin/perl use strict ; use warnings ; use Data::Dumper ; use Test::More tests => 7 ; use List::Util ; my @l = ( [qw/a b c/], [qw/d e f/] ) ; my @s = List::Util::first { List::Util::first { $_ eq 'e' } @$_ } @l ; ok( @s, 'e is found' ) ; ok( $s[0], 'e is really found' ) ; is( ref $s[0], 'ARRAY', 'e is in an ARRAYREF' ) ; my @t = List::Util::first { List::Util::first { $_ eq 'z' } @$_ } @l ; ok( ! @t, 'z is not found' ) || warn Dumper( \@t ); ok( ! $t[0], 'z is really not found' ) ; ok( ! ref $t[0], 'z is really, really not found' ) ; my $tSca = List::Util::first { List::Util::first { $_ eq 'z' } @$_ } @l ; ok( ! $tSca, 'z is not found in scalar' ) ;
From: mcdave [...] stanford.edu
Download (untitled) / with headers
text/plain 184b
On Mon Oct 01 17:14:23 2012, mcdave@stanford.edu wrote: Show quoted text
> If I call first BLOCK @l from a list context, I can make it return
[undef]. Of course, that's a typo; it's returning (undef).
Subject: Re: [rt.cpan.org #79949] Using "first" within a block for "first" causes a strange return value
Date: Mon, 1 Oct 2012 19:31:43 -0500
To: "bug-Scalar-List-Utils [...] rt.cpan.org" <bug-Scalar-List-Utils [...] rt.cpan.org>
From: Graham Barr <gbarr [...] pobox.com>
Download (untitled) / with headers
text/plain 513b
On Oct 1, 2012, at 16:15, "David Tindall Mcmath via RT" <bug-Scalar-List-Utils@rt.cpan.org> wrote: Show quoted text
> Queue: Scalar-List-Utils > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79949 > > > On Mon Oct 01 17:14:23 2012, mcdave@stanford.edu wrote:
>> If I call first BLOCK @l from a list context, I can make it return
> [undef]. > > Of course, that's a typo; it's returning (undef).
That's correct, it is supposed to. First returns a single scalar value. So on not finding anything it returns undef
From: mcdave [...] stanford.edu
Download (untitled) / with headers
text/plain 826b
On Mon Oct 01 20:32:31 2012, gbarr@pobox.com wrote: Show quoted text
> > On Oct 1, 2012, at 16:15, "David Tindall Mcmath via RT" <bug-Scalar- > List-Utils@rt.cpan.org> wrote: >
> > Queue: Scalar-List-Utils > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79949 > > > > > On Mon Oct 01 17:14:23 2012, mcdave@stanford.edu wrote:
> >> If I call first BLOCK @l from a list context, I can make it return
> > [undef]. > > > > Of course, that's a typo; it's returning (undef).
> > That's correct, it is supposed to. First returns a single scalar > value. So on not finding anything it returns undef
Duh. Yes. When I assign a scalar to an array, I get the one-element array containing that scalar. Just like it says in perldata. Thanks for the reminder. Nothing to see here... please close this bug so nobody finds it later.


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.