in reply to Re^2: Efficiency on Perl Code!
in thread Efficiency on Perl Code!

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.