Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: "uninitialized value in subroutine exit" warning from CGI.pm

by dave_the_m (Monsignor)
on Nov 10, 2017 at 15:26 UTC ( #1203124=note: print w/replies, xml ) Need Help??


in reply to Re: "uninitialized value in subroutine exit" warning from CGI.pm
in thread "uninitialized value in subroutine exit" warning from CGI.pm

I don't know what's going on at subroutine exit that would trigger the warning
On subroutine return, any return values are copied. If you return a substr lvalue, this will trigger the uninit warning at this point. For example this warns:
sub f { $_[0] } $a = f(substr(undef,0,1));
This is behaviour I would expect, and I'm not seeing a bug.

Dave.

  • Comment on Re^2: "uninitialized value in subroutine exit" warning from CGI.pm
  • Download Code

Replies are listed 'Best First'.
Re^3: "uninitialized value in subroutine exit" warning from CGI.pm (updated)
by haukex (Chancellor) on Nov 10, 2017 at 15:45 UTC
    On subroutine return, any return values are copied. [emphasis mine]

    D'oh! Thank you for the enlightenment on a Friday afternoon ;-)

    Update: Yep:

    $ perl -wMstrict *a = \substr(undef,0); # alias via glob $b = $a; # copy $a = 'x'; # assignment __END__ Use of uninitialized value in scalar assignment at - line 2. Modification of a read-only value attempted at - line 3.

    And just like above, on Perls <5.16 that dies with "Modification of a read-only value attempted at - line 1." (instead of line 3). So I should probably call the commit I referenced a bugfix! :-)

    Additional updates: Expanded the code example from the original version and added (and edited) the last paragraph.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1203124]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2019-07-20 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (5 votes). Check out past polls.

    Notices?