Jump to content

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

→‎version 2: updated DO loop to not read the file's contents into an array, used a (temporary) internal work area.
(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:
if iFID=='' | iFID=="," then iFID='REVERSEF.TXT' /*Not specified? Then use the default.*/
call lineout iFID /*close file, good programming practice*/
options noFast_lines_BIF_defaultnofast_lines_BIF_default /*an option just for Regina REXX. */
#= lines(iFID) /*#: the number of lines in the file. */
do j=# by -1 for # /*read file (backwards), from bot──►top*/
@.j=say linein(iFID, j) /*assigndisplay record contents of a record to──► arrayterminal.*/
say @.j /*display a record of the file ──► term*/
end /*j*/
call lineout iFID /*close file, good programming practice*/</lang>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.