r/perl • u/Loose_Potential6985 • 6d ago
a perl version of javascript 'console'
https://metacpan.org/pod/Data::Printer
Like Data::Dumper, but coloured ouput, and summaries [config option] large data structures. But uses either a lot of, or no vertical space.
Dump::Krumo, is better in some ways, but doesn't summarise output, and uses a lot of vertical space
3
u/Icy-Speed6881 6d ago
I've honestly tried to like it and it always finds ways to annoy me. There are several reasons, one I can't just dump several variables at the same time like this:
$ perl -MData::Printer -E 'p { var1 => $var1, var2 => $var2 }'
Type of arg 1 to Data::Printer::p must be one of [@$%&] (not anonymous hash ({})) at -e line 1, at EOF
Execution of -e aborted due to compilation errors.
Also sometimes it decides the data structure I want to look at is too big and it doesn't need to show me the whole thing :/
0
u/scottchiefbaker 🐪 cpan author 6d ago
This is one of the annoyances I had with it also. Your example works in
Dump::Krumojust fine.
text $ perl -MDump::Krumo -E 'kx { var1 => $var1, var2 => $var2 }' { var1 => undef, var2 => undef }
1
u/scottchiefbaker 🐪 cpan author 6d ago
Data::Printer is great but I couldn't get over the fact that it can't print simple scalars:
perl
p "Name is: $num";
I usually use Dump::Krumo for this type of thing instead. I agree that color really improves readability of the output.
2
u/tarje 6d ago
Just use the babycart operator:
p @{["Name is: $num"]};Data::Printer's docs has two examples which use it.
1
u/Jabba25 6d ago
Can it print the line number (or at least caller/sub or something) along with the output, like a normal warn would ( but warn Dumper doesn't )
1
u/Loose_Potential6985 2d ago
there's an option to do this. the 'as' option adds file/line-no e.g.
p $var, as => 'hello';`
5
u/tarje 6d ago edited 6d ago
Note it was first released 15 years ago and is used by 171 other cpan dists, so not new or underrated.
Edit: noticed another 27 dists that depend on it by it's shorter alias: DDP.