> Can someone explain how does one pass
> a parameter to a Perl Module?

There are a few ways.

#1 - On the use line

use My::Module qw(foo bar);

When you "use" a module it first loads the module and evaluates it.  Second
it runs the import() subroutine in the module (if there is one), passing the
params you specified on the use line.  BTW - this is how Exporter works, it
supplies an import() subroutine that exports variables/methods for you.  If
you need to use Exporter, and want your own import() sub, then you need to
do it a little differently.  Take a look at the perl docs for more info.

#2 - On object creation

my $obj = new My::Module('foo', 'bar');

#3 - Set via properties or methods

$obj->{key} = 'foo';
...or...
$obj->set_key('foo');

It really depends on what exactly you are trying to accomplish.

Rob



-----Original Message-----
From: Rajesh Dorairajan [mailto:[EMAIL PROTECTED]
Sent: Friday, September 26, 2003 1:00 AM
To: '[EMAIL PROTECTED]'
Subject: How to pass parameters to a module


Can someone explain how does one pass a parameter to a Perl Module? To
illustrate suppose I've My::Module

package My::Module;

BEGIN
{
  $scalar = $input;
}

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = ($scalar);

In the above script is there anyway to pass the $input variable to the
package My::Module from the calling script? Please excuse me if the code is
horrible, just trying to simplify what I want ;)

TIA

Rajesh

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to