【发布时间】:2018-08-23 13:21:40
【问题描述】:
我使用 MIME::Parse 解析多部分 MIME。我想要完整的部分,而不仅仅是头部或身体。据我所知,它将 CRLF 更改为 LF。这是个问题。
use MIME::Parser;
my $parser = new MIME::Parser ();
$parser->decode_headers (0);
$parser->decode_bodies (0);
$parser->output_to_core (1);
open (F, "myfile.txt");
my $mime = $parser->parse (\*F);
close (F);
my $mp = $mime->parts (0); // get the 1st part
my $ct = $mp->as_string ();
my $h = unpack ("H*", $ct);
$h = join (' ', $h =~ /(..)/g);
print "\n$h\n"; // inspect and compare with myfile.txt in a hex-editor
如果我使用十六进制编辑器查看 myfile.txt,则行分隔符是 CRLF (0x0d 0x0a)。 如果我检查打印输出,则它们更改为 LFs (0x0a)。
这是为什么呢?如何获取原始内容?
谢谢! 克里斯
【问题讨论】:
-
最好使用三参数
open,词法文件句柄,尤其是错误检查:open my $fh, '<', 'myfile.txt' or die $!;