Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

List's terminology and Parentheses in Perl

by LanX (Saint)
on Jul 18, 2020 at 12:03 UTC ( [id://11119489]=note: print w/replies, xml ) Need Help??


in reply to Split does not behave like a subroutine

You have cited perldocs, unfortunately without linking to the references.

List Terminology

The term "list value" was confusing me, in such cases I recommend looking into perlglossary#LIST ff.

NB: Perlglossary is from an appendix from the Camel (IIRC), while the perldocs were written by different authors.

  • LIST

    A syntactic construct representing a comma- separated list of expressions, evaluated to produce a list value. Each expression in a LIST is evaluated in list context and interpolated into the list value.

  • list

    An ordered set of scalar values.

  • list context

    The situation in which an expression is expected by its surroundings (the code calling it) to return a list of values rather than a single value. Functions that want a LIST of arguments tell those arguments that they should produce a list value. See also context.

  • list operator

    An operator that does something with a list of values, such as join or grep. Usually used for named built-in operators (such as print, unlink, and system) that do not require parentheses around their argument list.

  • list value

    An unnamed list of temporary scalar values that may be passed around within a program from any list-generating function to any function or construct that provides a list context.

Parentheses

I think one source of confusion (besides @arrays) is the syntactic meaning of parentheses ...(...)... in different constructs.

  • ()

    is an empty list

  • bareword(...)

    expects a LIST of arguments to a sub bareword °

  • (...)[subscript/slice]

    picks elements from a list

  • (...) =

    is a list assignment enforcing list context on the RHS updated

... those constructs impose a list context inside

But ...

  • "naked" (...) doesn't

    those parens are just for precedence

... neither do they impose their own context nor do they create a "list value".

Examples (updated)

please see Examples for "LIST", "list context", "list value", "list assigment", "list operator"

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

°) well modulo sub-prototype

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-28 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found