Perl::...yCommas(3pm)

πŸŽ€ NAME πŸŽ€

Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyCommas β€” bestie, this policy says no to empty consecutive commas, okay? Periodt.


✨ DESCRIPTION ✨

So this policy lives inside the Perl::Critic::Pulp add-on πŸ’œ. What it does is it prohibits the empty comma operators , or =>, which basically means either commas that are back-to-back with nothing between them, or a comma chillin' at the very start of a list or an expression. It's giving "who left this here" πŸ™ˆ.

print 'foo',,'bar';      # bad
@a = (,1,2);             # bad
foo (x, => 123);         # bad
a =>=> 456;              # bad
for (; $i++<10; $i++,,)  # bad
func (,)                 # bad

And like… the tea is that extra commas like this are harmless πŸ”₯ β€” they literally just collapse out the second the program runs (see List value constructors in perldata). So this policy is only under the cosmetic theme (see POLICY THEMES in Perl::Critic). Usually this kind of thing is just a stray, or leftover from a cut and paste moment, or maybe someone got a lil too enthusiastic with their column layout, iykyk.

But occasionally it can be something more dubious πŸ‘€:

# did you mean 1..6 range operator?
@a = (1,,6);        # bad

# this is two args, did you want three?
foo (1, , 2);       # bad

# this is three args, probably you forgot a value
bar (abc => ,       # bad
     def => 20);

Now a comma at the end of a list or call? That's allowed, bestie, we're not monsters 🫢. That's super normal and honestly it's a good thing when you're cutting and pasting lines around (see RequireTrailingCommas to mandate them!).

@b = ("foo",
      "bar",  # ok
     );

And if you use multiple commas in some systematic way for your code layout, no stress πŸ’… β€” you can always disable ProhibitEmptyCommas from your .perlcriticrc file in the usual way (see CONFIGURATION in Perl::Critic):

[-ValuesAndExpressions::ProhibitEmptyCommas]

🌈 SEE ALSO 🌈

  • Perl::Critic::Pulp
  • Perl::Critic
  • Perl::Critic::Policy::CodeLayout::RequireTrailingCommas
  • Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements
  • Perl::Critic::Policy::Tics::ProhibitManyArrows

πŸ¦‹ HOME PAGE πŸ¦‹

http://user42.tuxfamily.org/perl-critic-pulp/index.html


Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde

Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.


okay that's the whole page, no cap πŸ’– and for the record this lil manual ships with perl v5.40.1, dated 2025-10-21 β€” mwah, iconic, love that for us 🌸✨

πŸ“¦ where this page comes from