<?xml version="1.0" encoding="windows-1252"?>
<node id="527418" title="Tie a hash of hashes?" created="2006-02-02 15:14:59" updated="2006-02-02 10:14:59">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
Hello Monks,&lt;br&gt;
&lt;br&gt;
I was wondering if anyone knows if its possible to use Tie::IxHash (or something similar) in such a way that all 

hashes retain their key order.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
My situation is this:&lt;br&gt;
&lt;br&gt;
I've got a text file that needs modifying, and it is structured remarkably similar to a hash of hashes (I just 

need to search and replace '()' with '{}' and '=' with '=&gt;'). Because of the structure, creating a hash with a 

'do' statement is very easy. The problem is, after I've performed the necessary changes, I'd like to output the 

file again in the same order. Usually when I need to preserve the key order for a hash, I use 'Tie::IxHash', but 

since I'm creating the hash of hashes from a file, I can't tie second level of hashes with 'Tie::IxHash'.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
E.g. &lt;br&gt;
Script:&lt;br&gt;
&lt;code&gt;
use Data::Dumper;
use Tie::IxHash;
tie %data, 'Tie::IxHash';

  do "File";

  $data{SomeMoreStuff}{SomeMoreData} = 'x';

  print Dumper \%data;
&lt;/code&gt;
File:&lt;br&gt;
&lt;code&gt;
%data = (
SomeStuff =&gt; {
  SomeData =&gt; 'a',
  SomeMoreData =&gt;'b',
  OtherData =&gt;'c',
},
SomeMoreStuff =&gt; {
  SomeData =&gt;'a',
  SomeMoreData =&gt; 'b',
  SomeExtraData =&gt; 'c',
  OtherData =&gt; 'd'
}
);
&lt;/code&gt;
The output looks like:&lt;br&gt;
&lt;code&gt;
$VAR1 = {
          'SomeStuff' =&gt; {
                           'OtherData' =&gt; 'c',
                           'SomeMoreData' =&gt; 'b',
                           'SomeData' =&gt; 'a'
                         },
          'SomeMoreStuff' =&gt; {
                               'OtherData' =&gt; 'd',
                               'SomeMoreData' =&gt; 'x',
                               'SomeExtraData' =&gt; 'c',
                               'SomeData' =&gt; 'a'
                             }
        };
&lt;/code&gt;
The output I want:&lt;br&gt;
&lt;code&gt;
$VAR1 = {
          'SomeStuff' =&gt; {
                           'SomeData' =&gt; 'a'
                           'SomeMoreData' =&gt; 'b',
                           'OtherData' =&gt; 'c',
                         },
          'SomeMoreStuff' =&gt; {
                               'SomeData' =&gt; 'a'
                               'SomeMoreData' =&gt; 'x',
                               'SomeExtraData' =&gt; 'c',
                               'OtherData' =&gt; 'd',
                             }
        };
&lt;/code&gt;
&lt;br&gt;
Anyone have any thoughts on how to tie the second level hashes without needing to parse the file line by line and 

tie each hash as its created?&lt;br&gt;
&lt;br&gt;
Thanks!
</field>
<field name="reputation">
2</field>
</data>
</node>
