#!/usr/bin/perl -w use strict; my $cmd = shift; while (my $filename = shift) { # Perform operation to new file. Exit on error. # TODO: On error, report command that caused problem and the resulting # error message before dying. die if `$cmd $filename 2>&1 >$filename.new`; # If the output is different than the input, replace the old version with # the new one. If nothing was changed, discared the new version and leave # the old one untouched. if (`diff $filename.new $filename`) { rename "$filename.new", $filename; } else { unlink "$filename.new"; } }