Not a comment on the code - just a bit of a pick-me-up for you.
- You are not crap, if you were crap you would not have use strict; or the '-w' flag set.
- We all have trouble at times with things that others take for granted. I, for example, have a Spoonerism problem. This is where you swap the first letters of two word as you are speaking. The more important it is that I don't appear stupid the more I do it. eg: "I'm as jober as a sudge, officer".
- Even the best get it wrong and can't fix it. I have a degree in physics so a friend calls me to get help with a simple maths problem. Can't do it - don't even know where to start. Brain is a complete blank. Friend hangs up and I crack it in seconds. Lods saw, as it were.
Go for a walk, kick a ball, have a cup of tea. The worst way to crack a problem is to keep trying to crack it while you know you are stuck. This is why I'm here at the monks for a bit - I too am stuck on a problem.
You're fine.
--tidiness is the memory loss of environmental mnemonics