Hi. I have a file which looks like this:
a_12_3_5- k_3_4_6-a_12_3_5- q_1_5_7_9- q_1_5_7_9- a_9_4_5-c_3_4_6- c_3_4_6-r_4_5_7- b_1_1_3- v_1_5_7- d_12_4_5-e_4_5_6- g_5_6_7-d_6_8_6- b_1_1_7-f_3_8_7_8-d_4_1_4- d_4_1_5-b_1_1_7-f_3_8_3 b_1_1_7-f_3_8_7_8-d_4_1_4- e_3_3_1-f_3_8_7-f_21_3_1-b_1_1_7-a_1_1_1-
This is a space-separated file. The strings appearing before and after the space is made up of smaller substrings, namely b_1_1_3- , k_3_4_6-, b_12_4_5- etc. I have to check how many of the smaller substrings on the Left side of the space are contained in the string appearing on right side of the space. For eg: The 1st line has the substring a_12_3_5- which is present in the string on the right hand side. The 2nd line shows exact match with the right side. 3rd line however shows that there is only one substring on the left side (c_3_4_6-) which is contained in the string on the right side. 4th and 5th lines represent cases wherein no substring on left side is contained in the string on right side. Next line shows that there is only one substring (b_1_1_7-) that is contained in the string on right side. The last line shows that there are 2 substrings b_1_1_7- and f_3_8_7- which are contained in the string on the right hand side. Thus effectively, I want to see how many of the substrings on the left hand side are contained in the string on the right hand side. I am trying to get the output in the following manner, such that each line in my file is appended with three numbers i.e number of substrings in left side, number of substrings in right side, no.of substrings on left side that are contained in the right side.
a_12_3_5- k_3_4_6-a_12_3_5- 1 2 1 q_1_5_7_9- q_1_5_7_9- 1 1 1 a_9_4_5-c_3_4_6- c_3_4_6-r_4_5_7- 2 2 1 b_1_1_3- v_1_5_7- 1 1 0 d_12_4_5-e_4_5_6- g_5_6_7-d_6_8_6- 2 2 0 b_1_1_7-f_3_8_7_8-d_4_1_4- d_4_1_5-b_1_1_7-f_3_8_3- 3 3 1 b_1_1_7-f_3_8_7_8-d_4_1_4- e_3_3_1-f_3_8_7-f_21_3_1-b_1_1_7-a_1_1_1- 3 + 5 2
I have so far been able to get the above output , but cant seem to get upto the last portion of the line. I have tried using os and also index functions. but cant seem to get ahead. PLease help!

In reply to matching substrings on each line by anasuya

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.