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

Warning on @_ outside subroutine #13953

Closed
p5pRT opened this issue Jun 23, 2014 · 11 comments
Closed

Warning on @_ outside subroutine #13953

p5pRT opened this issue Jun 23, 2014 · 11 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 23, 2014

Migrated from rt.perl.org#122162 (status was 'rejected')

Searchable as RT122162$

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2014

From @epa

Created by @epa

There should be a warning if @​_ is used outside a subroutine.
Ideally, this warning should be at compile time rather than run time.

Perl Info

Flags:
    category=core
    severity=wishlist

Site configuration information for perl 5.18.2:

Configured by Red Hat, Inc. at Tue Jan  7 14:45:19 UTC 2014.

Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
   
  Platform:
    osname=linux, osvers=3.11.9-200.fc19.x86_64, archname=x86_64-linux-thread-multi
    uname='linux buildvm-12.phx2.fedoraproject.org 3.11.9-200.fc19.x86_64 #1 smp wed nov 20 21:22:24 utc 2013 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -Dccdlflags=-Wl,--enable-new-dtags -Dlddlflags=-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -Wl,-z,relro  -Dshrpdir=/usr/lib64 -DDEBUGGING=-g -Dversion=5.18.2 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64/perl5/vendor_perl -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Dusedtrace=/usr/bin/dtrace -Duselargefiles -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin -Dusesitecustomize'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.8.2 20131212 (Red Hat 4.8.2-7)', 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='gcc', ldflags =' -fstack-protector'
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc -lgdbm_compat
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.18'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,--enable-new-dtags'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wl,-z,relro '

