On 03/22/2012 10:12 AM, Kronheim, David (Contr) wrote:
My question is that how can I sort the values. I googled for a while.
sort $abbrev{$a} cmp $abbrev{$b} it complains that:
You need to put the sort test in a block:
for my $key ( sort { $abbrev{$a} cmp $abbrev{$b} } keys %abbrev ) {
print "key=$key, value=$abbrev{$key}\n";
}
Since the default sort order, where items are sorted as strings in ASCII
sequence is not being changed, the following is sufficient:
for my $key (sort keys %abbrev) {
print "key=$key, value=$abbrev{$key}\n";
}
those sorts are not the same. the question was sorting by the hash
values and you sort by the hash keys. maybe in this case the values sort
in the same order as the keys since they are abbrevs but you can't
assume that.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/