ファイルをbase64との間で変換するためのスクリプトを作成しました。Perl - Base64とのエンコード
# Setup default mode
my $mode = '';
my $encoding = 'base64';
my $file = '';
GetOptions(
'mode=s' => \$mode, # mode = Encode/decode
'help!' => \$help, # help message
'encoding=s' => \$encoding,
'file=s' => \$file
) or die "Incorrect usage!\n";
if($help) {
print "Common on, it's really not that hard.\n";
} else {
print "# Script parameters provided : \n";
print "# Mode set to $mode.\n";
print "# Encoding is set to $encoding\n";
print "# Input File set to $file \n";
}
open(FILE, "$file") or die "$!";
open FILEOT, ">$file.out" or die "$!";
binmode FILEOT;
binmode STDOUT;
switch ($mode) {
case "encode" {
print "# Encoding file $file to $encoding \n";
print "# Processing .... \n\n";
while (read(FILE, $buf, 60*57)) {
$encoded = encode_base64($buf);
print $encoded;
print FILEOT $encoded;
}
}
case "decode" {
print "# Decoding file $file from $encoding \n";
print "# Processing .... \n\n";
while (read(FILE, $buf, 60*57) {
$decoded = decode_base64($buf);
print $decoded;
print FILEOT $decoded;
}
}
エンコード部分は意図したとおりに動作します。デコード部は出力を与えません。私はそれを好きなの入力ファイル与えた:
My name is John
I eat pineapples
を、それは何も出力を与えません。バッファリングされた読み込みは、すでにこのスクリプトですでにエンコードされているファイルをデコードする場合には必要ないかもしれないと思います。私は上記のテストを使ってbase64エンコーディングバージョンを生成しましたが、その逆は何も与えません。誰でも助けてくれますか?
に興味があります。あなたが実行している*実際のコード*を投稿しない限り、あなたの質問に役立つ回答は得られません。 'while(read(FILE、$ buf、60 * 57){' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 'あなたが書いたすべてのPerlプログラムの先頭に 'all'という警告文を使用します; myが' 'my''を使用しているのであれば、 – Borodin