Hash Sorting Problem

2008-02-25 Thread Anirban Adhikary
Dear List I have written the following code . use Data::Dumper; %file = (14 = GGG, 11 = AAA, 101 = EEE, 1 = TTT); print Dumper \%file; @arr1 = sort { $file{$b} cmp $file{$a} } keys %file; #the oldest entry lies at the top position print Dumper

Re: Hash Sorting Problem

2008-02-25 Thread John W. Krahn
Anirban Adhikary wrote: Dear List Hello, I have written the following code . use Data::Dumper; %file = (14 = GGG, 11 = AAA, 101 = EEE, 1 = TTT); print Dumper \%file; @arr1 = sort { $file{$b} cmp $file{$a} } keys %file; #the oldest entry lies at

Re: Hash Sorting Problem

2008-02-25 Thread Anirban Adhikary
Dear List I need to delete each element after every execution of the foreach loop and I need to update sorted the @arr1 after every execution of the foreach loop. I have tried a lot but not able to do this Pls help... Thanks Regards Anirban Adhikary On Mon, Feb 25, 2008

Re: Hash Sorting Problem

2008-02-25 Thread MK
On 02/25/2008 04:32:42 AM, Anirban Adhikary wrote: - Dear List - - I need to delete each element after every execution of the foreach - loop and - I need to update sorted the @arr1 after every execution of the - foreach - loop. I have tried a lot but not able to do this Pls -

Re: Hash Sorting Problem

2008-02-25 Thread Chas. Owens
On Mon, Feb 25, 2008 at 4:32 AM, Anirban Adhikary [EMAIL PROTECTED] wrote: Dear List I need to delete each element after every execution of the foreach loop and I need to update sorted the @arr1 after every execution of the foreach loop. I have tried a lot but not able to do this

hash containing a hash, sorting keys help

2007-05-05 Thread Ken Foskey
I cannot get the syntax right for child lookup, Data::Dumper confirms that I have the structure as I expect (logic may be totally wrong though). I going to do a webpage pstree command. foreach my $child (sort keys( $parent{$pid} )) { dump_process( $child ); } Type of arg 1 to

Re: hash containing a hash, sorting keys help

2007-05-05 Thread yaron
/Jerusalem שבת 5 מאי 2007 Subject: hash containing a hash, sorting keys help I cannot get the syntax right for child lookup, Data::Dumper confirms that I have the structure as I expect (logic may be totally wrong though). I going to do a webpage pstree command. foreach my $child (sort keys( $parent

Re: hash containing a hash, sorting keys help

2007-05-05 Thread Rob Dixon
Ken Foskey wrote: I cannot get the syntax right for child lookup, Data::Dumper confirms that I have the structure as I expect (logic may be totally wrong though). I going to do a webpage pstree command. foreach my $child (sort keys( $parent{$pid} )) { dump_process( $child ); }

Re: hash containing a hash, sorting keys help

2007-05-05 Thread Tom Phoenix
On 5/5/07, Ken Foskey [EMAIL PROTECTED] wrote: foreach my $child (sort keys( $parent{$pid} )) { dump_process( $child ); } Type of arg 1 to keys must be hash (not hash element) at ./visualise.cgi line 46, near } ) That's saying that you're giving the keys() operator a hash

Re: hash containing a hash, sorting keys help

2007-05-05 Thread Ken Foskey
On Sat, 2007-05-05 at 07:19 -0700, Tom Phoenix wrote: On 5/5/07, Ken Foskey [EMAIL PROTECTED] wrote: foreach my $child (sort keys( $parent{$pid} )) { dump_process( $child ); } Type of arg 1 to keys must be hash (not hash element) at ./visualise.cgi line 46, near } )

hash sorting

2003-12-14 Thread B. Rothstein
I have a hash where each key is a first name linked to a last name, any suggestions on how to loop through the hash to sort the list by the last names? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: hash sorting

2003-12-14 Thread Randy W. Sims
On 12/15/2003 3:17 AM, B. Rothstein wrote: I have a hash where each key is a first name linked to a last name, any suggestions on how to loop through the hash to sort the list by the last names? Check the Perl FAQ. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail:

Re: hash sorting

2003-12-14 Thread Owen
On Mon, 15 Dec 2003 00:17:17 -0800 B. Rothstein [EMAIL PROTECTED] wrote: I have a hash where each key is a first name linked to a last name, any suggestions on how to loop through the hash to sort the list by the last names? Something like this perhaps? #!/usr/bin/perl -w use strict; my

hash sorting

2003-01-10 Thread Yacketta, Ronald
Can some please help here :) I have the following sub dbMonthlySelect() { my $query; my $result; $query = select * from mbstats_se where STATDATE=TO_DATE('12/30/02','MM/DD/YY'); $result = doQuery($query,'dbMonthlySelect'); my $i =

RE: hash sorting

2003-01-10 Thread Timothy Johnson
Try using 'cmp' instead of '=' in your sort. Then it will sort alphanumerically. -Original Message- From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]] Sent: Friday, January 10, 2003 4:43 PM To: [EMAIL PROTECTED] Subject: hash sorting Can some please help here :) I have the following

