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

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-12-20 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls