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

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

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
September 7, 2013 09:20
Subject:
Re: [perl #4514] two bugs: substitution on a list
Message ID:
20130907091858.GG2177@iabyn.com
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.


-- 
In economics, the exam questions are the same every year.
They just change the answers.

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