如何在不使用 :content_file 选项的情况下将响应作为文件处理?
示例代码:
my $ua = LWP::UserAgent->new;
my $response = $ua->get('http://example.com/file.zip');
if ($response->is_success) {
# get the filehandle for $response->content
# and process the data
}
else { die $response->status_line }
我需要将内容作为文件打开,而不事先将其保存到磁盘。你会怎么做?
Example code:
my $ua = LWP::UserAgent->new;
my $response = $ua->get('http://example.com/file.zip');
if ($response->is_success) {
# get the filehandle for $response->content
# and process the data
}
else { die $response->status_line }
I need to open the content as a file without prior saving it to the disk. How would you do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以打开一个指向标量的假文件句柄。如果文件参数是标量引用,Perl 会将标量的内容视为文件数据而不是文件名。
You can open a fake filehandle that points to a scalar. If the file argument is a scalar reference, Perl will treat the contents of the scalar as file data rather than a filename.
不完全是一个文件,但这里有一个相关的问题: 纯 Perl 中从另一个 HTTP 资源进行流式传输的最简单方法是什么?
Not quite a file, but here is a relevant SO question: What is the easiest way in pure Perl to stream from another HTTP resource?