hashmap - Perl Setting Value of Constant to value of Hash Key -
is there way set value of perl constant value in perl hash?
this not working:
use constant test => $configdata{'key'}; print test."\n";
this prints newline character.
is misuse of concept of constant? values still known @ compile time, not live inside perl module or perl script itself.
here's working example using readonly module. put sub directly in test script, external.
#!/usr/bin/perl use strict; use warnings; use readonly; use data::dumper; readonly::hash %configdata => loadconfighash(); sub loadconfighash { %hash = (one => 1, 2 => 2, 3 => 3); return %hash; } print dumper \%configdata; # assignment fail , generate fatal error $configdata{two} = 4; print dumper \%configdata;
Comments
Post a Comment