On Wed, 17 Jan 2001, Dave Thomas wrote:
> matz / zetabits.com (Yukihiro Matsumoto) writes:
> 
> > OK.  But unlike readlines and each, read is not fundamentally for
> > reading whole file.  What kind of method do you want?
> > 
> >   (a) exactly like:
> > 
> >         f = open(path)
> >         begin
> >           f.read(*args)
> >         ensure
> >           f.close
> >         end
> > 
> >   (b) takes no argument, to read whole file always.
> > 
> >   (c) something else.
> 
> Hi Matz:
> 
> I'd vote for 'a'.
> 

Why not 'a' _and 'b' (or does that make it 'c'?)

f.read -> read entire file
f.read(10) -> read line #10
f.read(10,30) -:> start at 10, read next 30 ( while !eof if file lenght < 30
lines) f.read(-1) -> read entire file in reverse order from end, or...
f.read(-1,30) -> read file last 30 lines of file in reverse order while !bof if
file < 30 lines

and, of course

f.read(30,10) -> start at line 30 and read lines 30, read 10 lines in revers
order

Now, some of these may be of questionable balue, some not (as in you _know_ the
frist 5 lines of each file is useless header stuff, real data starts at line 6)
 but flexibility can come in handy sometimes.

Also, until you 'learn' it, readlines is a bit confusing; should there not be a
'readline' for a line by line read?  Changing behavior would be bad for legacy
code reasons.

Anyway, just some thoughts to add to the 'confusion' :-)

Regards,

Kent Starr
elderburn / mindspring.com