Ok. I found your problem. Here, let me show ya.
##changing .html to .asp in the links        
        if ( grep(/a href.*\.html/,$line) ){
            (my $newline = $line ) =~ s/\.html/\.asp/g;            
        print OUTFILE $newline . "\n";
        }
Ok, that is fine. Your problem, however, is after this. Bear in mind that you are going through these files line by line. Therefore, the line that you are replacing the old line with must be placed in the new file instead of the old line, right? So, keeping your above code in mind, you have just found a line that matches what you are looking for and have changed it. You have also printed that line to the newfile. But what do you do next?
         $body_temp = $_;
         $body_temp =~ s/(.*?)\<body\>(.*?)\<\/body\>/$2/i;
         chomp($body_temp);

         $body = "$body_temp" ;
        
         # Write the body to the output file
         print OUTFILE $body . "\n";
        }
...amongst all the other stuff you done with the html body tag, you printed the line again, because you never left that line before processing it through the stuff after your if statement. You won't leave that line until the end of the loop iteration. Therefore, you should use an 'else' block in your 'if-then' statement.

e.g.

while ( <FILE> ) {
    if ( this line matches this regex ) {
        change the line;
        # If you need to do something to this line
        # do it here
        print it to the new file;
    } else {
        # this line obviously does not match my regex
        # so ignore it (or do some more stuff to it) 
        # and move on to the next line.
        Stuff to do to the line I didn't have to change...
        print the old line to the new file
    }
}
See what Im doing? :)

----------
- Jim


In reply to Re: Re: Re: Re: Re: Changing .html to .asp by snafu
in thread Changing .html to .asp by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.