zzzeno has asked for the wisdom of the Perl Monks concerning the following question:
while (<$filename>) { print encode_base64($_); } sub encode_base64 ($) { my $res = ""; my $eol = "\n"; pos($_[0]) = 0; while ($_[0] =~ /(.{1,45})/gs) { $res .= substr(pack("u", $1), 1); chop($res); } $res =~ tr|` -_|AA-Za-z0-9+/|; my $padding = (3 - length($_[0]) % 3) % 3; $res =~ s/.{$padding}$/"=" x $padding/e if $padding; if (length $eol) { $res =~ s/(.{1,76})/$1$eol/g; } $res; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question about Binary files
by perlplexer (Hermit) on Apr 19, 2002 at 12:32 UTC | |
by Anonymous Monk on Apr 19, 2002 at 15:51 UTC | |
by graff (Chancellor) on Apr 20, 2002 at 04:41 UTC | |
by perlplexer (Hermit) on Apr 19, 2002 at 19:08 UTC | |
|
Re: Question about Binary files
by Anonymous Monk on Apr 20, 2002 at 15:02 UTC |