8

如何Data::Dumper将转储写入文件?

4

3 回答 3

26

Don't forget that you can specify the file handle to print to as in

print $LOG Dumper( \%some_complex_hash );

or use File::Slurp:

write_file 'mydump.log', Dumper( \%some_complex_hash );

Further thoughts: You might want to get into the habit of using:

warn Dumper( \%some_complex_hash );

and redirecting standard error to a file when you invoke your script (how you do this depends on the shell). For example:

 C:\Temp> sdf.pl 2>dump
于 2009-07-14T15:18:36.653 回答
8

The question is a bit unclear, but are you looking for something like this?

open my $FH, '>', 'outfile';
print $FH Dumper(\%data);
close $FH;

You can restore the data later by using eval.

于 2009-07-14T15:20:47.273 回答
8

使用打印

print FILE Data::Dumper->Dump($object);
于 2009-07-14T15:20:48.193 回答