"Perl newbie here, ..."

Start by reading "perlintro: Perl introduction for beginners".

"... and I am faced with the following problem: ..."

As already pointed out, PerlMonks is not a code writing service. See also: "How (Not) To Ask A Question: Do Your Own Work".

This was an interesting little problem, so I coded a solution that produced your "desired output". Here's the pseudocode for my solution:

ALGORITHM: find_common INPUT: list of files (file_list) DECLARE: hash of IDs (id_hash) CALL: get_data WITH references to file_list and id_hash CALL: get_common WITH reference to id_hash FUNCTION: get_data INPUT: file_list and id_hash LOOP: file_list EACH file OPEN: file LOOP: read line EACH line remove line terminator split line INTO id and string LOOP: split string EACH substring increment id_hash-id-substring value CLOSE: file RETURN: void FUNCTION: get_common INPUT: id_hash LOOP: id_hash EACH id LOOP: id_hash-id EACH substring SKIP: id_hash-id-substring value < 2 PRINT: id : id_hash-id-substring key RETURN: void

If you make an attempt at implementing that in Perl, I'll gladly review your effort and show you mine. There would be many ways you could code this; but do note that there is nothing complicated in the logic — if you read perlintro, you should have all of the tools necessary for this task.

— Ken


In reply to Re: Find common substrings by kcott
in thread Find common substrings by Anonymous Monk

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.