Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to How To Debug by DrHyde
in thread recursive algorithm by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-24 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found