dwmcewan has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I noticed some "uninitialized value in subroutine exit at /usr/pkg/lib/perl5/vendor_perl/5.26.0/CGI.pm line 472" warnings in our web server logs.
This was with CGI.pm version 4.36 running on "perl 5, version 26, subversion 0 (v5.26.0) built for x86_64-linux-thread-multi"
This warning was being generated by the following code in CGI.pm
sub self_or_default { return @_ if defined($_[0]) && (!ref($_[0])) &&($_[0] eq 'CGI'); unless (defined($_[0]) && (ref($_[0]) eq 'CGI' || UNIVERSAL::isa($_[0],'CGI')) # sli +ghtly optimized for common case ) { $Q = $CGI::DefaultClass->new unless defined($Q); unshift(@_,$Q); } return wantarray ? @_ : $Q; # <---- Line 472 of CGI.pm v4.36 }
I managed to track this down to some calls our code was making that were essentially:
print $cgi->textfield(-name=>"end_date", -default=>substr($pa->get_end_date(),0,10));
The $pa->get_end_date() call is part of a locally developed system that essentially queries a MySQL database. In the cases where the warning was appearing, the returned date was undefined (it was NULL in the DB)
Now, in retrospect I realise that this code was buggy and it has now been rewritten to handle undef dates. But what I don't understand, and was hoping to have explained here, is why the warning was coming out from somewhere deep within CGI.pm, rather than from the call to substr with an undefined first parameter
If I rewrite the above code to do the substr before the call to $cgi-textfield() (without also protecting it from an undef return value) I get the expected "Use of uninitialized value in substr at ..." warning.
I'd guess that its something to do with the differing contexts in which the substr is evaluated in, but a more definitive explanation would be greatly appreciated
Thanks,
Duncan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "uninitialized value in subroutine exit" warning from CGI.pm
by haukex (Archbishop) on Nov 10, 2017 at 10:30 UTC | |
by dave_the_m (Monsignor) on Nov 10, 2017 at 15:26 UTC | |
by haukex (Archbishop) on Nov 10, 2017 at 15:45 UTC | |
by LanX (Saint) on Nov 10, 2017 at 14:23 UTC | |
|
Re: "uninitialized value in subroutine exit" warning from CGI.pm
by NetWallah (Canon) on Nov 10, 2017 at 03:36 UTC | |
by dave_the_m (Monsignor) on Nov 10, 2017 at 09:44 UTC | |
|
Re: "uninitialized value in subroutine exit" warning from CGI.pm
by LanX (Saint) on Nov 10, 2017 at 03:36 UTC |