Comma Operators
Binary “,” is the comma operator. In scalar context it evaluates its left argument in void context, throws that
value away, then evaluates its right argument in scalar context and
returns that value. This is just like C’s comma operator. For
example:
$a = (1, 3);
assigns 3 to $a. Do not confuse the scalar context use with
the list context use. In list context, a comma is just the list argument
separator, and it inserts both its arguments into the
LIST. It does not throw any values away.
For example, if you change the previous example to:
@a = (1, 3);
you are constructing a two-element list, while:
atan2(1, 3);
is calling the function atan2
with two arguments.
The => digraph is mostly just
a synonym for the comma operator. It’s useful for documenting arguments
that come in pairs. It also forces any identifier to its immediate left to
be interpreted as a string. This autoquoting works only on identifiers,
not on numeric literals.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access