in reply to How to import constants from another perl script

We'd really need to see the code in order to explain what is or isn't happening.

Having said that, it would be better to put them in a separate module file (e.g. MyConstants.pm) then use MyConstants;. This allows you to use your constants in whatever scripts you want without polluting your namespace with whatever else is in globals.pl.

You can then make a decision whether you want to export the constants automatically (not generally recommended), export them on request (a much better alternative) or you can access them by name (e.g. MyConstants::ERROR).

Here's some doco that may help: constant, Const::Fast, Readonly and Exporter.

-- Ken

Replies are listed 'Best First'.
Re^2: How to import constants from another perl script
by stevenswj (Initiate) on Nov 01, 2010 at 06:22 UTC
    Alright the first reply appears to be correct, it seems my problem was not appending () to the end of the constant in order to print the value. Why is this necessary in script where it was not defined but not in the one it was defined?
      because if you don't have a BEGIN { } block around the require, the constants will be loaded at runtime. In other words, they aren't yet known at compile time of the script. Adding parens in this case is a hint to the compiler that the constants are subroutines (which they internally are), not barewords.

        and that's the reason I prefer Readonly instead. The constants end up being perl variables that you can't change. I find $SomeConstant more obvious than SomeConstant().

        ... but maybe that's just me.