Hi monks

My problem should be easy to solve, but I am still struggling very much to find a proper solution to it.

I have two txt fils containing two lists of words - one word per line - with a score (the score simply being the row number). I'd like to merge the two files, ordering the words according with a new ranking computed by multiplying the scores of the same word in the two files.

The files have the following format:

FILE 1 hello 1 today 2 well 3 yes 4
FILE 2 hello 1 yes 2 today 3 well 4

The output should look like:

hello 1 today 6 yes 8 well 12

I am by now reading FILE 1 line by line, reading through FILE 2 to match the same word, multiplying the scores and write the result out into a new file. As the list are huge, it seems to me a very BAD way to do this task. Any idea how I could do it better? Sorry if my question is too simple...

Thanks, Cla


In reply to Merging two list with simple operation by fanticla

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.