Is this the kind of thing you are looking for?

#!/usr/bin/perl # http://perlmonks.org/?node_id=1210791 use strict; use warnings; sub error { die s/\G/ *** Expected @_ -->/r, "\n" } sub want { /\G\s+/gc; /\G\Q$_[1]\E/gc ? shift : error "'$_[1]'" } sub expr { my $p = shift; /\G\s+/gc; my $value = /\G(T|F)/gc ? $1 : /\G\(/gc ? want expr(0), ')' : error "Operand"; $value = /\G\s+/gc ? $value : $p <= 1 && /\G\&\&/gc ? $value eq 'T' ? expr(2) : (expr(2), 'F') : $p <= 0 && /\G\|\|/gc ? $value eq 'T' ? (expr(1), 'T') : expr(1) : return $value while 1; } while(<DATA>) { my $answer = expr(0); /\G\s*\z/ or error "Complete Parse"; print tr/\n//dr, " = $answer\n"; } __DATA__ (T && F) || (F && F) (T && T) || (F && F) (T && F) || T

Outputs:

(T && F) || (F && F) = F (T && T) || (F && F) = T (T && F) || T = T

In reply to Re: Evaluate arbitrary boolean expressions by tybalt89
in thread Evaluate arbitrary boolean expressions by gauss76

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.