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 |