I didn't mention reusing $sth for reasons of execution efficiency. Some people find it more straightforward to reuse a scalar for a particular kind of resource in non-overlapping situations.

One could have a block scope around $sth and reuse the name as different lexical variables. One could simply reuse it. There could be an array of statement handles that's pushed and popped like a stack in some situations, or that treats the array as a set of statement handles that are all visible at once in other situations.

It's not a matter of only having one scalar for Perl to keep track of, but of only having to keep track of as many scalars in one's own head as there are active handles of that type. If I can reuse $sth, I know the one to fetch from is $sth. If not, is it $sth[23] or $sth[24] that holds the particular statment handle from which I need to fetch in this line?

I know some people don't think this way, but it's a decision that some people make. If you'd rather have a separate variable for each handle, go ahead. If it's easier for you to only keep track of as many as are actually in use, then I think that's a valid approach as well.


In reply to Re^3: Efficiency on Perl Code! by mr_mischief
in thread Efficiency on Perl Code! by Anonymous Monk

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.