![]() |
|
good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
How do I decode a MIME/BASE64 string?by faq_monk (Initiate) |
on Oct 08, 1999 at 00:32 UTC ( [id://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
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
|
|