LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-01-2010, 04:46 PM   #1
newbee21
LQ Newbie
 
Registered: Dec 2010
Posts: 1

Rep: Reputation: 0
Need help to sort hash of hashes by value in perl


Hi All,

I have a hash of hashes and I need to sort this by value and write to a javascript array file..

Currently I am using the following

foreach my $key(sort { keys %{$trans{$a}} <=> keys %{$trans{$b}}} keys %transmission)
{
foreach my $role(sort {$trans{$key}{$a} cmp $trans{$key}{$b}} keys %{$trans{$key}})
{
$transrecord.="if(srchtranslist['$key'] ==null){srchtranslist['$key']=new Object();srchtranslist['$key']['$role']=\"$trans{$key}{$role}\";}else{srchtranslist['$key']['$role']=\"$trans{$key}{$role}\";}\n";
}
}
and the sorting isn't working.

Please help

Newbee
 
Old 12-21-2010, 10:04 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 134

Rep: Reputation: 30
Hi,

Can you give us the output of your $trans variable from the code below

Quote:
use Data:ump qw(dump);

dump($trans);
 
Old 12-21-2010, 07:03 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,973
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Quote:
Originally Posted by tshikose View Post
Hi,

Can you give us the output of your $trans variable from the code below

It's
Code:
use Data::Dumper qw( dump );


Cheers,
Tink
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Perl - How to store and access an array in a hash of hashes? DevonB Programming 4 07-07-2010 07:57 AM
Perl hash of hashes props666999 Programming 2 09-07-2006 04:43 AM
Using hash value as key for other hash in Perl scuzzman Programming 6 02-14-2006 05:08 PM
Passing hash of hashes as a parameter (Perl) rose_bud4201 Programming 8 04-21-2005 07:18 PM
Hash-sort like in PERL in C++ nyk Programming 4 06-11-2004 08:40 AM


All times are GMT -5. The time now is 08:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration