Hi,

Hi all, I am trying to implement a co-relation problem in perl. I have two arrays i.e. array1 and array2 which contain following values.

array1 array2 read book eat apple book novel apple banana play football tennis football novel mazagine
I want my output as:
Hi all, I am trying to implement a co-relation problem in perl. I have two ar +rays i.e. array1 and array2 which contain following values. <c> array1 array2 array3 array4 read book novel magazine eat apple banana play football tennis
i tried implementing it with simple for loops as:
#Step no.1 for($i=0;$i<$arraylength;$i++) { for($j=0;$j<$arraylength;$j++) { if($array2[$i]eq $array1[$j]) { $array3[$i] = $array2[$j]; } } } #Step no.2 for($i=0;$i<$arraylength;$i++) { for($j=$i+1;$j<$arraylength;$j++) { if($array2[$i]eq $array2[$j]) { $array3[$i] = $array1[$j]; } } } #Step no.3 for($i=0;$i<$arraylength;$i++) { for($j=0;$j<$arraylength;$j++) { if($array2[$i]eq $array1[$j]) { $array4[$i] = $array3[$j]; } } }
But its not showing the proper output. It shows some random output in array3 and array4.

I guess there is some problem in the step no.2. It shows error stating that 'array3' cannot be null.

How can we initialize array to null values??

my @array3=(); #is it correct??

When the second step executes.. it compares the two same value but the value stored in array3 from array1 is not a string infact something like..HASH(0x82e3594), HASH(0x82e35a0). What could be the problem. Please guide me. Thanking you,

In reply to how to initialize array to null values 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.