Over 200 lines of spaghetti code with input parsing stirred in amongst everything else in one sub. No wonder you are having trouble debugging this puppy! Some hints that may help clean things up:
- Refactor your code to move all the input parsing out of the LHCC sub then pass the parsed data into the sub. That lets you write and debug the sub without having to get the input data parsing right to start with.
- Don't use goto
- Don't use empty {} in if/elsif/else statements - they obscure the fail conditions
- Don't repeat blocks of code - use a sub. That includes the large number of places where your code dies with a long and meaningless error message. Use a sub and pass a context to be included in the message. That will both clean up the code and help with debugging logic errors.
- Don't code for stuff that can't happen (n % 2 can only be 0 or 1) to avoid cluttering the code and obscuring the logic
- Use next to "early exit" loops. That avoids nesting code and makes it easier to understand.
- Check $key (and die) before using it.
- Why my @StatementsKeys = keys %Statements; when @StatementsKeys is not used anywhere?
I'll follow up with a somewhat tided version of your code in due course, but there are a lot of lines to delete and it's taking a while! ;).
True laziness is hard work
-
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.
|