|8.5 Variable Manipulation
A Vortex variable is denoted by a dollar sign ($
immediately followed by a name. Variable names consist of
alphanumerics, underscores, spaces or periods, and are
case-sensitive (ie. $value
variables). Except for local variables or function parameters,
variables do not need to be explicitly declared. Nor does a
variable always have to be a particular type; that is determined
when it is assigned.
Variables are automatically initialized from CGI form variables,
environment variables, and cookies on script startup; there is no
need to explicitly initialize them. A variable can be modified with
an assignment statement:
This assigns the string value "re"
to the variable
. Variables can also be set by some functions
and statements, such as <SQL>
Some variables are special and have reserved uses, such as $ret
for the return value of functions, or $loop
the iteration count in looping statements.
A variable is printed by simply giving its name with a dollar
sign in the Vortex script. If the variable name contains spaces, or
is adjacent to text not part of its name, it must be quoted to
The value of prefix is: $prefix
I $'prefix'opened the case.
The cost is $$100.
In the second line above, $prefix
is adjacent to
, so it is quoted to distinguish it from the
erroneous variable $prefixopened
. To print a literal
dollar sign, it must be escaped with two dollar signs, as in
the third line above.
As we've seen, variable values are automatically HTML-escaped
when printed, if the MIME output type is HTML.
SQL math can be used in variable assignments by enclosing the
right side in parentheses. The right side can then be just about
any valid SQL expression:
<$x = ($x + 5)> <!-- Add 5 to $x -->
<$y = ( 'my ' + ' test' )> <!-- Concatenate strings -->
<$z = (counter)> <!-- Make a new counter -->
Other assignment methods
Besides an assignment statement, variables can be set from the
result rows of a <SQL>
statement, as the return value of
builtin/user functions (eg. $ret
), or as special variables
in some circumstances.
All variables are global by default, meaning they are
visible in every function. Local variables - only visible to
a specific function or block - can be declared as well. The
most common form of these are function parameters, which we'll