in reply to Data::Dumper: What the Cabal doesn't want you to know.

Data::Dumper is not great at that. Why not use JSON or YAML instead?

  • Comment on Re: Data::Dumper: What the Cabal doesn't want you to know.

Replies are listed 'Best First'.
Re^2: Data::Dumper: serializing and deserializing
by ikegami (Patriarch) on May 30, 2023 at 21:49 UTC

    Data::Dumper isn't meant for this, but it can be done.

    use Data::Dumper qw( ); sub serializer { local $Data::Dumper::Purity = 1; local $Data::Dumper::Sortkeys = 1; # Optional, but requested local $Data::Dumper::Useqq = 1; # Optional. return Data::Dumper->Dump( [ $_[0] ], [qw( D )] ); } sub deserializer { my $D; eval( $_[0] ) or die ( $@ ); return $D; } my $text = serializer( $data ); my $copy = deserializer( $text );

    [Woops, this was supposed to be a reply to the OP.]