loris has asked for the wisdom of the Perl Monks concerning the following question:
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,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Avoiding if/else knots II
by shmem (Chancellor) on Aug 30, 2006 at 08:04 UTC | |
by Skeeve (Parson) on Aug 30, 2006 at 09:32 UTC | |
by shmem (Chancellor) on Aug 30, 2006 at 09:43 UTC | |
by Skeeve (Parson) on Aug 30, 2006 at 10:09 UTC | |
by shmem (Chancellor) on Aug 30, 2006 at 12:44 UTC | |
| |
|
Re: Avoiding if/else knots II
by polettix (Vicar) on Aug 30, 2006 at 09:57 UTC | |
|
Re: Avoiding if/else knots II
by Anonymous Monk on Aug 30, 2006 at 16:50 UTC |