Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

How to close a telnet connection when using strict

by han_perl (Sexton)
on Jul 13, 2004 at 18:32 UTC ( #374091=perlquestion: print w/replies, xml ) Need Help??

han_perl has asked for the wisdom of the Perl Monks concerning the following question:

I'm not able to close my telnet connection when I use strict. I'm using two files. One file contains the telnet connection routine with "use strict". The other file is the main program. It's giving me an error when I tried to close the connection.
************** file 1 ********************** use strict; use Net::Telnet; sub telnetConnect { my ( $connectionPt, $hostName ) = @_; $connectionPt = Net::Telnet -> new ( Timeout=>6000, Prompt => '/#/') +; $connectionPt -> open( $hostName ); $connectionPt -> login ( "root", "password" ); return $connectionPt; }; sub telnetDisconnect { $$_[0] -> close; }; sub xc { my ( $connectionPt, $cmd ) = @_; print "Command: $cmd\n"; $connectionPt -> cmd( "$cmd" ); }; ************ main file *********************** require("../lib/") or die "ERROR: cannot open host inform +ation file\n"; my $production = "sqa-e450-1"; my $appliance = "sqa-e450-2"; $pro = telnetConnect( $pro, $production ); $app = telnetConnect( $app, $appliance ); my $cmd = "uname -a"; @output = xc( $pro, $cmd ); print " Output1: @output\n"; telnetDisconnect( \$pro ); ********** output ************************* $ perl Command: uname -a Output1: SunOS sqa-e450-1 5.8 Generic_117350-02 sun4u sparc SUNW,Ult +ra-4 Can't call method "close" on an undefined value at ../lib/connection.p +l line 45.
Tried passing the variable by reference or no reference didn't work for me. Any idea on what's wrong.

edited: Tue Jul 13 17:39:55 2004 by jeffa - code tags

Replies are listed 'Best First'.
Re: How to close a telnet connection when using strict
by ysth (Canon) on Jul 13, 2004 at 19:03 UTC
    Your "required" file should have a true value at the end.

    $$_[0] uses $_ as an arrayref, probably not what you want; try dropping one of the $ and passing $pro, not \$pro. (Or use ${$_[0]}->close with passing \$pro.)

Re: How to close a telnet connection when using strict
by ccn (Vicar) on Jul 13, 2004 at 18:37 UTC

    It's not the "strict" problem
    seems that your $pro is undefined

Re: How to close a telnet connection when using strict
by Jonathan (Curate) on Jul 15, 2004 at 09:32 UTC
    $pro is defined in your code snippet and would resolve to a Net::Telnet object reference in your telnetDisconnect call.

    It looks to me like $pro gets overwritten in some of the code you've removed while creating your test case above. Check your code for incorrect $pro assignments.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://374091]
Approved by ysth
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2021-08-05 21:53 GMT
Find Nodes?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)

    Results (44 votes). Check out past polls.