Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

How To Debug

by DrHyde (Prior)
on Sep 06, 2012 at 10:23 UTC ( #992055=note: print w/replies, xml ) Need Help??

in reply to recursive algorithm

What's line 27? It's hard to tell because of the line wrapping that might have happened around the text "hydrogen bonds in this structure". Also your code is unreadable because you haven't indented it, there's no comments, and your variable names aren't meaningful (having $i and $ii is confusing), so I'm not even going to bother trying to figure it out. So what follows is pretty generic ...

How you debug this is simple: either in the debugger or using print statements, spit out the variables on line 27 and if any of them are not what you expect, then look through your code to find where they are defined (or not defined), and so on, until you find the problem.

If you *are* expecting undef variables, then you'll want to guard any against using them inappropriately. For example, if in this line:

$level--  if ($structure[$i] eq ")");

$structure[$i] may legitimately not be defined, then you should check for definedness before the comparison. Or if it's because $structure[$i] might legitimately not exist (eg if $i is beyond the end of the array) then check for existence instead of (or as well as) definedness, to prevent auto-vivification.

If you were dealing with a hash here instead of an array, I'd just point you at Tie::Hash::Vivify - one of the "interesting ways" it can auto-vivify is by dieing with a helpful message - see this for an example. But I can't see anything on the CPAN to do similar things for arrays.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992055]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2018-06-23 02:48 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.