Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    [LanX]: Network (1976 film) yeah
    [LanX]: yeah, we just had a discussion at work that SciFi in the 70s had more inovation
    [LanX]: (movies)
    [Your Mother]: Real ideas. Ideas grounded in reality as well.
    [LanX]: still some good newer ones. Oblivion had a great design, Moon was well acted
    [Your Mother]: Moon was mind bending and lovely and what's his nose Sam is *always* fun.
    [LanX]: the new BS Galactica series is my all time SoapFiction favourite ...
    [Your Mother]: I even liked "The Arrival" and I generally hate time travel (oriented) stuff.
    [Your Mother]: Gotta go. Stay out of trouble.
    [LanX]: no worries ... mainland Europe is safe ;-P

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (11)
    As of 2018-03-19 15:08 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (240 votes). Check out past polls.