Click to See Complete Forum and Search --> : perl modules


NathanTwist
03-26-2002, 06:19 PM
oye everybody
ive been giving perl a run down, and i feel pretty comfortable with it, so i figure the next step is modules; ill actually be able to do something useful. but somethings just not clicking. ive read a ways through all of the tutorials on cpan, but they all seem to refer to something ive never heard of, or some other such deterant. so can anyone give me the basic syntax for using a module? i just think that id be better able to grasp the man pages if i had an example in front of me
thanks again

iDxMan
03-26-2002, 07:21 PM
Typically something like : (using the Net::Telnet module as an example since that seems to pop into mind)


use Net::Telnet ();

$tl = new Net::Telnet (Timeout => 15);
$tl->errmode("return");
$tl->open("hostname");

if($tl->errmsg =~ /problem connecting/i) {
# grab your pants
}
#etc.. etc..


Of course each module differs, but that is a basic syntax you would use. Note the use of `errmode` and `open` are specific methods of Net::Telnet().

Check out the pod docs for each module.

-r

J-Tek
03-26-2002, 08:48 PM
if you're going to get into perl you should try joining a mailing list on
www.activestate.com (http://www.activestate.com)

there are some real masters there. and a diverse mailing list

hope that helps

NathanTwist
03-26-2002, 09:07 PM
but say i wanted to use a module in my script, is it just a matter of saying "use foo::bar" and then just using a subroutine as if it it was part of the program itself, like a C include statement?

NathanTwist
03-28-2002, 01:01 PM
guys...?

takshaka
03-28-2002, 03:01 PM
Depends on the module. OO modules are used like the Net::Telnet example above. Others export (or can export) subroutines directly into the main namespace.

Check the module documentation by doing 'perldoc foo::bar' You might also want to take a look at 'perldoc perlmod (http://www.perldoc.com/perl5.6.1/pod/perlmod.html#Perl-Modules)'.