Just use use constant
as a baseline and actually examine the source: constant.pm
.
That's essentially what it does as well:
my $pkg = caller;
# ...
{
no strict 'refs';
my $full_name = "${pkg}::$name";
# ...
my @list = @_;
*$full_name = sub () { @list };
}
Also, note that the constant
module has this feature: constant #Defining multiple constants at once
use strict;
use warnings;
use constant {
one_constant => 1,
other_constant => 2,
};
print one_constant, ' - ', other_constant, "\n";
Outputs:
1 - 2