Hi all, I am trying to compare the strings of 2 arrays. I have 2 arrays named array1 and array2 and their contents are as follows:
array1 array2 the_for_below and_press this_job online_Please #note that we have space at b +egining of online_Please. complete the_form_below #note that we have space at t +he end of the_form_below. and_press submit_will_only #note that we have space at b +egining of and_press.
I tried to compare the 2 arrays. I should be able to get that
array1[0]=array2[2] i.e. the_for_below = complete array1[3]=array2[0] i.e. the_for_below = and_press
I tried with my code:
for ($k=0;$k<$i;$k++) #where $i is the length of array. { for($l=0;$l<$i;$l++){ if(chomp($array1[$k]) eq chomp($array2[l])) { print"\n$array1[$k],$array2[$l]"; } }
But it does not show the desired output instead displays all the elements of array2 with each of the element of array1. Like...
the_for_below and_press the_for_below online_Please the_for_below the_form_below the_for_below submit_will_only this_job and_press this_job online_Please this_job the_form_below this_job submit_will_only ... and so on..
Please guide me through this... Thanking you

In reply to compare 2 arrays of strings by sharan

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.