In Perl, how can I write the output of Dumper to a file?

joe picture joe · Jul 14, 2009 · Viewed 24.4k times · Source

How can I make Data::Dumper write a dump into a file?

Answer

Sinan Ünür picture Sinan Ünür · Jul 14, 2009

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