Hello Ksonar,

Welcome to the Monastery. Check this question (Difference between two arrays - is there a better way?), it contains all the answers to your problem.

Update: A few comments regarding the sample code that you provided.

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. This is a binding operators =~ read more here perlop/Binding Operators.

One final note:

In Perl you do not need to loop arrays in C style for ( $j = 0 ; $j < $array1Size ; $j++ ) you can loop them through foreach my $element (@array) {} read more here perlop/Foreach Loops. In case you want to iterate over two equal size arrays you can do it like this foreach my $index ( 0 .. $#array ){} but in your case your arrays are not same in size so you can not use this method just for reference, read more here How do I Loop over multiple arrays simultaneously ?.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Matching arrays with different number of elements and element size by thanos1983
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.