Search code examples
perldebuggingdumpdata-dumper

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?


Solution

  • 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