SPUG: Net::Telnet

Benjamin John Turner bjturner at mac.com
Thu Sep 6 19:28:28 CDT 2001


At 4:55 PM -0700 9/6/2001, Martin, Asa wrote:
>I have a question that pertains to Net::Telnet, but it is really a 
>general object oriented question. When I create a new Net::Telnet 
>object, I store the result in a variable (i.e. my $t = 
>Net::Telnet->new('myhost.com');
>
>I want to put the creation of the object in a subroutine and have 
>the subroutine return the $t object. Then pass that object to other 
>subroutines to do other things to it.

	It sounds like what you really want to do is subclass 
Net::Telnet. That way you could say things like:

my $t = new Net::Telnet::Subclass( 'host', 10, 'password', 'secret' );
$t->change_password( 'newpassword','verysecret ');
# etc., etc.

	That would be the object-oriented way to do things, anyway. It 
might also help you find your bug, since it's highly likely that 
you'd trigger an error earlier and closer in the code to the actual 
problem.

>This doesn't work. It says: "Can't call method 'print' without a 
>package or object reference." And the line number is the first 
>$t->print line in the change_pass subroutine.
>
>Is this possible? Does this make sense?

	It should work as you described it, which probably means there's 
a bug in your code. I'd walk through this code in the perl debugger 
and make sure that you are getting a object back from your call to 
Net::Telnet and that that object is being correctly passed along to 
the other functions you've defined.
		Benjamin Turner
-- 
Benjamin John Turner          |  bjturner at bigfoot.com
http://www.usfca.edu/turner/  |  bjturner at whowhere.com

"The happiest of people don't necessarily have the best of 
everything; they just make the most of everything that comes along 
their way."

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list