Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Dual personality: Module and script

by Anonymous Monk
on Aug 03, 2004 at 15:55 UTC ( [id://379717]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^3: Dual personality: Module and script
by Aristotle (Chancellor) on Aug 03, 2004 at 16:13 UTC

    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.
        unless (defined caller) { ... } really is the simplist and best way to do this.

        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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://379717]
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-19 17:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found