Dearly beloved Monks,
We are gathered here today to try to help me understand what kinds of commands can be strung together with commas, and what kinds can't, for concise coding.
For example, this works as I would expect (i.e. $x gets the value of $i before the "next" command occurs:
perl -e 'for $i (1..9){$x = $i, next if $i == 5;print $i};END{print "\
+n$x\n"}'
Output:
12346789
5
But here, I would have expected "Next" to print, but as you can see, it doesn't:
perl -e 'for $i (1..9){print "Next", next if $i == 5;print $i}'
Output:
12346789
Questions:
1. Why does '$x = $i' get executed, but 'print "Next"' seems not to, in the above examples?
2. Why didn't I get some kind of error/warning (still nothing even with the '-w' switch), in my 2nd example?
3. Where can I read up about which kinds of commands can be strung together with commas, and which can't?
Thank you!
tel2
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.