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!
|
|---|