Perl::...ollarAB(3pm)
π Perl::Critic::Policy::Community::DollarAB β¨
okay so bestie, real talk β this is a page from the User Contributed Perl Documentation collection, and it's all about one specific Perl::Critic policy called Perl::Critic::Policy::Community::DollarAB. buckle up, it's short and it's spicy π«Ά
πΈ NAME πΈ
Perl::Critic::Policy::Community::DollarAB β do NOT use $a or $b as variable names outside of sort. like, ever. periodt. π
π¦ DESCRIPTION π¦
so here's the tea, bestie π: the special variables $a and $b are reserved for sort() and similar functions. those functions literally assign to them so they can iterate over pairs of values. it's their whole thing. their moment. their main character energy. π
and here's the part that gets people in trouble: these are global variables. so when you go and declare them as lexical variables with my to use them outside that context? yeah, that can break the usage of those functions. not slay. not it. π
just use different names for your variables. it costs nothing and it saves you a whole villain arc.
my $a = 1; # not ok
my $abc = 1; # ok
sort { $a <=> $b } (3,2,1); # ok
see how easy that was? the last two? iconic. the first one? not ok. π«
β¨ AFFILIATION β¨
this policy is part of Perl::Critic::Community. it's got a whole friend group, iykyk π
π CONFIGURATION π
okay so you CAN customize this one, and honestly? obsessed. π
this policy can be configured to allow $a and $b in additional functions β you just drop an entry into a .perlcriticrc file, like this:
[Community::DollarAB]
extra_pair_functions = pairfoo pairbar
and boom, pairfoo and pairbar get the same pass that sort gets. very demure, very mindful. π
π AUTHOR π
Dan Book, "dbook@cpan.org" β shoutout to the author, fr fr π«Ά
π 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.
π SEE ALSO π
Perl::Critic
and that's the whole page, bestie β no cap. this gem ships with perl v5.40.1, dated 2025-03-22, and lives under the Perl::...ollarAB(3pm) name in the User Contributed Perl Documentation. go forth and rename your $a and $b, you've got this πβ¨π¦
π¦ 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