Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
    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
    if inconclusive ...
perl -Dt

Test 1 :
perl -MO=Deparse,-p ($a = 'foo'); ($b = (\$a)); print("b : $$b\n"); print("b2 : ${$b;}\n"); 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 ( enter ( nextstate ( const(PV("foo"\0)) ( gvsv(main::a) ( sassign ( nextstate ( gvsv(main::a) ( srefgen ( gvsv(main::b) ( sassign ( nextstate ( pushmark ( const(PV("b : "\0)) ( gvsv(main::b) ( rv2sv ( concat ( const(PV("\n"\0)) ( concat ( print b : foo ( nextstate ( pushmark ( const(PV("b2 : "\0)) ( gvsv(main::b) ( rv2sv ( concat ( const(PV("\n"\0)) ( concat ( print b2 : foo ( leave

Eurica !

Now, for those who did not spot it, here is what i am seeing :
    The first line which has ( 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) :
( nextstate ( nextstate ( pushmark ( pushmark ( const(PV("b : "\0)) ( const(PV("b2 : " +\0)) ( gvsv(main::b) ( gvsv(main::b) ( rv2sv ( rv2sv ( concat ( concat ( const(PV("\n"\0)) ( const(PV("\n"\0) +) ( concat ( concat ( print ( 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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-01-28 23:34 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (74 votes). Check out past polls.