http://qs321.pair.com?node_id=594435


in reply to How do I print the values of a hash, sorted by the hash keys?

There's more than one way to do it.

Here's the obvious way:

foreach my $key ( sort keys %data ) { print $data{$key}; }

Here it is, using a map within a single print call:

print map { $data{$_} } sort keys %data;

Here's a way using a hash slice:

foreach my $val ( @data{ sort keys %data } ) { print $val; }

Even the slice can be printed in a single print call:

print @data{ sort keys %data };

Of course, you'll want to set up the variables $, and $\ appropriately...