Re: Sorting hash values

2006-04-05 Thread Jeff Pang
> >And it doesn't work. Any help is appreciated. > Hello,I'd modify your script as follow,and it could work for me. use strict; use warnings; my %rules_new = (aaa => [11,22,33,44], bbb => [55,66,77,88], ); for my $rule (sort {&compute_probability($b) <=> &compu

RE: sorting hash

2005-12-27 Thread Timothy Johnson
From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] Sent: Mon 12/26/2005 6:40 AM To: beginners@perl.org Cc: Subject: RE: sorting hash Anders Stegmann <mailto:[EMAIL PROTECTED]> wrote: : How do I do that?

Svar: RE: sorting hash

2005-12-26 Thread Anders Stegmann
Thanks for replying! I think I tried everything but that! Anders. Anders Stegmann Ph.d. student Royal Veterinary and Agricultural University Institute of Food Science Section of Food Microbiology Rolighedsvej 30 Building 2-74 Room R074 DK-1958 Frederiksberg C Tlf. +45 35 28 31 58 >>> "Charles

RE: sorting hash

2005-12-26 Thread Charles K. Clarkson
Anders Stegmann wrote: : How do I do that? Use 'sort'. use strict; use warnings; my %hash = qw(1 A 2 B 3 C); foreach my $key ( sort { $a <=> $b } keys %hash ) { print "$key => $hash{$key}\n"; } __END__ The big question is: Are you using the right data

Re: sorting hash

2005-12-26 Thread John Doe
Anders Stegmann am Montag, 26. Dezember 2005 15.22: > Hi! Hello > I have a script like: > > %hash = qw(1 A 2 B 3 C); > while (($key, $value) = each %hash) { > print "$key => $value\n"; > } > > it prints out: > > 1 => A > 3 => C > 2 => B > > I want it to print out a sorted hash like: > > 1 =

Re: Sorting hash of hashes

2005-10-06 Thread Jeff 'japhy' Pinyan
On Oct 6, Rose, Jeff said: I have been trying to sort a hash but I cannot figure it out for the life of me I've fixed a bit of the formatting below... my %message = ( $messageid => { From=> $from, To => $to, To_Num => $num, Sub_IP => $ip, Subject => $subject,

Re: sorting hash list for CGI Form

2004-03-09 Thread R. Joseph Newton
Scott Taylor wrote: > Hello all, > > When I populate this hash (%SrcIDs) from "SELECT id, desc, from myTable > order by desc" it What does "it" refer to here? If you mean the SQL engine, which does care about the content of order clauses, you are mistaken. Your data set is returned in the prope

Re: sorting hash list for CGI Form

2004-03-09 Thread James Edward Gray II
On Mar 9, 2004, at 3:39 PM, Scott Taylor wrote: Hello all, Howdy. When I populate this hash (%SrcIDs) from "SELECT id, desc, from myTable order by desc" it doesn't order by the description field "desc". (printing each row in the while loop show that the SQL is sorted) See inlined change bel

Re: sorting hash numerically

2003-02-04 Thread Pete Emerson
perldoc -q sort foreach $empNo (sort {$a<=>$b} keys %empName) { On Tue, 2003-02-04 at 08:17, Rob wrote: > Hi, I want to sort a hash based on the employee number; I used a foreach > loop but it sorts the hash based on the ascii value. How would I get it > to sort on integer values? -- To unsu

RE: Sorting Hash of arrays by how many elements

2003-02-04 Thread Paul Kraus
DOHT! Ya that would do it wouldn't it. Thanks. -Original Message- From: Jenda Krynicky [mailto:[EMAIL PROTECTED]] Sent: Monday, February 03, 2003 6:16 PM To: Perl Subject: Re: Sorting Hash of arrays by how many elements From: "Paul Kraus" <[EMAIL PROTECTED]> &g

Re: Sorting Hash of arrays by how many elements

2003-02-03 Thread Peter Scott
In article <008301c2cbbd$15c27c40$8afea8c0@pkraus>, [EMAIL PROTECTED] (Paul Kraus) writes: >This is straight from the camel pg 277. >Unless I misunderstand this then the items with 3 elements should be at >the top not in the middle. >What am I doing wrong? > >Can someone break down what the sort

Re: Sorting Hash of arrays by how many elements

2003-02-03 Thread Jenda Krynicky
From: "Paul Kraus" <[EMAIL PROTECTED]> > This is straight from the camel pg 277. > Unless I misunderstand this then the items with 3 elements should be > at the top not in the middle. What am I doing wrong? > > Can someone break down what the sort statement in this situation is > doing. Referenc

Re: Sorting Hash of arrays by how many elements

2003-02-03 Thread Wiggins d'Anconia
See inline. Paul Kraus wrote: This is straight from the camel pg 277. Unless I misunderstand this then the items with 3 elements should be at the top not in the middle. What am I doing wrong? Can someone break down what the sort statement in this situation is doing. References are still confusi

Re: sorting hash after deref

2003-01-10 Thread Mark Goland
> foreach my $i ( sort { $a <=> $b } (keys (%hash))) { >print "$i => $hash{$i}\n" if ( defined $hash{$i} ); > } > } > how about foreach my $i ( sort ( keys(%hash) ) ) { print "$i => $hash{$i}\n"

RE: Sorting hash "values"

2002-12-30 Thread Wagner, David --- Senior Programmer Analyst --- WGO
the key. Wags ;) -Original Message- From: Rajendra Babu, Praveen [mailto:[EMAIL PROTECTED]] Sent: Monday, December 30, 2002 16:29 To: 'Mark Anderson'; [EMAIL PROTECTED] Subject: RE: Sorting hash "values" Hello /\/\ark, Thanks for your reply. The below code

RE: Sorting hash "values"

2002-12-30 Thread Rajendra Babu, Praveen
h $key ( sort { $hash{$b} <=> $hash{$a} } keys %hash )" Can someone please explain ??? -Praveen -Original Message- From: Mark Anderson [mailto:[EMAIL PROTECTED]] Sent: Tuesday, 31 December 2002 10:23 AM To: Rajendra Babu, Praveen; [EMAIL PROTECTED] Subject: RE: Sorting hash &

Re: Sorting hash "values"

2002-12-30 Thread Dave K
$ perl -e ' %hash = ( "h" => 100, "a" => 2000, "z" => 50, "b" => 600 ); for(sort { $hash{$b} <=> $hash{$a} } keys %hash) { print $hash{$_}, " = $_\n"; }' 2000 = a 600 = b 100 = h 50 = z HTH "Rajendra Babu" <[EMAIL PROTECTED]> wrote in message [EMAIL PROT

RE: Sorting hash "values"

2002-12-30 Thread Mark Anderson
It helps to answer your question if you show us what you've already done, and tell us what you know... perldoc -f keys perldoc -f sort /\/\ark -Original Message- From: Rajendra Babu, Praveen [mailto:[EMAIL PROTECTED]] Sent: Monday, December 30, 2002 3:16 P

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
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 = ( "server.one.com", "15", > "server.two.com", "5", > "server.three.co

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
Here is one shot: %usernum = ( "server.one.com", "15", "server.two.com", "5", "server.three.com", "14", "server.four.com", "9" ); foreach my $MyId (sort {$a->[1] <=>$b->[1]} map{[$_,$usernum{$_}]} keys %usernum) { printf "%-s\n", $My

Re: Sorting hash by element

2001-06-16 Thread Paul Johnson
On Sat, Jun 16, 2001 at 09:31:13AM -0700, Peter Scott wrote: > At 09:15 AM 6/16/2001 -0700, Ron Anderson wrote: > > > >And can I sort the hash by last name and then first name? > > Consider using instead a hash-of-hashes or hash-of-arrays(perldoc perllol). And when you need more efficiency type

Re: Sorting hash by element

2001-06-16 Thread Me
> But, if you did, I think this should work: But then it is saturday morning. Sigh. Ignore my attempt; use Peter's. > sub room { my $s = $shash{$_}; (split /\t/)[2] }; Wrong, twice. You wanted lastname, not room. And the split isn't working on the right thing. Peter's solution is clearer, n

Re: Sorting hash by element

2001-06-16 Thread Me
> $shash{"student1"} = join("\t", ("bob", "tyson", "room5")); > $shash{"student2"} = join("\t", ("ron", "anderson", "room4")); > $shash{"student3"} = join("\t", ("dave", "lee", "room2")); > $shash{"student4"} = join("\t", ("tim", "barker", "room3")); > $shash{"student5"} = join("\t", ("roger", "fa

Re: Sorting hash by element

2001-06-16 Thread Peter Scott
At 09:15 AM 6/16/2001 -0700, Ron Anderson wrote: >Hi! > >Using the following hash as an example: > >$shash{"student1"} = join("\t", ("bob", "tyson", "room5")); >$shash{"student2"} = join("\t", ("ron", "anderson", "room4")); >$shash{"student3"} = join("\t", ("dave", "lee", "room2")); >$shash{"stude