Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: load a module or another: Dumper or dd

by haukex (Bishop)
on Jan 10, 2019 at 09:46 UTC ( #1228300=note: print w/replies, xml ) Need Help??


in reply to load a module or another: Dumper or dd

As an alternative, here's something I regularly use some variation of (Update: examples: 1, 2, 3) to output strings or other small data structures as part of my debug output:

sub pp { die "bad number of args to pp" unless @_==1; return Data::Dumper->new([shift])->Terse(1)->Purity(1)->Useqq(1) ->Quotekeys(0)->Sortkeys(1)->Indent(0)->Pair('=>')->Dump; }

As for your question of wanting to load either one or the other module, here's an example of how I would have done it - with this, you can always use dd, no matter which module is available, although of course the output will look different:

BEGIN { if ( eval { require Data::Dump; 1 } ) { Data::Dump->import('dd'); } else { require Data::Dumper; *dd = sub { print Data::Dumper->new(\@_)->Purity(1) ->Useqq(1)->Quotekeys(0)->Sortkeys(1)->Dump }; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1228300]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2021-07-29 02:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?