note
Preceptor
<P>Assuming I'm looking at the right lines, you're contemplating the difference between:</P>
<CODE>
#print $channel "$cmd\n";
#while (<$channel>) {
print {${$channel}} "$cmd\n";
while (<${$channel}>) {
</CODE>
<P>That's because you're having a problem with passing references to filehandles. $channel is a filehandle. You're passing it by reference:</P>
<CODE>$self->{_ssh2_channel} = \$channel;</CODE>
<P>Which means when you're trying to use it - as a filehandle - you need to dereference first. Consider if you will:<P/>
<CODE>
#!/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 );
</CODE>
<P>This will give you the same error - because what you're passing _into_ the subroutine is not a filehandle, it's a reference to a filehandle. <P/>
<CODE>
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 );
</CODE>
<P>This works, because the filehandle has dereferenced. I think this is what is happening in your code - a filehandle is basically a reference to a file, and you are passing a reference _to_ that reference. <P/>
<P>Edit: Check 'perldoc -f print': If you're storing handles in an array or hash, or in general
whenever you're using any expression more complex than a
bareword handle or a plain, unsubscripted scalar variable to
retrieve it, you will have to use a block returning the
filehandle value instead...</P>
<P>Therefore in the example above, you could instead do:</P>
<CODE>
print {$$ref_to_fh} "Even more stuff\n";
</CODE>
<P>That's the essence of what that 'not a GLOB' message means - print doesn't like (recognise) your filehandle</P>
1039009
1039009