Sample code for 30+ languages & platforms
Perl

Get Contents of File as Base64

See more Encryption Examples

Demonstrates how to read the contents of a file and convert to a base64 string.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

my $bd = Chilkat2::BinData->new;

my $success = $bd->LoadFile('qa_data/jpg/starfish.jpg');
if (!$success) {
    print "Failed to load file.\n";
    exit;
}

print $bd->GetEncoded('base64'), "\n";

# If you want mult-line base64:
print "--\n";
print $bd->GetEncoded('base64_mime'), "\n";

# If you want hex..
print "--\n";
print $bd->GetEncoded('hex'), "\n";

# etc..