Challenge 3: Sort an Array of Hashrefs by Name — Possible Solution ==================================================================== use strict; use warnings; use feature 'say'; my @people = ( { name => "Ada", age => 28 }, { name => "Alan", age => 41 }, { name => "Grace", age => 36 }, ); my @sorted_names = map { $_->{name} } sort { $a->{name} cmp $b->{name} } @people; say "@sorted_names"; Output: Ada Alan Grace WHY THIS WORKS AS AN ANSWER ------------------------------ @people is reused completely unchanged from the chapter's own example, an array of anonymous hashrefs (Course 1, Chapter 9). sort { $a->{name} cmp $b->{name} } @people reuses the chapter's own sort-by-field pattern directly — structurally identical to the chapter's own sort { $a->{age} <=> $b->{age} } @people example, but swapping <=> (numeric comparison, Course 1, Chapter 5) for cmp (STRING comparison, also Course 1, Chapter 5) since name holds text, not a number — using <=> on strings here would trigger the exact numeric-coercion gotcha Course 1, Chapter 5's own warn-box covered. map { $_->{name} } ... reuses the chapter's own extraction step from its chained-pipeline example, pulling just the name field back out of each now-sorted hashref — since $_ inside map refers to each element of whatever list map is applied to (here, the already-sorted array of hashrefs), $_->{name} correctly retrieves each person's name in sorted order. The final result, "Ada Alan Grace", confirms alphabetical ordering by name — Ada before Alan before Grace — rather than the age-based order the chapter's own original example would have produced from the same underlying data.