http://www.perlmonks.org?node_id=899027


in reply to Re: perl -pi -e s'/^\s+//'g $file
in thread perl -pi -e s'/^\s+//'g $file

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