Hello thanos1983. One precision on this:

When you compare if ( $array1[$j] =~ $array2[$k] ) you are not comparing the strings read perlop/DESCRIPTION. You should use eq for strings and == for integers.
It's mostly true, if you consider "compare" to only mean check that two strings are equal. As you said, the =~ will bind the left operand to the right, which will be interpreted as a regex (so this is the same as $array1[$j] =~ m/$array2[$k]/ if $array2[$k] is a string). When the string in the regex does not have meta characters (as is the case for all strings in the first array), this will actually check that the first string contains the second. Checking for inclusion may be considered one flavor of "comparing" two strings (and the test would be true when the strings are equal).

Do note that the strings in the second array are longer than the ones in the first, so eq won't work. $array2[$k] =~ /$array1[$j]/ might work as it checks that the second string contains the first (notice that I have inverted the two), except if the string in @array1 contains metacharacters (in which case it can either give the wrong result, or just die). That's why my advice is to use index instead.


In reply to Re^2: Matching arrays with different number of elements and element size by Eily
in thread Matching arrays with different number of elements and element size by Ksonar

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.