yonyon100 yonyon100 - 1 year ago 66
Perl Question

<> operator buffer size

I have a file with very long lines that I need to process and I found that the process gets stuck/'really slow' because the buffer is not big enough or due to the fact that handling a very long line might take a while. Here's a code sample:

open FH, "<$fname" or die "...";
while (<FH>) {

The line processing is not "heavy".

I looked for something to solve it and came across
but it looks like it wasn't maintained for a while now and I don't want to use a module with version 0.001. How can I modify the
operator buffer size? Or alternatively, is there any way to know the line length before reading it with

Answer Source

It may be that what you need is this:

$/ - can be set to a numeric value, for a number of bytes to read from a file.

Setting $/ to a reference to an integer, scalar containing an integer, or scalar that's convertible to an integer will attempt to read records instead of lines, with the maximum record size being the referenced integer number of characters.

Source: perlvar

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download