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

Re: Idea for new warning - scalar assignment from @_

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
January 13, 2020 18:37
Subject:
Re: Idea for new warning - scalar assignment from @_
Message ID:
20200113183754.48a8854f@shy.leonerd.org.uk
On Mon, 13 Jan 2020 19:20:07 +0100
Sergio Iglesias <sergio.iglesias7890@gmail.com> wrote:

> I think there are reasons because one may want to count the number of
> arguments doing this without getting a warning.
> 
> Anyway it is my opinion.

Well sure; it'd be

  a) an opt-in warning, and
  b) trivially simple to disarm by explicit `scalar`; as per

     my $argc = scalar @_;

The warning is purely for @_ appearing on its own on the RHS of
scalar assignment. None of the following would apply, for example:

  if( @_ ) ...

  if( @_ > 2 ) ...

  my $argc = 0 + @_; 

-- 
Paul "LeoNerd" Evans

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

Thread Previous | 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