๐Ÿ“˜ Hash in Perl 6

๐Ÿ“˜ Hash in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.

Hashes provide a few methods with clear semantics, for instance:

my %hash = Language => 'Perl', Version => 6;

say %hash.elems;ย  # number of pairs in the hash
say %hash.keys;ย ย  # the list of the keys
say %hash.values; # the list of the values

Hereโ€™s the output:

ย 2
(Version Language)
(6 Perl)

It is possible to iterate not only over the hash keys or values but also over whole pairs:

for %hash.pairs {
ย ย ย  say $_.key;
ย ย ย  say $_.value;

The .kv method returns a list containing the alternating keys and values of the hash:

say %hash.kv # (Version 6 Language Perl)

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code