After having received a lot of helpful advice in the thread staring with Avoiding if/else knots, I have decided to go for the dispatch table approach. However, even though I don't really have the problem of non-integer ranges, I still don't want to have to construct a table with around, say, 60 combinations of which only around, say, 20 are distinct. So maybe "A|*|*|*" maps to Case 1, "B|A|*|*" maps to Case 2, "B|B|*|*" maps to Case 3, etc.

To get around this I thought I would just use regexps to match groups of conditions and map them onto a set of generic keys which represent the unique cases. Thus for a given case, I would dynamically create a string of delimited fields from the current conditions and then try to match certain parts of the string. In the matching case I would then set the generic key, otherwise I would try the next match. As the cases are all disjoint from the point of view of pattern matching, the order in which I do the matching is not important. Can anyone see any possible drawbacks to this approach?

Thanks,

loris


"It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ."

In reply to Avoiding if/else knots II by loris

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.