bennymack has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks, in my quest for enlightenment I have stumbled across compile time optimizations using Deparse and I would like to "compile" a list of compiler optimizations. I imagine there's a perl man page that has them but if not, perhaps someone could point me to a webpage that has a list or maybe we could make our own. An example optimization that I discovered is:
$ perl -MO=Deparse -e '$foo{__PACKAGE__."::foo"}=1;' $foo{'main::foo'} = 1; -e syntax OK
Instead of
$ perl -MO=Deparse -e '$foo{__PACKAGE__,"::foo"}=1;' $foo{join $;, 'main', ':foo'} = 1; -e syntax OK
Thanks in advance!

Replies are listed 'Best First'.
Re: List of Compiler Optimizations
by blazar (Canon) on Apr 21, 2006 at 13:12 UTC

    Your example is misleading since the two snippets actually do different things. Check $; in perldoc perlvar. It is used to be used to create "multidimensional" hashes, but now we have better means, i.e. references, to do so.

    In general you should not be too worried about micro-optimizations. Indeed people is often advised against doing so.

    Oh! and the instructive bit in this example is that B::Deparse is precisely helping you to notice the difference between the two constructs, not to discover "compile time optimizations"...

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: List of Compiler Optimizations
by dave_the_m (Monsignor) on Apr 21, 2006 at 13:26 UTC
    As far as I'm aware, no such list exists. The particular optimisation you are seeing there is constant folding, eg
    $ perl -MO=Deparse -e'$x=1+2*3' $x = 7; $
    Dave.