Re: How to pass parameters to a module
Hi! It's easy! There is one sample: sub do_somethig { my @[EMAIL PROTECTED]; if (! ($passed_params[0])) { print "Not passed parametrs" } my @lines; #Do something ... return @lines; } On Thu, 25 Sep 2003 21:59:53 -0700, Rajesh Dorairajan <[EMAIL PROTECTED]> wrote: 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 -- With best regards, Juris Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to pass parameters to a module
> 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]
Re: How to pass parameters to a module
Rajesh Dorairajan wrote: 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 Suppose you are calling this from a script say script.pl in script.pl put BEGIN { $GLOBAL::input="THIS IS PASSED TO THE MODULE"; require My::Module; } and in the package put $scalar=$GLOBAL::input; I am not very sure if this a "good" way of doing it but works. And BTW you can not do *use* My::Module , You will have to do *require* My::Module Ram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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