iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

August 8, 2008
Reader Question: What graphics compression program do you use?
About
 
August 7, 2008
Google's Big Mistake: Getting Rid of Google Page Creator, What Do...
About
 
August 7, 2008
Wish XML a happy birthday
About
 
August 7, 2008
Poll: How important is SEO to your overal website strategy?
About
 
August 7, 2008
How to Create a Search Feature with PHP and MySQL
WebReference.com
 
August 7, 2008
1 comment
.net
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /CGI and Perl

Useful Perl Scripts With Regular Expressions 

  Views:    21163
  Votes:    5
by Matthew Drouin 11/07/04 Rating: 

Synopsis:

Many people talk about Perl and many more about regular expressions but unless you are a programmer you probably never use either. We will discuss a few unique and very useful ways to use both of them.
Pages: firstback2 3 4 5 6 forwardlast
The Article

Introduction

Most computer users, especially software engineers, have had a need to modify multiple files to either add a line of text, modify a line of text, or completely remove a line of text. The problem is that there never seems to be a piece of software out there that can help you with this problem. Some programs let you get close to doing what you want but in my experience none ever let you do exactly what you want; so a few hours are spent opening each file and editing them manually.

Well I finally had enough and I wrote a couple little Perl scripts that use regular expressions to edit only the selected file types. The script will modify, add, or remove any text you would want. Since these are Perl scripts you cannot just type what you want to do into a pretty text box and have the program do it; rather you will have to make some small modifications to the files in order for it to modify the files as you would like.

We will walk though how to modify the Perl script to make it do a few different things that most people would want and then discuss other possible uses for the scripts. We will even discuss how to get the script to traverse directories since that is usually where the biggest issues arise when needing to modify multiple files.

Beyond just being able to edit this script so that you can use it to parse and edit your files you should learn a little bit about regular expressions which is always something that people dislike. Most programmers that have used regular expressions but have run into issues where regular expressions just grab more than you want them to. In most languages regular expressions do a maximum munch, meaning they take as much as possible instead of stopping at the first spot where stopping would be permitted by the expression. We will discuss how to make the regular expression grab a smaller portion because this will help when we want to modify simple HTML pages and more specifically maybe a <body> tag that has attributes in it.

Pages: firstback2 3 4 5 6 forwardlast

Similar/related articles:


 
  Sponsors