Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Array Element Substitution

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

    Earth

    Jupiter

    Venus

    Mars

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

    Host1

    Host2

    Host3

    Host4

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-12-20 13:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls