in reply to unexpected debugging help
Looks like you've found The PerlMonks algorithm.
And also a tutorial (on database programming, but it could apply to just about everything) recommends exactly what you are saying.