in reply to java/c has main - perl has ?
I do this all the time, mostly as a way of incorporating unit test code into my modules, but I've seen no good reasons why it shouldn't be done for other purposes. I do it like this.
package My::Module; ... return 1 if caller; #! perl -slw package main; use My::Module; my $thing = My::Module->new(); # Do My::Thing:)
Use the module in the normal way in other programs, or invoke it using perl -x libpath/My/Module.pm to run the embedded program. The -x is only needed if you want any shebang line switches to be processed, omit it and put your switches on the command line if you prefer.
|
|---|