in reply to Find common substrings
"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
|
|---|