Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 41926
Status: resolved
Priority: 0/
Queue: Perl-Critic

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

Bug Information
Severity: Unimportant
Broken in: 1.092
Fixed in: (no value)



Subject: Uninitialized value warning on zero-arg select.
Running Perl::Critic against a file that uses the zero-argument select() gets you the message 'Use of uninitialized value in numeric eq (==) at /usr/local/lib/perl5/site_perl/5.10.0/Perl/Critic/Policy/InputOutput/ProhibitOneArgSelect.pm line 40.' The attached 'select' script demonstrates the problem when run with severity --stern (or anything more severe). The problem appears to be that ProhibitOneArgSelect.pm determines the number of arguments to the select by using 'scalar parse_arg_list($elem)', but a couple paths through parse_arg_list do a zero-argument return. I have not traced the flow through this subroutine to determine what path is actually taken, but I note that the zero-argument return returns undef in scalar context. The attached universal diff against version 1.092 of this module appears to fix the problem by the rather brute-force method of assigning the output of parse_arg_list to array @args, then using 'scalar @args' to determine the number of arguments. Other solutions are certainly possible. I have not downloaded 1.093_03, but a look at the code seems to say that its behavior would be the same. In theory, ProhibitOneArgBless.pm has the same problem, but since there is no zero-argument bless, the behavior is not likely to be observed in the wild. $ perl -v This is perl, v5.10.0 built for darwin-2level $ uname -a Darwin white2 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386 Thank you for your time and attention. Tom Wyant
Subject: ProhibitOneArgSelect.patch
--- ProhibitOneArgSelect.old 2008-09-02 14:40:01.000000000 -0400 +++ ProhibitOneArgSelect.pm 2008-12-24 09:07:13.000000000 -0500 @@ -37,7 +37,8 @@ return if $elem ne 'select'; return if ! is_function_call($elem); - if( scalar parse_arg_list($elem) == 1 ) { + my @args = parse_arg_list($elem); + if( scalar @args == 1 ) { return $self->violation( $DESC, $EXPL, $elem ); } return; #ok!
Subject: select
Download select
application/octet-stream 74b

Message body not shown because it is not plain text.

CC:
Subject: Re: [rt.cpan.org #41926] Uninitialized value warning on zero-arg select.
Date: Wed, 24 Dec 2008 17:28:03 +0000 (GMT)
To: bug-Perl-Critic [...] rt.cpan.org
From: perl [...] galumph.com
Thanks for finding this! It's interesting that I can't seem to find a simple way to get around this without the temporary variable.
This is something I have never really known either. After much struggle, I finally read the manual. perldoc -f scalar says, and I quote: "There is no equivalent operator to force an expression to be interpolated in list context because in practice, this is never needed. If you really wanted to do so, however, you could use the construction '@{[ (some expression) ]}', but usually a simple '(some expression)' suffices." Well, you live and learn. I've interpolated expressions with @{[ ]}, but never thought about it beyond that. At any rate, I certify that $ perl -E 'sub foo{return} $n = @{[foo]}; say $n' prints '0'.
Subject: Re: [rt.cpan.org #41926] Uninitialized value warning on zero-arg select.
Date: Thu, 25 Dec 2008 18:43:50 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Chris Dolan <chris [...] chrisdolan.net>
On Dec 25, 2008, at 6:37 PM, Tom Wyant via RT wrote: Show quoted text
> Queue: Perl-Critic > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=41926 > > > This is something I have never really known either. After much > struggle, > I finally read the manual. perldoc -f scalar says, and I quote: > > "There is no equivalent operator to force an expression to be > interpolated in list context because in practice, this is never > needed. > If you really wanted to do so, however, you could use the > construction > '@{[ (some expression) ]}', but usually a simple '(some expression)' > suffices." > > Well, you live and learn. I've interpolated expressions with @ > {[ ]}, but > never thought about it beyond that. At any rate, I certify that > > $ perl -E 'sub foo{return} $n = @{[foo]}; say $n' > > prints '0'.
If your goal is just to force list context, then the goatse operator is more performant, as it skips creation of the arrayref: perl -E 'sub foo{return} $n =()= foo; say $n' 0 Chris
This has been released as http://search.cpan.org/~elliotjs/Perl-Critic-1.094001/ Thanks. -Jeff