Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: evaling dumped cyclic structures

by valdez (Monsignor)
on Nov 27, 2002 at 16:47 UTC ( [id://216111]=note: print w/replies, xml ) Need Help??


in reply to evaling dumped cyclic structures

Set $Data::Dumper::Purity to 1:

#!/usr/bin/perl use Data::Dumper; $Data::Dumper::Purity = 1; $old = { name => "bob" }; $young = { name => "bob jr" }; $old->{child} = $young; $young->{parent} = $old; $string = Data::Dumper->Dump([$old],[qw(old)]); undef $old; undef $young; eval "$string"; $check = Data::Dumper->Dump([$old],[qw(old)]); if ($string ne $check) { print "eek!\n"; } print "\n---\n$string---\n$check\n";

Data::Dumper's man page says:

The default output of self-referential structures can be `eval'ed, but the nested references to `$VAR'n will be undefined, since a recursive structure cannot be constructed using one Perl statement. You should set the `Purity' flag to 1 to get additional statements that will correctly fill in these references.

Ciao, Valerio

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-24 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found