Rexx Programming/Example Code

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Hello World:[edit | edit source]

Code: Say "Hello World"

Output: Hello World


Uniq:[edit | edit source]

Usage: uniq < filename or cat filename | uniq


Shows that stem variables may be indexed by strings

as well as numbers. I use it as an improved version of

the unix 'uniq' program.

Code:[edit | edit source]

/* Show only one copy of each line in a whole file */

seen. = 0 /* a stem variable */

Do While Lines() > 0 /* read input lines until no more */

Parse Pull this_line /* get a line */

  If seen.this_line Then Iterate /* use the line as an index, and if seen (value of 1), loop to get next line */

  Say this_line /* If it's a previously unseen line, indicate we've now seen it */

end