Syntactic Confectionery Delight PerlMonks

### Does Data::Dumper give you eye strain? Use Test::More::is_deeply() for debugging!

by tphyahoo (Vicar)
 on Jul 20, 2005 at 09:05 UTC Need Help??

I'll keep it short today. Do you use Data::Dumper for debugging your data structures? Does it give you eye strain?

Anybody else have creative debugging tips?

• Comment on Does Data::Dumper give you eye strain? Use Test::More::is_deeply() for debugging!

Replies are listed 'Best First'.
Re: Does Data::Dumper give you eye strain? Use Test::More::is_deeply() for debugging!
by adrianh (Chancellor) on Jul 20, 2005 at 11:05 UTC

It's often useful, but you do have to bear in mind that it only looks at the basic structure of the objects, and ignores many things, e.g.:

is_deeply( {}, bless({}, 'Foo'), 'is_deeply ignores blessed' );
[download]

will pass. Test::Deep is a useful module if you're interested in some of the detail.

Re: Does Data::Dumper give you eye strain? Use Test::More::is_deeply() for debugging!
by demerphq (Chancellor) on Jul 20, 2005 at 18:39 UTC

Try using Data::Dump::Streamer instead. Its much easier to read than DD is. Also, a newly released module called Test::Struct was put together explicitly to allow for testing fine grained differences which is_deeply() will not pick up. (Actually is_deeply is horribly named, it doesnt really do a deep comparison at all.)

---
$world=~s/war/peace/g I'm not sure I quite agree that is_deeply doesn't do a deep comparison at all, though I agree that it has a quirk or two. But more to the point, what does Test::Struct offer that Test::Deep doesn't? Not meant rhetorically, I'm just curious, since they both seem to have the same basic goal. If God had meant us to fly, he would *never* have given us the railroads. --Michael Flanders I think I should leave that up to Fergal to answer, however its my understanding that what T::S does is different from what T::D does (I know for sure that the latter is considerably more flexible and attempts to solve problems that T::S doesnt and never will). Test::Struct was simply my attempt at making an is_deeply() that worked the way I expect it to. To save you reference to some very long and nasty perl-qa threads I'll simply say that as the author of the most accurate Perl Data serialization module currently on CPAN I found every other tool for testing insufficient for my purposes. Test::Struct is/was a prototype I wrote for the kind of testing I wished had been around for Data::Dump::Streamer. Some argue that this level of accuracy is only really useful for testing serialization modules but whatever. Anyway i wrote T::S just before i went on holiday (which im still on) so its in an alpha state right now, somethiong i plan to resolve when i return. ---$world=~s/war/peace/g

TS is the strictest possible comparison that doesn't involve comparing reference addresses, so if $x=[];$y=[] then TS will say that [$x,$x] is not the same as [$x,$y] because one is an array with 2 refs to 1 array and the other has refs to 2 different arrays. This is a valid difference. TD ignores this difference. TD also lets you do something a little bit like regular expressions for data structures.
Re: Does Data::Dumper give you eye strain? Use Test::More::is_deeply() for debugging!
by chromatic (Archbishop) on Jul 20, 2005 at 17:51 UTC

I use YAML's Dump() function, which doesn't eat up so much whitespace.

Good idea. I do the following but the YAML would be more terse and probably easier to read after all.

use Data::Dumper;
$Data::Dumper::Terse = 1;$Data::Dumper::Indent = 1;
[download]
Re: Does Data::Dumper give you eye strain? Use Test::More::is_deeply() for debugging!
by Forsaken (Friar) on Jul 21, 2005 at 07:27 UTC
I'll keep it short today. Do you use Data::Dumper for debugging your data structures?

Yes, indeed I do

Does it give you eye strain?

Well, just try to imagine this...I use Data::Dumper to check on all the data my irc bot has on all the people it shares channels with...and have it dump that data on me *inside* one of those irc channels. I leave it up to you to imagine what kind of mayhem that causes when I mess something up and it does it in the wrong channel ;-)

Remember rule one...

Create A New User
Node Status?
node history
Node Type: perlmeditation [id://476435]
Approved by Tanalis
Front-paged by planetscape
help
Chatterbox?
 [Discipulus]: I dunno if i can read Dumas in french.. must try some chapter to see erix . o O( "what fools the french are, Jeeves" ) [choroba]: Also some Достое́вс кий [Discipulus]: mmh windows understand something like: cd c:\\\\path\\\\to weird..

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2017-05-24 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favorite model of computation is ...

Results (183 votes). Check out past polls.