Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open pipes with OO style?

Tags:

pipe

perl

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

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";
like image 294
namako Avatar asked Oct 15 '22 17:10

namako


1 Answers

You should check out IO::Pipe and FileHandle.

like image 188
Jonathan Leffler Avatar answered Oct 18 '22 04:10

Jonathan Leffler