in reply to Out of memory problems
"Entirely undefining $/ makes the next line input operation slurp in the remainder of the file as one scalar value"Set $/ to some reasonable size, maybe to satisfy memory limitations. Then you can match blocks of the file in much the way TedPride describes. Something like this
#undef $/; $/ = \2048; # 2K blocks my $blocksz = 2048; open IN, "tmp"; open OUT, ">>$ARGV[1]"; #more efficient when parsing more than one b +lock #Extract the necessary data bits my $block01 = <IN>; my $block02 = ''; while ($block02 = <IN>) { my $block = $block01.$block02; $block =~ s/11110100.{8}(.{1520})11110100.{8}(.{464}).{1056}/$1$2 +/g; # $_ =~ s/11110100.{8}(.{1520})11110100.{8}(.{464}).{1056}/$1$2/g; # $final - pack("B*", $_); #Conver data back to original binary fo +rmat # $final = pack("B*", $block); # this is wrong $final = pack("B*", substr($block,0,$blocksz)); # this should wor +k print OUT "$final"; $final = ''; # this is strictly unnecssary but does keep variable + clean # undef $final; $block01 = substr($block,-$blocksz); # this moves the upper bloc +k down } $final = pack("B*", substr($block,-$blocksz)); # get final block print OUT "$final"; close OUT; close IN;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Out of memory problems
by tperdue (Sexton) on Oct 21, 2004 at 16:22 UTC | |
by periapt (Hermit) on Oct 21, 2004 at 18:51 UTC | |
by tperdue (Sexton) on Oct 22, 2004 at 11:19 UTC | |
by periapt (Hermit) on Oct 22, 2004 at 13:59 UTC | |
by tperdue (Sexton) on Oct 23, 2004 at 14:38 UTC | |
by tperdue (Sexton) on Oct 26, 2004 at 12:28 UTC | |
by tperdue (Sexton) on Oct 21, 2004 at 21:32 UTC |