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


in reply to Re: My problems to understand the Perl documentation [updated]
in thread My problems to understand the Perl documentation

Thank you jo37 for your work!
This is not true, it gives (99).

Sorry, I had an error in my test script. Now I also get 99.

Your example made me understand that a prototype also defines the context (scalar/list) for the evaluation of the arguments.

My point is that the function split is not fully described in the Perl documentation

My conclusion from this is that split is a Perl sub, without prototype.

I have however realized that:

Somewhere in split this differences from a normal Perl sub should be included. As split behaves more like an operator it is perhaps better to call it an operator. It is also implemented as an operator and not as a Perl sub.

Replies are listed 'Best First'.
Re^3: My problems to understand the Perl documentation
by haukex (Archbishop) on Aug 24, 2020 at 08:44 UTC
    Reading index-functions I get the impression that split is a function.

    That list also includes things that are clearly not a function, like and, __END__, and m.

    The function prototype returns the prototype of a function as a string (or undef if the function has no prototype). prototype "CORE::split" returns undef

    You seem to be ignoring the part of that doc that says:

    If FUNCTION is a string starting with CORE::, the rest is taken as a name for a Perl builtin. If the builtin's arguments cannot be adequately expressed by a prototype (such as system), prototype returns undef, because the builtin does not really behave like a Perl function.
    As split behaves more like an operator it is perhaps better to call it an operator.

    Please read carefully Terms and List Operators (Leftward):

    Actually, there aren't really functions in this sense, just list operators and unary operators behaving as functions because you put parentheses around the arguments.

    Several things in Perl only make sense when you read all of the documentation.

Re^3: My problems to understand the Perl documentation
by LanX (Saint) on Aug 24, 2020 at 18:58 UTC
    Split IS a builtin function.

    I told you already that the fact you can't easily replicate it with sub doesn't mean it's not a function.

    Perl is not Lisp where the whole syntax can be expressed with one single s-expression .

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re^3: My problems to understand the Perl documentation
by LanX (Saint) on Aug 24, 2020 at 19:11 UTC
    > Reading index-functions I get the impression that split is a function.

    That's taken from perlfunc and there it clearly states

    Here are Perl's functions (including things that look like functions, like some keywords and named operators ) arranged by category.

    It should better have been named "keyword-index"

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re^3: My problems to understand the Perl documentation
by jo37 (Deacon) on Aug 23, 2020 at 19:42 UTC
    My conclusion from this is that split is a Perl sub, without prototype.

    Is there any built-in without a prototype? I don't think so.

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
      > Is there any built-in without a prototype? I don't think so.

      Yes, several.

      You can check yourself with prototype

      From the docs:

      If FUNCTION is a string starting with CORE:: , the rest is taken as a name for a Perl builtin.

      If the builtin's arguments cannot be adequately expressed by a prototype (such as system), prototype returns undef, because the builtin does not really behave like a Perl function.

      Otherwise, the string describing the equivalent prototype is returned.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      Is there any built-in without a prototype?

      On 5.28, prototype returns undef for at least the following (I may have missed a few, and I omitted most things that I think most people would classify as keywords and operators instead of functions, like use, goto, and -X):

      chomp chop defined delete do eval exec exists grep map print printf require return say select sort split system

      Added minor clarifications.

        > most people would classify as keywords and operators instead of functions

        For me any reserved word is a keyword, this includes functions.

        I know what you mean but "keyword" doesn't describe it.

        See also perlfunc#Perl-Functions-by-Category ... which is even more confusing.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery