Perl::...meLine(3pm)
β¨ NAME β¨
Perl::Critic::Policy::CodeLayout::ProhibitIfIfSameLine β bestie, please don't put an if right after an if on the same line π
(also hi, this is a User Contributed Perl Documentation page, section 3pm, and the title got tragically truncated to Perl::...meLine(3pm) because man pages fear long names, iykyk π)
πΈ DESCRIPTION πΈ
Okay so this policy is part of the Perl::Critic::Pulp add-on. It is begging you β respectfully, lovingly β not to write an if statement on the same line as an if that came before it. Not the vibe. π«Ά
if ($x) {
...
} if ($y) { # bad
...
}
if ($x) {
...
} elsif ($y) { # was "elsif" intended ?
...
}
The whole idea here? When an if sits in the exact same spot where an elsif would go, a human reader is gonna be like "waitβ¦ was that a typo or are you being mysterious π". Could be a genuine mistake, could just be confusing β either way, not it.
So on that basis, this policy lives under the bugs theme and is medium severity (see "POLICY THEMES" in Perl::Critic for the deets, bestie).
π¦ Unless π¦
An unless...if gets treated exactly the same way, no cap. Perl genuinely allows unless ... elsif, so the same potential elsif-layout confusion shows up. Same energy, same flag. π
unless ($x) {
...
} if ($y) { # bad
...
}
unless ($x) {
...
} elsif ($y) { # maybe meant to be "elsif" like this ?
...
}
Now, whether unless ... elsif is a good idea at all is a whole other conversation π β sometimes it just suits a combination of conditions, and that's between you and your code.
π Statement Modifiers π
Important: this policy only applies to a statement followed by a statement. An if used as a statement modifier? Not affected at all, we leave it alone. And honestly it's totally usual to put that one on the same line as the statement it's modifying β that's just how it goes.
do {
...
} if ($x); # ok, statement modifier
β All One Line β
Two if statements written out on the same line? Yeah, that triggers the policy. Sorry, it's the rules. π§
if(1){one;} if(2){two;} # bad
Perhaps there could be an exception or an option for when both statements are entirely on the one line, or some such, for code that's trying to be all compact and cute. But as of right now? Nope. π
π Disabling π
As always β if you simply do not care about this, you can disable ProhibitIfIfSameLine from your .perlcriticrc (see "CONFIGURATION" in Perl::Critic for how that works):
[-CodeLayout::ProhibitIfIfSameLine]
π SEE ALSO π
Perl::Critic::PulpPerl::CriticPerl::Critic::Policy::ControlStructures::ProhibitCascadingIfElsePerl::Critic::Policy::ControlStructures::ProhibitUnlessBlocks
π HOME PAGE π
<http://user42.tuxfamily.org/perl-critic-pulp/index.html>
π COPYRIGHT π
Copyright 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 thing bestie, hope it slayed π stay licensed, stay valid πΈ
this icon of a manual page was served up by perl v5.40.1 on 2025-10-21 β periodt. π
π¦ 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