ngbabu has asked for the wisdom of the Perl Monks concerning the following question:
$s=time(); open(FH, "$ARGV[0]"); open(OUT, ">$ARGV[1]"); binmode FH; binmode OUT; $/=undef; $line=<FH>; $line=~s!(\d{3}\s(\/[^\n]*? f1)\s*([^\n]+sh\s*)+?\d{3}\s)ns!$1$2!gs wh +ile($line=~/(\d{3}\s(\/[^\n]*? f1)\s*([^\n]+sh\s*)+?\d{3}\s)ns/gs); print OUT $line; $e=time(); $r=$e-$s; close(FH); close(OUT); print "Done...\nRuntime: $r seconds";
This is code is loading entire file content and doing the replacement. If we read line by line we can avoid the out of memory problem. But my replacement is depending on previous line. The below is the input:
224 /EuclidSymbol f1
(D) -22 673 sh
.....
320 ns
.....
221 ns
224 /EuclidSymbol f1
(D) -22 673 sh
.....
320 /EuclidSymbol f1
.....
221 /EuclidSymbol f1
I tried with Tie::File but is not loading Binary data. Please suggest how can i solve the problem. My file size is around 3GB.
Regards,
Ganesh
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Out of Memory
by Anonymous Monk on Mar 15, 2010 at 12:13 UTC | |
|
Re: Out of Memory
by shmem (Chancellor) on Mar 15, 2010 at 22:46 UTC |