Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Optimizations in Perl are rather limited. This is mostly due to the very permissive type system, and the absence of static typing. Features like <code>eval</code> etc. don't make it any easier, either.</p> <p>Perl does not optimize code like</p> <pre><code>my $foo = 1; if ($foo) { ... } </code></pre> <p>to </p> <pre><code>do { ... }; </code></pre> <p>However, one can declare compile time constants:</p> <pre><code>use constant FOO =&gt; 1; if (FOO) { ... } </code></pre> <p>which is then optimized (constant folding). Constants are implemented as special subroutines, with the assumption that subs won't be redefined. Literals will be folded as well, so <code>print 1 + 2 + 3</code> will actually be compiled as <code>print 6</code></p> <p>Interesting runtime optimizations include method caching, and regex optimizations. However, perl won't try to prove certain properties about your code, and will always assume that variables are truly <em>variable</em>, even if they are only ever assigned once.</p> <p>Given a Perl script, you can look at the way it was parsed and compiled by passing perl the <code>-MO=Deparse</code> option. This turns the compiled opcodes back to Perl code. The output isn't always runnable. When <code>'???'</code> turns up, this indicates code that was optimized away, but is irrelevant. Examples:</p> <pre><code>$ perl -MO=Deparse -e' "constant" ' # literal in void context '???'; $ perl -MO=Deparse -e' print 1 + 2 + 3 ' # constant folding print 6; $ perl -MO=Deparse -e' print 1 ? "yep" : "nope" ' # constant folding removes branches print 'yep'; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload