[Neworleans-pm] Tie::Hash::Indexed question
B. Estrade
estrabd at mailcan.com
Tue Nov 4 09:17:14 PST 2008
I can't seem to find it via Dr. Google, and before I go to IRC or PM, I wanted to ask here.
If I use Tie::Hash::Indexed to define an ordered hash, should this apply to all hashes in a nested data structure? The following example does not propagate this to nested hashes:
#!/bin/env perl
use strict;
use Tie::Hash::Index;
tie my %test, 'Tie::Hash::Indexed';
%test = ( 1 => { a => 100,
b => 200,
c => 300, },
2 => { d => 400,
e => 500,
f => 600, },
3 => { g => 700,
h => 800,
i => 900, },
);
foreach my $key (keys(%test)) {
print "$key\n";
foreach my $ikey (keys(%{$test{$key}})) {
print " $ikey\n";
}
}
1;
__END__
The output looks like:
1
c
a
b
2
e
d
f
3
h
g
i
But I want:
1
a
b
c
2
d
e
f
3
h
i
j
And this indicates that the nested hashs are not 'tie'd. Does anyone one know if there is something I can do when 'tie'ing the root hash so that this property is passed down? If not, how would I 'tie' and anonymous hash?
And before anyone tells me that I should be using an array, note that I am writing up a test for something that doesn't required ordered keys to be expressed. I am trying to work within existing code to generate a "worst-case" hash order, and for that I need to make sure that certain keys are accessed in-order.
Cheers,
Brett
--
B. Estrade
Louisiana Optical Network Initiative
+1.225.578.1920 aim: bz743
:wq
More information about the NewOrleans-pm
mailing list