in reply to split and sysread()

If you're trying to match patterns in blocks that you've pulled in via sysread(), you risk failing to match patterns that span blocks.

Matching in huge files describes a workaround that you might be able to adopt it to your purposes.

Replies are listed 'Best First'.
Re: Re: split and sysread()
by BrowserUk (Patriarch) on Apr 19, 2003 at 09:31 UTC

    Take another look. The last line of the loop, $buffer = substr($buffer, rindex($buffer, "\n")); in conjunction with the length $buffer as the fourth parameter to sysread has the effect of grabbing any partial line from the end of the buffer and moving it to the beginning where the next buffer load is then appended.

    In this way, every line is processed as a complete line whilst benefiting from reading large chunks from the file without resorting to slurping the whle file into memory.

    See my post below for two variations of the algorithm and a benchmark.


    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.