Perl 如何使用OO样式打开管道?
我以新的风格重写了我的旧代码,如下所示:Perl 如何使用OO样式打开管道?,perl,pipe,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风格的IO中处理管道 添加: 谢谢,乔纳森,很好 # read
#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风格的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";
#从管道中读取。
$pipe=IO::pipe->新建;
$pipe->reader('some_program');
$data=;
#从管道中写入。
$pipe=IO::pipe->新建;
$pipe->writer('some_program');
打印$pipe“foo,bar,baz”;
您应该签出并删除