On Thu, Apr 16, 2009 at 00:58, Emen Zhao <emenzhaow...@gmail.com> wrote:
> This is off topic. But I'm just curious about why "4096" is picked here. Is
> there any particular reason behind it? I guess you can even calc the lines
> like this -
> perl -0777 -wne 'print scalar ($_=~s/\n//g)' filename
>
> Thanks,
> Emen
>

4096 bytes is 4k which is often the size of one block on the disk.
Since the filesystem must read in one block at a time the code might
as well use the full block.  You could read more, but the general idea
is to work with blocks so that, by the time you are done counting the
newlines in the first block, a second block has been put into memory
by the read-ahead cache.  Reading the entire file into memory can be a
very bad idea (such as when the file is 12 gigs and you only have 2
gigs of RAM).


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to