in reply to Rebinding closures, possible?

Is there a way to do this or something similar in Perl?

Not to the best of my knowledge. Perl doesn't have the concept of the "scope" objects in JavaScript. With the odd way that block scoped lexicals are handled I think it would be tricky to add/fake one (although I'm not an expert on the Perl internals so I could be wrong there).

Is this just a curiosity question or do you have a goal in mind? If so it might be useful to describe what you're trying to do since there is almost certainly way of doing it that doesn't involve rebinding closures :-)

Replies are listed 'Best First'.
Re: Re: Rebinding closures, possible?
by bsb (Priest) on Dec 16, 2003 at 23:25 UTC
    Is this just a curiosity question or do you have a goal in mind?

    Just curiousity. Reading about Javascript, I tried to translate the idea to Perl. There's been moments when I thought it would be a good idea, but I've invariably been wrong.

    Re: "scope objects", the nearest Perl equivalent would be "local". If you were to put a localizing wrapper around a sub that used global names you'd be getting close to what JavaScript 1.2 does (I guess). But then the sub isn't a proper closure, the process is manual and any another subs called would also get the dynamic scope.