Before re-inventing the wheel, thought I should see if the wise monks have a solution:
Consider a program with a list of matching rules for files, say:
- * => action1
- *.txt => action2
- *.tx? => action7
- fred/* => action3
- fred/*.mac => action4
- george.txt => action5
- fred/george.txt => action6
Now, consider a find-like program that traverses a directory (or otherwise gets a list of candidate files) and applies each candidate file to the ruleset, selecting zero or 1 actions.
Clearly, the user would expect the selected action to be the most specific match - which seems like "the one satisfied by using the fewest/least powerful wildcards from the selected rule"
Algorithimicly, it might be something like:
- Match file to each fule; discard if no rules match.
- Accept if exactly one rule matches
- Otherwise, assign a score to each matching rule by counting the number of characters consumed by each wildcard. Accept the rule with the lowest score
Alternatively, the apache config file rules would work, except that in this case one wants only the final action to be applied.
I would have expected that this problem has been solved many times before, but haven't seen it in CPAN or elswhere. (I'm not wedded to the exact syntax used above.) Any pointers? Any solutions?
thanks
This communication may not represent my employer's views,
if any, on the matters discussed.
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.