Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: sorting hash of hashes

by shadowsong (Monk)
on Oct 28, 2015 at 22:56 UTC ( #1146336=note: print w/replies, xml ) Need Help??


in reply to sorting hash of hashes

Hi dilip.renkila

In addition to what Athanasius has outlined re: your inner-most foreach loop and Laurent_R re: your initial data structure, here is a snippet of code and its output to help with the syntax of sort

Code

#!/usr/bin/perl -lw use strict; my %update = ( '2' => { '25' => { 'i' => 5000025, 'o' => 5000025 }, '4' => { 'o' => 5000004, 'i' => 5000004 }, '19' => { 'i' => 5000019, 'o' => 5000019 }, '2' => { 'o' => 5000002, 'i' => 5000002 }, }, '6' => { '7' => { 'i' => 5000007, 'o' => 5000007 }, '13' => { 'o' => 5000013, 'i' => 5000013 }, } ); for my $id (sort {$a <=> $b} keys %update) { for my $index (sort {$a <=> $b} keys %{$update{$id}}) { print "$update{$id}->{$index}->{i},$update{$id}->{$index}->{o}"; } } __END__

Output

5000002,5000002 5000004,5000004 5000019,5000019 5000025,5000025 5000007,5000007 5000013,5000013

Good Luck!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1146336]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2019-05-23 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (142 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!