http://qs1969.pair.com?node_id=1151843


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

#from Anonymous Monk code > my %allowed = qw{ ( ( ) ) ! !! & && }; > my $finalExpr = map { $allowed{$_} || die "not allowed '$_'" } split + '', $expr;

The %allowed hash doesn't look right and it isn't, among other things because it forgets digits [0-9]. A solution along these lines might do something like using taint mode for the script and then:

print "EXPR = ",$newExpr,"\n"; # don't know how to execute shell commands without [A-Za-z] letters $newExpr =~ /^([\d\s()&|!]+)$/; printf "%b\n", eval $1; }
Ron

Replies are listed 'Best First'.
Re^3: Logic expression evaluation not working. What am I doing wrong?
by AnomalousMonk (Archbishop) on Jan 04, 2016 at 20:02 UTC
    The %allowed hash doesn't look right ...

    I would be more concerned about the map statement:

    c:\@Work\Perl>perl -wMstrict -le "my $expr = '(!(C)&T)&!Q'; my %allowed = qw{ ( ( ) ) ! !! & && C 1 T 1 Q 1 }; my $finalExpr = map { $allowed{$_} || die qq{not allowed '$_'} } spli +t '', $expr; print qq{'$finalExpr'}; " '11'


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

      I would be more concerned about the map statement:

      :D I was hoping the OP would be concerned when trying, so he can get a link to Basic debugging checklist

      Then add the missing  join '',

        The map also fails if any of  C T Q is 0. This is easily fixed, but as you say, it's always nice to try stuff.


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

Re^3: Logic expression evaluation not working. What am I doing wrong?
by Anonymous Monk on Jan 04, 2016 at 18:41 UTC

    Why would boolean logic need more than 1 and 0?

    If using %allowed all the values are already untainted