in reply to Re: Re: How Perl Optimize your code & some code TIPS ;-P
in thread How Perl Optimize your code & some code TIPS ;-P

In fact, they're identical. Perl rewrites this:

my $bar = "hello, $foo";

into this:

my $bar = "hello, " . $foo;

$ perl -MO=Terse -e '$var = "String";  $var = "foo$var"'

$ perl -MO=Terse -e '$var = "String";  $var = "foo" . $var'

Strip out the addresses (0x*) and do a diff. Almost the same :-)

Arjen

Replies are listed 'Best First'.
Re^4: How Perl Optimize your code & some code TIPS ;-P
by diotalevi (Canon) on Jan 26, 2003 at 16:49 UTC

    No really, it's the same. The null operations are never seen by runtime perl and only exist in the optree as artifacts. I took the output from both of your lines, stripped out the null operations and they are 100% identical. Incidentally B::Concise provides better output than B::Terse.

    $ perl -MO=Terse -e '$var = "String"; $var = "foo$var"' LISTOP leave [1] OP enter COP nextstate BINOP sassign SVOP const PV "String" SVOP gvsv GV *var COP nextstate BINOP sassign BINOP concat [1] SVOP const PV "foo" SVOP gvsv GV *var SVOP gvsv GV *var $ perl -MO=Terse -e '$var = "String"; $var = "foo" . $var' LISTOP leave [1] OP enter COP nextstate BINOP sassign SVOP const PV "String" SVOP gvsv GV *var COP nextstate BINOP sassign BINOP concat [1] SVOP const PV "foo" SVOP gvsv GV *var SVOP gvsv GV *var

    Seeking Green geeks in Minnesota