On Dec 2, 2005, at 21:52, [EMAIL PROTECTED] wrote:
Hi all,
I don't know if the question that I am going the ask fits the
beginner level,
but I am certainly a beginner in perl.
Is it possible for a module to refer to its calling script? For
example, if I
create a module called MyModule.pm, and use it in a script
MyScript.pl by saying
"use MyModule;", is it possible to refer to the calling script
(MyScript.pl in
this case) and get some information about it during the process of
writing the
module (MyModule.pm in this case)?
Yes. When the module is used the import() function, if any, is
called. There caller() returns what you want:
% cat tmp/Foo.pm
package Foo;
sub import {
print((caller)[1]);
}
1;
% cat tmp/foo.pl
use Foo;
% perl -Itmp tmp/foo.pl
tmp/foo.pl
You can assign that to a package variable or whatever.
This way, I want to make the behaviour of the
module flexible based on where it is called.
Nevertheless, this sounds strange. Without more information looks
like the module is parametrizable and the script needs to make the
proper calls or proper module set up. Using caller() for that looks
suspicious.
-- fxn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>