For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2006 > Printing the output of a hash of hashes in insertion order









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Printing the output of a hash of hashes in insertion order
dsblue

2006-03-23, 6:58 pm

Hi,
Previously I have been outputting the keys of a Hash in insertion
order by using Tie::Ixhash. Does anybody know how I can output the keys
of a Hash of Hashes in insertion order?
Apologies for the basic question

Paul Lalli

2006-03-23, 6:58 pm

dsblue wrote:
> Hi,
> Previously I have been outputting the keys of a Hash in insertion
> order by using Tie::Ixhash. Does anybody know how I can output the keys
> of a Hash of Hashes in insertion order?
> Apologies for the basic question


If I understand you correctly, you basically want all the "inner"
hashes to also be IxHash's, correct? If that's true, you could do it
manually... each time you add a new hash reference to the outer hash,
tie the hash that this new reference references to the IxHash class.

Alternatively, and probably better all around, use the
Tie::IxHash::Easy module. It does exactly that for you, automatically.

Paul Lalli

Daniel

2006-03-23, 6:58 pm

dsblue schrieb:
> Hi,
> Previously I have been outputting the keys of a Hash in insertion
> order by using Tie::Ixhash. Does anybody know how I can output the keys
> of a Hash of Hashes in insertion order?
> Apologies for the basic question


Why not keep an array of references to the elements.

# untested (this machine has no perl):
$hash{FOO}->{BAR} = 'Hello World';
push @in_order, \$hash{FOO}->{BAR};

or just keep a list of the keys while creating them:
push @in_order, 'BAR';

etc.

Daniel Cutter
print chr--$g+ord for'KWVX%GUW]RP^-^Tb]2[UXa\j#'=~m$.$g;

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com