Re: Read a list with undefined length



On 3/25/2011 2:15 PM, glen herrmannsfeldt wrote:
Allamarein<matteo.diplomacy@xxxxxxxxx> wrote:
When I use the READ statement, I use data file of this kind:

npts
25

x y
2 5
7 9
10 13
....

(snip)
Are branch specifiers if an error (ERR=label), end-of-file
(END=label), or end-of-record (EOR=label) condition occurs.
EOR can only be specified for nonadvancing READ statements."

Could I use this optional input for my purpose?

This has resulted in long discussions in the past.
There is no easy answer.

<snip>

My least favorite is to read the whole file counting records
but not storing data, REWIND, allocate, and read again. I am
not recommending it, but that is what some do.


No, it's not going to get any style points, but this might be the quickest and easiest way to solve the problem. Unless we're talking about files with millions of records, it will take longer to code a solution -- any solution -- than it will take to run the program. A program that takes ten minutes to write will be quicker in the end than one that takes an hour to code.

(It's the same thing that makes scripting languages like Perl so popular. Sure, they're slow, but if that fact is irrelevant to the task at hand, it's a fact that's easily forgotten.)

Louis


.