I would like to suggest OO way.
Package with constants:
package C;
use vars qw( $AUTOLOAD %const_values );
my %const_values = ( CONST_1 => 1,
CONST_2 => 23,
CONST_3 => 'Test',
. . .
);
use overload '``' => sub { return $const_values{shift} } ;
# All constants can be accessed as by using AUTOLOAD
sub AUTOLOAD {
no strict 'refs', 'subs';
if ($AUTOLOAD =~ /.*::([A-Z]\w+)$/) {
my $const_name = $1;
*{$AUTOLOAD} = sub {return $const_values{$const_name}};
return $const_values{$const_name};
}
return undef;
}
1;
Usage in my test.pl:
#!/usr/bin/perl -w
use C;
print "Const 1:".C->CONST_1."\n";
print "Const 2:".C->CONST_2."\n";
print "Const 3:".C->CONST_3."\n";
__DATA__
Const 1: 1
Const 2: 23
Const 3: Test
Hope that it will be usefull for you.
--------------------------------
SV* sv_bless(SV* sv, HV* stash);