HP3000-L Archives

June 2004, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Vance, Jeff H (Cupertino)" <[log in to unmask]>
Reply To:
Vance, Jeff H (Cupertino)
Date:
Thu, 24 Jun 2004 12:29:30 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (49 lines)
> Hi, I am writing a small script that reads a number from a 
> file, increments it with one and writes it back to the file. 
> If i write this as a sequence of commands in the shell
> 
> setvar count 0
> input count <myfile
> setvar count !count+1
> echo !count >myfile

As mentioned, by default, MYFILE will live in the TEMP domain. If you
want this file to be permanent then you need to either explicitly SAVE
it, or issue a file equation which does the same.

First, you don't need to initialize count to 0. This causes count to be
treated as an integer, but the CI does not enforce strict typing and
count can easily be changed into a string. 

In fact the second line, input count <myfile, does just that. The INPUT
command creates string variable so the value of count is "1", or
whatever the number is in the file. Unless MYFILE is a variable record
width file, the value of count is probably "1   <79 blanks>"

The third line, setvar count, !count+1, works but it may have been luck.
!count causes the value of count to be inserted into the command line,
so we have:
  setvar count 1      <79 blanks> + 1
Since the CI removes unnecessary blanks it all works fine. If you had
written:
  setvar count count+1 
it would have failed with this error:
  Unexpected character found in string. (CIERR 9815)
because you are trying to add +1 to a string value. INPUT always treats
the value as a string.

Here's another way to write the script:
  input count <myfile
  setvar count ltrim(rtrim(count))
  if not numeric(count) then
     echo expected a number in MYFILE, instead got: !count
     return
  endif
  setvar count !count+1

HTH,
 Jeff Vance, vCSY

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2