From: Liviu Daia (no email)
Date: Mon Sep 01 2003 - 15:06:51 EDT
On 31 August 2003, Liviu Daia <> wrote:
> Off topic, but still related: can some Perl-Fu master out there
> please explain (preferably in layman terms) why the following
> abomination works fine for encoding files as Base64:
>
> perl -MMIME::Base64 -e 'print encode_base64 $b while (read STDIN, $b, 57)' <file
>
> while this one only works for small files:
>
> perl -MMIME::Base64 -pne '$/=\57; $_=encode_base64 $_' <file
FWIW: the second incantation doesn't work because $/ is changed in
the middle of the loop, after the first chunk has been read. Thanks to
Kyle Dent for helping me out of it.
Conclusion: the following can be used as a poor man's Base64
encoder:
perl -MMIME::Base64 -pe 'BEGIN{$/=\57};$_=encode_base64 $_' <file
Regards,
Liviu Daia
-- Dr. Liviu Daia e-mail: Institute of Mathematics web page: http://www.imar.ro/~daia of the Romanian Academy PGP key: http://www.imar.ro/~daia/daia.asc
|
|
|