Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I've found something more like the following to be useful:

                    my $max_len = max(8096,map{length} @strings);
                    my $regexp = "(" . join("|", map {quotemeta} @strings) . ")";
                    my @buf = ('');
                    while (1) {
                            my $len = read($fh, $buf[1], $max_len);
                            last unless $len;
                            if ("@buf" =~ /$regexp/o) {
                                    return $1;
                            }
                            shift @buf;
                    }

    I've not benchmarked which solution is faster, but I'd speculate that the substr is slower than the concat plus shift. Note that this implementation pulls a minimum of 8096 bytes at a time, but it might be longer is the match strings are longer.