in reply to Optimizing Perl Code - single versus double quotes really that important?

Speed-wise, I don't think it makes much difference. (As has already been pointed out.) The fact that you could replace:

$info1 = "this is some sample stuff".$info_in."<br><br>"; print <<__ENDER__; $info1 . . __ENDER__

With:

print <<__ENDER__; this is some sample stuff $info_in <br><br> . . __ENDER__

Which then suggests this:

$info[1] = "this is some sample stuff $info_in <br><br>"; .. foreach my $outfo ( @info ) { print "$outfo\n"; }

Might be something you want to look at to do some cleanup...

Replies are listed 'Best First'.
Re^2: Optimizing Perl Code - single versus double quotes really that important?
by ikegami (Patriarch) on Feb 05, 2009 at 18:02 UTC

    Speed-wise, I don't think it makes much difference

    Speedwise, it makes no difference. They produce exactly the same code.

    $ perl -MO=Concise,-exec -e'$x = qq{a $b c}' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 <$> const[PV "a "] s 4 <#> gvsv[*b] s 5 <2> concat[t3] sK/2 6 <$> const[PV " c"] s 7 <2> concat[t4] sKS/2 8 <#> gvsv[*x] s 9 <2> sassign vKS/2 a <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e'$x = q{a }.$b.q{ c}' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 <$> const[PV "a "] s 4 <#> gvsv[*b] s 5 <2> concat[t3] sK/2 6 <$> const[PV " c"] s 7 <2> concat[t4] sKS/2 8 <#> gvsv[*x] s 9 <2> sassign vKS/2 a <@> leave[1 ref] vKP/REFC -e syntax OK

      Well...

      perl -MO=Concise,-exec -e '$x=qq{a $b c}' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> const[PV "a "] s 4 <#> gvsv[*b] s 5 <2> concat[t3] sK/2 6 <$> const[PV " c"] s 7 <2> concat[t4] sKS/2 8 <#> gvsv[*x] s 9 <2> sassign vKS/2 a <@> leave[1 ref] vKP/REFC -e syntax OK perl -MO=Concise,-exec -e '$x=q{a $b c}' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> const[PV "a $b c"] s 4 <#> gvsv[*x] s 5 <2> sassign vKS/2 6 <@> leave[1 ref] vKP/REFC -e syntax OK

      So obviously there is some minor difference at compile-time. (Which would be the only difference I expect.) Once compiled equivalent expressions produce equivalent op-code, it's just that the compile process isn't exactly the same.

      Unlikely to be noticeable though, and really irrelevant to my original reply.

        Apples and oranges. Those snippets don't build the same string. Of course they result in different code.