in reply to Re: Keys/Values being lost with this code--any help?
in thread Keys/Values being lost with this code--any help?

Thanks to all for your replies! This is what I was looking for. I must apologize for not being able to state what I needed in an understandable fashion. Please excuse me as I am still new to Perl and am just getting comfortable with the language! Thanks! PS: What would you use to sort this? Either by the key or by the value--which subroutines can be used? Thanks again.
  • Comment on Re: Re: Keys/Values being lost with this code--any help?

Replies are listed 'Best First'.
Re: Re: Re: Keys/Values being lost with this code--any help?
by lestrrat (Deacon) on Sep 24, 2002 at 20:59 UTC
    ## 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"; }