Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

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

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:

  1. 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.
  2. Don't use goto
  3. Don't use empty {} in if/elsif/else statements - they obscure the fail conditions
  4. 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.
  5. 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
  6. Use next to "early exit" loops. That avoids nesting code and makes it easier to understand.
  7. Check $key (and die) before using it.
  8. 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

In reply to Re: Hash Uninitialized Values Error by GrandFather
in thread Hash Uninitialized Values Error by slinky773

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 scrutinizing the Monastery: (12)
As of 2024-04-23 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found