Perl::...zation(3pm)

πŸ“¦
version 0.04 Β· 2 versions
, in fedora 43

πŸ’– 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 (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