Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

BUG in warnings uninitialized for derefed hashes?

by LanX (Sage)
on Oct 21, 2015 at 21:30 UTC ( #1145594=perlquestion: print w/replies, xml ) Need Help??

LanX has asked for the wisdom of the Perl Monks concerning the following question:

Today I head to localize an "uninitialized value" warning in a fairly big here doc with many interpolated variables.

Surprisingly Perl didn't tell me which variable was causing the trouble.

A closer investigation revealed that accessing hash entries via a dereference omitted the details.

Here a test in 5.22

$ perl -wE 'my $x={};my %h; say "plain $h{new} deref $x->{new}"' Use of uninitialized value $h{"new"} in concatenation (.) or string at + -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1 +. plain deref

is it a bug or is there a reason why Perl can't localize $x?

FWIW I tested 5.8.9 and back then no hints at all where given:

$ perlbrew use perl-5.8.9 $ perl -we 'my $x={};my %h; print "plain $h{new} deref $x->{new}"' Use of uninitialized value in concatenation (.) or string at -e line 1 +. Use of uninitialized value in concatenation (.) or string at -e line 1 +.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re: BUG in warnings uninitialized for derefed hashes?
by dave_the_m (Monsignor) on Oct 21, 2015 at 21:46 UTC
    It's a limitation rather than a bug. By the time perl discovers that it has an uninitialised value, it has already executed a whole series of ops (pad variable load, deref, hash lookup, concat) that lead up to that point. I added the facility in 5.10.0 where at that point it backs up, searches back through the optree, and tries to figure out what was executed and what triggered loading the uninit value. This is based on a "reasonable effort", and is by no means comprehensive, as that would involve huge complexity.

    Dave.

      > It's a limitation rather than a bug.

      I agree, but I needed to report it to rule out that a case was forgotten.

      Additionally others might stumble again over this, and now it's searchable.

      > I added the facility in 5.10.0

      Thanks a lot, it's a very useful feature :)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1145594]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2022-05-26 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?