You wrote:BEGIN {
my $constants = (
FOO => 'foo',
BAR => 'bar',
BAZ => 'baz',
);
foreach my $name ( keys %constants ) {
no strict 'refs';
*{$name} = sub () { $constants{$name} };
}
...
}</blockquote>
If you're going to make constants, do them the proper way with the constant pragma. What you wrote is roughly how constant.pm works in versions prior to 5.9 but the next versions of perl have a different implementation for constant and you'll want your code to do the right thing regardless.BEGIN {
require constant;
my %constants = (
FOO => 'foo',
BAR => 'bar',
BAZ => 'baz',
);
foreach my $name ( keys %constants ) {
constant->import( $name => $constants{$name} );
}
}
You also goofed and made a variable $constants instead of %constants.