Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Data::Dumper too noisy

by samwyse (Scribe)
on Dec 03, 2008 at 03:14 UTC ( #727576=note: print w/replies, xml ) Need Help??

in reply to Data::Dumper too noisy

How about monkey-patching Data::Dumper?
use Data::Dumper; use DateTime; use DateTime::TimeZone; use Math::BigInt; $var = { number => 1, bigint => Math::BigInt->new(), datetime => DateTime->now(), tz => DateTime::TimeZone->new( name => 'America/Chicago' ), }; $Data::Dumper::Useperl = 1; *Data::Dumper::_dump_orig = \&Data::Dumper::_dump; *Data::Dumper::_dump = sub { return "Math::BigInt->new('".$_[1]->bstr()."')" if ref $_[1] eq 'Math::BigInt'; return "rfc822('".$_[1]->strftime("%a, %d %b %Y %H:%M:%S %z")."')" if ref $_[1] eq 'DateTime'; return ref $_[1] if (ref $_[1]) =~ /^DateTime::TimeZone::/; goto &Data::Dumper::_dump_orig; }; print Dumper($var);
Running it returns this:
$VAR1 = { 'bigint' => Math::BigInt->new('0'), 'number' => 1, 'tz' => DateTime::TimeZone::America::Chicago, 'datetime' => rfc822('Wed, 03 Dec 2008 04:12:53 +0000') };
Note that most people would prefer that you subclass Data::Dumper to do the same thing, but this works if you need something quick and dirty.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://727576]
[Corion]: Hmm - I think I'm not really making friends at $work. "We" (as in $current_project) should enter some Changes into the system, and I just told the Transition Manager, who should do that or tell somebody to do that to learn the system in which they ...
[Corion]: ... should create that Change.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2017-10-23 12:05 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (279 votes). Check out past polls.