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

Yuval Yaari yuval at windax.com
Sun Jun 6 09:36:19 PDT 2004


1) I thought it's obvious. I've read about it so many times.
Personally, I hate people who give names like $a and $b (though I did it a
few times and noticed that problem - but don't tell anyone).
But it's a well known... bug (?) in strict because of functions such as sort.

2) Did you try use diagnostics; ?
Also, use strict; use warnings; and/or use diagnostics; do not replace
re-reading your code, or debugging it.
Though they usually solve all of my problems :)

  --Yuval


Gabor Szabo said:
>
> There are two issues that might or might not relate to each other. Look
> at this code:
>
> #!/usr/bin/perl
>
> 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.';
>
>
> f(1);
> f(-1);
>
> 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:
> 1)
> 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.)
>
>
> 2)
> 		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 ?
>
>
> 3)
> There might be other small thing, just these two came up recently.
>
>
> Gabor
>
>
>
>
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/mailman/listinfo/perl






More information about the Perl mailing list