Perl::...ements(3pm)
π Perl::Critic::Policy::ValuesAndExpressions::ProhibitNullStatements π
okay bestie so this is a User Contributed Perl Documentation manual page, and the policy it's about lives at Perl::Critic::Policy::ValuesAndExpressions::ProhibitNullStatements. Let's get into it β¨
β¨ NAME β¨
Perl::Critic::Policy::ValuesAndExpressions::ProhibitNullStatements β it says no to empty statements (aka those stray lil semicolons just vibing on their own) π«Ά
π¦ DESCRIPTION π¦
So this policy is part of the Perl::Critic::Pulp add-on, and what it does is prohibit empty statements β meaning a bare ; semicolon sitting there with nothing to do. Lowkey this happens because of a typo where you double up a semi like
use Foo;; # bad
or it's a stray one you left chillin' at the end of a control structure, like
if ($foo) {
print "foo\n";
return;
}; # bad
Now, no cap, an empty statement is harmless β it doesn't do anything bad. That's why this policy is filed under the "cosmetic" theme (the full deets on themes are in "POLICY THEMES" in Perl::Critic) and it's only medium severity. But bestie, it is shockingly easy to leave a semi behind when you're chopping code around β especially when you're converting a statement into a loop or a conditional. It's giving accidental leftovers π
π Allowed forms
A C style for (;;) { ... } loop? Totally fine, iconic, allowed. Those semicolons are expression separators and having empties in there is super normal.
for (;;) { # ok
print "infinite loop\n";
}
A semicolon at the start of a map or grep block is allowed too. Why? Because people use it to make sure Perl parses the thing as a block and not as an anonymous hash. (Perl makes that decision at the exact point it parses the {. A ; right there forces it to be a block when Perl might otherwise guess wrong. Want more on this? Go check "map" in perlfunc.) π
map {; $_, 123} @some_list; # ok
grep {# this is a block
; # ok
length $_ and $something } @some_list;
The map form is way more common than the grep one, but honestly they suffer the exact same ambiguity. It's just that grep doesn't normally inspire people to write quite such convoluted forms as map does. iykyk π
πΈ Try/Catch Blocks
The Try, TryCatch and Syntax::Feature::Try modules all add new try block statement forms. Here's the tea: these statements don't require a terminating semicolon β same as how an if doesn't require one. So any semicolon hanging out there gets reckoned as a null statement. π
use TryCatch;
sub foo {
try { attempt_something() }
catch { error_recovery() }; # bad
}
Important though β this does not apply to other try modules like Try::Tiny and friends. Those are implemented as ordinary function calls (with prototypes), so for them a terminating semicolon is completely normal. π§
use Try::Tiny;
sub foo {
try { attempt_something() }
catch { error_recovery() }; # ok
}
π CONFIGURATION π
"allow_perl4_semihash"β boolean, default false. If you set it true, then Perl 4 style documentation comments like the one below are allowed. π
;# Usage:
;# require 'mypkg.pl';
;# ...
The ; must be at the start of the line, no exceptions. This whole thing is fairly outdated, which is exactly why it's disabled by default. But if you're crunching through some old code and you need it, you can enable it by adding this to your .perlcriticrc file:
[ValuesAndExpressions::ProhibitNullStatements]
allow_perl4_semihash=1
π SEE ALSO π
Perl::Critic::PulpPerl::CriticPerl::Critic::Policy::CodeLayout::RequireFinalSemicolon
π HOME PAGE π
http://user42.tuxfamily.org/perl-critic-pulp/index.html
β COPYRIGHT β
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/>.
and that's a wrap bestie π«Ά this page is from perl v5.40.1, dated 2025-10-21 β slay, go forth and delete your stray semicolons π β¨
π¦ where this page comes from
- ubuntu resolute: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- ubuntu stonking: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms