RE: sorting %hash entries

2002-07-23 Thread David . Wagner
Subject: Re: sorting %hash entries ok.. that worked, now how about if i wanted it to go the other way.. from most to least? dan "David Wagner" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Here is one shot: > > > %usernum =

Re: sorting %hash entries

2002-07-23 Thread John W. Krahn
Dan wrote: > > ok.. that worked, now how about if i wanted it to go the other way.. from > most to least? my @sorted = sort { $usernum{$b} <=> $usernum{$a} } keys %usernum; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [

Re: sorting %hash entries

2002-07-22 Thread Sudarshan Raghavan
On Tue, 23 Jul 2002, dan wrote: > ok.. that worked, now how about if i wanted it to go the other way.. from > most to least? foreach my $MyId (sort {$usernum{$a} <=> $usernum{$b}} keys (%usernum)) { print "$MyId\n"; } This will print server.two.com server.four.com server.three.com server.one

Re: sorting %hash entries

2002-07-22 Thread dan
\n", $MyId->[0]; > } > > Output: > server.two.com > server.four.com > server.three.com > server.one.com > > > Wags ;) > -Original Message- > From: dan [mailto:[EMAIL PROTECTED]] > Sent: Monday, July 22, 2002 14:45 > To: [EMAIL P

Re: sorting hash entries

2002-07-22 Thread victor
the command 'sort' allow you to put in your own routine to do sorting. %usernum = ("server.one.com" => "15", "server.two.com" => "5", "server.three.com" => "14", "server.four.com" => "9"); @arr = sort {$usernum{$a} <=> $usernum{$b}} (keys %usernum); print j

Re: sorting %hash entries

2002-07-22 Thread John W. Krahn
Dan wrote: > > I have a small query regarding how to sort hash entries in numerical order. > > %usernum { "server.one.com" "15", > "server.two.com" "5", > "server.three.com" "14", > "server.four.com" "9" } > > How can i get perl to ret

RE: sorting %hash entries

2002-07-22 Thread David . Wagner
rt {$a->[1] <=>$b->[1]} map{[$_,$usernum{$_}]} keys %usernum) { printf "%-s\n", $MyId->[0]; } Output: server.two.com server.four.com server.three.com server.one.com Wags ;) -Original Message----- From: dan [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 14:

sorting hash entries

2002-07-22 Thread dan
(sorry if this message comes twice.. didn't appear to have sent the first time) I have a small query regarding how to sort hash entries in numerical order. %usernum { "server.one.com" "15", "server.two.com" "5", "server.three.com" "14",

sorting %hash entries

2002-07-22 Thread dan
I have a small query regarding how to sort hash entries in numerical order. %usernum { "server.one.com" "15", "server.two.com" "5", "server.three.com" "14", "server.four.com" "9" } How can i get perl to return these 4 server names in th