Is it possible to open a pipe-based filehandle which prints to a variable in perl?

Posted by blackkettle on Stack Overflow See other posts from Stack Overflow or by blackkettle
Published on 2010-04-19T11:20:09Z Indexed on 2010/04/19 11:23 UTC
Read the original article Hit count: 177

Filed under:
|

Hi, I know I can do this,


------
open(F,">",\$var);
print F "something cool";
close(F);
print $var;
------

or this,

 

open(F, "| ./prog1 | ./prog2 > tmp.file");
print F "something cool";
close(F);

but is it possible to combine these? The semantics of what I'd like to do should be clear from the following,


open(F,"|./prog1 | ./prog2", \$var);
print F "something cool";
close(F);
print $var;

however the above clearly won't work.

A few minutes of experimenting and googling seems to indicate that this is not possible, but I'd like to know if I'm stuck with using the `` to capture the output.

© Stack Overflow or respective owner

Related posts about perl

Related posts about file-io