Perl 6 Cool Perl 6 #31

Consider...

for %addrbook.classify({ .value.substr(0,1).uc }).sort -> $g {
    say "{$g.key}:";
    .say for $g.value».invert».fmt("  %-32s %s");
}

So, the outer loop iterates over the sorted pairs, passing each to $g in the block.

The say "{$g.key}:" line outputs the group letter and colon.

Copyright © 2010
http://www.pmichaud.com/2010/pres/