Arg, parse arg, command line, and ? 
Author Message
 Arg, parse arg, command line, and ?

I have not used REXX much.  Every time I go to use it I seem to have
problems deciphering the docs.

Currently, I can not seem to understand arg, parse arg, arg(), etc.  I
am using OREXX and OS/2.  I write a program, Test.cmd and invoke it like
this:

  Test some thing else

and do this in the program

  parse arg arg1 arg2 arg3

expecting to get:

  arg1 == 'some'
  arg2 == 'thing'
  arg3 == 'else'

I also expect to get:

  count = arg()
  args1 = arg( 1 )
  args2 = arg( 2 )
  args3 = arg( 3 )

  count == 3
  args1 == 'some'
  args2 == 'thing'
  args3 == 'else'

But I don't.  The documentation says, as I recall, that you do something
like "parse arg template_list" where template_list is a series of
variable names separated by blanks.

I run into similar problems trying to write subroutines.

Can someone explain this in a way easy to remember.

--
Mark Miesfeld



Mon, 08 Nov 1999 03:00:00 GMT  
 Arg, parse arg, command line, and ?

: I have not used REXX much.  Every time I go to use it I seem to have
: problems deciphering the docs.
:
: Currently, I can not seem to understand arg, parse arg, arg(), etc.  I
:
:   Test some thing else
:
: and do this in the program
:
:   parse arg arg1 arg2 arg3
:
: expecting to get:
:
:   arg1 == 'some'
:   arg2 == 'thing'
:   arg3 == 'else'

yes, that is what to expect and it will work

: I also expect to get:
:  
:   count = arg()
:   args1 = arg( 1 )
:   args2 = arg( 2 )
:   args3 = arg( 3 )
:
:   count == 3
:   args1 == 'some'
:   args2 == 'thing'
:   args3 == 'else'

No, rexx doesn't behave like this, there is no 'count'
that automatically holds the number of args from the
command line or a 'arg(#)" function that returns arg
values if you put in the position number.  Most likely
you are thinking of argc and argv in C/C++

: But I don't.  The documentation says, as I recall, that you do something
: like "parse arg template_list" where template_list is a series of
: variable names separated by blanks.

parse arg arg1 arg2 arg3     --> parse 3 space separated words
                          on the command line into arg1,2,3

parse arg arg1 arg2 arg3 .  --> puts first 3 in the proper
                                 args but dumps anything from
                                 word4 onward into the "."

another good example, I just did this in a PPP script in rexx

datestring = date('e')       /* returns DD/MM/YY  format */
parse var datestring . "/" month "/" .

the   DD(day) part falls into the '.' and is lost,
the YYyear falls into the "." at the end and I'm left
with the    month = MM (05 for May).  All I wanted
was the month.  So this is one way parse var works

Parse var              <-- parses a variable

parse arg             <--  parses command line or linein

parse linein     works a lot like parse arg

Mark



Mon, 08 Nov 1999 03:00:00 GMT  
 Arg, parse arg, command line, and ?

I'd suggest that when you have a chance you buy a good book on REXX, e.g.,
"Teach Yourself REXX in 21 Days". Meanwhile, I will attempt to explain what is
happening in the code that you posted.

        When you invoke Test with the command:
        Test some thing else

you are not passing it three arguments, but just one. Your code should give you:

 ARG1   == 'some'
 ARG2   == 'thing'
 ARG3   == ' else'
 COUNT == 1
 ARGS1 == 'some thing else'
 ARGS2 == ''
 ARGS3 == ''

Note the leading blank in ARG3. Were you to change your program to use

        parse arg arg1 arg2 arg3 .

or

        parse arg arg1 arg2 arg3 arg4

then you would get the expected value of argument 4. the general rule is that the
last variable gets all of the remaining separator characters.

As to subroutines,

        call A x y z

is not the same as

        call A x,y,z

the first passes one parameter, the second passes three.


Quote:
>I have not used REXX much.  Every time I go to use it I seem to have
>problems deciphering the docs.

>Currently, I can not seem to understand arg, parse arg, arg(), etc.  I
>am using OREXX and OS/2.  I write a program, Test.cmd and invoke it like
>this:

>  Test some thing else

>and do this in the program

>  parse arg arg1 arg2 arg3

>expecting to get:

>  arg1 == 'some'
>  arg2 == 'thing'
>  arg3 == 'else'

>I also expect to get:

>  count = arg()
>  args1 = arg( 1 )
>  args2 = arg( 2 )
>  args3 = arg( 3 )

>  count == 3
>  args1 == 'some'
>  args2 == 'thing'
>  args3 == 'else'

