in reply to Re^2: Eliminating "used only once" warnings from List::Util::reduce
in thread Eliminating "used only once" warnings from List::Util::reduce
I think a better solution would simply be for Perl to completely ignore $a and $b with respect to "used only once" warnings.
The biggest problem is: which $s & $b?
That is, it is fairly easy to preempt the warnings for $main::a & $main::b -- by soemthing as simple as BEGIN{ $main::a || $main::b } somewhere in List::Util.pm; -- but if reduce() is called from some other package they won't be the right ones. Ie. If reduce() is called from package fred,then it'll be $fred::a & $fred::b.
And there is no way to determine which package you were called from at BEGIN time. With this added to List::Util.pm:
BEGIN{ printf "'%s'\n", scalar caller(); $main::a || $main::b }
The current package at BEGIN time is main for both of these:
C:\test\primes>perl -Mstrict -MList::Util=reduce -wE" say reduce{ $a + +$b } 1,2,3" 'main' 6 C:\test\primes>perl -Mstrict -wE"package fred; use List::Util qw[ redu +ce ]; say reduce{ $a +$b } 1,2,3" 'main' Name "fred::a" used only once: possible typo at -e line 1. Name "fred::b" used only once: possible typo at -e line 1. 6
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Eliminating "used only once" warnings from List::Util::reduce
by davido (Cardinal) on Jul 30, 2013 at 19:28 UTC | |
by BrowserUk (Patriarch) on Jul 30, 2013 at 19:33 UTC |