Data::Dumper
examples/references/data_dumper_dump.pl
#!/usr/bin/perl use strict; use warnings; use Data::Dumper (); my $data_structure = { phones => { Foo => 123, Bar => 345, Baz => 678, } }; open my $fh, '>', 'dumped.data' or die; print $fh Data::Dumper->Dump([$data_structure], ['data_structure']); close $fh;
examples/references/data_dumper_dump.dump
$data_structure = { 'phones' => { 'Bar' => 345, 'Baz' => 678, 'Foo' => 123 } };
examples/references/data_dumper_restore.pl
#!/usr/bin/perl use strict; use warnings; my $data_structure; my $filename = 'dumped.data'; if (open my $fh, '<', $filename) { local $/ = undef; my $dump = <$fh>; eval $dump; } else { die "Could not open '$filename' $!"; } print "Foo: $data_structure->{phones}{Foo}\n"; # Foo: 123 print "Bar: $data_structure->{phones}{Bar}\n"; # Bar: 345 print "Baz: $data_structure->{phones}{Baz}\n"; # Baz: 678