Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Are global variables "bad"?

by jpearl (Scribe)
on Apr 21, 2009 at 21:47 UTC ( [id://759126]=note: print w/replies, xml ) Need Help??


in reply to Re: Are global variables "bad"?
in thread Are global variables "bad"?

Hmm. Ok, well this brings up another question. I guess I kind of assumed that "our" variables were just another way of declaring variables that could be used throughout the main program. Now that I think of it, I guess that makes no sense. Which, er might mean I'm using that incorrectly.

If you declare a "local" variable with "my" in the main scope, you can still access it in all of the subroutines in the program. So, how is using "our" different than that? Is that similar to declaring something "public" in an object in java? i.e. if I were creating an object everyone could access (change?) an "our" declared variable, while a "my" declared variable ... not accessible? Or not changeable?

Update: ok, little trip to our has revealed that I appear to have been completely wrong, except for the parts I was right about. Something which I'm still not clear about though is the accessibility of "our" vs. "my" declared variables. If one can "access" them does that imply the ability to change them? I'm thinking about this as an "our" variable being able to be accessed by something outside the main scope... is it just visible, or is it mutable? (are "my" declared variables visible outside of the scope they are called in? I'm assuming definitely not mutable).

Replies are listed 'Best First'.
Re^3: Are global variables "bad"?
by Argel (Prior) on Apr 21, 2009 at 22:40 UTC
    I think you might like the my() and our() thread. Lots of good links and discussion.

    Elda Taluta; Sarks Sark; Ark Arks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found