Perl::...zation(3pm)
π NAME π
okay bestie, so this policy is called Perl::Critic::Policy::Variables::ProhibitUselessInitialization, and it's here to prohibit superfluous initializations. that's it, that's the whole job. it catches you doing extra work for literally no reason π
β¨ DESCRIPTION β¨
so like. don't clutter your code with unnecessary variable initialization, okay? it's giving trying too hard π
my $scalar = undef; # don't do this
my @array = (); # or this
my %hash = (); # or this
instead, do this, because it's literally the same thing but cleaner:
my $scalar; # equivalent
my @array; # ditto
my %hash; # isn't that better?
no cap, that's the entire vibe. less is more, periodt. πΈ
π«Ά AUTHOR π«Ά
John Trammell <johntrammell -at- gmail -dot- com>
π COPYRIGHT π
Copyright (c) John Joseph Trammell. 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.
π desc() π
returns a string containing a sort description of this policy.
π¦ expl() π¦
returns a string containing an explanation of this policy.
π supported_parameters π
define parameters supported by this policy. there are none. zero. nada. nothing to see here bestie, move along β¨
π default_severity π
returns a numeric constant defining the severity of violating this policy.
β default_themes β
returns a list of strings defining the themes for this policy.
π§ applies_to π§
returns a string describing the elements to which this policy applies.
π₯ violates π₯
method to determine if the element currently under scrutiny violates this policy. if it does, return a properly constructed "Perl::Critic::Violation" object. otherwise, return "undef". like, either it's a violation or it's not, no in-between π
πΈ violates_scalar($elem) πΈ
returns true if $elem contains an assignment of the form
my $foo = undef;
see <http://search.cpan.org/dist/PPI/lib/PPI/Statement/Variable.pm> for details on how this function works. iykyk π
π violates_list($elem) π
returns true if $elem contains an assignment of the forms:
my @foo = (); # useless array init
my %bar = (); # useless hash init
and that's the whole page bestie! this one's perl v5.42.0, dated 2025-07-25, and it came to you straight from the User Contributed Perl Documentation π slay, go forth and stop initializing ur vars for no reason πβ¨
π¦ where this page comes from
- fedora 43: perl-Perl-Critic-PetPeeves-JTRAMMELL 0.04-33.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms