On 04/12/2010 07:12, Jonathan Pool wrote:

I'm seeking a strategy for diagnosing a bug that seems difficult to
reduce to a simple reproducible case.

The bug is that a hash element apparently becomes undef. When used as
an argument to "split" or "index", it generates a "Use of
uninitialized value" error.

The mysterious thing about this bug is that it disappears if
irrelevant contextual changes are made to the code or the data. For
example, if a "warn" statement is inserted, or a "my $dumb =
'dumb';" statement is inserted, before the element is going to be
used, then the element does not lose its defined value. If a "use
utf8" pragma invocation is added to the existing "use encoding
'utf8'" invocation, the bug disappears. The bug also disappears if
the (approximately 20K characters long) text file whose content has
been read into the element's value is lengthened or shortened by a
few characters.

I have reproduced this under Perl 5.8.8 and 5.12.2.

It's not obvious to me how to debug something like this, because my
usual method of inserting diagnostic "warn" statements into the code
is one of the things that stop this bug from appearing. What
approach should I try?

AAre you familiar with the perl debugger? You could set an action (command 'a') to display the variable's value every time a particular source line is executed; a watch (command 'w') to trace every time it changes its value; or a conditional breakpoint (command 'b') to pause execution at a given source line if the variable is undefined.

Alternativel you could take a look at the Tie::Watch module to do a similar thing without using the debugger.

I would like to see the Perl source to be able to be more helpful to you.

- Rob

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to