han_perl has asked for the wisdom of the Perl Monks concerning the following question:
Tried passing the variable by reference or no reference didn't work for me. Any idea on what's wrong.************** 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/connection.pl") 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 Perl1.pl 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.
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 | |
|
Re: How to close a telnet connection when using strict
by ccn (Vicar) on Jul 13, 2004 at 18:37 UTC | |
|
Re: How to close a telnet connection when using strict
by Jonathan (Curate) on Jul 15, 2004 at 09:32 UTC |