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

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

Thread Previous | Thread Next
From:
demerphq
Date:
January 13, 2020 21:16
Subject:
Re: Idea for new warning - scalar assignment from @_
Message ID:
CANgJU+UHknZe1YH-2rvN4MydjmYVoF3f1=xWdnUHKr94WiuvCQ@mail.gmail.com
On Mon, 13 Jan 2020 at 19:38, Paul "LeoNerd" Evans
<leonerd@leonerd.org.uk> wrote:
>
> 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 + @_;

FWIW, this sounds pretty convincing to me.

cheers,
Yves
-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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