如何打开OO风格的管道?

时间:2009-02-03 07:49:02

标签: perl pipe

我以新的方式重写旧代码,如下所示:

#old style
open(FD,"file");

#new style
$fh = IO::File->new("file","r");

文件还可以,但我不知道如何打开管道。

# read from pipes.
open(PIPE,"some_program |");

# write to pipes.
open(PIPE,"| some_program");

如何处理OO Style IO中的管道?

中加入:
谢谢乔纳森,没关系。

# read from pipes.
$pipe = IO::Pipe->new;
$pipe->reader('some_program');
$data = <$pipe>;

# write from pipes.
$pipe = IO::Pipe->new;
$pipe->writer('some_program');
print $pipe "foo,bar,baz";

1 个答案:

答案 0 :(得分:4)

您应该查看IO::PipeFileHandle