in reply to 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;

Replies are listed 'Best First'.
Re: Re: Re: How Perl Optimize your code & some code TIPS ;-P
by Aragorn (Curate) on Jan 25, 2003 at 14:35 UTC
    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

      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