Assignments

Assignments in Rexx usually take this form:

name = expression

For name, specify any valid variable name. For expression, specify the information to be stored, such as a number, a string, or some calculation. Here are some examples:

a=1+2
b=a*1.5
c="This is a string assignment. No memory allocation needed!"

The PARSE instruction and its variants PULL and ARG also assign values to variables. PARSE assigns data from various sources to one or more variables according to the rules of parsing. PARSE PULL, for example, is often used to read data from the keyboard:

/* Using PARSE PULL to read the keyboard                              */
say "Enter your first name and last name"   /* prompt user            */
parse pull response       /* read keyboard and put result in RESPONSE */
say response              /* possibly displays "John Smith"           */

Other operands of PARSE indicate the source of the data. PARSE ARG, for example, retrieves command line arguments. PARSE VERSION retrieves the information about the version of the Rexx interpreter being used.

The most powerful feature of PARSE, however, is its ability to break up data using a template. The various pieces of data are assigned to variables that are part of the template. The following example prompts the user for a date, and assigns the month, day, and year to different variables. (In a real application, you would want to add instructions to verify the input.)

/* PARSE example using a template */
say "Enter a date in the form MM/DD/YY"
parse pull month "/" day "/" year
say month
say day
say year

The template in this example contains two literal strings ("/"). The PARSE instruction uses these literals to determine how to split the data.

The PULL and ARG instructions are short forms of the PARSE instruction. See the Object Rexx: Reference for more information on Rexx parsing.