in reply to Re: Should "use strict" complain if I use a variable that is not declared?
in thread Should "use strict" complain if I use a variable that is not declared?

I understand that it does squelch the stricture complaint, but must it? I would suggest that it could, as an alternative, assume that under some conditions the variable might not be declared, and complain. It is supposed to be strict, after all.

  • Comment on Re^2: Should "use strict" complain if I use a variable that is not declared?

Replies are listed 'Best First'.
Re^3: Should "use strict" complain if I use a variable that is not declared?
by Corion (Patriarch) on Jun 28, 2010 at 11:23 UTC

    The variable is declared. It might just not be initialized. The two are distinct, and strict is only about declaration.

Re^3: Should "use strict" complain if I use a variable that is not declared?
by ikegami (Patriarch) on Jun 28, 2010 at 19:40 UTC
    Corion explained that it's proper for strict not to give an error, but Perl could certainly emit a warning or throw an error.

    The only complication would be backwards compatibility. People rely on the behaviour of a conditionally executed my even though the docs have long warned against it.

    sub foo { my $x if 0; print ++$x, "\n"; } foo() for 1..3;
    1 2 3

    Note that using the hardcoded zero there warns Deprecated use of my() in false conditional.