Sadly, I can't comment on much here except for some stylistic issues. And I'll chip in these two bits, just because this is what struck me as I looked at this code and recalled both my own experiences with similar things and some reading I've been doing lately on the practice of programming. Of course, this script was probably written quickly for a specific purpose, and I don't doubt that it works well. But if it comes time to change this in a few months, or if someone else is going to adapt it or use it, the structure of the code is going to be an obstacle.
The deeply nested "if-else" and looping structures do a lot to obscure the logic behind this program. In more than one instance there is an "if" followed by another "if", neither of which takes an "else" case. It is much clearer in these case to use an "and". Likewise, many of the condition branchings could be probably be eliminated by similarly using "and" and "or" instead of nesting.
Following this thought, I've also got a bias towards moving functionality into smaller routines of 5-25 lines and calling those from within branches and loops as much as possible. This assists the reader in understanding the code more than it assists the machine in being fast, but this is Perl, so speed is not our primary concern. Done this way, each level of routine reads quickly (like an outline) and I don't need to keep mental track of any more details than necessary. It may eventually mean less work for the programmer as well, since the functions will be easier to test in isolation... and comments become almost unneeded-- the code becomes self-documenting.
Again, these are just my thoughts, and I don't want to seem overly critical. I find myself programming this way all the time for shorter scripts, but it seems like taking a few minutes to do some higher level planning, even writing pseudocode for the main body of the program, can often save some real headaches when the script starts to get bigger than the screen (and more likely, starts to get bigger than my brain can manage to keep track of).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||