如何打开OO风格的管道? [英] How can I open pipes with OO style?

查看:103
本文介绍了如何打开OO风格的管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用新样式重写了旧代码,如下所示:

I rewrite my old code in new style, like below:

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

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

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

Files are ok, but I don't know how to open pipes.

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

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

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

How to treat pipes in OO Style IO?

添加:
谢谢乔纳森,很好.

adding:
thanks Jonathan, it's fine.

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

推荐答案

您应签出 IO :: Pipe FileHandle .

这篇关于如何打开OO风格的管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