我正在尝试编写一个自定义的base64编码函数来学习Perl语言,但是我目前还没有成功。我已经得出了以下结果,但它不起作用,而且我不知道该如何继续。
sub base64($) {
# Split string into single bits
my $bitstring = unpack("B*", $_[0]);
# Pack bits in pieces of six bits at a time
my @splitsixs = unpack("(A6)*", $bitstring);
my @enc = ("A".."Z", "a".."z", "0".."9", "+", "/");
# For each piece of six bits, convert them to integer, and take the corresponding place in @enc.
my @s = map { $enc[pack("B6", $_)] } @splitsixs;
join "", @s;
}
有人能解释一下我在这个转换中做错了什么吗?(暂时不考虑我没有考虑填充的事实)
map { $enc[pack("B6", $_)] } @splitsixs
返回了一个常量流的“A”,但我不太明白为什么它是常量的。 - trenta3