|go ahead... be a heretic|
"uninitialized value in subroutine exit" warning from CGI.pmby dwmcewan (Initiate)
|on Nov 10, 2017 at 02:53 UTC||Need Help??|
dwmcewan has asked for the
wisdom of the Perl Monks concerning the following question:
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
I managed to track this down to some calls our code was making that were essentially:
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