Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

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

You'll get a lot of people telling you that a "list" lives on the stack. You'll probably get a few people telling you that a "list" is things separated by commas. In fact, the word "list" is used for many different things in the Perl documentation and so anyone who tries to define it strictly for you is likely to cause you confusion when you run into one of the many parts of the Perl documentation that use the word "list" to mean something else.

In the Perl documentation, it is best to interpret "list" as an English word that describes several items of nearly any type associated together in a specific order. Within parts of the documentation, you will probably be able to infer more precisely what the word "list" is being used for within that section. But there are also parts where the word "list" is used in one way rather close to it being used in quite a different way.

An array, however, does have a rather precise meaning in Perl. It is something that you can push or pop or shift or unshift or splice. An array is a list of scalar values held in a structure that gives you access to make modifications to that list. It often has a name but it can be anonymous. Array is a type of Perl variable. You can take a reference to it.

The most important Perl concept that comes closest to being a "List" (capital "L") is better named "an operation that would return a list of scalar values if used in a list context". The concept of "a list of scalar values on the stack" is an oft-invoked image but I don't find it useful (unless you are trying to define "List", in which case it is certainly a simple definition, though a misleading one and not nearly the most important one, in my experience).

The "operation that would return a list of scalar values if used in a list context" aims right at the heart of Perl's list and scalar contexts. These will often be called "list" for short.

A list of expressions separated by commas is one way to write an "operation that would return a list of scalar values if used in a list context". Note that the list of expressions is not the same list as the list of scalar values that might be returned. This is important because, in a scalar context, this list of expressions returns the value that is returned by the last expression when it is called in a scalar context. This can be quite different from the last value of the list of scalar values that would be returned if the list of expressions were called in a list context.

Many have previously summed up what the above paragraph describes by saying that a list in a scalar context returns the last value of the list. So beware when you hear someone make restrictive proclamations about "lists" in Perl.

- tye        

In reply to Re: Differ. array and List (there is no List) by tye
in thread Differ. array and List by Anonymous Monk

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others browsing the Monastery: (6)
    As of 2024-07-21 11:11 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found

      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.