Talk:Reverse the order of lines in a text file while preserving the contents of each line

From Rosetta Code

Incredibly vague task

Once again, the master of vagarity has struck. Some details need to be hammered out for this to be a task.

  • What is a line?
    • Is it a record that ends with a 0xD character?
    • a 0xA character?
    • a 0xA 0xD digraph?
    • Is there a particular encoding that can be assumed? (ASCII?, EBCDIC?, ISO-Latin-1?, UTF8?)
    • How about binary files?
  • What is to be reversed?
    • Each record in the file?
    • The order of records in a file?
    • Both?
    • What about binary files?
  • What restrictions are there on holding the file in memory?
    • Can it be read in all at once?
    • Does it need to be processed a record at a time?
    • Does it need to be read in starting from the end of the file, proceeding to the beginning?
      • If so, should it be processed in non-record sized blocks?
      • Or a byte / character at a time? (Which circles back around to encoding.)

Every single one of these questions will change the way the program must be written. --Thundergnat (talk) 14:34, 3 August 2021 (UTC)


I'll attempt to clarify at least one of your points.   It appears, from the   Ring   computer programming langage example,   that what is meant is to show the lines/records in reverse order,   and not change the order of the characters within each line (record).   I will also add a very small "file"   (to the task's preamble)   so that we can compare output(s) without having to show the input lines(records).     -- Gerard Schildberger (talk) 15:16, 3 August 2021 (UTC)

line/record termination

This might not be the proper forum or time to address the issue of line/record termination,   but not all operating systems terminate a line (or record) with any specific character (or characters).   That information may be contained in a meta structure,   which (may) contain the block length, record length, and type of blocking (if there is blocking), among other information.   It is (or can be) the purpose of the computer programming language (or operating system) to examine the operating system's file system and/or file structure to determine how to read/write lines/records and how they're delineated (if at all).     -- Gerard Schildberger (talk) 16:18, 3 August 2021 (UTC)

rename this task ?

Perhaps this (draft) task should be renamed to:

             Display the order of the lines of a file in reverse order 

--or--

             Display the order of the lines of a file in reverse 

... or somesuch wording.     -- Gerard Schildberger (talk) 16:30, 3 August 2021 (UTC)


re-wording of the task requirements

I hope I got the re-wording of the (draft) task's requirements such that there is little room for misinterpretation.   My first draft change could've been interpreted as the original file was to be written with the reversed order of lines/records.   Also, I don't know if I got the "where to read" the lines/records,   so I tried to generalize   (memory = storage?).   We old-timers liked to use "core",   but that referred to different century.     -- Gerard Schildberger (talk) 20:03, 3 August 2021 (UTC)