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

Idea for new warning - scalar assignment from @_

Thread Next
Paul "LeoNerd" Evans
January 13, 2020 18:09
Idea for new warning - scalar assignment from @_
Message ID:
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

Paul "LeoNerd" Evans      |  |

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About