http://www.perlmonks.org?node_id=267720


in reply to "Useless use of private variable in void context"

I concur with chromatic that the line you posted almost certainly isn't the line that is causing the error.

The binary chop technique of commenting out lumps of code is a very useful one, but isn't always practical. Often commenting out one block of code early in the routine, causes so many errors later in the code that the compiler aborts before it ever gets to the error you're trying to find. Another technique I picked up somewhere is to introduce a deliberate but benign error, one that won't cause the compiler to abort, and then move this slowly through the code until it transitions from appearing before the error you're trying to track down to after.

Here it is before

#! perl -slw use strict; my $deliberate_error=''; my $i; length $deliberate_error; $i; __END__ D:\Perl\test>test Useless use of length in void context at D:\Perl\test\test.pl8 line 7. Useless use of private variable in void context at D:\Perl\test\test.p +l8 line 9.

And here after

#! perl -slw use strict; my $deliberate_error=''; my $i; $i; length $deliberate_error; __END__ D:\Perl\test>test Useless use of private variable in void context at D:\Perl\test\test.p +l8 line 7. Useless use of length in void context at D:\Perl\test\test.pl8 line 9.

Simplistic, but it can sometimes be very effective.

Wouldn't it be nice if the error reported was

Useless use of $i in void context at ....


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller