How can I set the file-read buffer size in Perl to optimize it for large files?

前端 未结 4 578
暗喜
暗喜 2021-01-05 06:15

I understand that both Java and Perl try quite hard to find a one-size-fits all default buffer size when reading in files, but I find their choices to be increasingly antiqu

4条回答
  •  悲哀的现实
    2021-01-05 06:48

    I'm necroposting since this came up on this perlmonks thread

    It's not possible to use setvbuf on perls using PerlIO, which the default since version 5.8.0. However, there is the PerlIO::buffersize module on CPAN that allows you to set the buffer size when opening a file:

        open my $fh, '<:buffersize(65536)', $filename;
    

    IIRC, you could also set the default for any new files by using this at the beginning of your script:

        use open ':buffersize(65536)';
    

提交回复
热议问题