Hi.

The easiest solution is to remember that Tie::IxHash is just a normal class under the "tie" scenes. Yes, it defined a few "magic" methods (FETCH, STORE, etc), but it is still just a variable blessed into a class. You can use this property to create a Tie::IxHash object, freeze this object with Data::Dumper, then used the thawed Tie::IxHash object to create a new tied hash.

Something like this:

#!perl use strict; use warnings; use Data::Dumper qw(Dumper); use Tie::IxHash; tie (my %x, 'Tie::IxHash'); %x = ( 'A' => 1, 'B' => 2, 'C' => 3, ); print join "", (map { "$_ = $x{$_}\n" } keys %x), "\n"; my $x = Tie::IxHash->new(%x); my $dumped; { local $Data::Dumper::Terse = 1; $dumped = Dumper($x); } print "Dumper: $dumped\n"; undef $x; print "\$x is undef\n\n" unless $x; my $y = eval $dumped; tie (my %y, 'Tie::IxHash'); @y{$y->Keys} = $y->Values; print join "", (map { "$_ = $y{$_}\n" } keys %y), "\n"; __END__ A = 1 B = 2 C = 3 Dumper: bless( [ { 'A' => '0', 'C' => '2', 'B' => '1' }, [ 'A', 'B', 'C' ], [ '1', '2', '3' ], 0 ], 'Tie::IxHash' ) $x is undef A = 1 B = 2 C = 3

I hope that this helps.

Cheers,

-- Dave :-)


$q=[split+qr,,,q,~swmi,.$,],+s.$.Em~w^,,.,s,.,$&&$$q[pos],eg,print

In reply to Re: Tie and Data::Dumper by DaveH
in thread Tie and Data::Dumper by shemp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.