home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / os2 / programm / 8015 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  1.6 KB

  1. Path: sparky!uunet!vnet.ibm.com
  2. From: pmuellr@vnet.ibm.com (Pat Mueller)
  3. Message-ID: <19930125.150906.802@almaden.ibm.com>
  4. Date: Mon, 25 Jan 93 17:52:01 EST
  5. Newsgroups: comp.os.os2.programmer
  6. Subject: Re: Rexx question
  7. Lines: 52
  8.  
  9. >I'm doing a little Rexx programming and came upon the following:
  10. >/* */
  11. >
  12. >line = "prpipgphptp"
  13. >
  14. >do while((n = pos("p", line)) \= 0)
  15. > line = overlay(" ", line, n)
  16. >end
  17. >
  18. >say line
  19. > ...
  20. >The output when this program is run is the following:
  21. >
  22. >prpipgphptp
  23. >...
  24.  
  25. The construct
  26.    do while((n = pos("p", line)) \= 0)
  27. while legal, probably doesn't do what you want it to.  It compares
  28. the variable "n" with the value of the pos() function call.  The
  29. resulting comparison (whose value is 0 or 1) is compared to 0.
  30.  
  31. Basically, rexx has no assignment operator that can be used within
  32. expressions (like C does).  Your second try is the way to do it.
  33.  
  34. When in doubt, insert a 'trace ?i' line at the top of your program
  35. and you'll see all the gory details of statement evaluation.  An
  36. example follows:
  37.  
  38.      4 *-* line = "prpipgphptp"
  39.        >L>   "prpipgphptp"
  40.        +++ Interactive trace.  TRACE OFF to end debug, ENTER to continue
  41.  
  42.      6 *-* do while((n = pos("p", line)) <> 0)
  43.        >L>   "N"
  44.        >L>   "p"
  45.        >V>   "prpipgphptp"
  46.        >F>   "1"
  47.        >O>   "0"
  48.        >L>   "0"
  49.        >O>   "0"
  50.  
  51.     10 *-* say line
  52.        >V>   "prpipgphptp"
  53.    prpipgphptp
  54.  
  55.  
  56. If still in doubt, comp.lang.rexx is the best place to get answers
  57. regarding rexx in general.
  58.  
  59. Patrick Mueller                  addr:  pmuellr@vnet.ibm.com
  60. IBM Cary, North Carolina         phone: 919-469-7242
  61.