If your file size is small then you can use this simple approach.
open(INPUT1, "file1"); my ($havar1, $havar2i, $Genename); while (<INPUT1>) { my $startvar; if ($_ =~ /([^-]+)-(.*)/) { $Genename = $1; my @sparr = split('_', $2); open(INPUT2, "file2"); while(<INPUT2>) { if ($_ =~ /([^-]+)-(.*)/) { my @sparr1 = split('_', $2); if (($Genename eq $1) && ($sparr[0] < +$sparr1[0]) && ($sparr[1] > $sparr1[0])) { print "$Genename\t$sparr[0]\t$ +sparr[1]\t$1\t$sparr1[0]\t$sparr1[1]\n"; } } } close(INPUT2); } } close(INPUT1);
----Otherwise hash will be the better option -------
my ($havar1, $havar2); open(INPUT1, "file1"); open(INPUT2, "file2"); while (<INPUT1>) { map{push(@{$havar1->{$1}}, $_)} split('_',$2) if ($_ =~ /([^-] ++)-(.*)/); } while (<INPUT2>) { map{push(@{$havar2->{$1}}, $_)} split('_',$2) if ($_ =~ /([^-] ++)-(.*)/); } close(INPUT1); close(INPUT2); foreach my $key (keys %{$havar1}) { if (exists $havar2->{$key}) { my $cnt = @{$havar1->{$key}}; my $cnt1 = @{$havar2->{$key}}; for(my $i=0; $i < $cnt; $i=$i+2) { for (my $j=0; $j < $cnt1; $j=$j+2) { if (($havar1->{$key}->[$i] < $havar2-> +{$key}->[$j]) && ($havar1->{$key}->[$i+1] > $havar2->{$key}->[$j])) { print "$key\t$havar1->{$key}-> +[$i]\t$havar1->{$key}->[$i+1]\t$key\t$havar2->{$key}->[$j]\t$havar2-> +{$key}->[$j+1]\n"; } } } } }

In reply to Re: Qurey through array of array by brsaravan
in thread Qurey through array of array by sesemin

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.