Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: In need of a Dumper that has no pretentions to being anything else.

by fergal (Chaplain)
on Feb 23, 2005 at 06:22 UTC ( #433594=note: print w/ replies, xml ) Need Help??


in reply to Re: In need of a Dumper that has no pretentions to being anything else.
in thread In need of a Dumper that has no pretentions to being anything else.

My patch doesn't remove circular ref protection. Circular ref protection comes from keeping a track of all the refs we've seen so far and I've not touched that.

DD also keeps track of all scalars that it sees so that when you run this

use Data::Dumper; my %s=('key',1); my $s=\$s{'key'}; print Dumper([\%s, $s])
you get
$VAR1 = [ { 'key' => 1 }, \$VAR1->[0]{'key'} ];
that is, it was able to spot that the 1 in %s{key} is actually the same 1 that's in $s.

My patch removes this ability when $Deepcopy = 0. This is consistent with the rest of the deepcopy behaviour and means that now that the only thing that can cause a backreference to some other part of the structure is circularity.


Comment on Re^2: In need of a Dumper that has no pretentions to being anything else.
Select or Download Code
Re^3: In need of a Dumper that has no pretentions to being anything else.
by halley (Prior) on Feb 23, 2005 at 14:50 UTC
    Fair enough-- the patch doesn't give a lot of context and I didn't look at the whole. It's squirrelly code. I was just putting in a note that any quick change could break a lot of people.

    --
    [ e d @ h a l l e y . c c ]

Re^3: In need of a Dumper that has no pretentions to being anything else.
by demerphq (Chancellor) on Feb 23, 2005 at 14:54 UTC

    Note that DD only gets it right with print Dumper([\%s, $s]) but not with print Dumper([$s, \%s])

    For that you need a better dumper. I wonder if its arguable that the tracking you are talking about disabling is actually not required for Purity=0 dumps.

    ---
    demerphq

      Depends on what you mean by "right". I get
      $VAR1 = [ \1, { 'key' => ${$VAR1->[0]} } ];
      which can't be evaluated correctly by Perl's eval but it does contain all the necessary information. A human can see what's going on and it's probably possible to write something that would reconstruct the correct sturucture but it would involve some sort of constraint solver.

      Purity just controls whether it should be compatible with eval(). Even with Purity=0, this information should be preserved otherwise certain structures would have identical output even though they're not identical.

      Deepcopy controls whether we care about cross references so it definitely should be dropped when you have Deepcopy=1.

        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?)

        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.

        ---
        demerphq

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://433594]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-07-25 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (169 votes), past polls