in reply to Rename html page titles
As for opening the file for appending, that probably isn't what you want to do. Open the source file and a temp file. Read from the source file, then write out each line(modified/unmodified) to the temp file. unlink() the source file, and rename the temp file to the original filename.if(/<title>(.+)<\/title>/i){ print $1; $notitle = 0; last; }
foreach my $file(@files){ open(TMP, '>/tmp/temp.html') || die "tmp file open failed:$!\n"; open(FILE, "$file") || die "source file open failed: $!\n"; while(<FILE>){ s/<title>(.+)<\/title>/<title>$new_title<\/title>/i; print TMP $_; } close(TMP); close(FILE); unlink($file); rename('/tmp/temp.html', $file); }
|
|---|