Printing a variable only if it exisits
If a variable does not exist, then printing it produces an error. There are several methods of getting around this.
- We will start by setting
$hasval
to Has a Value, and not setting$noval
- Our test line will be:
Testing ($noval) and ($hasval)
- Suppress error messages (for part or all of document) with
$OPT_verbose=-3
(not recommended!)e.g.$pushset $OPT_verbose=-3 $test $pop $OPT_verbose
$set $defaultval1=''l
results in:Testing () and (Has a Value)- Using
$if
statement, e.g. using the pattern$if $xxx||$xxx||$endif
results in:Has a Value - Inline conditional statement, e.g
Testing ($iftrue $noval $noval '') and ($iftrue $hasval $hasval '')
results in:Testing () and (Has a Value) - The preferred way using
Testing ($noval.whenunset('')) and ($hasval.whenunset(''))
results in:Testing () and (Has a Value)