perl自带的base64模块我知道,但是开发之后的代码要在客户那里运行,
客户的机器是否有base64模块无法确认,于是我想把base64代码放到程序里面。
我在cpan下载了「MIME-Base64-Perl-1.00.tar.gz」,在里面找到如下代码
01sub encode_base64 ($;$)
02{
03 if ($] >= 5.006) {
04 require bytes;
05 if (bytes::length($_[0]) > length($_[0]) ||
06 ($] >= 5.008 && $_[0] =~ /[^\0-\xFF]/))
07 {
08 require Carp;
09 Carp::croak("The Base64 encoding is only defined for bytes");
10 }
11 }
12
13 use integer;
14
15 my $eol = $_[1];
16 $eol = "\n" unless defined $eol;
17
18 my $res = pack("u", $_[0]);
19 # Remove first character of each line, remove newlines
20 $res =~ s/^.//mg;
21 $res =~ s/\n//g;
22
23 $res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
24 # fix padding at the end
25 my $padding = (3 - length($_[0]) % 3) % 3;
26 $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
27 # break encoded string into lines of no more than 76 characters each
28 if (length $eol) {
29 $res =~ s/(.{1,76})/$1$eol/g;
30 }
31 return $res;
32}
问题:1。03-11行感觉是版本确认,还有其他特殊含义么,我想删掉不知道可以否。
2。刚开始搞perl开发,cpan的代码我直接用可以么?有没有版权专利什么的?
3。不知道我直接用这段代码有什么需要注意的地方么?还不是特别理解其他代码的意思。
客户的机器是否有base64模块无法确认,于是我想把base64代码放到程序里面。
我在cpan下载了「MIME-Base64-Perl-1.00.tar.gz」,在里面找到如下代码
01sub encode_base64 ($;$)
02{
03 if ($] >= 5.006) {
04 require bytes;
05 if (bytes::length($_[0]) > length($_[0]) ||
06 ($] >= 5.008 && $_[0] =~ /[^\0-\xFF]/))
07 {
08 require Carp;
09 Carp::croak("The Base64 encoding is only defined for bytes");
10 }
11 }
12
13 use integer;
14
15 my $eol = $_[1];
16 $eol = "\n" unless defined $eol;
17
18 my $res = pack("u", $_[0]);
19 # Remove first character of each line, remove newlines
20 $res =~ s/^.//mg;
21 $res =~ s/\n//g;
22
23 $res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
24 # fix padding at the end
25 my $padding = (3 - length($_[0]) % 3) % 3;
26 $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
27 # break encoded string into lines of no more than 76 characters each
28 if (length $eol) {
29 $res =~ s/(.{1,76})/$1$eol/g;
30 }
31 return $res;
32}
问题:1。03-11行感觉是版本确认,还有其他特殊含义么,我想删掉不知道可以否。
2。刚开始搞perl开发,cpan的代码我直接用可以么?有没有版权专利什么的?
3。不知道我直接用这段代码有什么需要注意的地方么?还不是特别理解其他代码的意思。
