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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.