logo
Free, Micro AI Code Reviews That Run on Git Commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, Micro AI Code Reviews That Run on Git Commit | Product Hunt git-lrc - Free, Micro AI Code Reviews That Run on Git Commit | Product Hunt

Perl::Critic::Policy::Community::DollarAB - Don't use $a or $b as variable names outside sort

Affiliation

       This policy is part of Perl::Critic::Community.

Author

       Dan Book, "dbook@cpan.org"

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

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)

See Also