in reply to sysread failure

To follow up on what brother Fletch said, sysread is really only something you'll need to use when munging a binary file. For any line-oriented file, just open the file and read it with open and the diamond operator while(<>){ .. }. And then close it, of course.

And don't worry that you have to read 8K blocks to get decent throughput -- the part of Perl that reads lines from files has had (from what I've heard) a great deal of attention paid to it over the last twenty or so years, and is probably about as fast as it could possibly be.

Also, seeing a repeated pattern in a regular expression should be a sign that there's probably a better way. Again, brother Fletch has suggested split. Try it -- I think you'll like it.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^2: sysread failure
by ikegami (Patriarch) on Aug 11, 2010 at 15:35 UTC

    sysread is really only something you'll need to use when munging a binary file.

    read is really only something you'll need to use when munging a binary file.

    sysread is only needed when you need unbuffered IO (e.g. when you use select) or when you want partial reads from pipes and sockets.

    the part of Perl that reads lines from files has had (from what I've heard) a great deal of attention paid to it over the last twenty or so years

    Actually, I heard it's quite slow, in part due to the minuscule 4k buffer. I'm not saying that reading 8k chunks and breaking them down into lines on the user side is any faster.

Re^2: sysread failure
by Anonymous Monk on Aug 11, 2010 at 14:04 UTC
      sysread ne sysopen