I am writing an script which will allow a user with root access to rename a majordomo list and all associated files to a new name. I had gotten almost completely finished with the first try when I ran into a logic problem(moving a file to a new name and then trying to open it using the same ref doesn't really work, in case you were wondering). I sat up at this and thought for a moment: What's the best way to do this?
A given majordomo list has a multitude of files associated with it. Lets take a simple example: mylist.
The files for mylist are these:
/path/to/lists/mylist
/path/to/lists/mylist.config
/path/to/lists/mylist.passwd
/path/to/lists/mylist.resend
/other/path/to/archives/mylist/mylist.0101
/other/path/to/archives/mylist/mylist.NNNN
Along with the files for the list itself the script also needs to change the entries in /etc/aliases. Many of the listfiles themselves also have the listname inside of them. resend for example contains the listname to allow for proper addressing of incoming and outgoing mail messages.
My original script was this: a sub to change the filenames, a sub to move and rename the archives(and their directory), and a sub to change the aliases file, and one last one to modify the contents of files.
My question is this: Should I make the script as exact as possible in the subroutines and what they do or should I spend time making the subroutines very generic and do most of the logical work in the main routine (eg finding the list of files, sending them off to the modify routine then to the rename routine, etc).
I've never taken any programming classes but, rather ironically, my job has come to include a good bit of it. I suppose this is pretty basic concept. My thinking is the latter is prefered as it would allow you to much more easily re-use code and thus bring the overall amount of necessary programming down...
And hey, if anyone has suggestions as to a good way of structure thing as a whole or nifty way to do certain tasks ("renaming" a directory is still elluding me, I can only think to mkdir, move files, and then rmdir), please chime in...
Thanks
_____________________
mjn
2001-05-14 Edit by Corion : Changed title to be more descriptive.