Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

drhyde (1683)

drhyde
  (email not shown publicly)
http://www.cantrell.org.uk/david

Journal of drhyde (1683)

Wednesday November 10, 2004
04:39 AM

Data::Compare bugfix, or Why I'm Stupid

[ #21788 ]
Jenda found a nasty (and stupid) bug in Data::Compare, which I fixed in version 0.12. I then removed the debugging print statements in version 0.13. Damn you, evil test environment, for hiding them from me :-)

Now as to why the bug was stupid.

Data::Compare keeps track of how deeply recursed it is, so that it can yell at you if you try to compare stupidly deep structures. This is mostly so I can pre-empt perl's own warning about this, but I also think it's a good thing in its own right. To do this, whenever the Compare function is called, it increments a counter. This counter is passed to recursive invocations of Compare in a hashref.

As is good practice, as soon as my subroutine starts, I make my own local copy of all the parameters that are passed to it, eg my $foo = shift;, so that any changes are localised. So I never bothered decrementing the counter, expecting the previous value to re-appear on exit from each subroutine. Trouble is, I was making my own local copy of a reference, and not a local copy of a value. So I was getting bitten by pass-by-reference vs the effective pass-by-value you get by making local copies of your parameters.

This is especially embarrassing because one of the talks I've given (at a Linuxbierwanderung) is entitled Perl Gotchas. In which I mention pass-by-reference vs pass-by-value. Doh!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.