in reply to The Comma Operator
The latter arguments are thrown away because the '=' binds more tightly than the comma. If these were subroutines, they would have evaluated before being discarded.> perl -MO=Deparse,-p -e '$d, $e, $f = 1,2,3;' -e syntax OK ($d, $e, ($f = 1), '???', '???');
Note the parens around everything; to answer your question about why it evaluates all three terms, it is a list that gets discarded after evaluating its elements, which look like functions so they're evaluated as functions.> perl -MO=Deparse,-p -e 'print(1),print(2),print("\n");' -e syntax OK (print(1), print(2), print("\n"));
And your description was exactly right.> perl -MO=Deparse,-p -e 'print 1, print 2, print "\n";' -e syntax OK print(1, print(2, print("\n")));
|
|---|