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
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
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
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:
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
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].
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;
>> }
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
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
[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
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
11 matches
Mail list logo