If they are separate scripts then I cannot think of a way in which one script can pass on the telnet object to another script. if you want something like this you need to break them into modules and call the method to start the telnet process and return the telnet object. Once you get the telnet object you should be able to use it another place .
BTW, how are you doing the telnet? are you using the command 'telnet" or using a module? I would recommend Net::Telnet
-SK
update: Here is a code snippet using Net::Telnet
#!/usr/bin/perl -w
use Net::Telnet;
my $telnet;
# Your prompt setting might be different
$telnet = new Net::Telnet ( Timeout => 10, Errmode => 'die', Prompt =>
+ '/.*%/');
$telnet->open('YOUR HOSTNAME'); # Enter your host name here
print ("Please enter Username: ");
$user = <STDIN>;
print ("Please enter password: ");
$pass = <STDIN>;
$telnet->login($user, $pass); # You can hard code user/pass but here i
+ am getting getting user input to avoid typing them in.
print ($telnet->cmd('date')); # Run a command then print out the resul
+t
You can put this entire block until execution into a package/sub. Then whenever you want to execute a command you can just use the telnet object that was created. (assuming your return it back to the caller)
|