为什么用Perl的LWP下载我的图像会给我一个错误大小的文件? [英] Why does my image download with Perl's LWP give me the wrong-sized file?
本文介绍了为什么用Perl的LWP下载我的图像会给我一个错误大小的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Perl从HTTP服务器获取图像。
I am trying to get an image from an HTTP server using Perl.
我有文件的完整URL并且我正在尝试使用
I have the full URL of the file and am attempting to use
my $data = LWP::Simple::get $params{URL};
my $filename = "image.jpg";
open (FH, ">$filename");
print FH $data;
close (FH);
现在,从逻辑上讲,至少对我来说,这应该有效。但文件的大小略有不同,我无法解释原因。
Now, logically, to me at least, this should work. But the files are slightly different sizes, and I can't work out why.
帮助!
推荐答案
您需要使用 binmode
将图像数据正确写入磁盘。
You need to use binmode
to properly write the image data to disk.
my $data = LWP::Simple::get $params{URL};
my $filename = "image.jpg";
open (FH, ">$filename");
binmode (FH);
print FH $data;
close (FH);
否则它被解释为文本,并且换行符被提供。
Otherwise it is interpreted as text, and the newlines get munged.
这篇关于为什么用Perl的LWP下载我的图像会给我一个错误大小的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文