Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$a and $b should be exempt from "used only once" warnings. #13402

Closed
p5pRT opened this issue Nov 4, 2013 · 4 comments
Closed

$a and $b should be exempt from "used only once" warnings. #13402

p5pRT opened this issue Nov 4, 2013 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 4, 2013

Migrated from rt.perl.org#120462 (status was 'resolved')

Searchable as RT120462$

@p5pRT
Copy link
Author

p5pRT commented Nov 4, 2013

From daoswald@gmail.com

Sample code​:

~$ perl -MList​::MoreUtils=pairwise -wE 'say for pairwise { $a + $b }
@​{[1,2,3,4,5,6]}, @​{[100,200,300,400,500,600]};'

Output​:

Name "main​::b" used only once​: possible typo at -e line 1.
Name "main​::a" used only once​: possible typo at -e line 1.
101
202
303
404
505
606

"sort" is already exempt from "used only once" warnings, because it's
common for $a and $b to be used only once. $a and $b are also exempt
from strict vars. These special variables should be exempt from "used
only once" warnings altogether.

Such an exemption is unlikely to allow bugs to slip into peoples code.
$a and $b are special enough that people already are (or should be)
careful with their usage. And the common use case does include using
them only once. Better to exempt just $a and $b than to encourage
users to disable "used only once" at a more far-reaching scope.

This issue is a problem for List​::MoreUtils, List​::BinarySearch, or
any other extension code that makes use of $a and $b in ways similar
to "sort."

The only reason that List​::Util​::reduce doesn't suffer from the issue
is that the author has added this to the import subroutine​:

${caller."​::a"}=${caller."​::a"};

...which really seems to code smell to me, and is only effective if
the user imports "reduce" (calling it by the fully-qualified name and
not importing it would bypass the "caller​::a" trick).

Rather than forcing module authors to play this sort of trick, or
rather than encouraging users to shut off "only once" warnings
altogether, Perl should just exempt $a and $b.

Output from perl -V​:

davido@​catalina​:~$ perl -V
Summary of my perl5 (revision 5 version 18 subversion 1) configuration​:

  Platform​:
  osname=linux, osvers=3.11.0-12-generic, archname=x86_64-linux
  uname='linux catalina 3.11.0-12-generic #19-ubuntu smp wed oct 9
16​:20​:46 utc 2013 x86_64 x86_64 x86_64 gnulinux '
  config_args='-de
-Dprefix=/home/davido/perl5/perlbrew/perls/perl-5.18.1
-Aeval​:scriptdir=/home/davido/perl5/perlbrew/perls/perl-5.18.1/bin'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.8.1', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib
/usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib
  libs=-lnsl -ldl -lm -lcrypt -lutil -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
  libc=, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.17'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib
-fstack-protector'

Characteristics of this binary (from libperl)​:
  Compile-time options​: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV
  PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_MALLOC_WRAP
  PERL_PRESERVE_IVUV PERL_SAWAMPERSAND USE_64_BIT_ALL
  USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE
  USE_LOCALE_COLLATE USE_LOCALE_CTYPE
  USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
  Built under linux
  Compiled at Oct 26 2013 14​:58​:51
  %ENV​:
  PERL5LIB="/home/davido/.perlbrew/libs/perl-5.18.1@​5.18/lib/perl5"
  PERLBREW_BASHRC_VERSION="0.66"
  PERLBREW_HOME="/home/davido/.perlbrew"
  PERLBREW_LIB="5.18"
  PERLBREW_MANPATH="/home/davido/.perlbrew/libs/perl-5.18.1@​5.18/man​:/home/davido/perl5/perlbrew/perls/perl-5.18.1/man"
  PERLBREW_PATH="/home/davido/.perlbrew/libs/perl-5.18.1@​5.18/bin​:/home/davido/perl5/perlbrew/bin​:/home/davido/perl5/perlbrew/perls/perl-5.18.1/bin"
  PERLBREW_PERL="perl-5.18.1"
  PERLBREW_ROOT="/home/davido/perl5/perlbrew"
  PERLBREW_VERSION="0.66"
  PERL_LOCAL_LIB_ROOT="/home/davido/.perlbrew/libs/perl-5.18.1@​5.18"
  PERL_MB_OPT="--install_base /home/davido/.perlbrew/libs/perl-5.18.1@​5.18"
  PERL_MM_OPT="INSTALL_BASE=/home/davido/.perlbrew/libs/perl-5.18.1@​5.18"
  @​INC​:
  /home/davido/.perlbrew/libs/perl-5.18.1@​5.18/lib/perl5/x86_64-linux
  /home/davido/.perlbrew/libs/perl-5.18.1@​5.18/lib/perl5
  /home/davido/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1/x86_64-linux
  /home/davido/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1
  /home/davido/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1/x86_64-linux
  /home/davido/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1
  .

--

David Oswald
daoswald@​gmail.com

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2013

From @cpansprout

I realised this was easier than I thought, so I went ahead and did this in commit ea23863.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2013

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2013

@cpansprout - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Nov 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant