OK.. not much to do with your question since others have answered it, but as I suggested in your other post, you don't need to use 4 different variables to refrence the line you're working with. Here is your code, removing all the variables that you don't need.. oh and adding "use strict" and -w if you didn't have it already...
#!/usr/bin/perl -w
use strict;
my $filename = './index.html';
open (FILE, $filename);
open OUTFILE, '>out.asp';
while(<FILE>){
# walk each file
chomp;
#grabbing and printing everything between the body tags
if (/<body.*?>/i ... /<\/body.*?>/i){
# this is a body line
# extract the body
#changing .html to .asp in the links
if (/href.*\.html/i) {
s/\.html/\.asp/gi;
}
s/(.*?)\<body\>(.*?)\<\/body\>/$2/i;
# Write the body to the output file
print OUTFILE "$_\n";
}
}
close(FILE);
close OUTFILE;
I think everyone would agree that only using one variable to manipulate one line of text makes things much clearer.
Rich
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.