Unless you're only looking at:
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
$str = "((a=1 )or(a =2))and(((a= 3)and(a = 4))or( (a= 5)and(a= 6)))";
and not arbitrary strings of ands and ors and parens, I don't think this is the best way to go about it. I gather:
a=1
is equivialant to perl's:
a == 1 ? 1 : 0;
and you've got the value of 'a' somewhere ($a perhaps?):
which, now that I type it, might be a better way to handle it. Replace "a=1" w/ that, (maybe - slightly tested):
$str =~ s/\(\s*(\w+)\s*=\s*(\d+)\s*\)/(\$$1 == $2 ? 1 : 0)/g;
# print "$str\n";
if ( eval $str ) {
print "true\n";
} else {
print "false\n";
}
# print "$str\n";
if ( eval $str ) {
print "true\n";
} else {
print "false\n";
}
let perl do the logic/paren matching for you.
a
Andy Bach, Sys. Mangler
Internet: [EMAIL PROTECTED]
VOICE: (608) 261-5738 FAX 264-5030
"If you don't say anything, you won't be called on to repeat it"
Calvin Coolidge
Internet: [EMAIL PROTECTED]
VOICE: (608) 261-5738 FAX 264-5030
"If you don't say anything, you won't be called on to repeat it"
Calvin Coolidge