It's hard to properly understand on what criteria you want to sort based on your description. As you want to order by the value of the 'name' field (which is non-numerical), you should use the cmp operator instead of <=> in your sort.
Now, if what you want to do is order by a non-numerical field, and then in case of equality fall back to comparing numerical fields (like the 'age' field for example), the usual way is to declare a little sub you'll use with the sort function.
for my $id (sort by_name_and_age keys %hash) { print "$hash{$id}{'item'} - $hash{$id}{'name'}\n"; } sub by_name_and_age { # Sort by reversed ASCII order... $hash{$b}{'name'} cmp $hash{$a}{'name'} or # ... or by ascending age value. $hash{$a}{'age'} <=> $hash{$b}{'age'}; }
As always, it's a good idea to read (again) the documentation of sort.
In reply to Re: numerical and non numerical sorts
by Fang
in thread numerical and non numerical sorts
by rsiedl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |