in reply to Re: Re: Re: Generating a grep command at run time
in thread Generating a grep command at run time

I am not sure what you mean by read normally instead of line-by-line.

I mean doing read(FH, $buf, $size); instead of my $buf = <FH>;. The plain read() call is faster than line-by-line reading, though generally harder to program around for many practical purposes. Most of the time, disk access will be a greater factor than the method of reading the file, so it's not something that I lose sleep over.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Generating a grep command at run time
by Limbic~Region (Chancellor) on May 22, 2003 at 17:23 UTC
    hardburn,
    Your example is just changing the default buffer window - it is still reading it exactly as I have described. This is not faster than $var = <FH>; if you set the buffer smaller than the default. The only advantage speed wise to this method is if you do not care about newlines, which it appears that chimni is interested in. Now, it is possible to use a large buffer and write your own newline handler for reading through the buffer - you have to be sure to prepend whatever is left over on the last "line" on the next read to make sure lines that split are handled correctly. This seems like a lot more work to me - if you need that much speed - use the *nix grep.

    Cheers - L~R