Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: non-global $/

by halley (Prior)
on Jun 22, 2005 at 13:37 UTC ( [id://469007]=note: print w/replies, xml ) Need Help??


in reply to non-global $/

Well, that's exactly what local does. Think of each variable name as referring to a stack of variables instead of just one. The local keyword pushes on a new value for a while, and at the end of its scope, the top value is popped and discarded. Other subroutines which might use that same variable will still see the top value.

All of the built-in "punctuation" variables are globals, not package variables. The exception are the two "default" variables, $_ and @_, which (1) get localized values automatically in many situations, and (2) assume the 'main::' package if not otherwise specified.

To avoid the problem, don't do a local and call subroutines that are outside your control. The need to redefine $/ or other built-in vars should be really confined to one or two low-level statements which use those variables to tune their behavior.

--
[ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found