Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Help! My variables are jumping off a cliff!

by Jenda (Abbot)
on Feb 26, 2012 at 14:26 UTC ( [id://956269]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Help! My variables are jumping off a cliff!
in thread Help! My variables are jumping off a cliff!

If your variables have several hundred lines wide scopes, you've got a problem. Such a variable is just very very very slightly better than an outright global.

Keep in mind that Perl has BLOCK scoping, not subroutine scoping. So a variable declared within a block (whether it's a block that belongs to a loop, an if() or just a bare block) only "exists" within that block, not in the whole subroutine. So do declare your variables in the smallest possible block and you will not have to worry about accidentally "destroying" a variable. You can (and at times should) even create blocks just to restrict the scope of a variable!

Jenda
Enoch was right!
Enjoy the last years of Rome.

  • Comment on Re^3: Help! My variables are jumping off a cliff!

Replies are listed 'Best First'.
Re^4: Help! My variables are jumping off a cliff!
by oko1 (Deacon) on Feb 26, 2012 at 15:36 UTC

    If your variables have several hundred lines wide scopes, you've got a problem. Such a variable is just very very very slightly better than an outright global.

    Agreed, totally - and it's not an error that an experienced programmer is going to commit. But that can be said of many, if not most, errors that "warnings" catches - and we typically tell people to "always - yes, ALWAYS - enable warnings." I'm saying that this is a dangerous error, and one that should be noted and treated as such rather than some minor, optional after-thought.

    -- 
    I hate storms, but calms undermine my spirits.
     -- Bernard Moitessier, "The Long Way"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-25 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found