in reply to Re^4: Dual personality: Module and script
in thread Dual personality: Module and script

FWIW, I agree that my suggestion (of using $0) is not the best...I would actually use merlyn's suggestion of using caller. I generally eschew the use of such magic variables when there's a way to do it that might be easier for someone looking at it later to figure out.

Brad

Replies are listed 'Best First'.
Re^6: Dual personality: Module and script
by Anonymous Monk on Aug 04, 2004 at 14:27 UTC
    I actually was ahead of you and changed to "caller" right after I tried $0, albeit it worked for me, and I was not insisting on robust solution for any and all Perl/OS/hardware combinations.

    It came as simple as adding the short standalone subroutine and one line of testing :)
    standalone() if (!defined caller); # command-line or "system"