Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Determination of a subs' invocation from within the sub [RESOLVED]

by Bloodnok (Vicar)
on Mar 12, 2014 at 17:22 UTC ( #1078053=perlquestion: print w/replies, xml ) Need Help??

Bloodnok has asked for the wisdom of the Perl Monks concerning the following question:

Greetings fellow monasterians ,

Once again I seem to have encountered a question for which I don't seem to be able to find an answer and am resorting to propgating the question up to the knowledgeable brethren herein - to whit and viz:- within any sub, say some_sub, is it posible to be able to distinguish between the following 2 possible invocations ... &some_sub; and some_sub(@_); ??

TIA ,

Update: Resolved and quickly, thanx to BrowserUk.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re: Determination of a subs' invocation from within the sub
by BrowserUk (Patriarch) on Mar 12, 2014 at 17:34 UTC
    is it posible to be able to distinguish between the following 2 possible invocations ... &some_sub; and some_sub(@_); ??

    Yes. Inspect (caller(0))[4] to determine if the function was called with or without arguments.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Bugger, it's always the simplest solutions I manage to overlook.

      Very many TFT BrowserUk.

      A user level that continues to overstate my experience :-))
Re: Determination of a subs' invocation from within the sub
by kennethk (Abbot) on Mar 12, 2014 at 17:37 UTC
    Not to be flippant, but this smacks of an XY Problem, or at least unnecessarily high levels of cleverness. Why would you need to tell the difference?

    Assuming you have a Good Reason™, one difference is prototype checking. From perlsub:

    Not only does the & form make the argument list optional, it also disables any prototype checking on arguments you do provide. This is partly for historical reasons, and partly for having a convenient way to cheat if you know what you're doing. See Prototypes below.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-05-22 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (78 votes). Check out past polls.

    Notices?