in reply to search and replace text in multiple files in a directory
tr/// is the transliteration operator, good for converting individual characters into some other character (or counting, or deleting individual characters). It's not helpful in this case.
You actually want to look at the s/// substitution operator, for what you're trying to accomplish. Here is a description of what to do:
open $filename for reading. Open a temporary file for output. Scan through $filename line by line using the while( <INFILE> ) {..... construct. Inside the loop, on each line, use the substitution operator to identify matches, and substitute for your new text. Then print each line back out to your temp file. After the loop terminates, close both file handles, and rename the temp file to replace the original file.
If you're operating in a multi-user or web server context, file locking will also be advisable.
Dave
|
|---|