|
|
|||||||
| Home Page |
|||||||
Using Perl and Regular Expressions to Process Html Files - Part 2In this article we will discuss how to change the contents of an HTML file by running a Perl script on it.
Line 5 This line takes the contents of the $line variable and, via the OUT file handle, writes the line to new_file1.htm. Line 6 This line closes the 'while' loop. The loop is repeated until all the lines in file1.htm have been examined. Lines 7 and 8 These two lines close the two file handles that have been used in the script. If you missed off these two lines the script would still work, but it's good programming practice to close file handles, thus freeing up the file handle names so they can be used, for example, by another file. Running the Script As the purpose of this article is to explain how to use regular expressions to process HTML files, and not necessarily how to use Perl, I don't want to spend too long describing how to run Perl scripts. Suffice to say that you can run them in various ways, for example, from within a text editor such as TextPad, by double-clicking the perl script (script1.pl), or by running the script from an MS-DOS window. (The location of the Perl interpreter will need to be in your PATH statement so that you can run Perl scripts from any location on your computer and not just from within the directory where the interpreter (perl.exe) itself is installed.) So, to run our script we could open an MS-DOS window and navigate to the location where the script and the HTML file are located. To keep life simple I've assumed that these two files are in the same folder (or directory). The command to run the script is: C:>perl script1.pl If the script does work (and hopefully it will), a new file (new_file1.htm) is created in the same folder as file1.htm. If you open the file you'll see the the two lines that contained [h1] tags have been modified so that they now read [h1 class="big"]. In Part 3 we'll look at how to handle multiple files.
Rate this Article:
Current: 0 / 5 stars - 0 vote(s).
Article Tags: Process, Html, Perl, Expression, Conversion, Processing, Convert, Expressions, Regular Article Source: http://www.articlesbase.com/programming-articles/using-perl-and-regular-expressions-to-process-html-files-part-2-362029.html About the Author:John is a web developer working for My Health Questions Matter, a company dedicated to helping patients to get the most out of their interaction with health care professionals such as doctors, midwives, and consultants by generating a set of health questions a patient can ask at an appointment.
Related ArticlesUsing Perl and Regular Expressions to Process Html Files - Part 1 Pdf to Word: Text Flow Vs. Original Format Black and White Photo Conversion Automatically Running a Script From Within a Web Page Web Designing as a Profession The Ultimate Solution for a Client Conversion System That You Can Learn About Today Free Ipod Video Converter Tips Checklist for the Tenant Selection Process Got a Question? Ask.Ask the community a question about this article:Frequently Asked Questions What need to make connection from dial up modem ... Connection from dialup modem to another modem that use mobile SIM card? I'm an Vietnamese citizen studing to Australia ... I've been using Duofem pills for 2 months but I ... Why do I have to use regular flour when making ... Converting a queen frame to a double Latest Programming ArticlesCool Desktop Wallpapers Tips for Buying Software Online Mvc Design Pattern Advantages of Low Cost Contract Programmers in Freelance Programming A Guide to Cnc Kits A Guide to Cnc Tube Bending Machines Ways to Hire Dedicated Php Programmers Top 4 Reasons Why Addressing Web Accessibility is Important More from John DixonUsing Php to Populate a Drop Down List Box From a Mysql Database Table Using Php to Validate Form Fields Finding Hidden Characters in a File Web Site Promotion Tips Exploiting Google Adsense Using Perl and Regular Expressions to Process Html Files - Part 1 Size Really Does Matter Running a Cgi Script on a Web Server |
|||||||
|
Article Categories
|
|||||||
|
|
|||||||