in reply to When DOESN'T "Use of uninitialized value" show up?

I hit upon the right search terms somewhere. The crucial pointer was from ambrus of these precincts, in Re: What is true and false in Perl?. He pointed to the perlsyn man page. The current version says, at http://perldoc.perl.org/perlsyn.html#Declarations,

The only things you need to declare in Perl are report formats and subroutines (and sometimes not even subroutines). A variable holds the undefined value (undef) until it has been assigned a defined value, which is anything other than undef. When used as a number, undef is treated as 0 ; when used as a string, it is treated as the empty string, "" ; and when used as a reference that isn't being assigned to, it is treated as an error. If you enable warnings, you'll be notified of an uninitialized value whenever you treat undef as a string or a number. Well, usually. Boolean contexts, such as:

my $a; if ($a) {}

are exempt from warnings (because they care about truth rather than definedness). Operators such as ++ , -- , += , -= , and .= , that operate on undefined left values such as:

my $a; $a++;

are also always exempt from such warnings.

I believe that "when used as a reference that isn't being assigned to, it is treated as an error" is inaccurate or out of date: autovivification happens and is not an error (unless, I'm told, you use the no autovivification pragma).

Also, I think it's easier to explain boolean as being a scalar context that does not "treat undef as a string or a number", so the fact that it doesn't provoke a warning falls out as a consequence.

Replies are listed 'Best First'.
Re^2: When DOESN'T "Use of uninitialized value" show up?
by ikegami (Patriarch) on Dec 17, 2011 at 05:34 UTC

    I believe that "when used as a reference that isn't being assigned to, it is treated as an error" is inaccurate or out of date

    I don't know if it's inaccurate because I have no idea what "treated as an error" means. It does need a rewording.

    I'll submit a bug report.