capturing STDOUT from and piped "into" program



Hi

I've read a lot good info on this list about capturing STDOUT but I'm
still having a problems grasping it. I think I'm missing something. I
am trying to capture the output from the "$p4 $spectype -i" command
and place it in a $scalar. I know I can't redirect directly into a
scalar.

open(FULLSPEC,"|$p4 $spectype -i");
print FULLSPEC @fullspec;
close(FULLSPEC);

Can someone please show me an example on how I can directly place the
output of the above example into a scalar variable?


Up to now I've cludged it by placing the output into a file and then
reading it however it's ugly.

open(FULLSPEC,"|$p4 $spectype -i > $outfile");
print FULLSPEC @fullspec;
close(FULLSPEC);

open(OUTPUT,"<$outfile");
$specout = <OUTPUT>;
close(OUTPUT);
chomp($specout);
unlink($outfile);
return $specout;

.