abachus has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have a quick question :
When reading from a handle, with say sysread(), if the call returns 0 bytes read, is this a reliable indication that the handle pointer (for want of better terminology) is at EOF ?

many thanks,

Isaac.

Replies are listed 'Best First'.
Re: is 0 bytes read EOF ?
by blue_cowdawg (Monsignor) on Sep 11, 2006 at 21:26 UTC
        When reading from a handle, with say sysread(), if the call returns 0 bytes read, is this a reliable indication that the handle pointer (for want of better terminology) is at EOF ?

    This from perldoc -f sysread "There is no syseof() function, which is ok, since eof() doesn’t work very well on device files (like ttys) anyway. Use sys- read() and check for a return value for 0 to decide whether you’re done. "

    Does this answer the question?

    This by the way must be my "evil" post because it is the 666th post! BWAHAHAHAHAAHAHAHA!!!


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: is 0 bytes read EOF ?
by friedo (Prior) on Sep 11, 2006 at 21:28 UTC
    As the docs indicate, a return of zero means EOF, and a return of undef means error.
Re: is 0 bytes read EOF ?
by GrandFather (Saint) on Sep 11, 2006 at 21:30 UTC

    The documentation for sysread says that it returns 0 on EOF.


    DWIM is Perl's answer to Gödel
      Thanks monks, I just wanted to be sure, i'm putting together a bit of code with select(), i will post here when help is needed.