For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2004 > Team! Help a newbie with $t->print("ls"); which fails.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Team! Help a newbie with $t->print("ls"); which fails.
Marco Perl

2004-07-24, 3:55 am


I have 2 functions. in func1 $t->print(); works fine.

but func1 got too long and I created func2 to continue on

$t->print(); statements. but $t->print(); of func2 does not work (perl interpreter does not know what $t is).

so!, how can I associate $t in func2 to $t in func1,

and continue on $t->print(); statements?

I'm always grateful for your input.

Code follows.

Marco.



sub func1 {

my ($forecast, $t);

use Net::Telnet ();

$t = new Net::Telnet;

$t->open("$ip");



$t->waitfor('/login: /');

$t->print("jeff");

$t->waitfor('/password: *$/i');

$t->print("papa");

$t-> waitfor( '/\-\> *$/i' ) ;

$t-> prompt( '/\-\> *$/i' ) ;



$t->print("pwd");

($forecast) = $t->waitfor('/\->/i');

print $forecast;



#above $t->print("pwd"); works fine and prints the result.

}



sub func2 {

$t->print("ls");

($forecast) = $t->waitfor('/\->/i');

print $forecast;



#this $t->print("ls"); does not work.

#interpreter complains.

}
#End

________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Ronald Yacketta

2004-07-24, 3:55 am

for starters $t is local to func1 via the usage of my

my ($forecast, $t);

secondly you could either declare $t as a global var or pass it to func2

-Ron



From: Marco Perl
Sent: Fri 7/23/2004 10:05 PM
To: beginners@perl.org; beginning_perl_tk@yahoogroups.com
Subject: Team! Help a newbie with $t->print("ls"); which fails.


I have 2 functions. in func1 $t->print(); works fine.

but func1 got too long and I created func2 to continue on

$t->print(); statements. but $t->print(); of func2 does not work (perl interpreter does not know what $t is).

so!, how can I associate $t in func2 to $t in func1,

and continue on $t->print(); statements?

I'm always grateful for your input.

Code follows.

Marco.



sub func1 {

my ($forecast, $t);

use Net::Telnet ();

$t = new Net::Telnet;

$t->open("$ip");



$t->waitfor('/login: /');

$t->print("jeff");

$t->waitfor('/password: *$/i');

$t->print("papa");

$t-> waitfor( '/\-\> *$/i' ) ;

$t-> prompt( '/\-\> *$/i' ) ;



$t->print("pwd");

($forecast) = $t->waitfor('/\->/i');

print $forecast;



#above $t->print("pwd"); works fine and prints the result.

}



sub func2 {

$t->print("ls");

($forecast) = $t->waitfor('/\->/i');

print $forecast;



#this $t->print("ls"); does not work.

#interpreter complains.

}
#End

________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com