Re: Sorting a hash by value, and displaying the key

2001-06-07 Thread rob chanter
On Sat, Jun 02, 2001 at 06:13:04PM +1000, iain truskett wrote: > Rob talked about > > foreach $value(sort {$a <=> $b} (values(%hash)) { > print $value; > } > > vs. > > foreach $value(sort byNum (values(%hash)) { > print $value; > } > > sub byNum { > $a <=> $b; > } > > > Am I corr

Re: Sorting a hash by value, and displaying the key

2001-06-02 Thread iain truskett
Rob talked about foreach $value(sort {$a <=> $b} (values(%hash)) { print $value; } vs. foreach $value(sort byNum (values(%hash)) { print $value; } sub byNum { $a <=> $b; } Am I correct in thinking that the anonymous subroutine is vaguely more efficient? -- iain.

Re: Sorting a hash by value, and displaying the key

2001-05-31 Thread Timothy Kimball
Paul Hodges wrote: : Try flipping the hash. : : my %flipped; : @flipped{values %HASH} = keys %HASH; : : That makes the keys of %HASH the values of %flipped, with the matching : values of %HASH being the keys to which they are assigned. : Now just do it the easy way. : : for my $key (sort ke

RE: Sorting a hash by value, and displaying the key

2001-05-31 Thread Paul
--- "Maynard, Garth" <[EMAIL PROTECTED]> wrote: > Caution: if you have any data that is repetitive, you will lose > information during the flipping process. An excellent point. Shouldn't be the case here, since the values were the order of entry, but it needed pointing out.

RE: Sorting a hash by value, and displaying the key

2001-05-31 Thread Maynard, Garth
Caution: if you have any data that is repetitive, you will lose information during the flipping process. Subject: Re: Sorting a hash by value, and displaying the key --- David Michael <[EMAIL PROTECTED]> wrote: > Hello, > I have a hash that needs to be displayed in a cert

Re: Sorting a hash by value, and displaying the key

2001-05-31 Thread Paul
--- Paul <[EMAIL PROTECTED]> wrote: > > --- David Michael <[EMAIL PROTECTED]> wrote: > > Hello, > > I have a hash that needs to be displayed in a certain order. I > > tried > > > > foreach $key (sort (keys %HASH)) { > > print $key; > > } > > > > that sorts alphabeti

Re: Sorting a hash by value, and displaying the key

2001-05-31 Thread Paul
--- David Michael <[EMAIL PROTECTED]> wrote: > Hello, > I have a hash that needs to be displayed in a certain order. I > tried > > foreach $key (sort (keys %HASH)) { > print $key; > } > > that sorts alphabetically. I need it in the order it was > inserted, so I made

Re: Sorting a hash by value, and displaying the key

2001-05-31 Thread rob chanter
On Thu, May 31, 2001 at 02:41:32PM -0500, David Michael wrote: > Hello, > I have a hash that needs to be displayed in a certain order. I tried > > foreach $key (sort (keys %HASH)) { > print $key; > } > > that sorts alphabetically. I need it in the order it was inserte

Re: Sorting a hash by value, and displaying the key

2001-05-31 Thread Timothy Kimball
David Michael wrote: : I have a hash that needs to be displayed in a certain order. I tried : : foreach $key (sort (keys %HASH)) { : print $key; : } : : that sorts alphabetically. I need it in the order it was inserted, so I made the :value a number that increased f

Re: Sorting a hash by value, and displaying the key

2001-05-31 Thread Brett W. McCoy
On Thu, 31 May 2001, David Michael wrote: > Hello, > I have a hash that needs to be displayed in a certain order. I tried > > foreach $key (sort (keys %HASH)) { > print $key; > } > > that sorts alphabetically. I need it in the order it was inserted, > so I made the value a

Sorting a hash by value, and displaying the key

2001-05-31 Thread David Michael
Hello, I have a hash that needs to be displayed in a certain order. I tried foreach $key (sort (keys %HASH)) { print $key; } that sorts alphabetically. I need it in the order it was inserted, so I made the value a number that increased for each key. I need to sort by