Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: question on constants

by wog (Curate)
on Jan 01, 2002 at 09:16 UTC ( #135491=note: print w/ replies, xml ) Need Help??


in reply to question on constants

My guess is that you were probably doing something like:

use module_that_tries_to_use_the_constant; use constant CFGDIR=>'/config/';

The problem with that is that perl tries to compile your module first, but doesn't know what main::CFGDIR is at the time since the use constant hasn't happened yet. You can probably get around this by putting the use constant before the other use or doing main::CFGDIR() in the module (this lets perl know that you're trying to call the function by that name; constants are really functions with a specific prototype).

(I'm guessing here. Next time -- give an error message.)

I would note that this is bad coding practice -- a module should be independent of the "main" program. You probably should be passing a configuration directory to the module, instead. (If you really need the speed boost constants give, then you can still get it this way by having this information be passed on the use line, and defining a constant within the module at compile-time based on that...)


Comment on Re: question on constants
Select or Download Code
Re: Re: question on constants
by smackdab (Pilgrim) on Jan 01, 2002 at 09:41 UTC
    Thanks, I did find that putting a '&' infront of the constant, got it to work...I'll also move my config stuff into a module, so that I am not grabbing stuff from the main program...but I am a little lazy ;-) (at time, more than a little!)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://135491]
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: (14)
As of 2014-07-31 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (252 votes), past polls