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
$hasvalto 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=''lresults in:Testing () and (Has a Value)- Using
$ifstatement, e.g. using the pattern$if $xxx||$xxx||$endifresults 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)
