NAME

Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements

DESCRIPTION

Perl's comma statement separator has really low precedence, which leads to code that looks like it's using the comma list element separator not actually doing so. Conway suggests that the statement separator not be used in order to prevent this situation.

The confusion that the statement separator causes is primarily due to the assignment operators having higher precedence.

For example, trying to combine two arrays into another like this won't work:

@x = @y, @z;

because it is equivalent to

@x = @y;
@z;

Conversely, there are the built-in functions, like print, that normally force the rest of the statement into list context, but don't when called like a subroutine.

This is not likely to produce what is intended:

print join q{, }, 2, 3, 5, 7, ": the single-digit primes.\n";

The obvious fix is to add parentheses. Placing them like

print join( q{, }, 2, 3, 5, 7 ), ": the single-digit primes.\n";

will work, but

print ( join q{, }, 2, 3, 5, 7 ), ": the single-digit primes.\n";

will not, because it is equivalent to

print( join q{, }, 2, 3, 5, 7 );
": the single-digit primes.\n";

AUTHOR

Elliot Shank <perl@galumph.com>

COPYRIGHT

Copyright (c) 2007 Elliot Shank. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.