Mac1 has asked for the wisdom of the Perl Monks concerning the following question:
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.. }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Array Element Substitution
by Athanasius (Archbishop) on Aug 23, 2012 at 16:13 UTC | |
by Mac1 (Initiate) on Aug 23, 2012 at 17:56 UTC | |
Re: Array Element Substitution
by Kenosis (Priest) on Aug 23, 2012 at 20:51 UTC | |
by Mac1 (Initiate) on Sep 04, 2012 at 21:47 UTC | |
by Kenosis (Priest) on Sep 04, 2012 at 21:59 UTC | |
Re: Array Element Substitution
by aaron_baugher (Curate) on Aug 23, 2012 at 20:00 UTC | |
Re: Array Element Substitution
by cheekuperl (Monk) on Aug 24, 2012 at 03:03 UTC | |
Re: Array Element Substitution
by Marshall (Canon) on Aug 24, 2012 at 10:17 UTC |