Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Hash Uninitialized Values Error

by GrandFather (Cardinal)
on Dec 26, 2013 at 01:45 UTC ( #1068388=note: print w/ replies, xml ) Need Help??

in reply to Hash Uninitialized Values Error

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

Comment on Re: Hash Uninitialized Values Error
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1068388]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-07-12 16:30 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (240 votes), past polls