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

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.

Replies are listed 'Best First'.
Re^4: How to import constants from another perl script
by thargas (Deacon) on Nov 01, 2010 at 13:09 UTC

    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).