On Tue, Oct 05, 2004 at 08:48:28PM -0400, Kripa Sundar wrote: > Thanks for the example. This is certainly an interesting > technique. But I still fail to see why going from perl to sh(1) > makes it easier to undo something.
As it turns out, I have also implemented 'atomic' operations on groups of files solely in perl. In this case, each undoable action stores an undo coderef in a global array after the 'do' action has completed. Then if/when an error occurs, the error handler code iterates through the array and fires off each coderef. Note that since the undo stack is stored in memory, it is lost when the script ends so I cannot easily undo actions anymore. Furthermore, the undo can only occur for software detectable errors, which means that the script could run successfully and still produce bad output. Of course one *could* write the script to undo its own, previous, actions but that becomes more complicated since you have have to figure out what the previous run actually did. The generated shell script, OTOH, contains all the state information it needs to 'do' or 'undo' *and* retains that state after execution. That may not sound like much until you find an error and decide that you need to rollback. > Moreover, I would guess that such undo-able scripts are > possible only in specialised domains. That's part of the point of program and text generation: some problems are easier solved by the tools that apply in that domain. And yes, there are many areas where the technique should not be used. > If I do a chgrp(1) or chmod(1), there is no straightforward > to undo it, unless I save the previous file properties some > place. Absolutely, but only if you are modifying existing files. And if I were doing that, remember that the perl script can stat() the file and write out that information as part of the undo process. > Even worse for rm(1) and rmdir(1). Of course, but I assume we are all adults here and understand the effects of our actions. -Gyepi _______________________________________________ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm

