Front page | perl.perl5.porters |
Postings from October 2014
Re: [perl #122947] [EXPERIMENT] Lvalue references
Thread Previous
|
Thread Next
From:
H.Merijn Brand
Date:
October 14, 2014 15:07
Subject:
Re: [perl #122947] [EXPERIMENT] Lvalue references
Message ID:
20141014170657.19e6248a@pc09.procura.nl
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)?
$ perl -wE'$_="Foo";substr $_,1,0,"x";say'
Fxoo
$ perl -wE'$_="Foo";substr($_,1,0)="x";say'
Fxoo
B says no
$ perl -MO=Concise -wE'$_="Foo";substr($_,1,0)="x";say'
g <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 47 -e:1) v:%,{,469764096 ->3
5 <2> sassign vKS/2 ->6
3 <$> const[PV "Foo"] s ->4
- <1> ex-rv2sv sKRM*/1 ->5
4 <#> gvsv[*_] s ->5
6 <;> nextstate(main 47 -e:1) v:%,{,469764096 ->7
- <1> ex-sassign vKS/2 ->c
b <@> substr[t3] vKS/REPL1ST,3 ->c
- <0> ex-pushmark s ->8
7 <$> const[PV "x"] s ->8
- <1> ex-rv2sv sKRM*/1 ->9
8 <#> gvsv[*_] s ->9
9 <$> const[IV 1] s ->a
a <$> const[IV 0] s ->b
c <;> nextstate(main 47 -e:1) v:%,{,469764096 ->d
f <@> say vK ->g
d <0> pushmark s ->e
- <1> ex-rv2sv sK/1 ->f
e <#> gvsv[*_] s ->f
-e syntax OK
$ perl -MO=Concise -wE'$_="Foo";substr $_,1,0,"x";say'
g <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 47 -e:1) v:%,{,469764096 ->3
5 <2> sassign vKS/2 ->6
3 <$> const[PV "Foo"] s ->4
- <1> ex-rv2sv sKRM*/1 ->5
4 <#> gvsv[*_] s ->5
6 <;> nextstate(main 47 -e:1) v:%,{,469764096 ->7
b <@> substr[t3] vK/4 ->c
- <0> ex-pushmark s ->7
- <1> ex-rv2sv sKM/1 ->8
7 <#> gvsv[*_] s ->8
8 <$> const[IV 1] s ->9
9 <$> const[IV 0] s ->a
a <$> const[PV "x"] s ->b
c <;> nextstate(main 47 -e:1) v:%,{,469764096 ->d
f <@> say vK ->g
d <0> pushmark s ->e
- <1> ex-rv2sv sK/1 ->f
e <#> gvsv[*_] s ->f
-e syntax OK
cmpthese (-3, {
arg3 => sub { my $foo = "foo"; substr ($foo, 1, 0) = "x"; },
arg4 => sub { my $foo = "foo"; substr $foo, 1, 0, "x"; },
});
Rate arg3 arg4
arg3 3235869/s -- -61%
arg4 8401562/s 160% --
--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using perl5.00307 .. 5.19 porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Thread Previous
|
Thread Next