Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I call a subroutine with in Perl Module?

Status
Not open for further replies.

Newbee21369

Programmer
Oct 13, 2004
30
0
0
US
This is what I have.

Perl Module:
#!/usr/bin/perl
use lib "/usr/tmhp/data/bin/scripts";
package Test;
use TMH;
use strict;
use DBI;

sub connect_dev_app ()
{
my $dbname = 'DBI:Oracle:TMHT2';
my $user = 'xxx';
my $password = 'xxx';
my $dbh;

$dbh = DBI->connect($dbname,$user,$password,
{
RaiseError => 1,
PrintError => 1,
AutoCommit => 0
});

TMH::writeConsole(*LOGFILE, "Connected to Database successfully\n");
return $dbh;
}

1;


External Script:

#!/usr/bin/perl

use lib "/usr/mypath/scripts";
use TestModule;


TestModule::connect_dev_app();
 
Given a caller named 'caller.pl':
Code:
#!perl
require 'waiting.pl';
&call_me();

and a listener named 'waiting.pl':
Code:
#!perl
sub call_me { print "Thanks for calling\n"; }
1;

running caller.pl prints out "Thanks for calling\n";

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Could be wrong here, but I alway's make sure that my "package" name is identical to the filename.

So if I have testMod.pm it would be defined as : package testMod

In the actual pl file i call it as: use testMod

and then tesMod::<function>




[ponder]KrK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top