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:

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


In reply to Re: The dreaded if-elsif-else construct (code) by toma
in thread The dreaded if-elsif-else construct (code) by deprecated

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.