http://qs321.pair.com?node_id=1078053

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.