develooper Front page | perl.perl5.porters | Postings from October 2014

Re: [perl #122947] [EXPERIMENT] Lvalue references

Thread Previous | Thread Next
From:
Eric Brine
Date:
October 14, 2014 17:47
Subject:
Re: [perl #122947] [EXPERIMENT] Lvalue references
Message ID:
CALJW-qGJ=Ph30bSbGLYZ1xA5jFxmBpE-X-DsDvt4F=LvMy1=Mg@mail.gmail.com
On Tue, Oct 14, 2014 at 11:06 AM, H.Merijn Brand <h.m.brand@xs4all.nl>
wrote:

> On Tue, 14 Oct 2014 15:43:40 +0100, "Paul \"LeoNerd\" Evans"
> <leonerd@leonerd.org.uk> wrote:
>
> > On Tue, 14 Oct 2014 08:47:15 -0400
> > Ricardo Signes <perl.p5p@rjbs.manxome.org> wrote:
> >
> > > Also, we have LVALUE refs.  Is this feature actually
> > > related to that?
> >
> > The things we have that are called LVALUE are the lvalues returned by
> > the substr() function so that mutations of it can affect the original:
> >
> >   my $str = "Hello world";
> >   substr( $str, 0, 5 ) = "Goodbye";   <== assignment to an LVALUE
>
> is that (internally) different from using the 4-arg form (which I
> prefer because it is much faster)?
>


Better examples:

my $ref = \substr($str, 0, 5);
$$ref = "Goodbye";

or

sub f { $_[0] = "Goodbye"; }
f( substr($str, 0, 5) );

B says no
>

If the assignment is optimized away, why is it slower? I'll try to look
into it tonight.

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