Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Array Element Substitution

by Athanasius (Chancellor)
on Aug 23, 2012 at 16:13 UTC ( #989346=note: print w/replies, xml ) Need Help??

in reply to Array Element Substitution

Hello Mac1, and welcome to the Monastery!

For the task outlined, I would build a hash with names-to-be-replaced as the keys, and their replacements as the values.

However, I think you should first clarify the format of your input files. Do you intend that each occurrence of “Jupiter” be replaced with “Host1”, each occurrence of “Mars” be replaced with “Host2”, etc.? If so, this scheme looks very brittle. For example, a single name out of place in either file would throw out the replacements for all words following.

Also, did you intend Jupiter Mars Earth to follow one another on the same line (as shown), or to appear on separate lines? This makes a difference to the way the input files are read in and parsed.

Please specify the precise formats of the two input files, and their relationship to each other. This will make it easier for the monks to help you (and may help to clarify your own thinking about the problem).

Athanasius <°(((><contra mundum

Replies are listed 'Best First'.
Re^2: Array Element Substitution
by Mac1 (Initiate) on Aug 23, 2012 at 17:56 UTC

    Thanks for your response. A hash approach would be great, but not sure how to make the substituions. The actual 'OriginalNames.txt' would contain the names one after another such as:





    The 'AlternateNames.txt' file would contain the exact replacement in the same order aligning to the 'OriginalNames.txt such as:





    Thus, Earth would be replaced by Host1, Jupiter replaced by Host2, Venus Replaced by Host3 and Mars replaced by Host4

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989346]
[markong]: is there any mean to get notified if there are new replies in a thread?

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2018-03-19 09:45 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (238 votes). Check out past polls.