rovf has asked for the wisdom of the Perl Monks concerning the following question:
Assuming the code like this:
the printout will contain somewhere something likeuse Data::Dumper; my $hashref={ ...., k1 => { .... k2 => { .... kN => {...., mydata => MyClass->new(), .... }}}}; print(Dumper($hashref));
I'm looking for a way to get $hashref pretty-printed, so that the result looks like this:.... mydata => bless(..., 'MyClass') ....
Note that the original hash should not be changed, and I don't know at compile time, where the mydata key is buried inside the hash. I even don't know whether it's name really is 'mydata'. I only know that somewhere in the hash are some data of type MyClass, and these are the ones where I want to take control on how they are pretty printed..... mydata => 'MyOwnRepresentation of the MyClass instance' ....
My first idea was to set
and handle everythin in myfreezer, but as far I can see, a freeze function can only change the internals to the object to be frozen. Is it possible to find a way (without writing a new pretty-printer from scratch)?sub MyClass::myfreezer { ... } $Data::Dumper::Freeze='myfreezer'
I also had a look at Data::Dumper::Streamer, which seems to have a more flexible "Freeze", but still I don't see how this can be achieved.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fine grain control over Data::Dumper
by ig (Vicar) on May 28, 2009 at 13:39 UTC | |
|
Re: Fine grain control over Data::Dumper
by kennethk (Abbot) on May 28, 2009 at 14:18 UTC | |
by rovf (Priest) on May 29, 2009 at 11:51 UTC | |
by Bloodnok (Vicar) on May 29, 2009 at 11:42 UTC | |
by rovf (Priest) on May 29, 2009 at 09:53 UTC |