Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 684
joe Avatar asked Jul 14 '09 15:07

joe


People also ask

What does dumper do in Perl?

8.39 Data::Dumper. Converts Perl data structures into strings that can be printed or used with eval to reconstruct the original structures. Takes a list of scalars or reference variables and writes out their contents in Perl syntax.

How do I print something in Perl?

print() operator – print operator in Perl is used to print the values of the expressions in a List passed to it as an argument. Print operator prints whatever is passed to it as an argument whether it be a string, a number, a variable or anything. Double-quotes(“”) is used as a delimiter to this operator.


1 Answers

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
like image 51
Sinan Ünür Avatar answered Nov 15 '22 20:11

Sinan Ünür