foreach my $id (
map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
map { [ (split( "\t", $students{$_} ))[1], $_ ] } keys %students )
{
printf "$id\t$students{$id}\n";
}
####
4873 Tom 2.9
236 Fred 3.2
1522 Susan 4.0
####
# Create a list of student IDs by taking the sorted
# list of anonymous arrays and returning the second
# element of each.
map { $_->[1] }
# Sort the list of anonymous arrays (created below)
# numerically, using the first element in the array
# (the GPA).
sort { $a->[0] <=> $b->[0] }
# For each key in %students, create an anonymous array:
# The first element is the GPA, obtained by taking
# the second element of the list created by splitting
# the value of $students{$_} on the tab, and the second
# element is the student ID.
map { [ (split( "\t", $students{$_} ))[1], $_ ] } keys %students )