On 10-05-16 11:17 PM, Uri Guttman wrote:
it can be used to save data (e.g. a config
file) in a file for reloading in the future (via running the dumper
output with eval).
By saving the output of Data::Dumper to a *.pm file, it can be reloaded
via "use".
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
# Set maximum depth for Data::Dumper, zero means unlimited
local $Data::Dumper::Maxdepth = 0;
use MyConfig;
our $MyConfig; # reference to a hash
sub save_config {
local $Data::Dumper::Purity = 1;
open my $cfg_fh, '>', 'MyConfig.pm' or die $!;
print {$cfg_fh} 'our ',
Data::Dumper->Dump( [ $MyConfig ], [ 'MyConfig' ] ),
"\n\n1;\n"
or die $!;
close $cfg_fh or die $!;
}
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
I like Perl; it's the only language where you can bless your
thingy.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/