Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Array Element Substitution

by Athanasius (Canon)
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

Comment on Re: Array Element Substitution
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]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2015-10-09 02:46 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (232 votes), past polls