Traversing a hash
Author: Scott Penrose
You want to perform an action on each entry (i.e., each pair) in a hash.
Source code: 05-05traversing.p6
#!/usr/bin/env perl6 use v6; my %hash = ( 'one' => 'un', 'two' => 'deux', 'three' => 'trois' ); for %hash.sort(*.key)>>.kv -> ($key, $value) { say "The word '$key' is '$value' in French."; } for %hash.keys.sort -> $key { say "$key => %hash{$key}"; } for %hash.sort { .say; }