You might want to tell us a little more about the problem you are trying to solve because your current solution is almost never the right way to do it.

It seems most likely that what you really need is a hash. Consider:

use strict; use warnings; use List::Compare; my $fileData = <<DATA; IL12::1::287,6,-17,-9,-21,-24,-15,-2,11,4,4,-15,-26,-16,-9,-18,-25,27, +17,6, IL12::1::329,-25,-18,-28,23,17,1,-3,-23, IL12::1::1108,-8,-21,17,-25,9,-6,-15,4, IL12::1::1536,-12,-28,23,-12,17,-25,14,19,20, IL12::1::1591,-17,-23,-7,-19,25,25,-25,-15,-26,23,29,-12,-25, IL12::1::803,24,-20,-24,12,8,-22, DATA my %items; my $referenceItem = 'IL12::1::287'; open my $inFile, '<', \$fileData; while (<$inFile>) { chomp; my ($item, @values) = split ','; $items{$item} = \@values; } for my $key (sort keys %items) { next if $key eq $referenceItem; my @common = List::Compare->new ($items{$referenceItem}, $items{$k +ey}) ->get_intersection (); print "Common for $key: @common\n" if @common; }

Prints:

Common for IL12::1::1108: -15 -21 -25 17 4 Common for IL12::1::1536: -25 17 Common for IL12::1::1591: -15 -17 -25 -26 Common for IL12::1::329: -18 -25 17 Common for IL12::1::803: -24

Perl is environmentally friendly - it saves trees

In reply to Re: how to make first element of an string as a the array name by GrandFather
in thread how to make first element of an string as a the array name by koleti

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.