I have a 3 gig binary file that I need to edit. I'm running into memory problems since I have to pack and unpack the file. I've tried running on a unix, linux and windows machine with no luck. Any ideas on what I can do? I basically need to open the file and edit it at a bit level. I need to find certain bit patterns and remove them. I've tried to edit using hex characters but have found when I remove the character instead of only 8 bits being removed 16 get removed. Have no idea why that happens.

Per requests below is the code:

#!/usr/local/bin/perl -w undef $/; #Clear the record seperator. $| = 1; #Don't Buffer data. Write out when available. open IN, "$ARGV[0]"; binmode IN; #Use binary mode so windows/DOS won't complain #Convert original file into binary and write to $final while (<IN>) { #Loop thru file and convert file to 1's/0's $array = unpack("B*", $_); open OUT, ">>tmp"; print OUT "$array"; close OUT; undef $array; } close IN; print "Finished unpacking data.\n\n"; undef $/; open IN, "tmp"; #Extract the necessary data bits while (<IN>) { $_ =~ s/11110100.{8}(.{1520})11110100.{8}(.{464}).{1056}/$1$2/g; $final - pack("B*", $_); #Conver data back to original binary for +mat open OUT, ">>$ARGV[1]"; print OUT "$final"; close OUT; undef $final; } close IN; unlink "tmp"; print "Finished converting to binary.\n\n";

20041021 Janitored by Corion: Added formatting


In reply to Out of memory problems by tperdue

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.