in reply to Re: Using hashref values in constant declarations.
in thread Using hashref values in constant declarations.
In terms of workarounds ...
For the benefit of the novice PerlMonk, it should be emphasized that none of the workarounds address (nor, I'm sure, were intended to address) the total mutability of the content of "constant" references:
A search of MetaCPAN for "lock" yields a couple of interesting-looking modules, neither of which have I used and so cannot recommend: Data::Lock and Array::Lock.c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "use constant { ONE => 1, FOUR => 4 }; use constant AREF => [ ONE .. FOUR ]; dd AREF; ;; AREF->[3] = 99; dd AREF; ;; AREF->[9] = 999; dd AREF; ;; $#{ +AREF } = -1; dd AREF; " [1, 2, 3, 4] [1, 2, 3, 99] [1, 2, 3, 99, undef, undef, undef, undef, undef, 999] []
In general, Perl handles the important concept of immutability very poorly. I have the vague notion that Perl 6 does better in this respect; can anyone comment?
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using hashref values in constant declarations.
by LanX (Saint) on Sep 10, 2017 at 10:32 UTC | |
|
Re^3: Using hashref values in constant declarations.
by haukex (Archbishop) on Sep 11, 2017 at 06:08 UTC |