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