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

Offer Kaye oferk at oren.co.il
Mon Jun 7 00:01:48 PDT 2004

> This is a bug in the program, just like a typo in the string value would
> be such bug too. In both cases the code is valid, so "use warnings" can't
> help here.
> > 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 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.
> Regards,
> Mikhael.

Everything you say is correct Mikhael, but I agree with Gabor that there
should be *some* way to catch this kind of mistake. At least using B::Lint
should catch such things, but it doesn't:
$ perl -MO=Lint foo.pl
   Implicit scalar context for array in shift at foo.pl line 16
   foo.pl syntax OK

So using Lint here doesn't catch the "used only once" variable but does warn
about an implicit scalar context for shift, which is weird IMHO, since shift
is supposed to work in scalar context...

Offer Kaye

More information about the Perl mailing list