Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

can some elaborate the difference between sysread/read sysseek/seek

by lightoverhead (Pilgrim)
on Sep 26, 2013 at 19:12 UTC ( [id://1055883]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks

I am sort of confused about sysread/read, sysseek/seek.

It seems there is no practical difference between these functions.

Could someone enlighten me a bit? Thanks

  • Comment on can some elaborate the difference between sysread/read sysseek/seek

Replies are listed 'Best First'.
Re: can some elaborate the difference between sysread/read sysseek/seek
by davido (Cardinal) on Sep 26, 2013 at 20:21 UTC
Re: can some elaborate the difference between sysread/read sysseek/seek
by wjw (Priest) on Sep 26, 2013 at 19:40 UTC
    Have never used either, but the way I read the docs

    sysseek

    and

    sysread

    implies that one
    (seek) gets you to a place in the file measured in position units(unicode or bytes) and returns success or not,
    and the other (read)
    reads from that place for some length in position units(unicode or bytes).

    So one gets you to where you want to start, and the other returns scalar data from the start position up to the length you ask for... Hope that is helpful...

    • ...the majority is always wrong, and always the last to know about it...
    • ..by my will, and by will alone.. I set my mind in motion
      sysread() is normally used for very low level I/O.
      Normally in Perl, you shouldn't be doing that.
      This is possible, but there are buffering complications.

      read() and seek() are much more normal.
      Do not mix read, seek or sysread and sysseek together.

Re: can some elaborate the difference between sysread/read sysseek/seek
by ikegami (Patriarch) on Sep 27, 2013 at 13:11 UTC

    sysread doesn't buffer. read buffers. On the rare occasions you need unbuffered IO (e.g. you want to use select), you need to use sysread and sysseek. (As such, sysread will always return as soon as data is available, if is there is data available than requested.) The rest of the time, you want to use read and seek.

Re: can some elaborate the difference between sysread/read sysseek/seek
by vsespb (Chaplain) on Sep 27, 2013 at 13:19 UTC
    sysread could also returns errors like EINTR.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1055883]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-24 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found