Skip Menu |

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 88848
Status: resolved
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: YKAR [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.33



Subject: List::Util::pairmap() usage producing 'once' warnings for $a and $b
If you run the attached script you'll get: Name "main::a" used only once: possible typo at /home/tor/tmp/test.pl line 8. Name "main::b" used only once: possible typo at /home/tor/tmp/test.pl line 8. Possible solution to this problem is to access caller's $a and $b during import like List::Pairwise is doing.
Subject: test.pl
#! /usr/bin/perl use strict; use warnings; use List::Util qw(pairmap); pairmap { $a = $b } 1 .. 10;
On Sat Sep 21 06:43:42 2013, YKAR wrote: Show quoted text
> If you run the attached script you'll get: > > Name "main::a" used only once: possible typo at /home/tor/tmp/test.pl > line 8. > Name "main::b" used only once: possible typo at /home/tor/tmp/test.pl > line 8. > > Possible solution to this problem is to access caller's $a and $b > during import like List::Pairwise is doing.
Ah yes. That looks simple enough. See patch attached. -- Paul Evans
Subject: rt88848.patch
diff --git a/lib/List/Util.pm b/lib/List/Util.pm index 042ef14..7f68175 100644 --- a/lib/List/Util.pm +++ b/lib/List/Util.pm @@ -20,6 +20,19 @@ $VERSION = eval $VERSION; require XSLoader; XSLoader::load('List::Util', $XS_VERSION); +sub import +{ + my $pkg = caller; + + # (RT88848) Touch the caller's $a and $b, to avoid the warning of + # Name "main::a" used only once: possible typo" warning + no strict 'refs'; + ${"${pkg}::a"} = ${"${pkg}::a"}; + ${"${pkg}::b"} = ${"${pkg}::b"}; + + goto &Exporter::import; +} + sub sum0 { return 0 unless @_;
Thank you very much for prompt action! I tested the patch and warnings are gone :)
Was released in 1.33 -- Paul Evans