A good way to approach a problem like this, and you don't know how, is to think how you would do it in real life and then tell the computer to to that exact same thing.

So we need a simile here.

You have, in front of you, a partly filled in crosswords puzzle. This is array 1. Your friend, whom you're on the phone with, has the exact same crosswords puzzle, but still entirely blank. This is array 2. What you and your friend want, is to solve this crossword puzzle over the phone but you want to be "on the same page", so the two of you have decided that you will give him all the answers you've already found.

How would you do this? You would walk through your answers and using their numbers as a reference, you relay the words you've found. So what you would say would sound like this: "One horizontal is monkey. Two vertical is bisshop. Fourty-six horizontal is mountain."

In other words, as you iterate over array 1, you keep track of the "position" you're at, and then use that to do the corresponding position in array 2 &mdash in this case, tell your friend to fill in the value you have at that position.

Which is exactly what BrowserUk and blue_cowdawg are doing above, here and here.


In reply to Re: Get same position value in 2nd array by muba
in thread Get same position value in 2nd array by Phinix

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.