Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How do I decode a MIME/BASE64 string?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:32 UTC ( #772=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

The MIME-tools package (available from CPAN) handles this and a lot more. Decoding BASE64 becomes as simple as:

    use MIME::base64;
    $decoded = decode_base64($encoded);

A more direct approach is to use the unpack() function's ``u'' format after minor transliterations:

    tr#A-Za-z0-9+/##cd;                   # remove non-base64 chars
    tr#A-Za-z0-9+/# -_#;                  # convert to uuencoded format
    $len = pack("c", 32 + 0.75*length);   # compute length byte
    print unpack("u", $len . $_);         # uudecode and print

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[Lady_Aleena]: atcroft, I just put a link to another module in one of my local ones. For a normal link L<text|url> the text would be written out then the url would follow the text in brackets <>. However, when I linked to another module, the text was written ..
[Lady_Aleena]: ... but no link. L<module name> might localize to where ever it is, like PerlMonks [id://1026423] does. (Cookies)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2017-05-27 04:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?