develooper Front page | perl.perl5.porters | Postings from September 2013

[perl #4514] two bugs: substitution on a list

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
September 8, 2013 05:25
Subject:
[perl #4514] two bugs: substitution on a list
Message ID:
rt-3.6.HEAD-1873-1378617923-46.4514-15-0@perl.org
On Sat Sep 07 02:21:21 2013, davem wrote:
> On Fri, Sep 06, 2013 at 07:24:44PM -0700, James E Keenan via RT wrote:
> > > On Wed Oct 25 08:41:02 2000, hv@crypt.compulink.co.uk wrote:
> > > > (After a report in clp.moderated from Peter Scott <peter@psdt.com>.)
> > > > 
> > > > perl -Dr -we '(($y) = "x") =~ s/a/b/'
> > > > 
> > > > shows that a) perl is trying to perform the substitution on the
string
> > > > '1' which is not what the caller intended, and b) '1' is not marked
> > > > readonly in this context, so no error is reported. I think both of
> > > > these are bugs: I think the former should be fixed by giving an
error
> > > > if the LHS of a binding operator is supplied as a list, and that the
> > > > latter should be fixed (if still relevant) by marking the count of
> > > > list elements as readonly.
> 
> I don't think either of these are bugs.
> 
> In the first instance, its a list assignment evaluated in scalar context,
> which is well-defined as returning the number of elements assigned.
> The result may be slightly unexpected to the uninitiated, but its no
> different than say
> 
>     $count = (($y) = "x");
> 
> which sets count to 1.
> 
> In the second instance, (($y) = "x") in scalar context is an expression
> that returns a well-defined numeric value. I see no rationale for it
> to be read-only, any more than any other expression should return a
> read-only value.

Hmm, but should aassign be allowed as a scalar lvalue?

We also allow:

read STDIN, @a=qw(foo bar), 10

Should we?

(I wrote earlier that I agreed.  Now I’m not sure.  Reopening....)

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: rejected
https://rt.perl.org:443/rt3/Ticket/Display.html?id=4514

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