On Apr 6, 2005, at 12:22, lohit wrote:
i have a strange requirement where in i have certain functionality to be achieved by calling a perlscript. say script.pl <parameters> but i also have to seperate these functionalities in a module script.pm
A different thread today reminded me that caller() could be useful here as well (depending on unknown details).
If usage options ara just module vs script, you can know which one is being performed dynamically because caller() returns undef for scripts in scalar context:
% cat foo.pm $called_as_module = caller;
if ($called_as_module) { print "called as module\n"; } else { print "called as script\n"; } % perl -Mfoo -e1 called as module % perl foo.pm called as script
Then, you could implement the funcionality once, call the corresponding subroutines if called as a script, and make a soft link if standard extensions are expected for each usage, for example.
-- fxn
PS: This "dualism" is indeed very common in Python. People write modules and implement tests that are run only if the file is interpreted as a script. The idiom there is
if __name__ == '__main__':
<called as a script, module tests go here>
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>