lock_keys#
Restrict a hash to its current keys, or to an explicit list.
Synopsis#
lock_keys(%hash); # pin the current keyset lock_keys(%hash, @keys); # pin to the given keyset
With one argument, subsequent attempts to assign to a key not
already in %hash croak with
Attempt to access disallowed key '...' in a restricted hash.
With more arguments, the extra keys specify the allowed set;
existing keys that do not appear in that set make the call croak
with Hash has key '...' which is not in the new key set. Keys in
the allowed set that are not yet present are accepted later (their
slots start as hidden placeholders).
delete and exists still work on a locked hash and do not
change the legal keyset — a deleted key can be reassigned, but a
brand-new key still cannot. Returns a reference to the hash.
A locked hash cannot be blessed; bless before locking if you
need both.