perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Gormley <cl...@traveljury.com >
Subject Re: Generic print concatenation question
Date Wed, 22 Oct 2008 10:48:49 GMT

> This is probably a question better asked to the perl monks or similar, 
> but if there are any of them lurking around here, it would save me a 
> subscription.

it's a subscription worth having :) I've learnt more about Perl since
I've been there than in the preceding decade.

> Now, my question is, considering the way perl handles these things 
> internally, how do these different forms compare in terms of eficiency ?

Perl sorts all of this out at compile time, so:

    print "$var1 text"
and
    print $var1.' text'

are represented by exactly the same opcodes:

perl -MO=Concise -e 'my $var = 'abc'; print $var .q{ text}'

c  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
5     <2> sassign vKS/2 ->6
3        <$> const[PV "abc"] s/BARE ->4
4        <0> padsv[$var:1,2] sRM*/LVINTRO ->5
6     <;> nextstate(main 2 -e:1) v:{ ->7
b     <@> print vK ->c
7        <0> pushmark s ->8
a        <2> concat[t2] sK/2 ->b
8           <0> padsv[$var:1,2] s ->9
9           <$> const[PV " text"] s ->a


perl -MO=Concise -e 'my $var = 'abc'; print "$var text"'

c  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
5     <2> sassign vKS/2 ->6
3        <$> const[PV "abc"] s/BARE ->4
4        <0> padsv[$var:1,2] sRM*/LVINTRO ->5
6     <;> nextstate(main 2 -e:1) v:{ ->7
b     <@> print vK ->c
7        <0> pushmark s ->8
-        <1> ex-stringify sK/1 ->b
-           <0> ex-pushmark s ->8
a           <2> concat[t2] sK/2 ->b
8              <0> padsv[$var:1,2] s ->9
9              <$> const[PV " text"] s ->a


clint


Mime
View raw message