gpt4 book ai didi

perl - 如何逐行读取 URL?

转载 作者:行者123 更新时间:2023-12-02 01:49:50 24 4
gpt4 key购买 nike

我正在寻找下面(虚构的)openremote 的“道德等价物”:

my $handle = openremote( 'http://some.domain.org/huge.tsv' ) or die $!;
while ( <$handle> ) {
chomp;
# etc.
# do stuff with $_
}
close $handle;

IOW,我正在寻找一种方法来打开远程文件的读取句柄,以便我可以逐行读取它。 (通常这个文件会比我想完全读入内存的要大。这意味着基于将 LWP::Simple::get(例如)返回的值填充到 中的解决方案IO::String 不适合。)

我敢肯定这确实是基本的东西,但经过大量搜索后我还没有找到它。

最佳答案

这是一个与其他响应非常相似的“解决方案”,但它通过使用 IO::All 来作弊。

use IO::All ;
my $http_io = io->http("http://some.domain.org/huge.tsv");

while (my $line = $http_io->getline || $http_io->getline) {
print $line;
}

在你有了一个带有 io->http 的对象之后,你可以使用 IO 方法来查看它(比如 getline() 等。 ).

干杯。

关于perl - 如何逐行读取 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23470858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com