What about Readonly?
E.g.
use Readonly;
Readonly my %h3 => (
k1 => [ { k=>1 }, { m=>2 } ],
k2 => [ { l=>90}, ],
);
print "old value: '$h3{k1}->[0]->{k}'\n";
$h3{k1}->[0]->{k} = 'New value';
print "new value: '$h3{k1}->[0]->{k}'\n";
gives
old value: '1'
Modification of a read-only value attempted at readonly.pl line 7
Note that %h3
is a hash, not a hashref. Hashrefs don't work well with Readonly:
use Readonly;
Readonly my $h2 => {
k1 => [ { k=>1 }, { m=>2 } ],
k2 => [ { l=>90}, ],
};
print "old value: '$h2->{k1}->[0]->{k}'\n";
$h2->{k1}->[0]->{k} = 'New value';
print "new value: '$h2->{k1}->[0]->{k}'\n";
gives
old value: '1'
new value: 'New value'