View Single Post
  #2 (permalink)  
Old 03-12-2008, 01:22 AM
arjkhanna arjkhanna is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 1,034
arjkhanna is on a distinguished road
Default Re: Perl its - strengths

In-place editing:

Combine regular expressions with the ability to edit files "in place" from the command line, and perl makes a dandy tool for performing a batch modification on a group of files

For example

suppose you have renamed the
Code:
 /home/george directory to /home/curious,
and want to update a few hundred scripts in the /usr/lib/yellowhat directory to point at the correct new path, then the you can just update with one liner

Code:
# perl -i.bak -p -e "s#/home/george#/home/curious#" `find . -print`
Now, this is a fairly simple example and could have easily been done using a tool such as sed, but the important thing is that you could have used any arbitrarily complex perl program as the filter, and done highly complex manipulations. Imagine an area code getting split and having to replace a single area code with one of two depending on the original exchange in hundreds of files. In perl, it would be a snap.
__________________
A.Rajesh Khanna
Reply With Quote