In message <[EMAIL PROTECTED]>,
Dmitry Kohmanyuk =?KOI8-R?B?5M3J1NLJyiDrz8jNwc7Ayw==?= writes:
: On Thu, Nov 29, 2001 at 06:20:37PM -0500, Michael G Schwern wrote:
:
: > Does the "read from the front and back" trick qualify as one or two
: > passes?
:
: I think there is terminology confusion here -
: a file (in Unix) is random-access array of bytes, which
: can be opened multiple times, seeked into any position (relative
: to beginning, current, or end), read and written.
:
: the entity which can be accessed only sequentally, without
: rewind or multiple opens, is called pipe (or `stream' in C++
: speak.)
Apparently I'm having trouble with precision thinking. :-(
Dmitry is understanding me best. Let me take another crack:
You have a finite sequence of unknown length, where each element in
the sequence is a string. Output the middle element of the sequence
(for a reasonable definition of middle), traversing the sequence at
most once and without storing the elements in an array.
Rather than implementing a stream and iterators or thunks, use a
file and Perl's readline operator to simulate the sequence. No
seeking, reopening, rewinding, or other sissy-such. :-)
Greg