Perl::...ations(3pm)
Perl::...ations(3pm) π
okay bestie, welcome to Perl::...ations(3pm), from the User Contributed Perl Documentation shelf β yes the title is literally abbreviated like that, it's giving mysterious, we love a short king β¨
β¨ NAME β¨
Perl::Critic::Policy::Community::ConditionalDeclarations β don't declare variables conditionally π
πΈ DESCRIPTION πΈ
so here's the tea, bestie. you can slap a postfix condition onto a variable declaration, like my $foo = $bar if $baz. cute, right? WRONG. π it's unclear β and literally undefined β whether that variable actually gets declared when the condition isn't met. the vibe check fails. it's giving "maybe a variable, maybe a ghost" π
instead, do the responsible main character thing: declare the variable first, then assign to it conditionally. or use the ternary operator to assign a value conditionally. slay.
my $foo = $bar if $baz; # not ok
my ($foo, $bar) = @_ unless $baz; # not ok
our $bar = $_ for 0..10; # not ok
my $foo; $foo = $bar if $baz; # ok
my $foo = $baz ? $bar : undef; # ok
and the lore: this policy is a subclass of the core policy Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations, and it performs the same function but in the "community" theme. same energy, different aesthetic π¦
π AFFILIATION π
this policy is part of Perl::Critic::Community. iykyk π«Ά
π CONFIGURATION π
this policy is not configurable except for the standard options. no notes, no knobs to fiddle with, it said what it said π
β AUTHOR β
Dan Book, dbook@cpan.org π
π COPYRIGHT AND LICENSE π
Copyright 2015, Dan Book.
this library is free software; you may redistribute it and/or modify it under the terms of the Artistic License version 2.0. fr fr, go wild (within the license, bestie) π
π¦ SEE ALSO π¦
Perl::Criticβ¨
perl v5.40.1 Β· 2025-03-22 β that's the version and the date, babe, and that's the whole page π bye bestie, go declare your variables unconditionally like the icon you are π§ββοΈπΈ
π¦ where this page comes from
- debian trixie: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu resolute: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu stonking: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms