I am trying to take a file, and copy it to an output file and then find all the <k> and make them into <p> instead. I want to use regex.
while (<INPUTFILE>)
{
if($_ != "<p>")
{
print OUTPUTFILE "$_\n";
}
else
{
print OUTPUTFILE "<k>";
}
}
I was trying something like this but I guess the $_ variable takes each line at a time. So It would prob be better to use write the entire file then try the regex search and replace? for that I have tried:
$_ =~ s/<k>/<p>/g;
<p>or<k>on lines or is there more content?<p>in the input and printing<k>when it finds it. Your description has the inverse logic. Which is right?use strict; use warnings;. It would have found a major error.choporchomp,$_already ends with a newline. So you shouldn't add one when youprint OUTPUTFILE "$_";.chomping the input, $_ contains a newline, your if($_ != "<p>") will always be !=, since your test literal has no newline - unless your input file ends with a line that isn't newline-terminated