Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: The Comma Operator

by da (Friar)
on Jul 20, 2001 at 19:24 UTC ( [id://98445]=note: print w/replies, xml ) Need Help??


in reply to The Comma Operator

This is an excellent application for Deparse. The -p parameter to Deparse gives you nearly as many parenthesis as perl can give you, which is useful for explainging things. I was first exposed to this trick by Brother MeowChow when I asked how in hell his .sig worked.

> perl -MO=Deparse,-p -e '$d, $e, $f = 1,2,3;' -e syntax OK ($d, $e, ($f = 1), '???', '???');
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 'print(1),print(2),print("\n");' -e syntax OK (print(1), print(2), print("\n"));
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.

___ -DA > perl -MPOSIX -le '$ENV{TZ}="EST";print ctime(1000000000)' Sat Sep 8 20:46:40 2001

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://98445]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found