Tie::IxHash::Easy with "eval()"

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'd like to use "Tie::IxHash" to maintain the order of keys in a hash.  
Since the hash can contain other hashes (and so on), I need to use
"Tie::IxHash::Easy" so that the nested hashes also maintain their ordering.

I'm reading the entire hash from a file.  The format of the file is exactly
like Data::Dumper so that I can build the hash by simply saying:


This fails because there's no way to "tie" the internal workings of eval to
"Tie::IxHash::Easy" so it always just returns a normal hash.  Copying the
returned into an IxHash has no effect because the ordering is already lost.

So, how can I load an IxHash from a file in Data::Dumper format and
preserve its order (including nested hashes)?


Re: Tie::IxHash::Easy with "eval()"

Quoted text here. Click to load it

Using MLDBM with Tie::IxHash::Easy and the default serializer seems to
work for a single level, eg.

use MLDBM 'Tie::IxHash::Easy'
tie my %h, 'MLDBM' or die ...;
@h{qw/key1 key2 key3 /} = 1..3;
print Dumper \%h;

and for a multi-level hash, you could theoretically write and then use
a custom serialization package
to do this IIUC (see MLDBM doc.) ... eg.,

use MLDBM 'Tie::IxHash::Easy','MyIxSerializer';
use strict;
use warnings;

Charles DeRykus

Site Timeline