[kw-pm] but i just put in a "print" statement. really!

Greg.Fenton@sybase.com Greg.Fenton at sybase.com
Wed Jun 22 05:27:22 PDT 2005

Just to be sure...have you tried removing this hack to see if the problem returns?

(I'm currently at a customer site where they can no longer repro the problem now that I had them remove the "only change we made" since hitting the problem...)

Greg Fenton
Principal Solutions Consultant
iAnywhere Solutions     http://www.ianywhere.com/

----- Original Message -----
From: kw-pm-bounces
Sent: 06/22/2005 04:46 AM
To: KW Perl list <kw-pm at mail.pm.org>
Subject: [kw-pm] but i just put in a "print" statement.  really!

  ok, this is the same thing you'd normally never believe but, i
swear, adding a simple "print" statement to a perl module for
debugging purposes suddenly made the program work.

  i have a hash with entries of the form:

	key => (reference to value hash with numerous fields)

and my subroutine accepts nothing more than a reference to the
top-level hash, and a string to search for as the value for one of the
fields in the hash that's the value corresponding to that key.
really, it's just that simple -- a "while each" loop through the hash,
for each key, get the reference to the value hash, and dereference
that to get to the field in question, then a string compare.

  however, after i initially loaded the hash and verified a number of
entries, i started searching.  the first time i looked for a
particular value, the search routine found it.

  the *second* time, however, it failed to find it, and a dump of the
hash showed, sure enough, no such entry.  whaaaa?  after much
debugging and head scratching, since the hash was fairly sizable, i
added a simple "print" statement to the top of the search routine to
print the number of keys in the hash, to see if suddenly there were
unexpectedly fewer keys, so i added the following:

  print "Currently, hash has " . (scalar keys %$href) . " elements.\n" ;

  lo and behold, suddenly the program starts to work properly.  what
the hell?  the only imaginable side effect is just taking the keys of
the hash, so i replaced that statement with:

  my @keys = keys %$href ;

and that *also* solved the problem.  so it appears that there's some
kind of side effect associated with just taking the keys of a hash.  i
don't know what else to think.

  i didn't write the rest of the surrounding code, so is it possible
that, elsewhere, a hash entry was deleted and taking the keys somehow
"cleans up" or reorganizes the hash.

  i know very well that you shouldn't mess with the keys of a hash
while iterating through it, but i don't (at first glance) see that
happening anywhere.  i'm just puzzled about what might be happening.



kw-pm mailing list
kw-pm at pm.org

More information about the kw-pm mailing list