in reply to Dual personality: Module and script

You could also check the value of $0. If your module is executed rather than imported, it will return the name of the module. Otherwise it will return the name of the script that imported it.

Brad

Replies are listed 'Best First'.
Re^2: Dual personality: Module and script
by Anonymous Monk on Aug 03, 2004 at 15:55 UTC
    Thank everybody for the replies.

    I was looking to what user bgreenlee replied.
    I do not think it is that terrible to have, on occasion and for private use,
    a module that is "require" as this is more similar to DLL,
    that can also be started from command line or "system"

    Solution works like charm.
    If loaded as stand alone, the suffix is .pm. If 'required' then the suffix is .pl all that is needed then
    if ($0 =~ /\.pm$/i) { # execute stand alone ) # fall thru for module.
    Thanks again for all replies.

      Of course, that's also the least robust solution of the four.

      Makeshifts last the longest.

        True and I agree
        but
        a working solution is all I needed, and it is simple and it works. No need to get too much robustness.
        I guess my second choice would be the "caller EXPR", so I keep this in mind if the simple solution stops working.
        thanks again for all replies.