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

Re: Using constants. What am I doing wrong?

by rlb3 (Deacon)
on Feb 21, 2005 at 23:02 UTC ( [id://433241]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Using constants. What am I doing wrong?

Hello,
A "use" statment is called at compile time, before any other code is evaluated. So when your constant is looking for $Base and it is not yet initialized. It might work if you put the $Base in a BEGIN block before the "use".

rlb3
  • Comment on Re: Using constants. What am I doing wrong?

Replies are listed 'Best First'.
Re^2: Using constants. What am I doing wrong?
by Random_Walk (Prior) on Feb 22, 2005 at 06:20 UTC

    update

    I am dumb, the one below does not work 'cos I put a my in the BEGIN block, when good habits turn bad! Without the my it works a charm

    >perl -le'BEGIN{$BASE="are belong to us"} use constant BASE => $BASE; print "all your base ", BASE' all your base are belong to us >

    original message

    I though that would work too but it does not for me

    > perl -le'BEGIN{$BASE="are belong to us"} use constant BASE => $BASE; print "all your base ", BASE' all your base > # but this does >perl -le'use constant BASE=>"are belong to us"; print "all your base ", BASE' all your base are belong to us >
    But I guess the OP was after something more flexible

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://433241]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.