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 retrieves command line arguments. PARSE VERSION retrieves the information about the version of the REXX interpreter being used. There are several other data sources that PARSE can access.
The most powerful feature of PARSE, however, is its ability to parse data according to a template that you supply. 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 the above example contains two literal strings ('/'). The PARSE instruction uses these literals to determine how to split up the data.
The PULL and ARG instructions are short forms of the PARSE instruction. See the Object REXX Reference for lots more on REXX parsing.