in reply to invocation mode - how discover?

Maybe you're looking for caller? Hard to tell given the vagueness of "method of invocation" (how your Perl program was called? how a given sub was called? how you were called on the phone? . . .)

Replies are listed 'Best First'.
Re^2: invocation mode - how discover?
by toolsmith (Novice) on Dec 10, 2005 at 14:43 UTC
    I apologize for the terseness of my message. What I'm really looking for, I think, is the name of the caller. For example, if the script was invoked by typing its name on the command line, that would be the shell and would equate to what I called COMMAND in my original question. If the program is called using backquotes from another perl script, I'd want the name of that script, or at least perl.exe as the caller--that would equate to SUBROUTINE in my original post. And FUNCTION in my original post is probably a rexx-only concept, sorta like using popen. I replied to your message out of the three, because "caller" really seems closest in intention to what I'm looking for, but as far as I can determine it only works for a subroutine called from within the same script. Maybe there's no way. I'm thinking now that a stack trace might give me what I want.
      caller is really only useful in a subroutine, to tell you the name of the subroutine that called it. I think I understand what you're asking for, but I don't understand why. The answer is that it's not easy (you'd have to start with getppid and then find the process that corresponds to that pid, then find its command). But in general, it's relatively rare for perl scripts to be called from each other by backticks. It's usually much better practice to factor out the parts that are needed in different places into subroutines. So the big question I have is, "What exactly are you trying to achieve?" It's usually a very bad idea (for debugging if nothing else) to have your program behave differently depending on who calls it. What are your end goals? There's probably a much more perlish way of doing it.
        Sorry. Duty called, kept me away. I am sure you are right that what I'm trying is a mistake. In fact, in perl it's a non-problem even when I'm making the mistake, because backticks automatically redirect stdout into an array. It's just residual rexx limitation workarounds that had me looking for a way to identify exernal caller. But I will play with getppid just for fun. Thanks again - Toolsmith