On Wednesday 09 Jun 2010 02:43:57 sillymonkeysoftw...@gmail.com wrote: > Hi everyone, > > I'm working with some customizable data from a config file, and can't > for the life of me figure out how to test conditionals from an > external source. > Does anyone have an idea how to accomplish something like: > > my $statement = "1 < 10 and 2 > 10"; # obviously false > my $result = ($statement) ? 1 : 0; # conditional test > > Now, $result will always be true(1), because the conditional is > really, in effect, just validating that $statement is a defined > scalar, not testing the statement. > But, how can I perform an actual conditional statement on this? > What I really want is: > > (1 < 10 and 2 > 10) ? 1 : 0; >
You can opt to use string eval, but this opens up a lot of security problems. Alternatively write your own parser for a mini-language: http://perl- begin.org/uses/text-parsing/ . Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Freecell Solver - http://fc-solve.berlios.de/ God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/