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.


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.