I have a binary file (PCL5) where I need to insert some information at specific points. The file consists of groups of pages (from 1 to n) separated by XML comments. The largest files are only about 50MB.
This is the first binary file I have worked with, so I am having difficulty...and after hours of searching, do not have a good answer.
Here is the first part - separate the page groups:
The next part is finding form feeds (Hex=0C, Dec=12) in each array element. However, because the file uses raster images there are "false" form feeds that I need to ignore. In this file, raster images begin with Esc*r? (Hex:1B 2A 72 ??, Dec: 27 42 114 ??) where ? is anything BUT 'B'. That may clue you in to the end of a raster image, which is Esc*rB (Hex:1B 2A 72 42, Dec:27 42 114 66).
So, my question is: How do I find each chr(12) that is not inside of a raster image, and then store the count of chr(12)'s for that array element as well as the byte position of each one?
Thanks in advance for the brain power.
This is the first binary file I have worked with, so I am having difficulty...and after hours of searching, do not have a good answer.
Here is the first part - separate the page groups:
Code:
my $pattern = chr(27) . chr(37) . chr(49) . chr(66) . chr(67) . chr(79);
my $cnt;
# Read each group into an array element
local($/) = $pattern;
open(FH, "< some.pcl");
binmode(FH);
@slurp = <FH>;
close(FH);
open(OUTFILE, "> summary.dat");
foreach $recip (@slurp)
{
# Ignore empty elements (1st is always empty)
if($recip ne '')
{
$end_tags = chr(47) . chr(62) . chr(34);
$position = index($recip, $end_tags);
$tags = substr($recip,1,$position + 2);
print OUTFILE $tags, "\n";
## This is where I need help
}
}
close OUTFILE;
The next part is finding form feeds (Hex=0C, Dec=12) in each array element. However, because the file uses raster images there are "false" form feeds that I need to ignore. In this file, raster images begin with Esc*r? (Hex:1B 2A 72 ??, Dec: 27 42 114 ??) where ? is anything BUT 'B'. That may clue you in to the end of a raster image, which is Esc*rB (Hex:1B 2A 72 42, Dec:27 42 114 66).
So, my question is: How do I find each chr(12) that is not inside of a raster image, and then store the count of chr(12)'s for that array element as well as the byte position of each one?
Thanks in advance for the brain power.