Challenge 2: Sorted Iteration — Possible Solution ==================================================================== use strict; use warnings; use feature 'say'; my %ages = ( "Grace" => 85, "Ada" => 28, "Alan" => 41, "Bob" => 33, ); foreach my $name (sort keys %ages) { say "$name: $ages{$name}"; } Output: Ada: 28 Alan: 41 Bob: 33 Grace: 85 WHY THIS WORKS AS AN ANSWER ------------------------------ foreach my $name (sort keys %ages) reuses the chapter's own iteration idiom directly, with sort added in front of keys — exactly the fix the chapter's own warn-box recommends: "if a specific, predictable order matters, sort explicitly: foreach my $name (sort keys %ages)." Without sort, per that same warn-box, the four names could print in any order at all, since Perl hashes carry no guaranteed ordering — sort keys %ages first produces a plain array of the four names in alphabetical order (Perl's default string sort, from Chapter 3, which happens to be exactly what's wanted here since names are strings), and THEN the foreach loop iterates over that already-sorted array. "$name: $ages{$name}" reuses the chapter's own string-interpolation- plus-hash-lookup pattern from its own iteration example, looking up each name's age by using $name (the current loop variable) as the hash key inside the very same loop that's iterating over those names.