in reply to Using Data::Dumper to dump an array of hashes to a file
Here's a little demo:
use strict; use warnings; use Data::Dumper; my @aoh = ( { a => 1 } ); my $file = 'diskstats.perldata'; out( $file, \@aoh ); undef @aoh; @aoh = in( $file ); sub out { my ( $file, $aoh_ref ) = @_; open my $fh, '>', $file or die "Can't write '$file': $!"; local $Data::Dumper::Terse = 1; # no '$VAR1 = ' local $Data::Dumper::Useqq = 1; # double quoted strings print $fh Dumper $aoh_ref; close $fh or die "Can't close '$file': $!"; } sub in { my ( $file ) = @_; open my $fh, '<', $file or die "Can't read '$file': $!"; local $/ = undef; # read whole file my $dumped = <$fh>; close $fh or die "Can't close '$file': $!"; return @{ eval $dumped }; }
Notes:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using Data::Dumper to dump an array of hashes to a file
by wishartz (Beadle) on Aug 14, 2008 at 17:32 UTC | |
by wishartz (Beadle) on Aug 14, 2008 at 17:37 UTC | |
|
Re^2: Using Data::Dumper to dump an array of hashes to a file
by alexm (Chaplain) on Aug 14, 2008 at 22:06 UTC | |
by kyle (Abbot) on Aug 15, 2008 at 01:21 UTC | |
by alexm (Chaplain) on Aug 15, 2008 at 07:47 UTC |