Perl::Critic::Policy::Community::DollarAB(3pm)

Perl::Critic::Policy::Community::DollarAB3pm

Don't use $a or $b as variable names outside sort

Overview

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

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

Releases

2 releases since Debian 12 (Bookworm); the text changed 1 time.

  1. 12
  2. 13

Author

Dan Book, "[email protected]"

From libperl-critic-community-perl 1.0.4-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.