#!/usr/bin/perl use strict; use warnings; sub test { $a = 1; $b = 2; print $a, "\n"; print $b, "\n"; } test(); 1;
下面是perl文檔中對這兩個變量的解釋:
perldoc perlvar $a $b Special package variables when using sort(), see "sort" in perlfunc. Because of this specialness $a and $b don't need to be declared (using use vars, or our()) even when using the "strict 'vars'" pragma. Don't lexicalize them with "my $a" or "my $b" if you want to be able to use them in the sort() comparison block or function.