
rovf
Veteran
Aug 17, 2011, 3:27 AM
Post #2 of 8
(3294 views)
|
Re: [Ted] Alter contents between tags
[In reply to]
|
Can't Post
|
|
I don't understand why you add '<BR>' when outputting the changed file, if all what you want is to change the one line containing the date, however... There are two things to consider: (1) You need to modify an existing file. The usual approach is that you read the original file, write to a new (modified) file, and (after closing) move the new file over the old one. Your case is however special, in that you alternatively also could edit the file in-place (since only one character is replaced by a different character). If you want to try this approach, open the file in binmode, read the whole file at once in a variable, do the substitution, go back to the beginning of the file (see the function 'seek') and write back the file. (2) You need to find the <date> line. The usual recommendation here is to use a HTML parser. However, if you know for sure that your files have a pretty regular format, which makes it easy to identify the <data> entry, you could use either - the index function to search for the entry (and use substr to replace the date separators), or - Use a regular expression together with the s/// operator. So just use whichever approach looks more familiar to you.
|