Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Using constants. What am I doing wrong?

by dws (Chancellor)
on Feb 22, 2005 at 04:05 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://433243]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-18 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found