"...no way of knowing if & where my search string will be split at new line "\n"...i try to load the whole file into a string and then do a pattern match"

I'm unsure if i understood your specs right but perhaps you want to do something like this:

use strict; use warnings; use feature qw(say); my $file = q(big.txt); my $size = -s( $file); my $pattern = qr((y+)(?:\n*)(y*)); open my $fh, '<', $file or die $!; read( $fh, my $data, $size ); close $fh; while( $data =~ m/$pattern/g ) { say qq($1$2); } __END__ # data like this: xyyyyyxxxx xxxxxxxxxx xxxxxxxxyy yyyxxxxxxx xxxxxxxxxx xxxxxxyyyy yxxxxxxxxx xxxxxxxxxx xxxxxyyyyy xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx # small version ;-) Desktop\monks>1129652.pl yyyyy yyyyy yyyyy yyyyy

The example runs on a 350MB file on XP 32bit with 2 GByte RAM in ~1s

Just an idea.

Regards, Karl

P.S.: If i use File::Map i get Out of Memory!

«The Crux of the Biscuit is the Apostrophe»


In reply to Re: Out of memory by karlgoethebier
in thread Out of memory by sandy105

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.