I can think of two ways to go. One is writing a parser for your rule language. You have operators, precedence and grouping, and you'll learn a lot by doing that brain excercise.

The quick way - but maybe not the best: reformat your rules on the fly until they are valid perl, and eval them (you wrote "write a new package" which you would then use, but that's just the same - the underlying inclusion mechanism is a string eval). Roughly something like this:

my %hash = ( genre => 'Rap', artist => 'Mozart', ); sub genre () { $hash {'genre'} } sub artist () { $hash {'artist'} } sub album () { $hash {'album'} } my $file = 'some_file.mp3'; $_ = "RULE = (genre eq Rap or genre eq HipHop) and artist ne RunDMC to + /music/Other"; if(s/^RULE\s*=\s*//) { my ($cond, $target) = split /\s+to\s+/, $_; eval $cond and print "rename $file, $target/$file\n"; }

Of course you must make sure your rules don't look like

RULE = (genre eq Rap or genre eq HipHop) and artist ne RunDMC to `rm - +r /music/Other`
i.e. you will have to sanitize your rules, and you'll probably run with -T (taint checks on).

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: file routing by shmem
in thread file routing by former33t

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.