Operators
Subscript adverbs — :exists / :delete
FullModify what a subscript does — test for a key, remove it, or ask for keys.
An adverb on a subscript changes what the access returns or does. :exists tests for a key without creating it, :delete removes it and returns its value, and :k/:v/ :kv/:p choose what a slice yields.
:exists and :delete #
my %h = a => 1, b => 2; say %h<a>:exists; say %h<a>:delete; say %h;
Output
True
1
{b => 2}:exists reports the key is present; :delete removes a (returning its value 1), leaving just b.
Shaping a slice — :kv / :p / :k #
On a slice, these adverbs choose what comes back: :kv the keys and values flat, :p them as pairs, :k just the keys.
my %h = a => 1, b => 2, c => 3; say %h<a b>:kv; say (%h<a c>:p).sort; say %h<a b>:k;
Output
(a 1 b 2)
(a => 1 c => 3)
(a b)Deleting from an array #
:delete works on an array element too, returning what it held and leaving a hole.
my @a = 10, 20, 30; say @a[1]:delete; say @a;
Output
20
[10 (Any) 30]Notes #
:existsdoes not autovivify — testing%h<missing>:existswon't create the key, unlike a bare%h<missing>in some lvalue contexts.:deleteworks on arrays too, removing the element (leaving a hole/Nil), and returns what it removed.- The value-shape adverbs pair with slices:
%h<a b>:kvgives(a 1 b 2),:pgives pairs,:kjust the keys that matched — the same family used by grep/first :k.