[Israel.pm] catching $a, $b unnecessary my and maybe other things

Gabor Szabo gabor at perl.org.il
Sun Jun 6 11:37:22 PDT 2004

There are two issues that might or might not relate to each other.
Look at this code:


use warnings "all";
use strict;

$a =  'Because of their special use by sort(), ';
$a .= 'the variables $a and $b are exempted from "strict vars" check.';


sub f {
	my $x = shift;
	my $y = "unknown";

	if ($x < 0) {
		$y = "negative";
	} elsif ($x > 0) {
		my $y = "positive";
	return $y;

There are two issues here:
use strict; (more precisely use strict "vars") does not care about
$a and $b. This issue is documented in perldoc strict but it still
caused me problems by not shouting. I guess it would be hard to see if
a certain occurance of $a and $b was part of a sort function or not
but there might be some flag (and option to use warnings) that will
catch all occurances of $a and $b
(I know grep can help in this but you have to actually remember to use it.)

		my $y = "positive";

within the elsif is actually a bug. In this case it is quite obvious
to a reader that the $y within this block is used only once. Can such
thing be caught programmaticaly ?

There might be other small thing, just these two came up recently.


More information about the Perl mailing list