Quote:
Actually, come to think of it, I do need to "replace that line" as well. Any idea how I might do that?Code:
my $var = 'Test'; my $new = 'Hello my friend!';
my $fa = 'test.txt';
my $fb = 'test.tmp.txt';
open FHA, "<$fa" or die $!;
open FHB, ">$fb" or die $!;
while (<FHA>) {
if (/^\Q$var\E$/i) {
print FHB "$new\n";
next;
}
print FHB;
}
close FHB;
close FHA;
unlink($fa) or die $!;
rename($fb, $fa) or die $!;
Quote:
Also, another problem (similar, but for a different script I'm making)... I want to read an HTML file, and set everything AFTER the tag <!--EDITBEGIN--> and BEFORE the tag <!--EDITEND--> as an variable.Code:
my $file = '/path/to/file.html'; open FH, $file or die $!;
my $string = do { local $/; <FH> };
close FH;
my ($wanted) = $string =~ m|<!--EDITBEGIN-->(.+?)<!--EDITEND-->|si;