Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Using constants. What am I doing wrong?

by dws (Chancellor)
on Feb 22, 2005 at 04:05 UTC ( #433243=note: print w/replies, xml ) Need Help??


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

Why doesn't the code below print "mybase"?

In Perl, execution of a script doesn't necessarily happen top-to-bottom. Certain constructs, notably

BEGIN { }
blocks, are executed as they are encountered. The use keyword is also processed when encountered, so that definitions it pulls in are available as the rest of the script is compiling. In your script, this means that
use constant BASE => $Base;
is being executed before $Base has been assigned a value. Since the purpose of the constant module is to establish constants, simply rewriting that line to
use constant BASE => 'mybase';
is sufficient.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2020-10-22 00:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (225 votes). Check out past polls.

    Notices?