How can I make Data::Dumper
write a dump into a file?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With