in reply to "if" in a my declaration statement causes problem

Combining "my" and "if" should issue a warning from the compiler. It's a gotcha, it's not intuitive behavior, and -- judging by how often it comes up on Perlmonks -- catches many otherwise able coders unawares.
  • Comment on Re: "if" in a my declaration statement causes problem

Replies are listed 'Best First'.
Re^2: "if" in a my declaration statement causes problem
by ysth (Canon) on Feb 22, 2006 at 19:21 UTC
    It should, yes. But don't expect it to in any 5.8.x release. The maint pumpking is very cautious about adding new warnings, and for a while there were a number of people advocating
    sub foo { my $x if 0; ... }
    to create a "static" variable, rather than using a closure
    { my $x; sub foo { ... } }