Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reserved keywords

Status
Not open for further replies.

mooniron

Programmer
Dec 15, 2002
26
TR
I would like to know whether we can use a string as a reserved keyword. For example I hold "and" keyword in a variable and I want to use it in an if statement like:

if (&quot;($myX == $myY) &quot;.$ao.&quot; ($myY < $myZ)&quot;)

and here I want the interpreter to understand $ao variable as and keyword. But of course it doesn't. Is there any way to do this?
Thanks..
 
Try:

if ($ao eq &quot;and&quot;) {
if (($myX == $myY) && ($myY < $myZ)) {
do something;
}
elsif ($ao eq &quot;or&quot;) {
if (($myX == $myY) || ($myY < $myZ)) {
do something
}




Blue [dragon]

If I wasn't Blue, I would just be a Dragon...
 
if (eval(&quot;($myX == $myY) &quot;.$ao.&quot; ($myY < $myZ)&quot;)) {
might do it

HTH
--Paul
 
Yes, &quot;eval&quot; is the way to go. It takes the string you give it as an argument, and does a run-time compiliation of it. So you can change $ao at run-time and actually change the logic that is evaluated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top