S
Sébastien Cottalorda
Hi all,
I encoutered a problem trying to sort a hash of hash on insertion order.
Here is the code:
#!/usr/bin/perl -w
use strict;
use Tie::IxHash;
no strict 'subs';
my %hash = ();
my %complex_hash = ();
die 'hash Tie Impossible' unless tie %hash,'Tie::IxHash';
die 'complex_hash Tie Impossible' unless tie %complex_hash,Tie::IxHash';
#======== First Part OK ======================
$hash{two} = 2;
$hash{one} = 1;
$hash{five} = 5;
$hash{three} = 3;
$hash{four} = 4;
print "$_ => $hash{$_}\n" foreach keys %hash;
print "--------------------------------------\n";
#======== Second Part not OK ==================
$complex_hash{value}{two} = 2;
$complex_hash{value}{one} = 1;
$complex_hash{value}{five} = 5;
$complex_hash{value}{three} = 3;
$complex_hash{value}{four} = 4;
foreach (keys %{ $complex_hash{value} }){
print "$_ => $complex_value{value}{$_}\n";
}
exit;
The first part is sorted correctly.
That's not the case for the second one.
If someone as a clue ?
Thanks in advance.
Sébastien
I encoutered a problem trying to sort a hash of hash on insertion order.
Here is the code:
#!/usr/bin/perl -w
use strict;
use Tie::IxHash;
no strict 'subs';
my %hash = ();
my %complex_hash = ();
die 'hash Tie Impossible' unless tie %hash,'Tie::IxHash';
die 'complex_hash Tie Impossible' unless tie %complex_hash,Tie::IxHash';
#======== First Part OK ======================
$hash{two} = 2;
$hash{one} = 1;
$hash{five} = 5;
$hash{three} = 3;
$hash{four} = 4;
print "$_ => $hash{$_}\n" foreach keys %hash;
print "--------------------------------------\n";
#======== Second Part not OK ==================
$complex_hash{value}{two} = 2;
$complex_hash{value}{one} = 1;
$complex_hash{value}{five} = 5;
$complex_hash{value}{three} = 3;
$complex_hash{value}{four} = 4;
foreach (keys %{ $complex_hash{value} }){
print "$_ => $complex_value{value}{$_}\n";
}
exit;
The first part is sorted correctly.
That's not the case for the second one.
If someone as a clue ?
Thanks in advance.
Sébastien