[ale] Base64 encoding in Perl

Christopher Fowler cfowler at outpostsentinel.com
Mon Feb 14 11:12:55 EST 2005


I'm trying to use MIME::Base64::encode to encode a 9m binary file into
Base64.  I'm using sysopen and sysread on the file but I'm not sure how
to append the result of the read into a data buffer.  Normally I would
simply do '$var1 += $buffer' but I think that is only good for strings
that are null-terminated and not simply a series of bytes. Can someone
tell me the best way to accomplish this task?  

                                                                                                                             
use MIME::Base64;
use Fcntl;
use strict;

die "base64.pl <filename>\n" unless $ARGV[0];
sysopen FILE, $ARGV[0], O_RDONLY or die "$!\n";
my $buffer = "";
my $n = 0;
my $data = "";
while(($n = sysread(FILE, $buffer, 1024)) > 0) {
        $data += $buffer;
}
                                                                                                                             
print MIME::Base64::encode($data, "");




More information about the Ale mailing list