ketema has asked for the wisdom of the Perl Monks concerning the following question:

need a little help. i want to encode and decode .jpg files to binary strings. I have read several posts on this site as well as the MIME-Base64 docs. i came up with this simple test:
open(PIC,"<","$dir\\$filename"); while (read(PIC,$_,57)) { $binData .= encode_base64($_); } close PIC; open(PIC,">","E:\\$filename"); print PIC decode_base64($binData);

the file gets created, but its not a viewable picture anymore, instead just a blob of various colors. Can someone please educate me? never mind, windows needs binmode before the write....searched for just jpg this time and found the answer

Replies are listed 'Best First'.
Re: jpg's and base 64
by Zaxo (Archbishop) on Dec 02, 2004 at 03:31 UTC

    Call binmode PIC; to read or write the file in raw binary mode.

    After Compline,
    Zaxo