IO :: All:如何从ARGV和DATA读取?

时间:2012-09-16 00:33:01

标签: perl

如何创建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

1 个答案:

答案 0 :(得分:5)

看起来像个错误。即使文档说它应该,传入句柄似乎也不起作用。这是一个消除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