Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: OUR declaration

by ikegami (Patriarch)
on Sep 23, 2006 at 03:35 UTC ( [id://574483]=note: print w/replies, xml ) Need Help??


in reply to OUR declaration

what does it mean that it does not CREATE a local variable?

That's mostly true. Consider these three programs:

$var = "value"; print($main::var eq "value" ? "true" : "false", "\n"); # true
our $var = "value"; print($main::var eq "value" ? "true" : "false", "\n"); # true

As you can see, with or without our, $var refers to $main::greet. No variable is created. The purpose of our is to do no strict 'vars'; on a per-variable basis. Like no strict 'vars';, the our directive is lexically scoped (although the variable isn't).

Remember that I said "mostly true". The exception is when the scope of the our spans packages.

package Test; $var = "value"; print($Test::var eq "value" ? "true" : "false", "\n"); # true
our $var; package Test; $var = "value"; print($Test::var eq "value" ? "true" : "false", "\n"); # false

Log In?
Username:
Password:

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

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

    No recent polls found