I am trying to extract multiple "image data" (images) from file - storage structure is as follows:

AZII*
.
.->e.g 20 bytes of data
.
AZII*
.
.
etc...

The following code extracts the data between AZII* and puts in to numbered files:
open (FILE, '1.dat') || die "$!"; $num=0; while ($line=<FILE>) { $num++ if $line =~/AZII*/; if ($line=~/AZII*/ .. /AZII*/) { open (DES, ">>out/$num.txt"); print DES $line; } if ($num == "5"){ # process 5 files only last; } }

The problem that I came across is the structure of the image files (tiffs in this case) should be fixed formatted as any binary structure e.g:

header
image data

currently the above code extracts the data in the following way:
look for AZII* if found output the whole line in to the file which damages the the image:

file 1:
-header(AZII*)
-image data
file 2:
-last row of image data from file 1 + header file 2 (AZII*)
-image data

Basically it prints the whole row of the last AZII* match.
The last row - .* part before AZII* should be printed in to file 1 and AZII* alone should start the next file2.

------------------------------------------------
e.g ƒÿýGDÄÄ#>q0‡‘‘„#"x°ÂñÇÿÿÿÿ ñ½ÿÿ AZII*
---------------------------------------------------

Where: ƒÿýGDÄÄ#>q0‡‘‘„#"x°ÂñÇÿÿÿÿ should be the end of file 1
And: AZII* should start the next file

heww hope this makes sense - any suggestions on how can I approach this.

Thanks,

In reply to File Extraction - Cont... by karavay

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.