perldata-dumper

How to read back a file written using Data::Dumper (but not with the default VAR naming)?


I have written a hash structure into a file using

print FILE Data::Dumper->Dump([$x], [ qw(*x) ]);

How do I read this back from file? If I use eval as shown in the following snippet, all I get is $VAR1 = undef;

local $/; $hash_ref = eval <FILE>;

Solution

  • You can use the core module Storable to do this type of task.

    use Storable;
    store \%table, 'file';
    $hashref = retrieve('file');