ActiveBlog

Perl special variables $a and $b
by Kevin "kj" Woolley

Kevin "kj" Woolley, February 3, 2006

Here's an often-used, but little-remembered fact about Perl that has caused some confusion on more than one occasion: $a and $b are special. They are (among other things) used in custom sort blocks, but unfortunately the Perl documentation uses them...

Here's an often-used, but little-remembered fact about Perl that has caused some confusion on more than one occasion:  $a and $b are special.

They are (among other things) used in custom sort blocks, but unfortunately the Perl documentation uses them in many examples.  I say that it is unfortunate because the use strict; pragma seems to ignore these two variables.  If you do the following:

use strict;

$a = "foo";
$b = "bar";
$c = "baz";
$d = "quux";

You will see that only $c and $d are flagged as errors.

My advice is to avoid using $a and $b except for custom sort blocks and other places that require their use.

Subscribe to ActiveState Blogs by Email

Share this post:

About the Author: RSS

kj is ActiveState’s Systems Administrator. He was born in London, Ontario, grew up in North Vancouver, and spent several years in the Northwest Territories doing technical sales. As a technical infrastructure specialist, he brings over twenty years of systems administration experience to ActiveState.