O’Reilly Hacks and Perl

Poking around ORA’s “hacks” site, I came across this quick note on searching and replacing with command-line perl:

perl -pi.bak -e ‘s/bgcolor=#ffffff/bgcolor=#000000/i’ *.html

The example, of course, is at the back of the pink camel book. In any case, -e says to work like sed, -p means to run the script against all the lines of the files enumerated on the command line, and the -i means to make the changes in place, but put a backup file out there first.

Something like this:

find -name Root | xargs perl -pi -e ‘s/cvs.oldserver.com/cvs.newserver.org/g’

works nicely for switching the CVS server from one machine to another when run across a CVS repository.

I may want to buy the Hacks books, but a lot of the listed hacks are things I already know or don’t care about. On the other hand, the explanations, such as this perl exposition, is nice. Similarly, the Google hacks may be entertaining.

There are also a number of useful hacks on the user-contributed hacks pages.

Comments are closed.