Good point about it all having to fit into RAM. Should be relatively straightforward to read byte by byte, although looking ahead for the two byte separator would need some finagling. hmmm, how about:
my $ifilename = 'file.in';
my $ofilename = $ifilename . '.bin';
open my $ifile, '<', $ifilename or die "could not open input file $!";
open my $ofile, '>', $ofilename or die "could not open output file $!"
+;
binmode $ifile;
binmode $ofile;
my $n = eof($ifile) ? "" : getc($ifile);
while ((my $c = $n) ne "") {
$n = eof($ifile) ? "" : getc($ifile);
print $ofile "$c$n" eq "\x4F\xFF" .. 1 ? $c : "\x0";
}
close $ifile;
close $ofile;
|