我用新的风格重写了我的旧代码,如下所示:
#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";