Just another Perl shrine | |
PerlMonks |
Re: Reactionary Coding?One-Shot Programsby ariels (Curate) |
on Jun 17, 2001 at 15:56 UTC ( [id://89153]=note: print w/replies, xml ) | Need Help?? |
The "extreme" (no pun or reference intended!) example of this would be writing "one-liners" -- running perl -[np] -e ... from your command line. I use that for massaging data files and for extracting simple statistics. Sure, I could modularise the statistics and write it just once, but looking up the exact interface for a counter-that-also-keeps-average-value will take longer than recoding it. Maintainability isn't an issue here: if you're asking a question about a log file in order to find out if it's an interesting question at all, you're most likely going to decide you don't care about the answer.
Similarly, we sometimes run programs for days on end, only to discover a small bug in output. We'll fix the bugs, no question, but we don't want to lose the CPU time. If a small script can fix the output, we want it! (However, as tilly points out above, you can only do this if you've a backup; perl -pi.bk -e ... is invaluable here). The "patch" code will never run again, as the bugs in the program have been fixed -- it only exists to correct a single output file! This is bioinformatics: some of our files are >1GB in size, so text editors are not an option; it's either sed, awk or Perl. In both cases, you want to write code iteratively (the first 5 versions never work), run it once, and throw it away. Of course, I always hide away a copy of the script in my home directory; I never know when I'll want to steal some stuff from an old script.
In Section
Meditations
|
|