[EMAIL PROTECTED] wrote:
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)? This way, I want to make the behaviour of the
module flexible based on where it is called.

Modules are not called; they are loaded. Subroutines in modules are called. Unless requested, I shan't get into the difference between compiling and running, yet alone modules, packages, and objects.

You can refer to the script name with $0. You could also do something like this:

# In the script
BEGIN {
  our $ScriptName = 'myscript';
  our @ModuleNames = ();
}

our @ModuleNames;
use mymodule;

__END__


# In each module
our @ModuleNames;
push @ModuleNames, 'this_module_name';

# Alternate
our @ModuleNames;
use File::Basename;
push @ModuleNames, basename( __FILE__ );

1; # All modules must return a non-false value
__END__


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to