delete
Removes the specified element(s) from a hash or array.
For hashes, removes the key-value pair and returns the deleted
value (or undef if the key did not exist). Read-only hashes
(such as %!) and Hash::Util-restricted hashes reject deletion
with an error. For arrays, sets the element to undef without
changing the array size; use splice to actually shrink.
Stash-backed hashes (accessed via %{"Package::"}) route the
deletion through the PackageRegistry so the symbol is removed
from the live stash, not just from the snapshot Hv.
Synopsis
delete $hash{$key};
delete @hash{@keys}; # hash slice
delete $array[$index];
my $val = delete $hash{$key}; # returns deleted value
Implementation Notes
perl5: pp_delete (
pp.c:5614). Stack has hv_sv, key_sv. Deletes the key from the hash and returns the old value (or undef).hv.c:1310-1348: if SvMAGICAL(hv) and element SvMAGICAL, call mg_clear(sv) before removing from hash (e.g. PERL_MAGIC_envelem -> unsetenv).