ODBiC Discussion Board


RE: OUTPUT a $variable$ without it being processed, Adrian Fitton, 02-25-2008

It's tricky, and it depends on exactly how things get processed

by Roger Harris, February 25, 2008 09:58

If you put a "\" character in front of the first "$" of a variable name, then it will not be "dereferenced" when it's encountered in a script. (The variable name without the "\" will be output.) That's useful for things like putting a variable name in the value of a hidden input in a form that you're outputting, but you don't want it evaluated when it's first output, you want it evaluated when the form is submitted. That covers a lot of cases where you just have a single variable name that you want output, but it doesn't work for the case where you do need to evaluate a variable that contains other variables that you don't want evaluated. That comes up in cases like inserting a variable with embedded variable references into a database column or when you're writing a variable to an output file: You need the containing variable evaluated but you don't want those embedded variables evaluated at that point -- you want them evaluated later when the column or file is actually used. (If I'm understanding what you're doing, I think that's your requirement.) In those cases, you can use the $varstr(...) function, which outputs the specified variable without dereferencing any embedded variables.

As a simple example, if the variable $val$ contains "The value is $variableName$, etc." then $varstr(val) will output just that string without evaluating $variableName$. IMPORTANT NOTE: the $varstr(...) always takes a single variable NAME as an argument, so you should not put "$" characters around that name. (i.e. $varstr($val$) will not work in this example -- it must be $varstr(val). It's a little confusing, but $varstr($val$) will first evaluate $val$ and then the $varstr(...) function will expect to find the variable name in that value. There are occasions where that's useful, but this isn't one of them. ;0)

So, it's possible, but tricky. If you can't get it working, please email me the scripts you're using and an explanation of what you need and I can help.


Replies:


Post Your Reply:

Name   
E-mail  optional
Topic  
Message:

HTTP Link: 
Link text: 

          


Copyright ©1997-2003, Roger Harris. All rights reserved.