The first thing I'd do to make that more maintainable is refactor it all into a series of well-named minimized-coupling subroutines, no longer than 20-30 lines each, and ideally about 10 lines each. That'd also remove about 90% of the global variables, which are generally also a sign of fragile code.
The second thing I'd do is take that middle switch out of there, and capture the regularities with code, and the irregularites with data. I bet you wrote a lot of it with cut and paste, and that should always be a clue.
Let me repeat. Cut and paste is generally a clue that you're doing something wrong.
On a longer-term basis, factoring out some of that code for re-use might be useful, which would also make testing easier. But unless you're also doing some similar tasks later, that might be an expense with no payback.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||