Will You Add?
#1 in Business Subscribe Email Print

You are here: Home > Computers and Technology > Software > Using Perl and Regular Expressions to Process HTML Files - Part 5

Tags

  • foreach
  • square
  • example
  • specific files
  • negative amortization
  • specific directoriesin

  • Links

  • Affluent Name Recipients of December Holiday Gifts
  • How To Save Time, Energy, and Money by Renting Your DVDs and Games Online
  • Enjoy The Convenience of Scented Jar Candles ??“ Inexpensive And Useful
  • Will You Add? - Using Perl and Regular Expressions to Process HTML Files - Part 5

    Is Debt Negotiation Bad? Points To Consider
    Debt negotiation companies that claim they can wipe your credit clean or guarantee they can reduce your debt are bad because they can’t deliver. But reputable companies can negotiate with your creditors, often reduci
    ose IN;
    11 close OUT;
    12 }

    The only new line here is line 1, which uses the glob function to search through specified directories and files. Firstly, it searches for file1.htm in the current directory, and then it search for all files ending in .shtm in directory1/subdirectory1, and then

    Why Do People Blog?
    You may have heard of a blog. You have seen several blogs on the internet or you may even have a blog yourself. Blogs are very popular these days. A blog is just a particular type of website. The entries are arra
    In Part 1 we had a quick look at what Perl and regular expressions are, and introduced the idea of using them to process HTML files. In Part 2 we developed a Perl script to process a single HTML file. In part 3 we looked at one way of processing multiple files. In Part 4 we looked at how to read in all the files in the current directory. In this, the last part, we'll look at how to read in specific files in specific directories.

    In Part 4 we wrote a script that enabled us to read in all the files in the current directory. Sometimes, however, you might need to process files that are located in different directories. script4.pl lists a script that will do this.

    Note: Due to display considerations, in the example code shown in this article, square brackets '[..]' are used in HTML/script tags instead of angle brackets '<..>'.

    script4.pl

    1 @allfiles=glob("file1.htm directory1/subdirectory1/*.shtm directory2/*.htm");
    2 foreach $name (@allfiles) {
    3 rename $file, "$file.bak";
    4 open (IN, "<$file.bak");
    5 open (OUT, ">$file");
    6 while ($line = [IN]) {
    7 $line =~ s/[h1]/[h1 class="big"]/;
    8 (print OUT $line);
    9 }
    10 close IN;
    11 close OUT;
    12 }

    The only new line here is line 1, which uses the glob function to search through specified directories and files. Firstly, it searches for file1.htm in the current directory, and then it search for all files ending in .shtm in directory1/subdirectory1, and then

    DMV Records Play Critical Role in Hiring Decisions
    DMV records, driving, motor vehicle records or MVRs provide detailed information about a person's traffic violations, DUIs, license suspensions. Unfortunately, most states no longer allow online access DMV records, s
    iles in the current directory. In this, the last part, we'll look at how to read in specific files in specific directories.

    In Part 4 we wrote a script that enabled us to read in all the files in the current directory. Sometimes, however, you might need to process files that are located in different directories. script4.pl lists a script that will do this.

    Note: Due to display considerations, in the example code shown in this article, square brackets '[..]' are used in HTML/script tags instead of angle brackets '<..>'.

    script4.pl

    1 @allfiles=glob("file1.htm directory1/subdirectory1/*.shtm directory2/*.htm");
    2 foreach $name (@allfiles) {
    3 rename $file, "$file.bak";
    4 open (IN, "<$file.bak");
    5 open (OUT, ">$file");
    6 while ($line = [IN]) {
    7 $line =~ s/[h1]/[h1 class="big"]/;
    8 (print OUT $line);
    9 }
    10 close IN;
    11 close OUT;
    12 }

    The only new line here is line 1, which uses the glob function to search through specified directories and files. Firstly, it searches for file1.htm in the current directory, and then it search for all files ending in .shtm in directory1/subdirectory1, and then

    List Building 104-How to Build Traffic for Your List Building Campaign
    List building can be one of the most lucrative ways to make money online. List building can be one of the most frustrating efforts you can make online, because it encompasses many areas in which you must do things r
    rectories. script4.pl lists a script that will do this.

    Note: Due to display considerations, in the example code shown in this article, square brackets '[..]' are used in HTML/script tags instead of angle brackets '<..>'.

    script4.pl

    1 @allfiles=glob("file1.htm directory1/subdirectory1/*.shtm directory2/*.htm");
    2 foreach $name (@allfiles) {
    3 rename $file, "$file.bak";
    4 open (IN, "<$file.bak");
    5 open (OUT, ">$file");
    6 while ($line = [IN]) {
    7 $line =~ s/[h1]/[h1 class="big"]/;
    8 (print OUT $line);
    9 }
    10 close IN;
    11 close OUT;
    12 }

    The only new line here is line 1, which uses the glob function to search through specified directories and files. Firstly, it searches for file1.htm in the current directory, and then it search for all files ending in .shtm in directory1/subdirectory1, and then

    New Port Richey Offers Florida Living at its Best
    Florida’s Gulf Coast is home to some of the most beautiful beaches in the world, a fact that rightly earns it the nickname of ‘Florida’s Beach’. New Port Richey, a small city in Pasco County on the western coast of F
    directory1/subdirectory1/*.shtm directory2/*.htm");
    2 foreach $name (@allfiles) {
    3 rename $file, "$file.bak";
    4 open (IN, "<$file.bak");
    5 open (OUT, ">$file");
    6 while ($line = [IN]) {
    7 $line =~ s/[h1]/[h1 class="big"]/;
    8 (print OUT $line);
    9 }
    10 close IN;
    11 close OUT;
    12 }

    The only new line here is line 1, which uses the glob function to search through specified directories and files. Firstly, it searches for file1.htm in the current directory, and then it search for all files ending in .shtm in directory1/subdirectory1, and then

    Difficulties Doing a Home Equity Loan Behind a Negative Amortization Mortgage (Payment Option Loans)
    If you need a home equity loan to refinance debt and currently have a negative amortization loan as your first mortgage, you may find the neg am can hold you hostage. It can be very difficult to get a second mortgage
    ose IN;
    11 close OUT;
    12 }

    The only new line here is line 1, which uses the glob function to search through specified directories and files. Firstly, it searches for file1.htm in the current directory, and then it search for all files ending in .shtm in directory1/subdirectory1, and then all files ending in .htm in directory2. The asterisk (*) is a wildcard, which means any filename.

    Running the script

    c:>perl script4.pl



    HTTP = HTML link (for blogs, profiles,phorums):
    <a href="http://www.atriclecheck.com/article/178737/atriclecheck-Using-Perl-and-Regular-Expressions-to-Process-HTML-Files--Part-5.html">Using Perl and Regular Expressions to Process HTML Files - Part 5</a>

    BB link (for phorums):
    [url=http://www.atriclecheck.com/article/178737/atriclecheck-Using-Perl-and-Regular-Expressions-to-Process-HTML-Files--Part-5.html]Using Perl and Regular Expressions to Process HTML Files - Part 5[/url]

    Related Articles:

    The #1 Marketing Skills

    From Contractor To Insurance Adjuster

    AARP Long Term Care Insurance

    Bookmark it: del.icio.us digg.com reddit.com netvouz.com google.com yahoo.com technorati.com furl.net bloglines.com socialdust.com ma.gnolia.com newsvine.com slashdot.org simpy.com shadows.com blinklist.com