in reply to Re^6: Match operator giving unexpected output
in thread Match operator giving unexpected output
the scalar comma operator is more like a "weak" semicolon, i.e. separating evaluated expressions without terminating a statement.
you'll sometimes see people writing stuff like
DB<119> $a=0 => 0 DB<120> while ($a++,$a<5) {print "$a\n"} 1 2 3 4
while only excepts one statement, so no semicolon possible.
But every comma separated part is executed, but only the last result is returned
so in your case, you'll get a warning, cause "a" is executed but never returned.
DB<108> use warnings; ("a","b") => ("a", "b") DB<109> use warnings; scalar ("a","b") Useless use of a constant (a) in void context at (eval 34)[multi_perl5 +db.pl:2279] line 1.
maybe it's best to say that scalar comma list is kind of a poor man's do block, but called in scalar context.
DB<135> sub ctx {print wantarray ? 'list' : defined wantarray ? 'sca +lar' : 'void'; return} DB<136> @a= do {ctx();ctx()} # list-do voidlist DB<137> do {ctx();ctx()};1 # void-do voidvoid DB<138> $a=do {ctx();ctx()} # scalar-do voidscalar DB<140> scalar (ctx(),ctx()) # scalar comma voidscalar DB<141> 1 while (ctx(),ctx()) # scalar (boolean) comma voidscalar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Match operator giving unexpected output
by Anonymous Monk on Jan 14, 2015 at 01:34 UTC | |
by LanX (Saint) on Jan 14, 2015 at 05:37 UTC | |
by Anonymous Monk on Jan 14, 2015 at 07:07 UTC |