http://qs1969.pair.com?node_id=1228300


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 }; } }