Dear All, I am using the following code to replace certain information in binary mode.
$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

The output should be as follows:

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


In reply to Out of Memory by ngbabu

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.