Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Assuming I'm looking at the right lines, you're contemplating the difference between:

#print $channel "$cmd\n"; #while (<$channel>) { print {${$channel}} "$cmd\n"; while (<${$channel}>) {

That's because you're having a problem with passing references to filehandles. $channel is a filehandle. You're passing it by reference:

$self->{_ssh2_channel} = \$channel;

Which means when you're trying to use it - as a filehandle - you need to dereference first. Consider if you will:

#!/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 );

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.

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 );

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.

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...

Therefore in the example above, you could instead do:

print {$$ref_to_fh} "Even more stuff\n";

That's the essence of what that 'not a GLOB' message means - print doesn't like (recognise) your filehandle


In reply to Re: Question regarding using references with Net::SSH2 in module by Preceptor
in thread Question regarding using references with Net::SSH2 in module by DarthBobToo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (14)
    As of 2014-09-02 09:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (21 votes), past polls