Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Out of memory

by karlgoethebier (Abbot)
on Jun 11, 2015 at 13:48 UTC ( [id://1130041]=note: print w/replies, xml ) Need Help??


in reply to Out of memory

"...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»

Replies are listed 'Best First'.
Re^2: Out of memory
by sandy105 (Scribe) on Jun 15, 2015 at 11:56 UTC

    I will try this and report back , thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1130041]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found