in reply to Image not displayed properly

I'll take a wild stab at this...

Is the image garbled after the 1024th byte (or some multiple thereof), perhaps? I always have to look up how to handle binary information in Perl and don't have a reference handy, but I'll bet the .= operator does not always Do The Right Thing (TM) with binary data. You know the size of the file - try reading the whole thing in all at once. Or use pack.
Update
Another possibility - you may need to set your output handle to binmode as well... Here's a snippet
$gifname = "picture.gif"; open(GIF, $gifname) or die "can't open $gifname: $!"; binmode(GIF); # now DOS won't mangle binary input from GIF binmode(STDOUT); # now DOS won't mangle binary output to STDOUT while (read(GIF, $buff, 8 * 2**10)) { print STDOUT $buff; }
that looks like it does exactly what you want. I found it in the O'Reilly Perl Cookbook Sample Chapter 8. O'Reilly rocks.
Update 2
On second thought, the snippet still doesn't handle the problem of concatenating binary data. Oh well.

Replies are listed 'Best First'.
Re: Re: Image not displayed properly
by Anonymous Monk on Aug 19, 2003 at 02:27 UTC
    I tried reading the whole file at once. Doesn't do the trick.

    Really I don't know what to do else...

    HEEEELP
      Mr bean says :
      Another possibility - you may need to set your output handle to binmode as well ...

      Do you do this? Your response was "I tried reading the whole file at once. Doesn't do the trick. " which is completely disconnected. binmode is the trick. Did you binmode?

      FYI - binmode is not just for "dos"

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.