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

Hi Monks!! Was wondering whether anyone has any suggestions as to a meaningful LENGTH (value of bytes read in) value for the read builtin? Of relevance might be that the read() will be used on email attachments that vary in size up to and around 2Mb. I've google'd this and the only suggestion is to have length set to an obvious value that is in a multiple of bytes (for example 1024). I was wishing to see what other Perl monks had as a suggestion. Thanks, Ed
  • Comment on meaningful LENGTH value in read() builtin

Replies are listed 'Best First'.
Re: meaningful LENGTH value in read() builtin
by sgifford (Prior) on Dec 12, 2004 at 08:18 UTC

    Perl's read is already buffered, so you can really read in whatever size block is most convenient without having a huge impact on performance. But generally I used a multiple of the system disk block, since the OS usually reads one block at a time, and the input buffer is usually also a multiple of the blocksize. Rather than try to figure out the system block size, I usually just use 8192 bytes, which is between 1 and 8 blocks on most systems.

    Depending on exactly what you want to do, I've found that using mmap is a very fast way to read through a mailbox. Sys::Mmap seems to provide a way to do this, although I've not used it (the program I wrote was in C).

      Thanks for that, exactly what I wanted to know. I suppose my *real* issue was knowing if there is a trade-off in performance by specifying a LENGTH of a particular type.