They call me obsessed. They call me crazy. But fear not, the Over-Optimizer is here. I, like many programmers, will optimise the smallest code just to eek out the smallest gains. In doing this you learn the art of optimsation.Also, i am a programmer, not an english teacher, so please ignore any spelling errors. See below :

Checking : $$var vs. ${$var}

Test Code :
#!/usr/bin/perl $a = "foo"; $b = \$a; print "b : $$b\n"; print "b2 : ${$b}\n";

Tests : perl -MO=Deparse,-p test_ref.pl
    if inconclusive ...
perl -Dt  test_ref.pl

Test 1 :
perl -MO=Deparse,-p test_ref.pl ($a = 'foo'); ($b = (\$a)); print("b : $$b\n"); print("b2 : ${$b;}\n"); test_ref.pl syntax OK

hmmmm, no real help there. Actually, based on the ";" added on the second print, ${$var} might be slower (which would make my guess wrong).

Test 2 :
perl -Dt test_ref.pl (test_ref.pl:0) enter (test_ref.pl:0) nextstate (test_ref.pl:3) const(PV("foo"\0)) (test_ref.pl:3) gvsv(main::a) (test_ref.pl:3) sassign (test_ref.pl:3) nextstate (test_ref.pl:4) gvsv(main::a) (test_ref.pl:4) srefgen (test_ref.pl:4) gvsv(main::b) (test_ref.pl:4) sassign (test_ref.pl:4) nextstate (test_ref.pl:7) pushmark (test_ref.pl:7) const(PV("b : "\0)) (test_ref.pl:7) gvsv(main::b) (test_ref.pl:7) rv2sv (test_ref.pl:7) concat (test_ref.pl:7) const(PV("\n"\0)) (test_ref.pl:7) concat (test_ref.pl:7) print b : foo (test_ref.pl:7) nextstate (test_ref.pl:9) pushmark (test_ref.pl:9) const(PV("b2 : "\0)) (test_ref.pl:9) gvsv(main::b) (test_ref.pl:9) rv2sv (test_ref.pl:9) concat (test_ref.pl:9) const(PV("\n"\0)) (test_ref.pl:9) concat (test_ref.pl:9) print b2 : foo (test_ref.pl:9) leave

Eurica !

Now, for those who did not spot it, here is what i am seeing :
    The first line which has (test_ref.pl:7) is entering the print statement. Reading from there to the end, there are two duplicated sections, meaning the exact same path is used for both de-referencers. So, to show it more clearly (sorry about any code wrapping) :
(test_ref.pl:4) nextstate (test_ref.pl:7) nextstate (test_ref.pl:7) pushmark (test_ref.pl:9) pushmark (test_ref.pl:7) const(PV("b : "\0)) (test_ref.pl:9) const(PV("b2 : " +\0)) (test_ref.pl:7) gvsv(main::b) (test_ref.pl:9) gvsv(main::b) (test_ref.pl:7) rv2sv (test_ref.pl:9) rv2sv (test_ref.pl:7) concat (test_ref.pl:9) concat (test_ref.pl:7) const(PV("\n"\0)) (test_ref.pl:9) const(PV("\n"\0) +) (test_ref.pl:7) concat (test_ref.pl:9) concat (test_ref.pl:7) print (test_ref.pl:9) print b : foo b2 : foo

So, $$var and ${$var} are the same after optimisation.
always more than one way to skin an amoebae
-- MZSanford

In reply to Re: Efficiency of $$var, ${$var} by MZSanford
in thread Efficiency of $$var, ${$var} by bladx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.