develooper Front page | perl.perl5.porters | Postings from January 2020

Idea for new warning - scalar assignment from @_

Thread Next
From:
Paul "LeoNerd" Evans
Date:
January 13, 2020 18:09
Subject:
Idea for new warning - scalar assignment from @_
Message ID:
20200113180919.6b6156b3@shy.leonerd.org.uk
I've now lost count of the number of bugs I've caused by

  my $message = @_;

when I meant either of

  my $message = shift;
  my ( $message ) = @_;

In the frigtningly rare case I wanted a count of the arguments, I'd
likely want to write it using the `scalar` operator explicitly, to
remind the human reader as much as perl itself:

  my $argc = scalar @_;

Therefore, would we consider adding a new warning?

  $ perl -Mwarnings -ce 'my $message = @_'
  Use of @_ in scalar assignment may be unintentional at -e line 1.

(cc github https://github.com/Perl/perl5/issues/17418)

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About