September 2017
Beginner
402 pages
9h 52m
English
Let's see what methods are available for the hashes.
First, the two methods, keys and values, return lists (sequences, to be strict) containing all the keys and values of the hash.
my %capitals = Spain => 'Madrid', Italy => 'Rome', France => 'Paris';my @countries = %capitals.keys;my @cities = %capitals.values;say @countries; # [France Italy Spain]say @cities; # [Paris Rome Madrid]
The kv method returns a list of both keys and values:
say %capitals.kv; # (France Paris Italy # Rome Spain Madrid)
A similar method, pairs, returns a list of pairs (pairs are data types containing a key and a value):
say %capitals.pairs; # (France => Paris # Italy => Rome # Spain => Madrid)
To invert the pairs, use the antipairs
Read now
Unlock full access