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


in reply to Re: Split does not behave like a subroutine
in thread Split does not behave like a subroutine

Thanks LanX for the answer! I have got a lot to think over.

To understand this: > The scalar comma operator returns the last element. I must understand in which list it is the last element.

I have to understand what (LIST) means in the documentation.

I believe you for Perl can say:

From List value constructors

(In the text it is very difficult to understand which parts apply to use in list context, scalar context or both.)

LVC1: List values are denoted by separating individual values by commas (and enclosing the list in parentheses where precedence requires it): (LIST)

LVC2: In a context not requiring a list value, the value of what appears to be a list literal is simply the value of the final element

LVC3: LISTs do automatic interpolation of sublists. That is, when a LIST is evaluated, each element of the list is evaluated in list context, and the resulting list value is interpolated into LIST just as if each individual element were a member of LIST.

LVC4: The null list is represented by (). Interpolating it in a list has no effect.

From Comma Operator

CO1: Binary "," is the comma operator.

CO2: In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value.

CO3: In list context, it's just the list argument separator, and inserts both its arguments into the list. These arguments are also evaluated from left to right.

My own definitions

Several (possible) lists can bee involved:

LVC_scalar_value: the scalar value which is the output from the constructor in scalar context

My first try to: The execution of syntactic construct (LIST)

The elements in LVC_arg are evaluated from left to right according to [CO2] or [CO3]. [CO2] and [CO3] gives the same execution order and the same side effects. The only difference is how the return value is created.

The execution of a element in LVC_arg is recursive according to [LVC3]. During this is the LVC_list_value created. Note that this execution of the elements are done in list context.

When the (LIST) is called in scalar context the LVC_list_value is not used. Instead is the LVC_scalar_value created and returned. The LVC_list_value is the value of the last element, in the last recursion. The execution of the last element is done in scalar context. An execution of the empty list, (), in list context is a "no operation" [LVC4]. The execution of an empty list in scalar contexts results in undef [?].