Name used only once warning issued in error?

--_000_BL0PR11MB32519FA58481891756F99236D40E0BL0PR11MB3251namp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

It seems that when a nested function created with local and used in a sort(=
) call that the

"Name used only once" warning is issued erroneously.

Minimum code to reproduce is below. The warning given is 'Name "main::test_=
local_sub" used only once: possible typo at /tmp/temp.pl line 8.'

use strict;
use warnings;
##
#  Minimum code to reproduce.
##
sub test{
    #no warnings "once";
    local *test_local_sub =3D sub {
        return 0;
    };
    for(0..100){
        my @sorted =3D sort test_local_sub (1,2,3,4);
    }
}

Uncommenting the line
     #no warnings "once";
will silence the warning as expected.

This seems incorrect behavior, but is it? For example, this only seems to c=
ome up when used with sort. If simply called by itself no warning is issued=
..


$ perl -V
Summary of my perl5 (revision 5 version 28 subversion 0) configuration:

  Platform:
    osname=3Ddarwin
    osvers=3D18.2.0
    archname=3Ddarwin-thread-multi-2level
    uname=3D'darwin adams-imac.fios-router.home 18.2.0 darwin kernel versio=
n 18.2.0: thu dec 20 20:46:53 pst 2018; root:xnu-4903.241.1~1release_x86_64=
 x86_64 '
    config_args=3D'-de -Dprefix=3D/Users/adamcrussell/perl5/perlbrew/perls/=
perl-5.28.0 -Dusethreads -Aeval:scriptdir=3D/Users/adamcrussell/perl5/perlb=
rew/perls/perl-5.28.0/bin'
    hint=3Drecommended
    useposix=3Dtrue
    d_sigaction=3Ddefine
    useithreads=3Ddefine
    usemultiplicity=3Ddefine
    use64bitint=3Ddefine
    use64bitall=3Ddefine
    uselongdouble=3Dundef
    usemymalloc=3Dn
    default_inc_excludes_dot=3Ddefine
    bincompat5005=3Dundef
  Compiler:
    cc=3D'cc'
    ccflags =3D'-fno-common -DPERL_DARWIN -mmacosx-version-min=3D10.14 -fno=
-strict-aliasing -pipe -fstack-protector-strong -I/opt/local/include -DPERL=
_USE_SAFE_PUTENV'
    optimize=3D'-O3'
    cppflags=3D'-fno-common -DPERL_DARWIN -mmacosx-version-min=3D10.14 -fno=
-strict-aliasing -pipe -fstack-protector-strong -I/opt/local/include'
    ccversion=3D''
    gccversion=3D'4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)'
    gccosandvers=3D''
    intsize=3D4
    longsize=3D8
    ptrsize=3D8
    doublesize=3D8
    byteorder=3D12345678
    doublekind=3D3
    d_longlong=3Ddefine
    longlongsize=3D8
    d_longdbl=3Ddefine
    longdblsize=3D16
    longdblkind=3D3
    ivtype=3D'long'
    ivsize=3D8
    nvtype=3D'double'
    nvsize=3D8
    Off_t=3D'off_t'
    lseeksize=3D8
    alignbytes=3D8
    prototype=3Ddefine
  Linker and Libraries:
    ld=3D'cc'
    ldflags =3D' -mmacosx-version-min=3D10.14 -fstack-protector-strong -L/u=
sr/local/lib -L/opt/local/lib'
    libpth=3D/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDef=
ault.xctoolchain/usr/lib/clang/10.0.0/lib /Applications/Xcode.app/Contents/=
Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /Applications/Xcode.a=
pp/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.=
sdk/usr/lib /usr/local/lib /opt/local/lib /usr/lib
    libs=3D-lpthread -lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=3D-lpthread -ldl -lm -lutil -lc
    libc=3D
    so=3Ddylib
    useshrplib=3Dfalse
    libperl=3Dlibperl.a
    gnulibc_version=3D''
  Dynamic Linking:
    dlsrc=3Ddl_dlopen.xs
    dlext=3Dbundle
    d_dlsymun=3Dundef
    ccdlflags=3D' '
    cccdlflags=3D' '
    lddlflags=3D' -mmacosx-version-min=3D10.14 -bundle -undefined dynamic_l=
ookup -L/usr/local/lib -L/opt/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_TIMES
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_IMPLICIT_CONTEXT
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
    USE_REENTRANT_API
  Locally applied patches:
    Devel::PatchPerl 1.56
  Built under darwin
  Compiled at Mar 12 2019 11:04:00
  %ENV:
    PERLBREW_HOME=3D"/Users/adamcrussell/.perlbrew"
    PERLBREW_MANPATH=3D"/Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.=
