Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

nested unbless of Data::Dumper output

by coke4all (Novice)
on Mar 20, 2013 at 09:54 UTC ( #1024487=perlquestion: print w/ replies, xml ) Need Help??
coke4all has asked for the wisdom of the Perl Monks concerning the following question:

Hi there,

iv the following problem. Ive created a nested Object Oriented Moose Object '$X' which consists itself of further Sub-Objects. One of the Sub-Objects '$y' is placed more than once within '$X'.

My aim now is to print out a PLAIN representation of the object '$X'.

At the moment i do this with:

my $plain = Dumper(unbless($X));

Generally this works, but the problem is that ive left one reference variable '$VAR1 = {...}' in this output ($plain). The reason is that ive the Sub-Object '$y' more than once within the Object '$X'.

Does anybody know how to avoid this?

Comment on nested unbless of Data::Dumper output
Download Code
Re: nested unbless of Data::Dumper output
by Anonymous Monk on Mar 20, 2013 at 10:35 UTC

    What is the problem?

    Where do you get unbless, maybe you want circular_off?

Re: nested unbless of Data::Dumper output
by Eliya (Vicar) on Mar 20, 2013 at 11:19 UTC

    Not entirely sure I understand what you need, but if the idea is to avoid cross references being created, you might want to try $Data::Dumper::Deepcopy = 1;

    For the following sample structure, the difference in output would be

    my $y = { foo => "bar" }; my $X = { a => $y, b => $y, c => $y }; $Data::Dumper::Deepcopy = 1; print Dumper($X);
    $VAR1 = { 'c' => { 'foo' => 'bar' }, 'a' => { 'foo' => 'bar' }, 'b' => { 'foo' => 'bar' } };

    while the default output (Deepcopy=0) would look like

    $VAR1 = { 'c' => { 'foo' => 'bar' }, 'a' => $VAR1->{'c'}, 'b' => $VAR1->{'c'} };

      Thanks, this is exactly what i needed!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1024487]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-12-20 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls