Perl::...alVars(3pm)
π Perl::...alVars(3pm) β the whole vibe, bestie
okay so this is a Perl::Critic policy page, from the User Contributed Perl Documentation, and it's literally called Perl::...alVars(3pm) β yes the name is truncated, that's just how it is, don't come for me π«Ά
β¨ NAME β¨
Perl::Critic::Policy::Variables::ProhibitLocalVars β bestie, use "my" instead of "local", except when you literally have to. That's the whole assignment. π
πΈ AFFILIATION πΈ
This Policy is part of the core Perl::Critic distribution. It's not some random side quest, it ships with the main thing. π
π¦ DESCRIPTION π¦
So since Perl 5, there are very few reasons to declare "local" variables. Like, the list is short and it's giving "only for the special cases." π
The most common exceptions are Perl's magical global variables. If you do need to modify one of those global variables, you should localize it first. And you should also use the English module to give those variables more meaningful names β because $/ is not a personality trait, bestie.
local $foo; #not ok
my $foo; #ok
use English qw(-no_match_vars);
local $INPUT_RECORD_SEPARATOR #ok
local $RS #ok
local $/; #not ok
See how local $foo; gets the side-eye while my $foo; slays? And the English module names are fine β $INPUT_RECORD_SEPARATOR and $RS are both ok β but the raw punctuation version local $/; is not ok. No cap. π
π CONFIGURATION π
This Policy is not configurable except for the standard options. That's it, that's the section. Nothing to tweak here, move along. β¨
π§ NOTES π§
Okay so important nuance, and I mean it: if an external module uses package variables as its interface, then using "local" is actually a pretty sensible thing to do. So Perl::Critic will not complain if you "local"-ize variables with a fully qualified name such as $Some::Package::foo.
But β and this is the tea β β if you're in a position to dictate the module's interface, I strongly suggest using accessor methods instead. Iconic advice, fr fr.
π SEE ALSO π
Perl::Critic::Policy::Variables::ProhibitPunctuationVarsβ go read that one next, iykyk π
π AUTHOR π
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> β the main character who wrote this. π
β COPYRIGHT β
Copyright (c) 2005-2011 Imaginative Software Systems. 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.
okay bestie quick vibe check π β none of that was a suggestion, the copyright and license lines are real, so keep them intact if you're passing this around.
and that's the page! π«Ά this whole thing ships with perl v5.42.0 and was last touched on 2024-10-23, so if you see that footer floating around (yes, Perl::...alVars(3pm) again, the truncated little icon that it is), that's just the timestamp being cute. mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms