SPUG: Net::Telnet

Martin, Asa asa.martin at attws.com
Thu Sep 6 18:55:43 CDT 2001


Hi,

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.

Here's an example:

sub new_object {

    my ($host,$timeout,$pass,$priv) = @_;

    my $t = Net::Telnet->new(Host=>$host, Timeout=>$timeout);

# do some $t->prints and $t->waitfors, etc...

    return $t;

}

sub change_pass {

    my ($t,$newpass,$newpriv) = @_;
     # use the $t object and $newpass and $newpriv to do more $t->prints and
$t->waitfors..

}

# and it is called like this in the main section:

my $t = new_object('host', 10, 'password', 'secret');
change_pass($t,'newpassword','verysecret');

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?

Thanks,

Asa Martin


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/spug-list/attachments/20010906/9368c833/attachment.htm


More information about the spug-list mailing list