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

前端之家收集整理的这篇文章主要介绍了如何使用perl转换base64编码的文件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有哪些方法可以使用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!

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

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

猜你在找的Perl相关文章