http://qs1969.pair.com?node_id=1145594

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!