I am trying to simplify the implementation of some Perl Best Practices by creating a module Constantsthat exports several scalars used throughout the book. In particular, $EMPTY_STRINGI can use almost every Perl script that I write. I would like to automatically export these scalars so that I can use them without defining them explicitly in each script.
package Example::Constants;
use Exporter qw( import );
use Readonly;
Readonly my $EMPTY_STRING => q{};
our @EXPORT = qw( $EMPTY_STRING );
Usage example:
use Example::Constants;
print $EMPTY_STRING . 'foo' . $EMPTY_STRING;
Using the above code results in an error:
Global symbol "$EMPTY_STRING" requires explicit package name
If I changed the declaration Readonlyto:
Readonly our $EMPTY_STRING => q{};
The error will be:
Attempt to reassign a readonly scalar
Is this not possible with mod_perl?
source
share