in reply to Re: How to import constants from another perl script
in thread How to import constants from another perl script

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?
  • Comment on Re^2: How to import constants from another perl script

Replies are listed 'Best First'.
Re^3: How to import constants from another perl script
by Anonymous Monk on Nov 01, 2010 at 08:54 UTC
    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.

        Well, if you do it properly (i.e. use BEGIN {} in this case), you don't need the parens (except in some rare cases where disambiguation is needed), and you have the added performance benefit of the subroutines being optimized away.

        Of course you can't interpolate subroutine calls in double quoted strings... which is a clear disadvantage if constant. But Readonly, OTH, is slow (because it relies on tied magic), and may occasionally cause other strangeness (for an example, see runtime problem; elusive error).