There are many situations in which you would like something to run each time you save a file (or a process modifies a file). Since linux kernel 2.6 this has been possible via the inotify mechanism. All you need is a client package for whichever language (bash, perl, ruby, python, …) you want to use.
For perl we have liblinux-inotify2-perl and for bash we have inotify-tools which I’ll illustrate here.
In this example, each time one of the specified files is saved (in vim), the script of unit tests will be invoked. This particular line uses the fact that vim implements a ‘save’ by way of ‘move, move, delete’, so we detect the first ‘move’…
tests=test/cari_plugin_defaults.pl sources="lib/Cari/Plugin/Defaults.pm lib/Cari/Plugin/Stash.pm" while inotifywait -qqe MOVE_SELF $tests $sources; do ./$tests; done
This is useful in lots of examples where you want to quickly see the results of editing source file(s), for example editing LaTeX files.
(Update: My latest vim issues ‘MODIFY’ instead of ‘MOVE_SELF’, so you’ll want to test yourself using inotifywait filename.)