Perl's comma operator ,
performs several duties. The most widely known duty is to serve as a list separator. List separators are referred to as "fat commas" [Conway 05].:
Code Block |
---|
my @list = (2, 3, 5, 7); |
Outside of list context, the comma can also be used to combine multiple expressions into one statement. Each expression is evaluated, and its result is discarded. The last expression's result is returned as the result of the comma operator. Commas operators are referred to as " Comma operators are called thin commas" [Conway 052005]. This behavior was adopted from C.
The potential for confusing thin commas with fat commas in list context is large enough to forbid use of the thin commas. Commas shall must be used only to separate items in list context.
...
This line of code looks like it would behave the same , but instead behaves quite differently:
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
MSC30-PL | lowLow | probableProbable | mediumMedium | P2P4 | L3 |
Automated Detection
Tool | Diagnostic |
---|---|
Perl::Critic | ValuesAndExpressions::ProhibitCommaSeparatedStatements |
Bibliography
...
2005] |
---|
...
"Thin Commas," p. 68 | |
---|---|
[CPAN] | Elliot Shank, Perl-Critic-1.116 ValuesAndExpressions::ProhibitCommaSeparatedStatements |
...