Posts

Showing posts from October, 2014

Perl constant hashrefs are actually functions

To get the keys of a constant hashref you first need to learn that a constant is actually a function and hence use () to get the keys from it INPUT: $ cat perlConstant.pl use Data::Dumper; use constant FOOHASH => { "foo" => "bar", }; print FOOHASH->{"foo"}."\n"; foreach $key (keys %{FOOHASH()}) { FOOHASH->{$key} = "bar1"; } print FOOHASH->{"foo"}."\n"; foreach $key (keys %{FOOHASH}) { FOOHASH->{$key} = "bar2"; } print FOOHASH->{"foo"}."\n"; OUTPUT: $ perl perlConstant.pl bar bar1 bar1