develooper Front page | perl.perl5.porters | Postings from April 2018

Re: [perl #133143] Warning when list assignment RHS is a scalar

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
April 23, 2018 14:25
Subject:
Re: [perl #133143] Warning when list assignment RHS is a scalar
Message ID:
CAHAeAG6VN=HPS_Oo6ok20f01sPGxye1MZ=fKfjwhN1o1zGSqFQ@mail.gmail.com
On Mon, Apr 23, 2018 at 3:53 PM, Ed Avis <perlbug-followup@perl.org> wrote:


> This is probably a mistake:
>
>     ($foo, $bar) = $baz;
>
> In my case it usually means that I wanted @{$baz} instead.
> For other programmers there might be some other reason.
> But surely it cannot be intentional.
>

  Oh, but it can.  You never know what other programmers might do
intentionally.


> A compile-time warning should be given when an assignment statement
> has a list of two or more items on the LHS, and the RHS is a scalar
> variable expression that begins with a $ sign.
>

  Sounds like this will break (well, start warning) on the common (quick
and dirty) slurp idiom:

  my $text = do { local (@ARGV, $/) = $filename; <> } ;

  .. and that's just off the top of my head.

  Do we really want "style" warnings on correct and intentional code?


Eirik

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