0/man"
    PERLBREW_PATH=3D"/Users/adamcrussell/perl5/perlbrew/bin:/Users/adamcrus=
sell/perl5/perlbrew/perls/perl-5.28.0/bin"
    PERLBREW_PERL=3D"perl-5.28.0"
    PERLBREW_ROOT=3D"/Users/adamcrussell/perl5/perlbrew"
    PERLBREW_SHELLRC_VERSION=3D"0.86"
    PERLBREW_VERSION=3D"0.86"
  @INC:
    /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib/site_perl/5.28=
..0/darwin-thread-multi-2level
    /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib/site_perl/5.28=
..0
    /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib/5.28.0/darwin-=
thread-multi-2level
    /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib/5.28.0



--_000_BL0PR11MB32519FA58481891756F99236D40E0BL0PR11MB3251namp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
It seems that when a nested function created with local and used in a sort(=
) call that the
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
&quot;Name used only once&quot; warning is issued erroneously.</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
Minimum code to reproduce is below. The warning given is 'Name &quot;main::=
test_local_sub&quot; used only once: possible typo at /tmp/temp.pl line 8.'=
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<span>use strict;<br>
</span>
<div>use warnings; &nbsp;<br>
</div>
<div>##<br>
</div>
<div>#&nbsp; Minimum code to reproduce.&nbsp; <br>
</div>
<div>## &nbsp;<br>
</div>
<div>sub test{<br>
</div>
<div>&nbsp; &nbsp; #no warnings &quot;once&quot;;<br>
</div>
<div>&nbsp; &nbsp; local *test_local_sub =3D sub {<br>
</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; return 0; &nbsp;<br>
</div>
<div>&nbsp; &nbsp; };<br>
</div>
<div>&nbsp; &nbsp; for(0..100){<br>
</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; my @sorted =3D sort test_local_sub (1,2,3,=
4); &nbsp;<br>
</div>
<div>&nbsp; &nbsp; } &nbsp;<br>
</div>
<span>}</span><br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
Uncommenting the line <br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
&nbsp; &nbsp; &nbsp;#no warnings &quot;once&quot;;<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
will silence the warning as expected.</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
This seems incorrect behavior, but is it? For example, this only seems to c=
ome up when used with sort. If simply called by itself no warning is issued=
..</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<span>$ perl -V<br>
</span>
<div>Summary of my perl5 (revision 5 version 28 subversion 0) configuration=
:<br>
</div>
<div>&nbsp; &nbsp;<br>
</div>
<div>&nbsp; Platform:<br>
</div>
<div>&nbsp; &nbsp; osname=3Ddarwin<br>
</div>
<div>&nbsp; &nbsp; osvers=3D18.2.0<br>
</div>
<div>&nbsp; &nbsp; archname=3Ddarwin-thread-multi-2level<br>
</div>
<div>&nbsp; &nbsp; uname=3D'darwin adams-imac.fios-router.home 18.2.0 darwi=
n kernel version 18.2.0: thu dec 20 20:46:53 pst 2018; root:xnu-4903.241.1~=
1release_x86_64 x86_64 '<br>
</div>
<div>&nbsp; &nbsp; config_args=3D'-de -Dprefix=3D/Users/adamcrussell/perl5/=
perlbrew/perls/perl-5.28.0 -Dusethreads -Aeval:scriptdir=3D/Users/adamcruss=
ell/perl5/perlbrew/perls/perl-5.28.0/bin'<br>
</div>
<div>&nbsp; &nbsp; hint=3Drecommended<br>
</div>
<div>&nbsp; &nbsp; useposix=3Dtrue<br>
</div>
<div>&nbsp; &nbsp; d_sigaction=3Ddefine<br>
</div>
<div>&nbsp; &nbsp; useithreads=3Ddefine<br>
</div>
<div>&nbsp; &nbsp; usemultiplicity=3Ddefine<br>
</div>
<div>&nbsp; &nbsp; use64bitint=3Ddefine<br>
</div>
<div>&nbsp; &nbsp; use64bitall=3Ddefine<br>
</div>
<div>&nbsp; &nbsp; uselongdouble=3Dundef<br>
</div>
<div>&nbsp; &nbsp; usemymalloc=3Dn<br>
</div>
<div>&nbsp; &nbsp; default_inc_excludes_dot=3Ddefine<br>
</div>
<div>&nbsp; &nbsp; bincompat5005=3Dundef<br>
</div>
<div>&nbsp; Compiler:<br>
</div>
<div>&nbsp; &nbsp; cc=3D'cc'<br>
</div>
<div>&nbsp; &nbsp; ccflags =3D'-fno-common -DPERL_DARWIN -mmacosx-version-m=
in=3D10.14 -fno-strict-aliasing -pipe -fstack-protector-strong -I/opt/local=
/include -DPERL_USE_SAFE_PUTENV'<br>
</div>
<div>&nbsp; &nbsp; optimize=3D'-O3'<br>
</div>
<div>&nbsp; &nbsp; cppflags=3D'-fno-common -DPERL_DARWIN -mmacosx-version-m=
in=3D10.14 -fno-strict-aliasing -pipe -fstack-protector-strong -I/opt/local=
/include'<br>
</div>
<div>&nbsp; &nbsp; ccversion=3D''<br>
</div>
<div>&nbsp; &nbsp; gccversion=3D'4.2.1 Compatible Apple LLVM 10.0.0 (clang-=
1000.11.45.5)'<br>
</div>
<div>&nbsp; &nbsp; gccosandvers=3D''<br>
</div>
<div>&nbsp; &nbsp; intsize=3D4<br>
</div>
<div>&nbsp; &nbsp; longsize=3D8<br>
</div>
<div>&nbsp; &nbsp; ptrsize=3D8<br>
</div>
<div>&nbsp; &nbsp; doublesize=3D8<br>
</div>
<div>&nbsp; &nbsp; byteorder=3D12345678<br>
</div>
<div>&nbsp; &nbsp; doublekind=3D3<br>
</div>
<div>&nbsp; &nbsp; d_longlong=3Ddefine<br>
</div>
<div>&nbsp; &nbsp; longlongsize=3D8<br>
</div>
<div>&nbsp; &nbsp; d_longdbl=3Ddefine<br>
</div>
<div>&nbsp; &nbsp; longdblsize=3D16<br>
</div>
<div>&nbsp; &nbsp; longdblkind=3D3<br>
</div>
<div>&nbsp; &nbsp; ivtype=3D'long'<br>
</div>
<div>&nbsp; &nbsp; ivsize=3D8<br>
</div>
<div>&nbsp; &nbsp; nvtype=3D'double'<br>
</div>
<div>&nbsp; &nbsp; nvsize=3D8<br>
</div>
<div>&nbsp; &nbsp; Off_t=3D'off_t'<br>
</div>
<div>&nbsp; &nbsp; lseeksize=3D8<br>
</div>
<div>&nbsp; &nbsp; alignbytes=3D8<br>
</div>
<div>&nbsp; &nbsp; prototype=3Ddefine<br>
</div>
<div>&nbsp; Linker and Libraries:<br>
</div>
<div>&nbsp; &nbsp; ld=3D'cc'<br>
</div>
<div>&nbsp; &nbsp; ldflags =3D' -mmacosx-version-min=3D10.14 -fstack-protec=
tor-strong -L/usr/local/lib -L/opt/local/lib'<br>
</div>
<div>&nbsp; &nbsp; libpth=3D/Applications/Xcode.app/Contents/Developer/Tool=
chains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib /Applications/Xcod=
e.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /Appli=
cations/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SD=
Ks/MacOSX10.14.sdk/usr/lib
 /usr/local/lib /opt/local/lib /usr/lib<br>
