Re: Sorting a hash to user needs

2009-07-08 Thread Chas. Owens
On Wed, Jul 8, 2009 at 15:09, "Alexander Müller" wrote: > Hi, > > I need an order for hash by user preferences. Because the criterion to order > the hash entries a not numerical and not should sorted alphabetical, I tried > following > > >   3 %hashToSort = ( >   4 "a" => "one", >   5 "b"

Sorting a hash to user needs

2009-07-08 Thread Alexander Müller
Hi, I need an order for hash by user preferences. Because the criterion to order the hash entries a not numerical and not should sorted alphabetical, I tried following   3 %hashToSort = (   4 "a" => "one",   5 "b" => "two",   6 "c" => "three",   7 ); @keys = sort { qw(a, b, c) } (

Re: Sorting a hash

2008-06-03 Thread Matthew Whipple
On Mon, 2008-06-02 at 11:53 -0700, Iain Adams wrote: > Hello, > > I am trying to sort a hash of hashes. > > my code looks like this > > foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > print OUT "$cnt 1, "; > } > > This prints out the correct numbers (the keys

Re: Sorting a hash

2008-06-03 Thread Iain Adams
On Jun 2, 8:43 pm, [EMAIL PROTECTED] (Jialin Li) wrote: > On Mon, Jun 2, 2008 at 1:53 PM, Iain Adams <[EMAIL PROTECTED]> wrote: > > Hello, > > > I am trying to sort a hash of hashes. > > > my code looks like this > > >  foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > >          

Re: Sorting a hash

2008-06-02 Thread Rob Dixon
Iain Adams wrote: > Hello, > > I am trying to sort a hash of hashes. > > my code looks like this > > foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > print OUT "$cnt 1, "; > } > > This prints out the correct numbers (the keys of the instances hash. > However the

Sorting a hash

2008-06-02 Thread Iain Adams
Hello, I am trying to sort a hash of hashes. My code looks like this: foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ print OUT "$cnt 1, "; } This is returning the correct part of the hash of hashes. However it is not being sorted correctly. All the instances keys a

Re: Sorting a hash

2008-06-02 Thread Li, Jialin
On Mon, Jun 2, 2008 at 1:53 PM, Iain Adams <[EMAIL PROTECTED]> wrote: > Hello, > > I am trying to sort a hash of hashes. > > my code looks like this > > foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > print OUT "$cnt 1, "; > } > > This prints out the correct number

Sorting a hash

