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
Download (untitled) / with headers
text/plain 310b
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
Download test.pl
text/x-perl 103b
#! /usr/bin/perl use strict; use warnings; use List::Util qw(pairmap); pairmap { $a = $b } 1 .. 10;
Download (untitled) / with headers
text/plain 441b
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
Download rt88848.patch
text/x-diff 570b
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


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.