Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Accessing main::Constant

by BrowserUk (Pope)
on Dec 16, 2009 at 06:07 UTC ( #812980=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Accessing main::Constant
in thread Accessing main::Constant

Firstly, the syntax would be $main::VAR

Secondly, the value of variables in main are not set until after the uses at the top of the code, so you would get undef. You could address that by setting the $VAR in a BEGIN block:

... BEGIN{ our $VAR = 'fred'; } use pg; ...

But the question is why would you want to do that?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^3: Accessing main::Constant
Select or Download Code
Re^4: Accessing main::Constant
by Anonymous Monk on Dec 17, 2009 at 08:01 UTC
    I've a similar scenario to be addressed,

    I've a hash in the pl file, which I need access it from a module. when Instead of using like $main::VAR->{a}->{b} everytime, Instead I wanted to make it($main:VAR) as a constant and When I need to do that operation, I will be calling it like CONSTANT->{a}->{b}.

    Am I doing it right?!
      What is the benefit in declaring a constant that contains a reference to a data structure? It doesn't make the child elements readonly...

      Also, I avoid use constant wherever possible and use Readonly instead. In my opinion its far more flexible...
        Also, I avoid use constant wherever possible and use Readonly instead.

        Then you are a victim of marketing and hyperbole.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-10-23 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (122 votes), past polls