Building on AnonyMonk's approach above (and this actually works):

c:\@Work\Perl>perl -wMstrict -MData::Dump -le "use constant OPS => qw{ ( ( ) ) ! ! | || & && }; ;; sub compile { my ($expr, $hr_vars) = @_; ;; my %xlate = (OPS, %$hr_vars); ;; $expr =~ s{ (.) } { exists $xlate{$1} or die qq{bad: '$1' at offset $-[1] in '$expr'}; $xlate{$1}; }xmsge; ;; return $expr; } ;; my %vars = qw(Q 0 T 1 C 0); dd \%vars; ;; my $expr = '(!(C)&T)&!Q'; print qq{initial expr: '$expr'}; ;; my $final_expr = compile($expr, \%vars); print qq{ final expr: '$final_expr'}; ;; my $result = eval $final_expr; if ($@) { print qq{eval of '$final_expr' failed: $@} } else { print qq{'$final_expr' -> '$result'}; } " { C => 0, Q => 0, T => 1 } initial expr: '(!(C)&T)&!Q' final expr: '(!(0)&&1)&&!0' '(!(0)&&1)&&!0' -> '1'
Some thoughts:


Give a man a fish:  <%-{-{-{-<


In reply to Re: Logic expression evaluation not working. What am I doing wrong? by AnomalousMonk
in thread Logic expression evaluation not working. What am I doing wrong? by perl_learner_2016

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.