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

Gabor Szabo gabor at pti.co.il
Sun Jun 6 23:15:13 PDT 2004

Well, I use $a, $b when writing examples of simple issues, especially for
my students. The use strict thing can get very emberassing when I am
trying to show the behaviour of use strict.
Probably I should start using other variables to avoid this.

In any case using $a and $b in live code can be considered a typical
problem of beginners, exactly the type of people whom would need some
strict-ness in the subject.

> > 2)
> > 		my $y = "positive";
> >
> > within the elsif is actually a bug.
> This is a bug in the program, just like a typo in the string value would
> be such bug too.

Well, not exactly.

> There is a good reason why   my $var = "value";   never produces a "used
> only once" warning. Only undeclared symbol table variables are covered by
> this warning. Declared "my" and "our" variables are excluded not to annoy
> an otherwise perfectly working code.

Sounds right but then

> BTW, if we speak about this example, of course you may use something like
> the following starting with perl 5.004:
> 	my (undef, undef, undef, undef, $mday, $mon) = localtime();
> but this is less readable in my opinion.

you might want to use this

 	my ($mday, $mon) = (localtime())[4,5];

or this
 	my ($mday, $mon) = (localtime)[4,5];

and avoid declaring tons of unused variables or assigning to undef.

In any of the above cases[1] of course we would have a bug as the fileds
mday and mon are the fields 3 and 4 so the correct code would be

 	my ($mday, $mon) = (localtime)[3,4];

but who can count so many undefs ? :)


[1] you got it right though in the original version with all the variables

More information about the Perl mailing list