Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hey all! I'm starting to learn Perl to help me on my job and I stumbled across a problem that I can't seem to solve.

First, I have a list of names that have an ID associated, like:

bananas 456

oranges 23

peaches 897236

kiwis 3726

(...)

Then, i have a list of those names, that need to be replaced with the associated ID.

bananas,oranges

peaches,peaches,peaches

kiwis

oranges

kiwis,oranges,bananas,bananas

(...)

My first tought was to put the 'name-id' data in a hash, since every name only has one ID, and they are all unique values.

I would then push the 'names to be replaced' file into an array, and iterate through all the hash keys, while looping the array, matching each key and replacing it with its value.

Sounded like a good ideia, but can't seem to iterate and replace both things effectively.

Maybe I'm overcomplicating a simple problem, but can you guys point me in the right direction?

Thanks in advance!

-R


In reply to iterating hash keys? by R56

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (12)
    As of 2014-07-23 06:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (133 votes), past polls