Beefy Boxes and Bandwidth Generously Provided by pair Networks
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
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":



  • 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 rifling through the Monastery: (6)
As of 2024-04-19 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found