G
Guest
I have a situation where I need to "Replace" a line of text in an HTML file.
The code I'm using does not "replace"... but instead, it adds another
line... effectively duplicating the number of lines each time the script
runs.
Below is a sample of my code:
###########################
sub main_page
{
open(MAIN,"$basedir/$mesgfile") || die $!;
@main = <MAIN>;
close(MAIN);
open(MAIN,">$basedir/$mesgfile") || die $!;
if ($followup == 0) {
foreach $main_line (@main) {
##---Title
if ($main_line =~ m/<!--Title-->/) {
print MAIN "<!--Title--> <title>$title</title>\n";
}
##---Page Formatting
if ($main_line =~ m/<!--Pformat-->/) {
print MAIN "<!--Pformat--> <body bgcolor=$BKcolor
text=\"#000000\" alink=\"#FF0000\" vlink=\"#FF00FF\" link=\"#0000FF\">\n";
}
##---Page Heading
if ($main_line =~ /<!--PHeading-->/) {
print MAIN "<!--PHeading--> <FONT FACE=$HeadingFont
SIZE=$HeadingSize COLOR=$HeadingColor> $HeadingText </FONT>\n";
}
#######################################
Any help would be greatly appreciated.
The code I'm using does not "replace"... but instead, it adds another
line... effectively duplicating the number of lines each time the script
runs.
Below is a sample of my code:
###########################
sub main_page
{
open(MAIN,"$basedir/$mesgfile") || die $!;
@main = <MAIN>;
close(MAIN);
open(MAIN,">$basedir/$mesgfile") || die $!;
if ($followup == 0) {
foreach $main_line (@main) {
##---Title
if ($main_line =~ m/<!--Title-->/) {
print MAIN "<!--Title--> <title>$title</title>\n";
}
##---Page Formatting
if ($main_line =~ m/<!--Pformat-->/) {
print MAIN "<!--Pformat--> <body bgcolor=$BKcolor
text=\"#000000\" alink=\"#FF0000\" vlink=\"#FF00FF\" link=\"#0000FF\">\n";
}
##---Page Heading
if ($main_line =~ /<!--PHeading-->/) {
print MAIN "<!--PHeading--> <FONT FACE=$HeadingFont
SIZE=$HeadingSize COLOR=$HeadingColor> $HeadingText </FONT>\n";
}
#######################################
Any help would be greatly appreciated.