I recommend converting your directory structure to an XML
file. Then you can apply any one of a number of
excellent XML perl modules to the problem.
A hierarchical data structure is a natural for an XML
document. For your case it could look like this:
<data>
<sprocket_logs>
<spacely>200</spacely>
</sprocket_logs>
<cog_logs>
<cogswell>100</cogswell>
<astro>1</astro>
<maimed_a_robot />
</cog_logs>
</data>
Producing this file should be relatively easy using
File::Find to load up a data structure and one of the
XML modules for dumping the data structure.
Then you have many choices for eliminating your big
switch statement. Here are a few ideas that came to
mind; there are better ideas, also:
- Access your XML as if it were a database using DBD::AnyData.
- Create a multilevel hash from the XML with XML::Simple
or one of the SAX modules.
Make a hash of subs that perform each action that
you would have in your giant switch statement. Dispatch
these subs as you loop through the multilevel hash.
- Use XSLT to replace the perl code that generates the
existing HTML view of your directory structure.
The XML approach will be easier to maintain because the
appropriate XML tools are in wide usage and worth learning
anyway.
It should work perfectly the first time! - toma
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:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.