Code:
open (file, "$file_name") or &error("Unable to open the file.");
@file=<file>;
close (file);
$line=0;
foreach $file (@file) {$line++;
if ($file=~ /<!--marker-->/i) {$line--;
@add="<!--marker-->\n string to be added\n";
splice (@file, $line, 1, @add);
open (sfile, ">$file_name") or &error("Unable to write to the file.");
print sfile @file;
close (sfile);
}
}
Think I got it right. If your unique marker was at the top of your file
any additions to the file would be added to the top of the file, well not
quite the top as the marker is the top line. <!--marker--> is transparent
in html, not sure how you could add to the tippy top of a text file. The
marker could be anyplace and it could be at the beginning or end of @add,
putting the string below or above the marker.
...Marker could also be any uniqe string. If the top line is unique and you
only want to add to the top once you could use it as the marker (match string)
and put it at the end of @add.
[This message has been edited by Dave (edited May 06, 1999).]