But this relies on constant folding happening after the PAD was populated.

That's pretty much necessary. But let's imagine it's not.

Anything that can be optimized away would run into that problem. It's hard to write a version that doesn't warn and can't be optimized away. For example, look at the following:

my $false = 0; # Perhaps a global. capture( $gold ) if $false; # `capture` doesn't need to exist.

Even that could be optimized away. And that's far from readable.

Since the symbol table is externally modifiable, the following can't be optimized away and provides a solution:

sub capture { } capture( $gold );

It does comes at a performance cost. You could, of course, use an opcode checker to optimize the call away. But then we're back to the beginning.

Actually, not really. An opcode checker manipulates ops, so that means the padop for $gold must have been created already. So that might be a very simple module that makes the intent clear.


In reply to Re^5: trouble with packages/eval/variable-scoping by ikegami
in thread trouble with packages/eval/variable-scoping by Ratazong

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.