Reverse the order of lines in a text file while preserving the contents of each line: Difference between revisions

Content added Content deleted
(Added Algol W)
(→‎version 2: updated DO loop to not read the file's contents into an array, used a (temporary) internal work area.)
Line 352: Line 352:
if iFID=='' | iFID=="," then iFID='REVERSEF.TXT' /*Not specified? Then use the default.*/
if iFID=='' | iFID=="," then iFID='REVERSEF.TXT' /*Not specified? Then use the default.*/
call lineout iFID /*close file, good programming practice*/
call lineout iFID /*close file, good programming practice*/
options noFast_lines_BIF_default /*an option just for Regina REXX. */
options nofast_lines_BIF_default /*an option just for Regina REXX. */
#= lines(iFID) /*#: the number of lines in the file. */
#= lines(iFID) /*#: the number of lines in the file. */
do j=# by -1 for # /*read file (backwards), from bot──►top*/
do j=# by -1 for # /*read file (backwards), from bot──►top*/
@.j= linein(iFID, j) /*assign contents of a record to array.*/
say linein(iFID, j) /*display record contents ──► terminal.*/
say @.j /*display a record of the file ──► term*/
end /*j*/
end /*j*/
call lineout iFID /*close file, good programming practice*/</lang>
call lineout iFID /*close file, good programming practice*/</lang>