Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: My problems to understand the Perl documentation

by bojinlund (Prior)
on Aug 23, 2020 at 18:59 UTC ( #11121011=note: print w/replies, xml ) Need Help??


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

  • Reading index-functions I get the impression that split is a function.
  • In perlsub is stated:
  • The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. ...
  • 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 (Thanks LanX )

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

I have however realized that:

  • Split's first argument, /PATTERN/, is not evaluated immediately. In some way it is kept for later usage.
  • The rest of the arguments are not treated like a Perl sub without prototype.

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 (Bishop) 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 (Sage) 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 (Sage) 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 (Hermit) 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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-01-28 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?