What you intended to be constant names are getting parsed as literal strings.
use strict; use warnings; use constant CONST1=>10; use constant CONST2=>12; my %var=( CONST1=>'test1', CONST2=>'test2', ); use Data::Dumper; print Dumper \%var; __END__ $VAR1 = { 'CONST1' => 'test1', 'CONST2' => 'test2' };
Internally, constants are functions. You can force them to be recognized by using function syntax:
my %var=( CONST1()=>'test1', CONST2()=>'test2', ); print $var{CONST1()}."\n"; print $var{10}."\n"; use Data::Dumper; print Dumper \%var; __END__ test1 test1 $VAR1 = { '10' => 'test1', '12' => 'test2' };
Or, as I personally prefer:
my %var=( (CONST1)=>'test1', (CONST2)=>'test2', ); print $var{(CONST1)}."\n"; print $var{10}."\n";
Makeshifts last the longest.
In reply to Re: Question related to the use of constants
by Aristotle
in thread Question related to the use of constants
by danielcid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |