Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Logic expression evaluation not working. What am I doing wrong?

by mr_ron (Chaplain)
on Jan 04, 2016 at 16:30 UTC ( #1151843=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1151843]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-12-01 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?