Re: sort hash

2011-06-23 Thread Irfan Sayed
thanks rob. it worked From: Rob Dixon To: beginners@perl.org Cc: Irfan Sayed Sent: Thursday, June 23, 2011 3:37 PM Subject: Re: sort hash On 23/06/2011 10:36, Irfan Sayed wrote: > Hi, > > i need to sort hash in descending order. > but the issue

Re: sort hash

2011-06-23 Thread Dr.Ruud
On 2011-06-23 11:36, Irfan Sayed wrote: [I need to sort a hash, but my keys are integers] Realize that all hash keys are strings. sort { $hash_fin{$b} <=> $hash_fin{$a} } keys %hash_fin You were almost there: sort { $b <=> $a } keys %hash_fin The <=> operator is numeric, so casts it

Re: sort hash

2011-06-23 Thread Rob Dixon
On 23/06/2011 10:36, Irfan Sayed wrote: > Hi, > > i need to sort hash in descending order. > but the issue is , in hash, i have key as integer value and the value > associated with that key is string > > so when i do sort it does not really sort the hash on the key level > > > i used follwoing

Re: sort hash in Data::Dumper

2010-06-20 Thread Chas. Owens
On Sun, Jun 20, 2010 at 04:41, philge philip wrote: > hi > > can someone tell me how i can sort by keys from a hash (huge data) stored > using Data::Dumper? snip Data::Dumper can be configured through the use of its package variables (or methods if you are using the OO version). For instance:

Re: sort hash in Data::Dumper

2010-06-20 Thread Shlomi Fish
On Sunday 20 Jun 2010 11:41:42 philge philip wrote: > hi > > can someone tell me how i can sort by keys from a hash (huge data) stored > using Data::Dumper? > You need to do: [code] my @keys = sort { $a cmp $b } keys(%hash); [/code] Is it causing a memory overflow? Regards, Shlomi Fi

Re: sort hash with an array as the value

2010-05-11 Thread Shlomi Fish
Hi Owen, On Tuesday 11 May 2010 14:10:49 Owen wrote: > I have this statement; > > foreach my $key ( keys %filehash ) { > print "$key $filehash{$key}->[0]\t\t\t$filehash{$key}->[3]\t > $filehash{$key}->[2]\t $filehash{$key}->[1]\n"; > } > > but wish to sort the output by $filehash{$key}->[0].

Re: sort %hash by key

2009-12-07 Thread Shawn H Corey
Robert Wohlfarth wrote: > On Mon, Dec 7, 2009 at 10:29 PM, wrote: > >> I'm fairly new to perl but loving it. I've run into some trouble though... >> Trying to sort a hash by it's key value, which is not a problem by itself; >> >> foreach(my $key (sort keys %channels)) { >>print $key; >> }

Re: sort %hash by key

2009-12-07 Thread Robert Wohlfarth
On Mon, Dec 7, 2009 at 10:29 PM, wrote: > I'm fairly new to perl but loving it. I've run into some trouble though... > Trying to sort a hash by it's key value, which is not a problem by itself; > > foreach(my $key (sort keys %channels)) { >print $key; > } > > What I've been struggling wit

RE: Sort hash by values

2001-06-18 Thread David Gilden
Thanks for all who helped with my Perl coding, I thought some folks here might benefit from me posting the final code I used on a current project: ---snip--- if ($sort_order == 1) { # sort by name (front part of the key) foreach my $key (sort {lc($a) cmp lc($b)} keys %index){ &print_ta

RE: Sort hash by values

2001-06-14 Thread Wagner-David
[EMAIL PROTECTED] Subject: RE: Sort hash by values Use of keys, map and sort (untested) foreach my $subject (sort {lc($a) cmp lc($b)} map {[ $_, $subjects{$_}]} keys %subjects){ printf "%-40s: %-s\n", $subjects{$subject->[0]}, $subject->[0]; } Wags ;) -Original Message- F

RE: Sort hash by values

2001-06-14 Thread Wagner-David
Use of keys, map and sort (untested) foreach my $subject (sort {lc($a) cmp lc($b)} map {[ $_, $subjects{$_}]} keys %subjects){ printf "%-40s: %-s\n", $subjects{$subject->[0]}, $subject->[0]; } Wags ;) -Original Message- From: David Gilden [mailto:[EMAIL PROTECTED]] Sent: Thursday, J