Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: my() and our()

by DrWhy (Chaplain)
on Aug 09, 2005 at 22:08 UTC ( [id://482448]=note: print w/replies, xml ) Need Help??


in reply to Re: my() and our()
in thread my() and our()

There are actually uses (well, at least one that I can think of) for our beyond use 'strict' context. I have had occasion to use our at the top of a file that contained multiple packages so that I could have a package global that was accessible without full qualification throughout the file. E.g.:

package X; our $global = 'Xglobal'; ... more stuff here ... package Y; print $global;

When run, this code prints Xglobal even though the reference to $global is in package Y's space and it was defined as being a global in package X. The our makes all unqualified references to the variable be assumed to be in the X package namespace even after you move into a different namespace. The same effect can be obtained with my(), except that then the variables are not accessible to other perl code that uses/requires this code.

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-24 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found