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

Comments

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Avoid using global/class-level mutable datatypes like list/dicts

Weakref proxy is for instance only ...