in reply to Re: Re: Keys/Values being lost with this code--any help?
in thread Keys/Values being lost with this code--any help?
## assuming my %hash = ( John => 20, Bill => 34, # etc... ); ## sort by name(key): foreach my $name ( sort keys %hash ) { print "$name: $hash{$name}\n"; } ## sort by number(value): foreach my $name ( sort { $hash{$a} <=> $hash{$b} } keys %hash ) { print "$name: $hash{$name}\n"; }
|
|---|