Your questions on regular expressions, and what they do in various contexts, with and without capturing parenthesis would probably be answered in perlre, perlrequick, and perlretut. There is additional reading proscribed at the bottom of each of those docs.

perlsyn discusses while(){}, but think of it this way: while evaluates a condition. In other words, while some condition exists, the loop proceeds. It's more akin to an "if()" statement except that the test repeats again and again until it fails. The test is a Boolean test; true or false. It doesn't make sense to discuss list context in terms of a Boolean evaluation.

foreach(), on the other hand, is an iterating loop construct. The Perl-style foreach iterates over a list of elements until it finishes with the last one. For each element in the list, there's one iteration, or one execution of the code within the blocks. In such a case it should be fairly obvious that the context is list context. On the other hand, the C style foreach loop is a bit of a special case. It provides a mechanism for the creation of a counter variable, does a conditional test (which is Boolean), and then provides a mechanism for incrementing the counter. But in this special case, it doesn't make sense to be talking about list context. In fact, perlop (in the section talking about IO operators) alludes to the fact that a for(;;) loop is sort of a disguise for a while() loop. So you could almost have a mind-entry of "Foreach (;;) (c-style loop): See also while()."

<STDIN> is pretty well documented in perlop. In scalar context it returns one record (or line). In list context, it returns all records (or lines) as separate list elements. In Boolean context it throws a warning under -w.

I actually think that after reading perlintro, perlsyn, perlop, and perlre you will have just about covered 90% of your context questions. And if you're really interested in Perl you were going to read those anyway. :)


Dave


In reply to Re: Easy Reference for Contexts by davido
in thread Easy Reference for Contexts by cat_baby

Title:
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, details, 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, summary, 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.