May i suggest replacing read with sysread, and 1024 with the value returned from
(stat($file))[11]?
The reason for doing so is that read is already buffered, and you're buffering it a second time... You should avoid it as you probably don't need it, and read directly...
About the size - "11 blksize preferred block size for file system I/O " - to quote from perldoc -f stat
open FILE,$file or die "$!";
my $len = (stat($file))[11];
while (sysread FILE, my $data, $len){ syswrite STDOUT, $data };
Would be my code of choice.
print is also bufferred I/O, and in the family of read, write, readline, getc, eof, printf seek and tell. It is also bufferred. It may or may not be a good idea to use buffering for writing either. Probably the latter if you're on the same filesystem.
I think that the most commonly used buffer size in pipes is 4096 bytes, and there's probably a reason for it too.
-nuffin
zz zZ Z Z #!perl
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.