</div>
<div>&nbsp; &nbsp; libs=3D-lpthread -lgdbm -ldbm -ldl -lm -lutil -lc<br>
</div>
<div>&nbsp; &nbsp; perllibs=3D-lpthread -ldl -lm -lutil -lc<br>
</div>
<div>&nbsp; &nbsp; libc=3D<br>
</div>
<div>&nbsp; &nbsp; so=3Ddylib<br>
</div>
<div>&nbsp; &nbsp; useshrplib=3Dfalse<br>
</div>
<div>&nbsp; &nbsp; libperl=3Dlibperl.a<br>
</div>
<div>&nbsp; &nbsp; gnulibc_version=3D''<br>
</div>
<div>&nbsp; Dynamic Linking:<br>
</div>
<div>&nbsp; &nbsp; dlsrc=3Ddl_dlopen.xs<br>
</div>
<div>&nbsp; &nbsp; dlext=3Dbundle<br>
</div>
<div>&nbsp; &nbsp; d_dlsymun=3Dundef<br>
</div>
<div>&nbsp; &nbsp; ccdlflags=3D' '<br>
</div>
<div>&nbsp; &nbsp; cccdlflags=3D' '<br>
</div>
<div>&nbsp; &nbsp; lddlflags=3D' -mmacosx-version-min=3D10.14 -bundle -unde=
fined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector-st=
rong'<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Characteristics of this binary (from libperl): <br>
</div>
<div>&nbsp; Compile-time options:<br>
</div>
<div>&nbsp; &nbsp; HAS_TIMES<br>
</div>
<div>&nbsp; &nbsp; MULTIPLICITY<br>
</div>
<div>&nbsp; &nbsp; PERLIO_LAYERS<br>
</div>
<div>&nbsp; &nbsp; PERL_COPY_ON_WRITE<br>
</div>
<div>&nbsp; &nbsp; PERL_DONT_CREATE_GVSV<br>
</div>
<div>&nbsp; &nbsp; PERL_IMPLICIT_CONTEXT<br>
</div>
<div>&nbsp; &nbsp; PERL_MALLOC_WRAP<br>
</div>
<div>&nbsp; &nbsp; PERL_OP_PARENT<br>
</div>
<div>&nbsp; &nbsp; PERL_PRESERVE_IVUV<br>
</div>
<div>&nbsp; &nbsp; PERL_USE_SAFE_PUTENV<br>
</div>
<div>&nbsp; &nbsp; USE_64_BIT_ALL<br>
</div>
<div>&nbsp; &nbsp; USE_64_BIT_INT<br>
</div>
<div>&nbsp; &nbsp; USE_ITHREADS<br>
</div>
<div>&nbsp; &nbsp; USE_LARGE_FILES<br>
</div>
<div>&nbsp; &nbsp; USE_LOCALE<br>
</div>
<div>&nbsp; &nbsp; USE_LOCALE_COLLATE<br>
</div>
<div>&nbsp; &nbsp; USE_LOCALE_CTYPE<br>
</div>
<div>&nbsp; &nbsp; USE_LOCALE_NUMERIC<br>
</div>
<div>&nbsp; &nbsp; USE_LOCALE_TIME<br>
</div>
<div>&nbsp; &nbsp; USE_PERLIO<br>
</div>
<div>&nbsp; &nbsp; USE_PERL_ATOF<br>
</div>
<div>&nbsp; &nbsp; USE_REENTRANT_API<br>
</div>
<div>&nbsp; Locally applied patches:<br>
</div>
<div>&nbsp; &nbsp; Devel::PatchPerl 1.56<br>
</div>
<div>&nbsp; Built under darwin<br>
</div>
<div>&nbsp; Compiled at Mar 12 2019 11:04:00<br>
</div>
<div>&nbsp; %ENV:<br>
</div>
<div>&nbsp; &nbsp; PERLBREW_HOME=3D&quot;/Users/adamcrussell/.perlbrew&quot=
;<br>
</div>
<div>&nbsp; &nbsp; PERLBREW_MANPATH=3D&quot;/Users/adamcrussell/perl5/perlb=
rew/perls/perl-5.28.0/man&quot;<br>
</div>
<div>&nbsp; &nbsp; PERLBREW_PATH=3D&quot;/Users/adamcrussell/perl5/perlbrew=
/bin:/Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/bin&quot;<br>
</div>
<div>&nbsp; &nbsp; PERLBREW_PERL=3D&quot;perl-5.28.0&quot;<br>
</div>
<div>&nbsp; &nbsp; PERLBREW_ROOT=3D&quot;/Users/adamcrussell/perl5/perlbrew=
&quot;<br>
</div>
<div>&nbsp; &nbsp; PERLBREW_SHELLRC_VERSION=3D&quot;0.86&quot;<br>
</div>
<div>&nbsp; &nbsp; PERLBREW_VERSION=3D&quot;0.86&quot;<br>
</div>
<div>&nbsp; @INC:<br>
</div>
<div>&nbsp; &nbsp; /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib=
/site_perl/5.28.0/darwin-thread-multi-2level<br>
</div>
<div>&nbsp; &nbsp; /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib=
/site_perl/5.28.0<br>
</div>
<div>&nbsp; &nbsp; /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib=
/5.28.0/darwin-thread-multi-2level<br>
</div>
<div>&nbsp; &nbsp; /Users/adamcrussell/perl5/perlbrew/perls/perl-5.28.0/lib=
/5.28.0<br>
</div>
<span></span><br>
</div>
<div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;=
 color: rgb(0, 0, 0);">
<br>
</div>
</body>
</html>

--_000_BL0PR11MB32519FA58481891756F99236D40E0BL0PR11MB3251namp_--
0
ac
5/12/2019 7:01:55 PM
perl.perl5.porters 47703 articles. 1 followers. Follow

0 Replies
33 Views

Similar Articles

[PageSpeed] 17

Reply: