HP 3000 Manuals

Substituting Strings [ Command Interpreter Access and Variables Programmer's Guide ] MPE/iX 5.0 Documentation


Command Interpreter Access and Variables Programmer's Guide

Substituting Strings 

Variables are dereferenced from left to right.  Their values are
substituted by the CI before the command is parsed or executed.  String
variables and constants can be concatenated to create a new string.
Variables and strings can be joined to create a new variable value.

To concatenate a string variable with a prefix, place the prefix
immediately before the exclamation point for the variable.  If spacing is
desired, the appropriate number of blanks must be inserted between the
two values.

In the following example, the ECHO command is used to display a string
made up of a string literal and the value of a variable that was set in a
previous example.  Note that the ECHO command requires explicit
dereferencing to display the contents of a variable.

     :ECHO GRADUATE: !CM_LAST_NAME
     GRADUATE: SMITH

If a dereferenced variable is enclosed in quotation marks, any
dereferencing within the quotation marks is performed first.  The
following example demonstrates the difference between string substitution
sequences.

     :SETVAR VAR1 "ABC"
     :SETVAR VAR 'hello'
     :SETVAR A 1
     :ECHO !VAR!A
     hello1
     :ECHO !"VAR!A"
     ABC

The first ECHO command is dereferenced from left to right.  The value of
the variable VAR (hello) is concatenated with the value of the variable A
(1).  No space was inserted between the two variables.

Since VAR!A in the second ECHO command is enclosed in quotes, the A is
dereferenced first.  The result, the variable name VAR1, is then
dereferenced to its value ABC.

Variables can be loaded with a string value composed of other variables
and strings.  It is important to remember that the type of variable is
defined by the data loaded into it.  String data must be enclosed in
quotes to define its type.  In this way, explicit or recursive
dereferencing must be performed to differentiate between variable names
and strings.  The following example creates a single variable for a name
by combining the contents of the first and last name variables.

     SETVAR CM_NAME  "!CM_FIRST_NAME !CM_LAST_NAME"
     SHOWVAR CM_NAME
     CM_NAME = CAROL SMITH

Expressions can also be used to set a variable value.  The following
example uses an algebraic equation to create the same result as in the
previous example.

     :SETVAR CM_NAME  CM_FIRST_NAME + " " + CM_LAST_NAME
     SHOWVAR CM_NAME
     CM_NAME = CAROL SMITH

Note that the string " " was added to the equation to maintain the proper
spacing.  Without this, adding the two variables would have concatenated
the variable values.



MPE/iX 5.0 Documentation