gpt4 book ai didi

perl - IO::All:如何读取 ARGV 和 DATA?

转载 作者:行者123 更新时间:2023-12-02 05:30:35 27 4
gpt4 key购买 nike

如何创建 IO::All对象读取文件句柄 ARGV 和 DATA?

use strict;
use warnings;
use 5.010_000;
use IO::All;

# none of these work...
my $io = io->handle(DATA);
my $io = io->handle(\*DATA);
my $f = \*DATA;
my $io = io->handle($f);
my $io = io->handle({$f});
my $io = io->handle({DATA});
my $io = io->handle({\*DATA});

say $io->slurp();

__DATA__
FOO
BAR
QUUX

最佳答案

看起来像一个错误。传递句柄似乎不起作用,即使文档说它应该。下面是一个示例,它消除了 DATA 的可能复杂性。

use strict;
use warnings;

use IO::All;

open my $fh, "<", "/etc/passwd" or die $!;

# Either of these should work according to the docs.
# my $io = IO::All->new($fh);
my $io = io->file->handle($fh);
print $io->all;

Please file a bug .

关于perl - IO::All:如何读取 ARGV 和 DATA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443549/

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