The reason you are getting the duplicates is because you print the $newline to the OUTFILE once you make the modification and then you print $_ to the OUTFILE regardless of whether there was a match or not. There are 2 courses of action I'd consider. One:
In place of the grep for the href and .html, use a regex and s/// combo such as:
if (m/a\shref/i) { s/.html/.asp/i }
Your other option if you prefer to keep the grep that you are using now is to use a 'continue' at the end of the if block. IE:
if ( grep(/a href.*\.html/,$line) ){
(my $newline = $line ) =~ s/\.html/\.asp/g;
print OUTFILE $newline . "\n";
continue;
}
WARNING: Solution 2 is untested but I don't see anything standing immediately in the way of it working.
UPDATE: In solution 2 change the 'continue' function to the 'next' function - don't know what I was thinking at the time. I apologize.
-Adam Stanley
Nethosters, Inc.
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.