I'm wondering, does -MO=Deparse
show you all of the Perl optimizations, and why doesn't this get folded in Perl 5.10?
$ perl -MO=Deparse -e'[qw/foo bar baz/]->[0]'
['foo', 'bar', 'baz']->[0];
-e syntax OK
Some on IRC thought that O=Deparse
might not be showing it all, but it certainly shows some constant folding.
$ perl -MO=Deparse -e'use constant "foo" => "bar"; foo'
use constant ('foo', 'bar');
'???';
-e syntax OK
Same result if I explicitly write the constant sub. While predictable, it is also rather interesting that the documentation in constant.pm
has you create a constant list rather than a constant array. I assume that not just is this not folded like scalar constants but it requires the overhead of creating a new array on every invocation.
$ perl -MO=Deparse -e'use constant foo => qw/foo bar baz/; (foo)[0]'
use constant ('foo', ('foo', 'bar', 'baz'));
(foo)[0];
-e syntax OK
The only conclusion that I can come to is -MO=Deparse
is showing all of the folding, and constant arrays are just not optimized out in Perl? Is this so? Is there a technical reason for it?