Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:

  • The return value context ( scalar or list ) controls how the return value is created.
  • The side effects (everything but the return value) of calling something does not depend on the return value context.

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_arg: The list of arguments in the List value constructor [LVC0]
  • LVC_par: The resulting parameter list value
  • LVC_list_value: the list value which is the output from the constructor in list context

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 [?].


In reply to Re^2: Split does not behave like a subroutine by bojinlund
in thread Split does not behave like a subroutine by bojinlund

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-16 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found