Having written the exact code once myself, I find it disgusting :P use
B::Deparse , then transform the results
$ perl -MO=Deparse -p -i.orig -e "s/foo/bar/; ... "
BEGIN { $^I = ".orig"; }
LINE: while (defined($_ = <ARGV>)) {
s/foo/bar/;
die 'Unimplemented';
}
continue {
die "-p destination: $!\n" unless print $_;
}
-e syntax OK
into a template
#!/usr/bin/perl --
use strict;
use warnings;
Main( @ARGV );
exit( 0 );
sub Main {
RuinSomeFilesOrig(@_);
}
sub RuinSomeFilesOrig {
local *ARGV;
local $^I = ".orig";
local @ARGV = @_;
LINE: while (defined($_ = <ARGV>)) {
s/foo/bar/;
...;
}
continue {
die "-p destination: $!\n" unless print $_;
}
}
then turn it into a distribution with
scriptdist :D