Hello Monks, I have been attempting to replace names within a given log file with a different set of names, but I want it to be configurable. Example, since I know the names in the log file,I would create an external file 'OriginalNames.txt' containing the known names that I want to replace. I would then create another file 'AlternateNames.txt' containing the replacement names.
The original log file would be opened and parsed searching for all of the instances of the names in the 'OriginalNames.txt' file and replace each name found with the names in the 'AlternateNames.txt' file.
However, I am running into a brick wall. I put together some of the code below, but sure how to loop through to make the substitutions. As always, your suggestions would help. Thanks again
open(ORIGINALNAMES,"./OriginalNames.txt"); # Eg. Jupiter Mars Earth et +c. @originalNames = <ORIGINALNAMES>; open(ALTERNATENAMES,"./AlternateNames.txt"); # Eg. Host1 Host2 Host3 e +tc. @alternateNames = <ALTERNATENAMES>; open(LOG,"./log.txt") or die; ## Log file containing names wanting to +be replaced eg. Jupiter Mars Earth etc. @log = <LOG>; chomp @log; ## Should I do a for for($i = 0; $i<=$#log; $i++) { ### Not sure how to proceed to loop through log file, find the origina +l names and then substitute with the Alternate Names.. }
In reply to Array Element Substitution by Mac1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |