An alternate way of looking at the problem (besides focusing on the comma's behavior as an operator): is that in the 2nd example, you are putting parentheses around a list. You'll get the same value assigned to "$s" whether you use parentheses or not.
In a way, it's similar to using semi-colons to separate statements that are grouped together:
my $s = do {"111"; "222"; "aaa"; "bbb"};
print $s."\n";
The above also prints "
bbb" -- but if you have
warnings on, it will also warn you that the first 3 items are ignored:
> perl -e '
use warnings;
my $s = do {"111"; "222"; "aaa"; "bbb"};
print $s."\n";'
Useless use of a constant ("111") in void context at -e line 3.
Useless use of a constant ("222") in void context at -e line 3.
Useless use of a constant ("aaa") in void context at -e line 3.
bbb
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.