in reply to Qurey through array of array

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"; } } } } }

Replies are listed 'Best First'.
Re^2: Qurey through array of array
by sesemin (Beadle) on Jan 22, 2009 at 22:36 UTC
    Hi brsaravan,

    Did you try the code? It seems to me that it does not print anything. I tired both versions.

    Thanks Pedro

      Sesemin,

      I posted after it worked well in my system. Did you save your input in two different files (file1 and file2)?.

      Thanks
      brsaravan
Re^2: Qurey through array of array
by sesemin (Beadle) on Jan 23, 2009 at 06:49 UTC
    Hi brsaravan,

    Thank you very much. It works perfect. Sorry I had to fix something to be able to run it.

    A+++

    Pedro