加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何使用perl转换base64编码的文件?

发布时间:2020-12-16 06:23:22 所属栏目:大数据 来源:网络整理
导读:有哪些方法可以使用Perl转换base64编码的文件? 我想查看和编辑该文件. $file base64result base64result: XML document$ls -l base64result -rw-r--r-- 1 dpadmin appadmin 52K Oct 28 12:57 base64result 这是我到目前为止所尝试的,但没有奏效: #!/bin/pe
有哪些方法可以使用Perl转换base64编码的文件?

我想查看和编辑该文件.

$file base64result 
base64result:   XML document

$ls -l base64result 
-rw-r--r--   1 dpadmin  appadmin     52K Oct 28 12:57 base64result

这是我到目前为止所尝试的,但没有奏效:

#!/bin/perl

###################################################
# decode_base64.pl:
###################################################

use strict;
use MIME::Base64 qw( decode_base64 );

open INFILE,'<',$ARGV[0];
open OUTFILE,'>',$ARGV[1];
binmode OUTFILE;
my $buf;
while ( $buf = <INFILE> ) {
    print OUTFILE decode_base64($buf);
}

close OUTFILE;
close INFILE;

输出:

$cat base64output
?ioz?"¢z{??÷¥¢—±?Yìz{

解决方法

你的代码是正确的(虽然我在下面进行了改进),并且你没有错误这意味着该文件是有效的base64.你得到的就是那里.

$cat decode_base64.pl
#!/usr/bin/perl

use strict;
use warnings;

use MIME::Base64 qw( decode_base64 );

binmode STDOUT;
while ( my $buf = <> ) {
    print decode_base64($buf);
}

$echo 'Hello,World!' | base64
SGVsbG8sIFdvcmxkIQo=

$echo 'Hello,World!' | base64 | decode_base64.pl
Hello,World!

如果你期待不同的东西,那么你的期望是错误的.

如果您想要获得不同的东西,则需要更改您提供的数据.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读