Perl::Critic::Policy::Community::DollarAB - Don't use $a or $b as variable names outside sort
Contents
Affiliation
This policy is part of Perl::Critic::Community.
Configuration
This policy can be configured to allow $a and $b in additional functions, by putting an entry in a
".perlcriticrc" file like this:
[Community::DollarAB]
extra_pair_functions = pairfoo pairbar
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.
Description
The special variables $a and $b are reserved for sort() and similar functions which assign to them to
iterate over pairs of values. These are global variables, and declaring them as lexical variables with
"my" to use them outside this context can break usage of these functions. Use different names for your
variables.
my $a = 1; # not ok
my $abc = 1; # ok
sort { $a <=> $b } (3,2,1); # ok
Name
Perl::Critic::Policy::Community::DollarAB - Don't use $a or $b as variable names outside sort
See Also
Perl::Critic
perl v5.40.1 2025-03-22 Perl::Critic::...unity::DollarAB(3pm)
