http://qs321.pair.com?node_id=718555


in reply to "Backing up" a subroutine during runtime.

Yep. This is truly an amazing feature of Perl.

I once did a similar thing with an IRC robot. It had various handlers that were triggered based on regexps matching things passing in a channel.

Without taking down the bot, I could edit the code of a particular handler on the server, and then connect to the channel, send a sekret™ private message to the bot, which would instruct it to reload the handler code, save the old code onto an array of coderefs attached to the trigger regexp, and install the new code in its place.

If the code failed to evaluate, it wouldn't get installed. If the new code ran for a while and I didn't like what it did, I could send another message to tell the bot to throw away the new version of the code and reinstate the version N-1.

I thought it was incredibly cool to be able to undo code changes, and have always kept it in the back of my mind hoping I'd be able to put it to use in Real Life sometime.

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: "Backing up" a subroutine during runtime.
by dextius (Monk) on Oct 21, 2008 at 20:49 UTC
    That is exactly what our code does. The ruby guys in my office were going on about how this is such a well covered tactic in their world. I wasn't out to prove them wrong, I just needed the equivalent functionality. I'm glad I found it.