Locally applied patches:
    Fedora Patch1: Removes date check, Fedora/RHEL specific
    Fedora Patch3: support for libdir64
    Fedora Patch4: use libresolv instead of libbind
    Fedora Patch5: USE_MM_LD_RUN_PATH
    Fedora Patch6: Skip hostname tests, due to builders not being network capable
    Fedora Patch7: Dont run one io test due to random builder failures
    Fedora Patch9: Fix find2perl to translate ? glob properly (RT#113054)
    Fedora Patch10: Update h2ph(1) documentation (RT#117647)
    Fedora Patch11: Update pod2html(1) documentation (RT#117623)
    Fedora Patch12: Disable ornaments on perl5db AutoTrace tests (RT#118817)
    Fedora Patch14: Do not use system Term::ReadLine::Gnu in tests (RT#118821)
    Fedora Patch15: Define SONAME for libperl.so
    Fedora Patch16: Install libperl.so to -Dshrpdir value
    Fedora Patch18: Fix crash with \\&$glob_copy (RT#119051)
    Fedora Patch19: Fix coreamp.t rand test (RT#118237)
    Fedora Patch20: Reap child in case where exception has been thrown (RT#114722)
    Fedora Patch21: Fix using regular expressions containing multiple code blocks (RT#117917)
    Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux
    Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux


@INC for perl 5.18.2:
    /home/eda/lib/perl5/
    /usr/local/lib64/perl5
    /usr/local/share/perl5
    /usr/lib64/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib64/perl5
    /usr/share/perl5
    .


Environment for perl 5.18.2:
    HOME=/home/eda
    LANG=en_GB.UTF-8
    LANGUAGE (unset)
    LC_COLLATE=C
    LC_CTYPE=en_GB.UTF-8
    LC_MESSAGES=en_GB.UTF-8
    LC_MONETARY=en_GB.UTF-8
    LC_NUMERIC=en_GB.UTF-8
    LC_TIME=en_GB.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/eda/bin:/home/eda/bin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/sbin:/usr/sbin
    PERL5LIB=/home/eda/lib/perl5/
    PERL_BADLANG (unset)
    SHELL=/bin/bash

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2014

From @Hugmeir

On Mon, Jun 23, 2014 at 5​:31 PM, Ed Avis <perlbug-followup@​perl.org> wrote​:

# New Ticket Created by "Ed Avis"
# Please include the string​: [perl #122162]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=122162 >

This is a bug report for perl from eda@​waniasset.com,
generated with the help of perlbug 1.39 running under perl 5.18.2.

-----------------------------------------------------------------
[Please describe your issue here]

There should be a warning if @​_ is used outside a subroutine.
Ideally, this warning should be at compile time rather than run time.

-1

Nothing wrong with using @​_ outside of a subroutine. And beyond being
a possible shortcut, it has its own use​:

sub foo {@​_}
@​_ = "val";
say &foo

This looks like the sort of warning/coding advice that would be better
implemented as a CPAN module.

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2014

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

@p5pRT
Copy link
Author

p5pRT commented Jun 24, 2014

From @epa

Brian Fraser <fraserbn <at> gmail.com> writes​:

Nothing wrong with using <at> _ outside of a subroutine. And beyond being
a possible shortcut, it has its own use​:

sub foo { @​_ }
@​_ = "val";
say &foo

This is a highly wizardly shortcut and only in very marginal cases is it
better than just foo("val"). The documentation does say

  This is an efficiency mechanism that new users may wish to avoid.

That is outweighed for me by the number of types I have typed @​_ instead of
@​$_ by mistake. But perhaps it's just me who does that?

--
Ed Avis <eda@​waniasset.com>

@p5pRT
Copy link
Author

p5pRT commented Jun 24, 2014

From @kentfredric

On 24 June 2014 18​:37, Ed Avis <eda@​waniasset.com> wrote​:

This is a highly wizardly shortcut and only in very marginal cases is it
better than just foo("val"). The documentation does say

This is an efficiency mechanism that new users may wish to avoid\.

That is outweighed for me by the number of types I have typed @​_ instead of
@​$_ by mistake. But perhaps it's just me who does that?

Another example (ab)use of it​:

--[ t.pl ]--
use v5.20;
use warnings 'all';

sub foo(@​) {
  return do "./real.pl";
}

say foo "Hello", "World";
say foo "This is a test";
--[ real.pl ]--
use v5.20;
use warnings 'all';

my $sum = 0;
for my $arg ( @​_ ) {
  $sum += 10000;
  for my $char ( split //, $arg ) {
  $sum += ord($char);
  }
}

return $sum;
--[ output ]--
21020
11269


I'm not sure if this will count as "Outside a sub" or not.

--
Kent

@p5pRT
Copy link
Author

p5pRT commented Jun 24, 2014

From @epa

Thanks for the example. In this case the code included by 'do' is within the subroutine when evaluated at run time.
Generally, when it comes to 'do' and 'eval', most static checks and warnings are defeated.
I had in mind a warning when @​_ appears at the top level of the program at compile time.

--
Ed Avis <eda@​waniasset.com>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http​://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Jun 24, 2014

From @ap

* Ed Avis <eda@​waniasset.com> [2014-06-24 08​:40]​:

That is outweighed for me by the number of types I have typed @​_
instead of @​$_ by mistake. But perhaps it's just me who does that?

I want to say I’ve never done that once. I cannot know for sure but
I would put money on it.

@p5pRT
Copy link
Author

p5pRT commented Jun 24, 2014

From @ikegami

On Tue, Jun 24, 2014 at 2​:37 AM, Ed Avis <eda@​waniasset.com> wrote​:

Brian Fraser <fraserbn <at> gmail.com> writes​:

Nothing wrong with using <at> _ outside of a subroutine. And beyond being
a possible shortcut, it has its own use​:

sub foo { @​_ }
@​_ = "val";
say &foo

This is a highly wizardly shortcut and [...]

Users of this feature can disable the warning if necessary.

@p5pRT
Copy link
Author

p5pRT commented Jun 24, 2014

From @ikegami

On Mon, Jun 23, 2014 at 11​:31 AM, Ed Avis <perlbug-followup@​perl.org> wrote​:

# New Ticket Created by "Ed Avis"
# Please include the string​: [perl #122162]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=122162 >

This is a bug report for perl from eda@​waniasset.com,
generated with the help of perlbug 1.39 running under perl 5.18.2.

-----------------------------------------------------------------
[Please describe your issue here]

There should be a warning if @​_ is used outside a subroutine.
Ideally, this warning should be at compile time rather than run time.

[Please do not change anything below this line]
-----------------------------------------------------------------

The benefit is extremely limited. I'm not sure it's worth the space in the
code or the time of developers to write and maintain the code.

Note that it would have to be a run-time warning too if you wanted to catch
C<< shift @​{"_"} >>.

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2014

From @rjbs

No, this warning is not worth it. This is easy to detect with a linter in simple cases, anyway.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2014

@rjbs - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant