Might help to see what format you want your config file to be in. But here's a quick hack. There might be ways to make it tighter in terms of variable scope and regex and so on, but it should work and be safe:

use strict; use warnings; no warnings 'uninitialized'; my (%cond, %func, @config, %config, $cond, $func); ### Sample function sub FUNC { print "Successful condition.\n"; } ### Config values to allow in conditions $cond{$_}++ for qw/COND1 COND2 COND3/; ### Functions that can be called upon successful condition $func{$_}++ for qw/FUNC/; ### Eliminate potential exploits, convert operators sub c_parse { return $_[0] if $cond{$_[0]}; return '&&' if $_[0] eq 'AND'; return '||' if $_[0] eq 'OR'; } ### Safe the config file, store pre-processed results for later sub c_initialize { while (<DATA>) { chomp; ($cond, $func) = split / /; $cond =~ s/[^\w\(\) ]+/ /g; $cond =~ s/(\w+)/c_parse($1)/eg; $func =~ s/\W+//g; return if !$func{$func}; push @config, [$cond, $func]; } } ### Run through config looking for successful conditions sub c_process { print "Testing conditions.\n"; for (@config) { ($cond, $func) = @$_; $cond =~ s/(\w+)/$config{$1} || 0/eg; eval "$func\(\) if $cond"; } } c_initialize(); $config{COND1} = 1; $config{COND3} = 1; c_process(); $config{COND3} = 0; c_process(); $config{COND2} = 1; c_process(); __DATA__ COND1 AND (COND2 OR COND3) FUNC

In reply to Re: Specifying multiple conditions in a config file by TJPride
in thread Specifying multiple conditions in a config file by korpenkraxar

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.