in reply to Reading from a filehandle written to by a subroutine?

use strict; use warnings; open FH, ">", "test$$.txt" or die $!; _cat(*FH, "This is a test\n"); sub _cat { my $fh = shift; my $data = shift; print $fh $data or die $! }
Update:
use strict; use warnings; my $data; #write to filehandle open WH, ">", "test$$.txt" or die $!; _write(*WH, "This is a test\n"); close WH; #read from filehandle into $data open RH, "test$$.txt" or die $!; _read(*RH, \$data); close RH; print $data; sub _write { my $fh = shift; my $data = shift; print $fh $data or die $! } sub _read { my $fh = shift; my $data = shift; $$data .= $_ while <$fh> }