What am I doing wrong?
while (my $zeichen = getc($handle1))
This will fail if the character you are reading is "0" or some other "false" value.

Try:

while (defined ( my $zeichen = getc($handle1) ) )
Also, although 'IEND' does signify the end marker of the PNG file it does so as part of a "chunk", and a chunk always ends with a CRC - from the PNG specs:
CRC
A 4-byte CRC (Cyclic Redundancy Check) calculated on the preceding bytes in the chunk, including the chunk type code and chunk data fields, but not including the length field. The CRC is always present, even for chunks containing no data.
So you will need to read/write a further 4 bytes after 'IEND'. I'm no expert on PNG files and can't say this is the correct way to do it but adding these two lines worked for me:
if ($buffer =~ /IEND/) { print $handle2 $buffer; read($handle1, $buffer, $bytes); ### 1 print $handle2 $buffer; ### 2 exit; }

In reply to Re: File extraction 2nd try by tangent
in thread File extraction 2nd try by knight.of.ni

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.