How to use parse arg

[Autolink] Menu

(see also Parameters for a REXX program)

To many new REXX users it's not clear when to use parse arg1, arg2, arg3 and when to use parse arg1 arg2 arg3

The simplest answer is:

parse arg1 arg2 arg3 is only used for parsing the parameter passed to a REXX program.

In every other case (internal and external REXX routines routines from DLLs, routines from within the macro space) you should use parse arg1, arg2, arg3

 
/* sample program to show the difference between parse arg            */
/* with and without commas                                            */

                    /* get our name                                   */
  parse source . . thisProgram

  if arg(1) = "" then
  do
    say "Now calling this program as an external program"
    say "(This is the same as if you call it in an OS/2 window)"

    cmdLine = thisProgram 'test1, test2, test3, test4,test5'
    say "==>> " cmdline
    'cmd /c ' cmdLIne
    say ""
    say "Now calling this program as an external procedure"
    rexxlIne =  'call ' fileSpec( 'N', thisProgram ) "test1, test2, test3, test4,test5"
    say "==>> " rexxline
    interpret rexxline

    exit
  end /* if */

  say '  The result of "parse arg1, arg2, arg3, arg4, arg5" is'
  parse arg arg1, arg2, arg3, arg4, arg5
  say '    arg1 is "' || arg1 || '"'
  say '    arg2 is "' || arg2 || '"'
  say '    arg3 is "' || arg3 || '"'
  say '    arg4 is "' || arg4 || '"'
  say '    arg5 is "' || arg5 || '"'

  say '  The result of "parse arg1 arg2 arg3 arg4 arg5" is'
  parse arg arg1 arg2 arg3 arg4 arg5
  say '    arg1 is "' || arg1 || '"'
  say '    arg2 is "' || arg2 || '"'
  say '    arg3 is "' || arg3 || '"'
  say '    arg4 is "' || arg4 || '"'
  say '    arg5 is "' || arg5 || '"'
exit 0


[Back: Get the first and the last char of a string]
[Next: Optimizing REXX programs for speed]