Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: question on constants

by wog (Curate)
on Jan 01, 2002 at 09:16 UTC ( [id://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...)

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://135491]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-23 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found