Perl: Can you check if a string is a boolean expression?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

GTM
Posts: 90
Joined: Tue Nov 10, 2009 4:53 am UTC

Perl: Can you check if a string is a boolean expression?

Postby GTM » Thu Sep 04, 2014 7:36 pm UTC

Follow up to something I asked a long time ago: viewtopic.php?f=11&t=106675

So eval works to evaluate boolean strings in Perl. is there an existing way to check if a string is a simple boolean expression (ie just strings and eqs and ==s and ||s and such) so I don't end up eval-ing random code?

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Perl: Can you check if a string is a boolean expression?

Postby ahammel » Thu Sep 04, 2014 8:14 pm UTC

I doubt that there's a built in method. You'd have to cook up a regex-based method, or just write a simple logical expression compiler and don't use Eval at all.

What are you making?
He/Him/His/Alex
God damn these electric sex pants!

GTM
Posts: 90
Joined: Tue Nov 10, 2009 4:53 am UTC

Re: Perl: Can you check if a string is a boolean expression?

Postby GTM » Thu Sep 04, 2014 8:20 pm UTC

A parser that reads files, and sometimes there are lines in the file that indicate to read the next few lines if it evaluates to true.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 11 guests