Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2022-01-22 10:47 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (62 votes). Check out past polls.