Re: hash sorting

2003-01-10 Thread Wiggins d'Anconia
and then print them at the bottom. There should be a way to get sort to do it correctly but this escapes me at the moment... http://danconia.org -Original Message- From: Yacketta, Ronald [mailto:[EMAIL PROTECTED]] Sent: Friday, January 10, 2003 4:43 PM To: [EMAIL PROTECTED] Subject: hash sorting

Re: hash sorting

2003-01-10 Thread david
Ronald Yacketta wrote: Can some please help here :) I have the following sub dbMonthlySelect() { my $query; my $result; $query = select * from mbstats_se where STATDATE=TO_DATE('12/30/02','MM/DD/YY'); $result =

RE: hash sorting

2003-01-10 Thread Timothy Johnson
: Re: hash sorting Timothy Johnson wrote: Try using 'cmp' instead of '=' in your sort. Then it will sort alphanumerically. This does not appear to help, perldoc perlop says: Binary cmp returns -1, 0, or 1 depending on whether the left argument is stringwise less than, equal to, or greater

RE: Hash Sorting?

2002-11-10 Thread Timothy Johnson
I think you're missing the intent of the original post. The poster wanted to know how to sort on the value. Otherwise you're correct. -Original Message- From: LRMK To: Kurtis Cc: [EMAIL PROTECTED] Sent: 11/9/02 9:55 AM Subject: Re: Hash Sorting? hashes are do not need to be sorted

Re: Hash Sorting?

2002-11-09 Thread LRMK
can access values in that order eg:- #first 1 is $hash{$keylist[0]} #2 nd $hash{$keylist[1]} #n th one $hash{$keylist} - Original Message - From: Kurtis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, November 07, 2002 5:00 AM Subject: Hash Sorting? Hello all

Re: Hash Sorting?

2002-11-07 Thread david
Kurtis wrote: Hey Timothy, I couldn't get it to work...I know you can sort on keys, so I went out the cheap wayI switched the values with my keys...it's no problem because my values are unique also why not just sort on the values? foreach my $value (sort {$a = $b}

RE: Hash Sorting?

2002-11-07 Thread Timothy Johnson
;looksmart.net] Sent: Thursday, November 07, 2002 4:25 PM To: [EMAIL PROTECTED] Subject: Re: Hash Sorting? Kurtis wrote: Hey Timothy, I couldn't get it to work...I know you can sort on keys, so I went out the cheap wayI switched the values with my keys...it's no problem because my

RE: Hash Sorting?

2002-11-07 Thread david
Timothy Johnson wrote: I guess it depends on whether you want the list of keys sorted by which has the highest value or the values themselves. The most common use of this for me is when I want to sort the keys or values of a hash using a hash reference, for example if I'm calculating

RE: Hash Sorting?

2002-11-07 Thread Timothy Johnson
PROTECTED] Subject: RE: Hash Sorting? Timothy Johnson wrote: I guess it depends on whether you want the list of keys sorted by which has the highest value or the values themselves. The most common use of this for me is when I want to sort the keys or values of a hash using a hash reference

Hash Sorting?

2002-11-06 Thread Kurtis
Hello all.. Does anyone know how to sort a hash in ascending order on the value? If possible, a little example! Thanks, Kurtis

RE: Hash Sorting?

2002-11-06 Thread Timothy Johnson
){ do something... } which I think is what you want. -Original Message- From: Kurtis [mailto:kurtis;asdal.net] Sent: Wednesday, November 06, 2002 3:01 PM To: [EMAIL PROTECTED] Subject: Hash Sorting? Hello all.. Does anyone know how to sort a hash in ascending order on the value

RE: Hash Sorting?

2002-11-06 Thread Perry, Alan
'; [EMAIL PROTECTED] Subject: RE: Hash Sorting? You can use the longer form of sort for this. You may have seen this before: my @array = sort {$a cmp $b} @unsorted; #$a and $b are default variables for the sort command. #to reverse sort, you can reverse $a and $b. You can also do this: foreach(sort

RE: Hash Sorting?

2002-11-06 Thread Timothy Johnson
Right you are. sorry. -Original Message- From: Perry, Alan [mailto:aperry;loislaw.com] Sent: Wednesday, November 06, 2002 3:17 PM To: [EMAIL PROTECTED] Subject: RE: Hash Sorting? I think the second example should be: foreach(sort {$hash{$a} cmp $hash{$b}} keys %hash){ do something

Re: Hash Sorting?

2002-11-06 Thread Kurtis
) { $value=$hash($key); #do something.. } - Original Message - From: Timothy Johnson [EMAIL PROTECTED] To: 'Perry, Alan' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, November 06, 2002 6:17 PM Subject: RE: Hash Sorting? Right you are. sorry. -Original Message