Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Depends on what you mean by "right".

Something that is reasonably close to valid perl that will recreate the original data. In this case the code is just plain wrong, with or without Purity mode.

this information should be preserved otherwise certain structures would have identical output even though they're not identical.

You mean like Data::Dumper does below? (And Data::Dump::Streamer does not?)

#!perl -l use Data::Dumper; use Data::Dump::Streamer; my ($x,$y); $x=\$y; $y=\$x; my $ary=[]; $ary->[0]=\$ary->[1]; $ary->[1]=\$ary->[0]; print "No purity\n---"; print Dumper([$x,$y]); print Dumper($ary); { print "With purity\n---"; local $Data::Dumper::Purity=1; print Dumper([$x,$y]); print Dumper($ary); } print "============\nWith DDS:"; print Dump([$x,$y]); print Dump($ary); print "************\nFergals Example With Dumper:"; { my %s=('key',1); my $s=\$s{'key'}; print Dumper(\%s,$s); print Dumper($s,\%s); print "============\nWith DDS:"; print Dump(\%s,$s); print Dump($s,\%s); } __END__ No purity --- $VAR1 = [ \\$VAR1->[0], ${$VAR1->[0]} ]; $VAR1 = [ \\$VAR1->[0], ${$VAR1->[0]} ]; With purity --- $VAR1 = [ \\do{my $o}, do{my $o} ]; ${${$VAR1->[0]}} = $VAR1->[0]; $VAR1->[1] = ${$VAR1->[0]}; $VAR1 = [ \\do{my $o}, do{my $o} ]; ${${$VAR1->[0]}} = $VAR1->[0]; $VAR1->[1] = ${$VAR1->[0]}; ============ With DDS: $ARRAY1 = [ \do { my $v = 'V: $ARRAY1->[1]' }, \do { my $v = 'V: $ARRAY1->[0]' } ]; ${$ARRAY1->[0]} = $ARRAY1->[1]; ${$ARRAY1->[1]} = $ARRAY1->[0]; $ARRAY1 = [ 'R: $ARRAY1->[1]', 'R: $ARRAY1->[0]' ]; $ARRAY1->[0] = \$ARRAY1->[1]; $ARRAY1->[1] = \$ARRAY1->[0]; ************ Fergals Example With Dumper: $VAR1 = { 'key' => 1 }; $VAR2 = \$VAR1->{'key'}; $VAR1 = \1; $VAR2 = { 'key' => ${$VAR1} }; ============ With DDS: $HASH1 = { key => 1 }; $SCALAR1 = \$HASH1->{key}; $SCALAR1 = 'R: $HASH1->{key}'; $HASH1 = { key => 1 }; $SCALAR1 = \$HASH1->{key};

probably possible to write something that would reconstruct the correct sturucture but it would involve some sort of constraint solver

See Data::Dump::Streamer for a dumper that handles these things properly. DD does a single pass over its dataset, and a depth first one at that, this almost guarantees that it will get things like this wrong. These are very old bugs, first raised by merlyn years ago (see a bug report that involves the dog pound) that still havent been fixed, and frankly probably will never be fixed.


In reply to Re^5: In need of a Dumper that has no pretentions to being anything else. by demerphq
in thread In need of a Dumper that has no pretentions to being anything else. by BrowserUk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2021-03-08 10:26 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (124 votes). Check out past polls.