in reply to Re: Eliminating "used only once" warnings from List::Util::reduce
in thread Eliminating "used only once" warnings from List::Util::reduce
This is quite helpful, as it identifies why the XS code I referred to works for sort, and not for reduce, and provides a suggestion for how to solve it at the module level. I suspect that it could even still be fixed in the Perl portion of the List::Util module (List/Util.pm) by overriding Exporter::import, and then from within the override, still calling the parent import. The one disadvantage I see in fixing this through import is that it doesn't deal with this:
use warnings; use List::Util (); my $reduced = List::Util::reduce { $a + $b } 1,2,3,4;
Import isn't called, and the warning will still occur (untested assertion). The simple retort to that is, well, if you do it that way, you've got to take responsibility for the warning. But I'm thinking that it still might be better just for perl to special-case $a and $b additionally, such that they're exempt from "only once" warnings altogether, just as they're exempt from strict vars.
...just thinking out loud. Thanks for your reply, it was helpful.
Dave
|
|---|