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

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

Thread Previous | Thread Next
From:
Ed Avis via RT
Date:
April 23, 2018 14:31
Subject:
[perl #133143] Warning when list assignment RHS is a scalar
Message ID:
rt-4.0.24-6080-1524493903-749.133143-15-0@perl.org
On Mon, 23 Apr 2018 07:25:37 -0700, Eirik-Berg.Hanssen@allverden.no wrote:

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

The warning I proposed wouldn't fire there because the LHS is not a simple list of scalars.

This example and the earlier one have in common that they are both declarations as well as assignments.
One is with 'my', one with 'local'.  So how about cutting back the warning a bit so that only pure assignments, not declarations, fire?

    ($foo, $bar) = $s;     # warns
    my ($foo, $bar) = $s;  # does not warn

The second case is something you might write as a more concise way of declaring two variables and assigning one of them.  Personally I'm not a fan, but I recognize that it might better be handled by a linter such as perlcritic, where people can more easily plug in their own opinions.


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=133143

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