in reply to sorting not sort
Hi,
I was just wondering why you'd not use a hash in a hash? I'd propose the following:
#!/usr/bin/perl use strict; use warnings; my $string = { index1 => { index11 => 4 }, index2 => { index21 => 3 , index22 => 2 }, index3 => { index31 => 1 } }; for my $i (sort keys %$string) { my $tmp = $string->{$i}; for my $j (sort keys %$tmp) { print $i . " " . $j . " " . $string->{$i}->{$j} . "\n"; } }
index1, index2, index3 and so on are just names I made up to fill the hash with something. You can replace them with your E1's, E2's, etc... The nested for loops sort in ascending order.
The hash in a hash for gives the following output:
index1 index11 4 index2 index21 3 index2 index22 2 index3 index31 1
- Comment on Re: sorting not sort
- Download Code
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sorting not sort
by gargle (Chaplain) on Aug 29, 2005 at 08:42 UTC |