Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Evaluate arbitrary boolean expressions

by gauss76 (Scribe)
on Mar 13, 2018 at 10:57 UTC ( [id://1210797]=note: print w/replies, xml ) Need Help??


in reply to Re: Evaluate arbitrary boolean expressions
in thread Evaluate arbitrary boolean expressions

Yes, sure, but my question is how can I evaluate your variable $bool to true or false?

  • Comment on Re^2: Evaluate arbitrary boolean expressions

Replies are listed 'Best First'.
Re^3: Evaluate arbitrary boolean expressions
by roboticus (Chancellor) on Mar 13, 2018 at 11:00 UTC

    gauss76:

    if ($bool) { print "It's true\n"; } else { print "It's false\n"; }

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      OK, that's great but how can I contruct the variable $bool on the fly?

      In general I will have a function that will return values 0 and 1. I can then combine these with operators || and &&. However if I write all this to a string variable $bool the test does not work properly!

        the test does not work properly!
        use strict; use warnings; use Test::More tests => 2; my $bool; sub odd { return $_[0] % 2; } $bool = (odd(3) && !odd(4)) || (!odd(3) && !odd(1)); ok ($bool, "First call is true"); $bool = (odd(3) && !odd(5)) || (!odd(3) && !odd(1)); ok (!$bool, "Second call is false");

        "It doesn't work" is as useful to a developer as "I'm ill" is to a medic. Try to be specific. SSCCE is best.

        If you are looking at actual functions, consider just using eval, at least in the case where your input comes from a trusted source (and not from the internet).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found