Tuesday, February 13, 2007

Keyboard Input

Like most programming and scripting languages, REXX looks at input and output as streams, or sequences of characters coming in or going out of the script. Input can be things like typing at a keyboard, reading a file, or downloading from a remote server. Output can be things like displaying on the screen, or saving to a file, or even uploading to a remote server or client.

The traditional model for a simple program is INPUT, PROCESS, OUTPUT. We talked about screen output already. Today we are discussing keyboard input.

In REXX, we can use:

  • PULL - takes user-entered data up to the first ENTER character. This input is converted to all upper case. Remember that REXX started on mainframes back when most data was upper case. It is then assigned to a variable.
  • PARSE PULL - same as PULL, except it leaves things in the original case.
#!/usr/bin/rexx
/* If not using Linux or Unix, remove these top two lines. */
/* pull-example.rex : simply shows how pull works. */
SAY "What is your name?"
PULL username
SAY "What is your address?"
PARSE PULL whereulive
SAY "Your name is" username
SAY "Your address is" whereulive
EXIT

If you type this in and save it as "pull-example.rex", you can test these things out. You will see that your name will always be fully-capitalized, while your address will keep the same upper and lower case that you enter.

In this case, we did no processing, merely spit the data back out at the user. We did not even make sure our data was clean (no unexpected input that could have negative effects on what our scripts do).

I encourage you to experiment with keyboard input and screen output in your REXX scripts. Be aware that you will soon tire of having to enter the same data repeatedly. This means that it is time for us to cover files soon.

Until next time, remember to practice REXX daily and you will soon find yourself figuring out how to do things you never thought possible.

technorati tags:

Blogged with Flock

0 comments:

Post a Comment

All comments are moderated. Your comment will show up after approval.