go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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
|
|