2008-06-02 Thread Iain Adams
Hello, I am trying to sort a hash of hashes. my code looks like this foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ print OUT "$cnt 1, "; } This prints out the correct numbers (the keys of the instances hash. However the sorting is a bit weird. The keys are all

Re: Sorting a hash of hashes

2006-02-03 Thread John W. Krahn
Scott Palmer wrote: > I am attempting to sort by a field in a hash within a hash and I am > having a hard time finding the right direction. I want the print out to > sort from smallest to largest in size. Any help would be greatly > appreciated. > > -- > #!

RE: Sorting a hash of hashes

2006-02-02 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Scott Palmer wrote: > I am attempting to sort by a field in a hash within a hash and I am > having a hard time finding the right direction. I want the print out > to sort from smallest to largest in size. Any help would be greatly > appreciated. > > Scott > > -

Sorting a hash of hashes

2006-02-02 Thread Scott Palmer
I am attempting to sort by a field in a hash within a hash and I am having a hard time finding the right direction. I want the print out to sort from smallest to largest in size. Any help would be greatly appreciated. Scott -- #!/usr/bin/perl # Set your s

Re: sorting a hash

2005-05-10 Thread perlocean
- Original Message - From: "Chris Charley" <[EMAIL PROTECTED]> To: Sent: Monday, May 09, 2005 7:03 PM Subject: Re: sorting a hash - Original Message - From: <[EMAIL PROTECTED]> Newsgroups: perl.beginners To: "Octavian Rasnita" <[EMAIL PROTECT

Re: sorting a hash

2005-05-10 Thread Octavian Rasnita
Ok, thank you much. Teddy - Original Message - From: "Chris Charley" <[EMAIL PROTECTED]> To: Sent: Monday, May 09, 2005 11:07 PM Subject: Re: sorting a hash > Hi Teddy > > This works :-) > > for (sort byname keys %$ref) { > print "$_ has

Re: sorting a hash

2005-05-09 Thread Chris Charley
- Original Message - From: <[EMAIL PROTECTED]> Newsgroups: perl.beginners To: "Octavian Rasnita" <[EMAIL PROTECTED]>; Sent: Monday, May 09, 2005 4:30 PM Subject: Re: sorting a hash - Original Message - From: "Octavian Rasnita" <[EMAIL PR

Re: sorting a hash

2005-05-09 Thread perlocean
- Original Message - From: "Octavian Rasnita" <[EMAIL PROTECTED]> To: Sent: Monday, May 09, 2005 2:32 PM Subject: sorting a hash Hi, I have a reference to a hash of hashes, something like: my $ref = { c => { name => 'a', age => 20, }, b => { name =

Re: sorting a hash

2005-05-09 Thread Chris Charley
Hi Teddy This works :-) for (sort byname keys %$ref) { print "$_ has the name $ref->{$_}{name} and has $ref->{$_}{age} years\n"; } sub byname { {$ref->{$a}{name} cmp $ref->{$b}{name}} } Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: sorting a hash

2005-05-09 Thread mgoland
- Original Message - From: Octavian Rasnita <[EMAIL PROTECTED]> Date: Monday, May 9, 2005 3:32 pm Subject: sorting a hash > Hi, Hello, > > I have a reference to a hash of hashes, something like: > > my $ref = { > c => { > name => 'a', >

sorting a hash

2005-05-09 Thread Octavian Rasnita
Hi, I have a reference to a hash of hashes, something like: my $ref = { c => { name => 'a', age => 20, }, b => { name => 'e', age => 24, }, a => { name => 'z', age => 14, }, }; I want to sort the persons with the codes 'a', 'b', and 'c' by their name, and print something like: "a has the name

Re: Sorting a hash with keys generated on the fly

2002-11-05 Thread Jenda Krynicky
From: "Scott, Joshua" <[EMAIL PROTECTED]> > I'd like to know the best/easiest way to sort a hash based on the > values of it's keys. Here is a snippet of my code. > > %somehash=(); > > foreach (@somearray) { > $somehash{$_}++; > }; > > Basically I'm getting a count of

Sorting a hash with keys generated on the fly

2002-11-05 Thread Scott, Joshua
I'd like to know the best/easiest way to sort a hash based on the values of it's keys. Here is a snippet of my code. %somehash=(); foreach (@somearray) { $somehash{$_}++; }; Basically I'm getting a count of unique items in an array and I want to sort by the number of each item. I've

Re: sorting a hash by using a function

2002-11-03 Thread John W. Krahn
Roiy Zysman wrote: > > Hi All, Hello, > How can i get the hash reference when i use a function to sort that hash. > e.g. i want to sort the hash according to is values > I can do something like this > sort {$hash{$a} cmp $hash{$b}} (keys %hash); > but i want to sort it by using a call to a funct

sorting a hash by using a function

2002-11-03 Thread Zysman, Roiy
Hi All, How can i get the hash reference when i use a function to sort that hash. e.g. i want to sort the hash according to is values I can do something like this sort {$hash{$a} cmp $hash{$b}} (keys %hash); but i want to sort it by using a call to a function , something like this foreach my $item

RE: sorting a hash - multiple key fields

2002-09-17 Thread Ramprasad A Padmanabhan
On Tue, 2002-09-17 at 19:58, Jeff AA wrote: > > > -Original Message- > > From: Ramprasad A Padmanabhan [mailto:[EMAIL PROTECTED]] > > Sent: 17 September 2002 14:44 > > To: [EMAIL PROTECTED]; Jeff Aa > > Cc: [EMAIL PROTECTED] > > Subject: R

RE: sorting a hash - multiple key fields

2002-09-17 Thread david
Jeff wrote: > Thanks for the response - some questions on your recommendation below: > > -Original Message- > From: david [mailto:[EMAIL PROTECTED]] > Sent: 17 September 2002 19:06 > To: [EMAIL PROTECTED] > Subject: Re: sorting a hash - multiple key fields > &

RE: sorting a hash - multiple key fields

2002-09-17 Thread Jeff
Thanks for the response - some questions on your recommendation below: -Original Message- From: david [mailto:[EMAIL PROTECTED]] Sent: 17 September 2002 19:06 To: [EMAIL PROTECTED] Subject: Re: sorting a hash - multiple key fields > the return statment is uneccessary. try someth

Re: sorting a hash - multiple key fields

2002-09-17 Thread david
Jeff Aa wrote: > Folks, > > I want to sort my masked hashes into neat little piles for easier > digestion: > Please note this is _example_ data 8-) > > my $h = { > a => { name => 'apple', taste => 3 }, > b => { name => 'peach', taste => 2 }, > c => { name => 'banana', taste => 2 }, > } >

RE: sorting a hash - multiple key fields

2002-09-17 Thread Jeff AA
> -Original Message- > From: Ramprasad A Padmanabhan [mailto:[EMAIL PROTECTED]] > Sent: 17 September 2002 14:44 > To: [EMAIL PROTECTED]; Jeff Aa > Cc: [EMAIL PROTECTED] > Subject: Re: sorting a hash - multiple key fields > > > Use this . I think you wud

Re: sorting a hash - multiple key fields

2002-09-17 Thread Ramprasad A Padmanabhan
Use this . I think you wud do better later to move the sort function to a seperate sub foreach $key (sort { ($$h{$a}{taste} eq $$h{$b}{taste} ) ? $$h{$a}{name} cmp $$h{$b}{name}: $$h{$a}{taste} \cmp $$h{$b}{taste} } (keys %$h)) { print "$key \n"; } Jeff Aa wrote: > Folks, >

sorting a hash - multiple key fields

2002-09-17 Thread Jeff AA
Folks, I want to sort my masked hashes into neat little piles for easier digestion: Please note this is _example_ data 8-) my $h = { a => { name => 'apple', taste => 3 }, b => { name => 'peach', taste => 2 }, c => { name => 'banana', taste => 2 }, } I want to sort first on taste and then

Re: sorting a hash by value.

2002-06-24 Thread Jeff 'japhy' Pinyan
On Jun 24, Postman Pat said: >I would like to sort a hash by value. The hash values are numbers. I would >like to sort this by desceding order. How would I do this? I have searched >and found nothing on it. I have found lots on sorting by key though... Where did you search? A single check to

Re: sorting a hash by value.

2002-06-24 Thread Nigel Peck
For some stupid reason I was imagining that foreach(sort { $hash{$a} <=> $hash{$b} } keys %hash) { was going to sort by the keys and not the values, overlooking the comparison being based on the value, thanks for pointing it out (now I understand :-) >>> "Shawn" <[EMAIL PROTECTED]> 06/24/02 10

RE: sorting a hash by value.

2002-06-24 Thread Bob Showalter
> -Original Message- > From: Postman Pat [mailto:[EMAIL PROTECTED]] > Sent: Monday, June 24, 2002 2:46 AM > To: [EMAIL PROTECTED] > Subject: sorting a hash by value. > > > Greetings, > I would like to sort a hash by value. The hash values are > numbers. I

Re: sorting a hash by value.

2002-06-24 Thread Shawn
>foreach(sort { $hash{$a} <=> $hash{$b} } values %hash) { > print "$_\n"; >} Err... This will not work... You will be trying to get a hash value based on the value... It's early my %hash=(thumb='122',tom=>'21',muffit=>'48',miss=>'31'); foreach(sort { $hash{$a} <=> $hash{$b} } values %hash

Re: sorting a hash by value.

2002-06-24 Thread Shawn
>> "Shawn" <[EMAIL PROTECTED]> 06/24/02 07:49am >>> > Hello Pat, > You can do it like so: > > my %hash; > foreach(sort {$hash{$a} <=> $hash{$b} } keys %hash) { > > } > > Shawn > > - Original Message

Re: sorting a hash by value.

2002-06-24 Thread Nigel Peck
quot; <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, June 24, 2002 1:46 AM Subject: sorting a hash by value. > Greetings, > I would like to sort a hash by value. The hash values are numbers. I would > like to sort this by desceding order. How would I do

Re: sorting a hash by value.

2002-06-23 Thread Shawn
Hello Pat, You can do it like so: my %hash; foreach(sort {$hash{$a} <=> $hash{$b} } keys %hash) { } Shawn - Original Message - From: "Postman Pat" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, June 24, 2002 1:46 AM Subj

sorting a hash by value.

2002-06-23 Thread Postman Pat
Greetings, I would like to sort a hash by value. The hash values are numbers. I would like to sort this by desceding order. How would I do this? I have searched and found nothing on it. I have found lots on sorting by key though... Please help dudes! Ciao LK -- To unsubscribe, e-mail: [EMAI

Re: sorting a hash alphabetically

2002-05-19 Thread Jolinar of Malkshur
See? I knew someone else would know a better way. Jolinar "Beau E. Cox" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hi - you suggested: > > > foreach $lastname (sort { $a cmp $b } keys %names) { > > print "$lastname, $names{$lastname}\n"; > > } > > That

RE: sorting a hash alphabetically

2002-05-19 Thread Beau E. Cox
Hi - you suggested: > foreach $lastname (sort { $a cmp $b } keys %names) { > print "$lastname, $names{$lastname}\n"; > } That works well. I'm lazy, so I usually do something like: print "$_, $names{$_}\n" for (sort keys %names); 1) for == foreach so save 4 keystrokes. 2) I use the for ..

Re: sorting a hash alphabetically

2002-05-19 Thread Jolinar of Malkshur
This is what I've been using and it seems to work well: foreach $lastname (sort { $a cmp $b } keys %names) { print "$lastname, $names{$lastname}\n"; } I'm pretty new to Perl, though, and someone else might know a better way. Jolinar "Jerry Preston" <[EMAIL PROTECTED]> wrote in message [EMAIL

sorting a hash alphabetically

2002-05-17 Thread Jerry Preston
Hi! I have a hash built in the following way: $names{ $ID } = $your_name; I want to l want to list in print $query->popup_menu( -name=>'Emp', -values=> \%who, -default=> \%who, ); but in alphabetically. How

Re: Sorting a hash table - Advanced;)

2002-02-28 Thread Vitali
"Tor Hildrum" <[EMAIL PROTECTED]> To: "Perl" <[EMAIL PROTECTED]>; "Steven M. Klass" <[EMAIL PROTECTED]> Sent: Thursday, February 28, 2002 3:01 PM Subject: Re: Sorting a hash table - Advanced;) > On 27/2/02 17:33, "Steven M. Klass"

Re: Sorting a hash table - Advanced;)

2002-02-28 Thread Tor Hildrum
>> Basically I want to format this so certain keys get printed in a certain >> order, but there may be some remaining keys that I want printed that I really >> don't care about. (a "catch-all" if you will) >> >> Thanks > > print "\n\n**Summary**\n"; > foreach my $key (keys %runset){ > print "N

Re: Sorting a hash table - Advanced;)

2002-02-28 Thread Tor Hildrum
On 27/2/02 17:33, "Steven M. Klass" <[EMAIL PROTECTED]> wrote: > Hi all, > > ok here is the fundamental code > > print "\n\n**Summary**\n"; > foreach my $key (keys %runset){ > printf ( "%-20s %-20s\n",$key, $runset{$key}); > } > > Now I want to sort this hash for example > print "\n\n**Summa

Sorting a hash table - Advanced;)

2002-02-27 Thread Steven M. Klass
Hi all, ok here is the fundamental code print "\n\n**Summary**\n"; foreach my $key (keys %runset){ printf ( "%-20s %-20s\n",$key, $runset{$key}); } Now I want to sort this hash for example print "\n\n**Summary**\n"; foreach my $key (keys %runset){ print "Name $runset{foo}"

Re: Sorting a Hash

2001-11-29 Thread Scott R. Godin
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Dale Pellerin) wrote: > I am very new to hashes (as well as Perl) and am having some difficulty with > a cgi script. This script allows individuals to post "announcements" via a > form. The form data is stored in a text file, sorted in descen

RE: Sorting a Hash

2001-11-28 Thread Wagner-David
/14/00 ^Script ends here Output: 12/14/00 11/15/01 12/01/01 02/01/02 Wags ;) -Original Message- From: Pellerin, Dale [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 28, 2001 08:03 To: [EMAIL PROTECTED] Subject: Sorting a Hash I am very new to hashes (as well as Perl) and a

Sorting a Hash

2001-11-28 Thread Pellerin, Dale
I am very new to hashes (as well as Perl) and am having some difficulty with a cgi script. This script allows individuals to post "announcements" via a form. The form data is stored in a text file, sorted in descending order by date, and printed to the html page. However, the script is currentl

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