in reply to END blocks created at run time?
It's not "queueing" the END block at run time. The problem is that you're dieing before assigning a value to your variable. So, in effect, you're trying to unlink undef.
You're thinking that the END block shouldn't be called if the subroutine is not called because you've placed the definition inside the subroutine body... That's incorrect. Named subroutines (of which BEGIN and END are just special breeds) are non-lexical. That means they all belong to the package they're declared in, not just the block. The only thing you're accomplishing by declaring your END routine inside the body of new_tmpfile_name is that you're creating a named closure (ie, END keeps a reference to $name, thus keeping it alive longer than it otherwise would be).
A corollary to this is the fact that if you were to call new_tmpfile_name multiple times, END would still only be called once and only the first temp file unlinked. I suspect this is not what you mean to happen.
A possible solution to do what you seem to be attempting would be to do a string eval. This has an unfortunate side-effect of being a little slow. :-( But it would definately work. :-) Anyway, I hope this bit of explaination helps. Have fun coding!
bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.
|
|---|