Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Dual personality: Module and script

by bgreenlee (Friar)
on Aug 03, 2004 at 15:23 UTC ( [id://379698]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://379698]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 14:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found