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

Re: Accessing Constant Hashes

by perrin (Chancellor)
on Jan 16, 2002 at 02:36 UTC ( [id://139066]=note: print w/replies, xml ) Need Help??


in reply to Accessing Constant Hashes

ar0n gave the right answer, but I just want to take a moment to say that constant in the current implementation is totally lame for exactly this reason, and I think you should avoid it completely. It doesn't work in quoted strings or HERE docs either without similar tricks. Just use globals or lexicals at the top of the file for your constants.

Replies are listed 'Best First'.
(lestrrat) Re(2): Accessing Constant Hashes
by lestrrat (Deacon) on Jan 16, 2002 at 02:46 UTC

    I personally would recommend using a constant if there's a possibility of constant folding:

    #!/usr/local/bin/perl use O qw/ Deparse /; use constant CONDITION => 0; if( CONDITION ) { print "condition true\n"; } else { print "condition false\n"; } __END__ ## and here's the output. notice that there are ## no if's me@myhost> ./test.pl ./test.pl syntax OK sub CONDITION () { package constant; $scalar; } print "condition false\n";;

    Otherwise I guess I could care less, but I use it more for a mental note than anything else -- it makes me aware that this value should be a constant

Log In?
Username:
Password:

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

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

    No recent polls found