>But I don't.  The documentation says, as I recall, that you do something
>like "parse arg template_list" where template_list is a series of
>variable names separated by blanks.

>I run into similar problems trying to write subroutines.

>Can someone explain this in a way easy to remember.

>--
>Mark Miesfeld


     Shmuel (Seymour J.) Metz
     Systems Programmer & JOAT
     Atid/2

Any unsolicited commercial junk E-mail will will be subject to
legal action.

I mangled my E-mail address to foil automated spammers; reply to
domain os2bbs dot com user shmuel to contact me.



Tue, 09 Nov 1999 03:00:00 GMT  
 Arg, parse arg, command line, and ?


: : I have not used REXX much.  Every time I go to use it I seem to have
: : problems deciphering the docs.  <snip>
:
: yes, that is what to expect and it will work

Thanks to everyone that replied, here and in e-mail.  I have got it all
straight now.  I forgot to use commas when I was trying to use 'parse
arg' to get the arguments in a subroutine.  Then, being in a rush, I
must have gotten myself mixed up as to what was working and what wasn't.

Oh well, live and learn.  But, after all these years you would think I
would have learned.  <g>

--
Mark Miesfeld



Tue, 09 Nov 1999 03:00:00 GMT  
 Arg, parse arg, command line, and ?



Quote:
>Can someone explain this in a way easy to remember.

Try reading TRL.  It is very clear and an excellent reference.  Also
the second best selling programming book ever! (so far). --

Dave Gomberg, FormMaestro!                     http://www.jcf.com

  Help stop Internet spam! Join CAUCE:   http://www.cauce.org/



Tue, 09 Nov 1999 03:00:00 GMT  
 Arg, parse arg, command line, and ?

Quote:
> Currently, I can not seem to understand arg, parse arg, arg(), etc. I write a program, Test.cmd and invoke it like
> this:

>   Test some thing else

> and do this in the program

>   parse arg arg1 arg2 arg3

              This is your template list

Quote:
>   arg1 == 'some'
>   arg2 == 'thing'
>   arg3 == 'else'

You should get this

Quote:

> I also expect to get:

>   count = arg()
>   args1 = arg( 1 )
>   args2 = arg( 2 )
>   args3 = arg( 3 )

You already have your template list so you already know what the count
is.  From what my documentation says count is not a function that can be
used with the arg function

Quote:
>   count == 3
>   args1 == 'some'
>   args2 == 'thing'
>   args3 == 'else'

What I've done here is allow you to read in any number of command line
arguements oh and a - 1 would = your count = arg().
This may seem like the long way around the problem but I think it may
work for you in the long run to do it this way

/**/
a = 2
/*I set this varible to 2 because below I need to start my checking for
command line arguement with the second varible*/

templist = 'parse arg templist.1 templist.2'
/*This varible is for the interpret command below.  It allows me to
dynamically interpret arguement that are placed into a varible.*/

do until arguement = 1
     interpret templist
     if templist.a = '' then arguement = 1; else arguement = 2
     if arguement = 2 then a = a + 1
     if arguement = 2 then templist = templist' templist.'a
     end
/*This DO UNTIL will work no matter how many arguements you pass it.
Wether it be 1 or 100 it will still parse them all into the your
program*/

b = 0
/*Just because you need it for the DO UNTIL below

do until b = a-1
     b = b + 1
     say templist.b
     end
/*Just a little something to show you the out put*/

if you really want COUNT to equal the number of arguements passed just
change all the A varible to COUNT.

It may sound like I think you don't know what the heck you are doing but
I write like this so that anyone that is just learning that may read
this message will understand what is going on.

I hope this help you.  If you have anymore question please e-mail me
directly.  If I do not know the answer I know someone who is an expert
in REXX and he will answer any question I ask him.  I would put his
email address here but I don't think that he would appreciate it that
much.

If you have questions please e-mail me directly and I will respond like
wise.



Sat, 13 Nov 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Strangeness from the arg'ed command line

2. Pass OS/2 Command Line Arg on Exit

3. command line arg's...

4. Command Line Arg Question...

5. Command line arg in windows

6. command line arg to stand alone tcl exe

7. command line arg evaluation: who did it ???

8. Changing actual arg via intent(in) formal arg in F90

9. dynamic method addition, problem with arg=arg in lambdas (was:

10. dynamic method addition, problem with arg=arg in lambdas (was:

11. GAWK: A couple of (related) suggestions re: arg parsing

12. Rexx for OS2 with PARSE ARG and forward slashes

 

 
Powered by phpBB® Forum Software