Search code examples
perldebuggingpretty-print

How can I use perl debuggers pretty print for a hash in normal program code?


In Perl debugger you can very nice output a hash like:

  DB<1> x \%my_hash

How can I use the debugger output method 'x' in my programm to log pretty formated hash data in my logfile?


Solution

  • Use Data::Dumper. It is a core module, so no installation required. It is a good debugging tool.

    use Data::Dumper;
    
    ...
    
    print Dumper \%my_hash;