Hi all, i am wondering if there is any way to get Data::Dumper to maintain tie() information on something that was dumped? Here is some sample code and output, demonsrating that when eval'ing a dumped string, the tie is gone.
use strict;
use warnings;
use Data::Dumper;
use Tie::IxHash;
{
tie (my %x, 'Tie::IxHash');
%x = (
'A' => 1,
'B' => 2,
'C' => 3,
);
print join "", map { "$_ = $x{$_}\n" } keys %x;
print "\n";
my $dumped;
{
local $Data::Dumper::Terse = 1;
$dumped = Dumper(\%x);
}
print "Dumper: $dumped\n\n";
my $y = eval $dumped;
print join "", map { "$_ = $y->{$_}\n" } keys %$y;
}
And here is the output:
A = 1
B = 2
C = 3
Dumper: {
'A' => '1',
'B' => '2',
'C' => '3'
}
A = 1
C = 3
B = 2
Its obvious that the problem is in the Dumper(), not the eval, because the value of $dumped does not contain any tie information, as a dumped object instance would have.
Any easy workarounds available?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.