in reply to Protect your subs... from *EVIL*.

You mean you use global vars! Shame on you jryan, shame, shame... ;-)

cLive ;-)

Replies are listed 'Best First'.
Re: Re: Protect your subs... from *EVIL*.
by jryan (Vicar) on Dec 22, 2003 at 20:30 UTC

    Well, use Sub::Sealed on all of your subroutines and there won't be anything wrong with using globals. ;)

      That's not quite right, globals are still globals even after Sub::Sealed because you only fixup the function's lexicals. In fact, even your lexicals are now globals after being sealed. So this effectively removes lexicals from your function and sneakily replaces them with globals.

        Not quite right; it seals any variable used within the sub that was declared outside of the sub (or at least, that's what it is supposed to do.). However, you are right in that part of this process involves turning these variables into globals, whether they were before or not. However, they are SECRET globals! Secret! Only ninjas can find them! :-)

      I dunno jryan,

      As a matter of readability and sanity, I'd pass the variable as an argument and taint-check as neccessary. Or use constants. Do you have an example where constants or untainting globals as arguments are not the best way to go?

      Just curious as to practical use. Nice bit of code though :)

      .02

      cLive ;-)

        Just curious as to practical use.

        Well, there isn't really one. :) I just wanted to see if it could be done. I had an argument/discussion with a CS proffessor a long time ago about closures. He claimed that a true closure would copy the values of variables in scope at the moment of creation. I claimed that that would be pretty useless. At any rate, seeing diotalevi's node the other day reminded me of the discussion, and so here we are.

        Its essentially a demonstration of the full power and glory of Perl's Reflective abilities used to essentially accomplish nothing.

        By the way, even before the update, the comment on the 2nd line was there ;)