develooper Front page | perl.perl5.porters | Postings from April 2001

Re: [ID 20010427.003] Data::Dumper is hard to use reliably

Thread Previous | Thread Next
From:
Benjamin Sugars
Date:
April 27, 2001 07:57
Subject:
Re: [ID 20010427.003] Data::Dumper is hard to use reliably
Message ID:
Pine.LNX.4.21.0104271047450.1807-100000@marmot.rim.canoe.ca
On Thu, 26 Apr 2001, Andrew Pimlott wrote:

[ ... deletia ... ]

> There's also the matter of needing to turn off strict.

[ ... deletia ... ]

> Finally, there are no examples of how to use Data::Dumper for reliable
> serialization (or at least, as reliable as feasible, with caveats about
> things like sub refs).  This is what I do:
> 
>     use Data::Dumper;
> 
>     $dumper = new Data::Dumper [ $data ];
>     $dumped = $dumper->Purity(1)->Dump;
>     ...
>     {
>         no strict 'vars';
>         local $VAR1;
>         eval $dumped;
>         die "toast: $@" if $@;
>         $data = $VAR1;
>     }

I won't address your comments about the difficulty of using
self-referential data, but the strictness can be addressed using the
two-argument form of new().

Serializing:
    my $dumper = Data::Dumper->new([ $data ], [ "data" ]);
    my $dumped = $dumper->Purity(1)->Dump;

Retrieving:
    my $data;
    eval $dumped;
    die "toast: $@" if $@;

And have you considered Storable?

Cheers,
-Ben

-- 
signer: can't create ~/.sig: Name not unique on network


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About