#print $channel "$cmd\n";
#while (<$channel>) {
print {${$channel}} "$cmd\n";
while (<${$channel}>) {
####
#!/usr/bin/perl
use strict;
use warnings;
sub print_to_fh
{
my ( $ref_to_fh ) = @_;
#$ref_to_fh is _not_ a filehandle. It's a scalar, that's a reference.
print $ref_to_fh "Some text\n";
}
open ( my $filehandle, ">", "testfile.txt" );
&print_to_fh ( \$filehandle );
close ( $filehandle );
####
sub print_to_fh
{
my ( $ref_to_fh ) = @_;
#$ref_to_fh is _not_ a filehandle. It's a scalar, that's a reference.
my $filehandle = $$ref_to_fh;
#Filehandle has dereferenced $ref_to_fh, so we can print to it now:
print $filehandle "Some more text\n";
}
open ( my $filehandle, ">", "testfile.txt" );
&print_to_fh ( \$filehandle );
close ( $filehandle );
####
print {$$ref_to_fh} "Even more stuff\n";