From: Jim Freeze Date: 2002-07-08T13:41:36+09:00 Subject: Re: How to determine EOF with sysread? On Mon, Jul 08, 2002 at 01:35:46PM +0900, Ned Konz wrote: > On Sunday 07 July 2002 08:58 pm, Jim Freeze wrote: > > Hi: > > > > How does one determine the eof when using > > sysread. The example below seems to indicate > > that using #eof? corrupts the file pointer. > > So don't use eof?. Use the EOFError that sysread raises > at the end of file: > Thanks all for the answers. Does it strike anyone as bad practice to use a rescue for control flow? I thought a more explicit test method would have been provided. Jim > buff_size = File.stat(ARGV[0]).blksize > File.open(ARGV[0]) { |f| > begin > loop { buff = f.sysread(buff_size); print buff } > rescue EOFError > print "\nDone.\n" > end > } > > > -- > Ned Konz > http://bike-nomad.com > GPG key ID: BEEA7EFE > > -- Jim Freeze If only I had something clever to say for my comment... ~