Re: The mystery of the missing (compound) variables.
- From: phillips_js@xxxxxxxxxxx
- Date: Sun, 11 May 2008 05:01:48 -0700 (PDT)
On May 10, 5:34 pm, Pit Zyclade <p...@xxxxxxxx> wrote:
Gordon Snider schrieb:
On Wed, 7 May 2008 11:54:29 UTC, Pit Zyclade <p...@xxxxxxxx> wrote:
phillips...@xxxxxxxxxxx schrieb:
...
So I use a text file with a max 50 records as a number all alone on
its line (so I can recover it as a number) and a following space-
separated text string line which can be PARSEd. Code snippet:
IF STREAM(file,"C","QUERY EXISTS")\="" THEN DO
CALL STREAM file,"C","OPEN READ"
rec_num = 0
DO FILELN = 1 TO 50
IF STREAM(file,"S")\="READY" THEN
LEAVE
ln = LINEIN(file)
IF LEFT(ln,1) > 0 THEN DO
....
....
....
The DO instruction opens a loop that initializes the control variable
FILELN to 1 and sets a
limit of 50 passes through the loop. This will stop reading files
greater
than 50 records, leaving the file OPEN and READY, and will pass
control
to the second last END clause.
The next IF instruction tests the STATE of the open file to see if it
is not equal
to 'READY'. The most likely reason for the STATE being not equal to
READY is
a NOTREADY condition due to END-OF-FILE. In the event of a STATE
other than READY the THEN LEAVE clause passes control to the second
last
END clause and the file is CLOSED with the CALL STREAM.
This clause would catch any files that had fewer than 50 records.
It would not catch any files that had exactly 50 or more records
because the control
variable of the DO loop (FILELN) would end looping after the 50th pass
and
send control to the second last END clause. The IF STREAM instruction
test for 'READY' would not be executed.
....
....
....
What happens by STRAEM(file,’S’)\=”READY” ???
I have tested in in my environment (WinXP, Rexx r4 from
KilowattSoftware) with a datfile “test.txt” structure:
line 1: several numbers separated with a blank
line 2: only one number
line 3: text without “-delimiters
line 4: pure blank
line 5: text with “-” as a string
line 6: only one digit.
My test program:
file="test.txt"
IF STREAM(file,"C","QUERY EXISTS")\="" THEN DO
CALL STREAM file, 'C' , "open read"
SAY "file "file" is open yet"
END
DO ln = 1 TO 50
SAY ln
a = LINEIN(file)
SAY a
rc=STREAM(file,"S")
SAY rc
END
The result demonstrates a correct listing of the lines 1 to 6,
then following by blank lines and
50 “READY”s !
Therefore, IF LINES(file)>0 or/and IF DATATYPE(left(a,1)\=”N” are better
statements for differentiation as STREAM(file,”S”).
Pit
Greifswald,Germany- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Well, it seems I should have been much more EXPLICIT in describing the
mystery !
/* REXX - Code to read file */
file = 'mydata.dat'
IF STREAM(file,"C","QUERY EXISTS")\="" THEN DO
CALL STREAM file,"C","OPEN READ"
rec_num = 0
DO FILELN = 1 TO 50
IF STREAM(file,"S")\="READY" THEN
LEAVE
ln = LINEIN(file)
IF LEFT(ln,1) > 0 THEN DO
rec_num = rec_num + 1
array1.rec_num = ln
SAY "Rec Num "rec_num array1.rec_num
END
ELSE DO
PARSE VALUE ln WITH " "array2.rec_num" "array3.rec_num"
"array4.rec_num
/* displays records correctly */
SAY array2.rec_num array3.rec_num array4.rec_num
END
END
CALL STREAM file, "C", "CLOSE"
END
/* following line displays all records correctly EXCEPT for */
/* the LAST record */
SAY array2.rec_num array3.rec_num array4.rec_num
/********** End of Code ************/
As I stated the 'mydata.dat' file is "a text file with a max 50
records as a number all alone on its line (so I can recover it as a
number) and a following space-separated text string line which can be
PARSEd." A 3-record text file is shown below:
23
<SP>array2.1<SP>array3.1<SP>array4.1
12
<SP>array2.2<SP>array3.2<SP>array4.2
57
<SP>array2.3<SP>array3.3<SP>array4.3
So I used the space delimiters <SP> to make sure LEFT(ln,1) and the
PARSE template would truely differentiate the lines in the file. It
turned out that LEFT(ln,1) > 0 didn't do a good job and
DATATYPE(LEFT(ln,1)) == "NUM" would have been much more robust.
Regardless, this didn't solve the mystery.
It seems that what I thought was the end of file was not, and the
exit:
IF STREAM(file,"S")\="READY" THEN
LEAVE
wasn't being triggered before the test LEFT(ln,1) > 0 failed, and some
end-of-file fragment was PARSEd to result in null array2.rec_num,
array3.rec_num, array4.rec_num members.
Anyway I fooled around with it, ensuring the file was truely truncated
at the last record etc., and found that replacing the PARSE line with
PARSE VALUE LINEIN(file) WITH " "array2.rec_num" "array3.rec_num"
"array4.rec_num
solved the problem.
Pit, Gordon, I really don't know why the mystery exists and I can only
guess why the substitute PARSE statement works. It may be a bug in the
Enterprise Alternatives flavor of REXX, who knows ?
"End Of Line"
.
- Follow-Ups:
- Re: The mystery of the missing (compound) variables.
- From: Gordon Snider
- Re: The mystery of the missing (compound) variables.
- From: Pit Zyclade
- Re: The mystery of the missing (compound) variables.
- References:
- The mystery of the missing (compound) variables.
- From: phillips_js
- Re: The mystery of the missing (compound) variables.
- From: Pit Zyclade
- Re: The mystery of the missing (compound) variables.
- From: Gordon Snider
- Re: The mystery of the missing (compound) variables.
- From: Pit Zyclade
- The mystery of the missing (compound) variables.
- Prev by Date: Re: The mystery of the missing (compound) variables.
- Next by Date: Re: The mystery of the missing (compound) variables.
- Previous by thread: Re: The mystery of the missing (compound) variables.
- Next by thread: Re: The mystery of the missing (compound) variables.
- Index(es):
Relevant Pages
|