But you can do it with hashes! Just use two hashes, one for each file. Then you can use the keys from data file 1 to find out whether corresponding key exists in the hash from data file 2. Below is a quick example:

#! /usr/bin/perl use strict; use warnings; my @d1 = qw{ CLS_S3_Contig2721-139_168 CLS_S3_Contig2722-375_390 CLS_S3_Contig2725-323_362 CLS_S3_Contig2725-455_480 CLS_S3_Contig2728-117_144 CLS_S3_Contig2728-437_472 CLS_S3_Contig2729-119_130 CLS_S3_Contig2729-163_220 CLS_S3_Contig2730-181_202 CLS_S3_Contig2730-361_384 CLS_S3_Contig2731-824_843 CLS_S3_Contig2731-1150_1201 CLS_S3_Contig2735-571_636 CLS_S3_Contig2735-677_710 CLS_S3_Contig2735-775_810 }; my @d2 = qw{ CLS_S3_Contig2721-142_169 CLS_S3_Contig6525-509_514 CLS_S3_Contig6525-493_502 CLS_S3_Contig6525-503_508 CLS_S3_Contig2977-365_376 CLS_S3_Contig2977-77_82 CLS_S3_Contig2977-83_90 CLS_S3_Contig4978-271_274 CLS_S3_Contig4978-385_388 CLS_S3_Contig2730-365_389 }; my %d_one = (); my %d_two = (); for( @d1 ) { my ($key, $start, $end) = $_ =~ /(.*)-(\d+)_(\d+)/; $d_one{$key}{'start'} = $start; $d_one{$key}{'end'} = $end; } for( @d2 ) { my ($key, $start, $end) = $_ =~ /(.*)-(\d+)_(\d+)/; $d_two{$key}{'start'} = $start; $d_two{$key}{'end'} = $end; } print "Genename(file1) start end ** Genename(file2) start end\ +n\n"; foreach my $key_one ( keys %d_one ) { if( $d_two{$key_one} ) { if( $d_two{$key_one}{'start'} >= $d_one{$key_one}{'start'} && $d_two{$key_one}{'start'} <= $d_one{$key_one}{'end'} ) { print "$key_one $d_one{$key_one}{'start'} $d_one{$ +key_one}{'end'}" . "** " . "$key_one $d_two{$key_one}{'start'} $d_two{$ +key_one}{'end'}\n"; } } }
Note, the limits are inclusive in my code. It produces the following output:
cpt2jmo@phantom:~$ ./2_hashes.pl Genename(file1) start end ** Genename(file2) start end CLS_S3_Contig2721 139 168** CLS_S3_Contig2721 142 169 CLS_S3_Contig2730 361 384** CLS_S3_Contig2730 365 389

Update: I removed the readmore -tags, since the code is not that long.

--
seek $her, $from, $everywhere if exists $true{love};

In reply to Re: Query through array of array by puudeli
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.