2009-02-03 31 views
5

我重写我的旧代码,新的风格,象下面这样:如何打开OO风格的管道?

#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"; 

回答