Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: Dual personality: Module and script

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


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

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.

Replies are listed 'Best First'.
Re^5: Dual personality: Module and script
by ysth (Canon) on Aug 03, 2004 at 19:28 UTC
    unless (defined caller) { ... } really is the simplist and best way to do this.
Re^5: Dual personality: Module and script
by bgreenlee (Friar) on Aug 04, 2004 at 11:23 UTC

    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

      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"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-29 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found