Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: "if" in a my declaration statement causes problem

by mrpeabody (Friar)
on Feb 21, 2006 at 23:06 UTC ( [id://531829]=note: print w/replies, xml ) Need Help??


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.

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 { ... } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2024-03-28 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found