Read a file line by line: Difference between revisions

m
→‎{{header|REXX}}: elided hardcoded input filename versions, elided a blank line.
m (Minor spacing fix)
m (→‎{{header|REXX}}: elided hardcoded input filename versions, elided a blank line.)
Line 2,699:
 
=={{header|REXX}}==
===basic version===
<lang REXX>/*REXX program to read and display (with count) a file, one line at a time.*/
parse arg fileID .
say 'Displaying file:' fileID
 
do linenumber=1 while lines(fileID)\==0 /* loop construct */
line=linein(fileID) /* read line */
say 'Line' linenumber':' line /* show line number and line */
end linenumber /* end loop and confirm which loop */
 
say
say 'File' fileID 'has' linenumber-1 'lines.' /*summary.*/</lang>
 
===known name version===
Or: the 'known name' short version:
<lang rexx>file='foobar.txt'
do while lines(file)\==0; say linein(file); end</lang>
 
===belt and suspenders===
The first &nbsp; '''linein''' &nbsp; invocation is used to position the record pointer (current position in the file for reading)
Line 2,735 ⟶ 2,717:
say 'file ' fID " has " #-1 ' records.' /*display the record count summary. */
call lineout fID /*close the input file (most REXXes). */
/*stick a fork in it, we're all done. */</lang><br><br>
<br><br>
 
===ARexx version===
<lang rexx>/* Also works with Regina if you state OPTIONS AREXX_BIFS ; OPTIONS AREXX_SEMANTICS */
Line 2,750 ⟶ 2,730:
ELSE EXIT 20
CALL Close filehandle
EXIT 0</lang>
</lang>
 
=={{header|Ring}}==