in reply to Import constants as scalar instead of bareword sub
it's much faster in many casesAnd much slower in other cases. Empty prototyped subs which only return a constant and are know at compile time are constant folded at compile time. Unlike variables:
I can live with modules exporting constants as subs, and I can live with modules exporting constants as variables. But I would oppose changing core modules. Errno, Fcntl and Socket export constants as subs. No need for a change.$ perl -MO=Deparse -e 'sub CONST(){1;} my $CONST = 1; print CONST, + $CONST' sub CONST () { 1 } my $CONST = 1; print 1, $CONST; -e syntax OK
|
|---|