I have two files (commented out in code below), and I would like to print out field 4 from file 2 when field 2 from file 1 falls numerically between fields 2 and 3 from file2, given field 1 from both files match each other.
#! perl -w
use strict;
use warnings;
#File1
#Chromosome Position ID A1 A2 Highalt_alt_counts Lowalt_alt_counts Highalt_missing Lowalt_missing
#1 10492 rs55998931 C T 6 7 3 3
#1 10583 rs58108140 G A 2 4 6 4
#1 10665 . C G 1 2 11 9
#File2
#chrom txStart txEnd name2
#1 66999638 67216822 SGIP1
#1 66999251 67216822 SGIP1
#1 33547778 33586132 AZIN2
#1 8378144 8404227 SLC45A1
my @loci;
open( my $loci_in, "<", "Highalt.Lowalt.allelecounts" ) or die $!;
while (<$loci_in>) {
my ( $chr, $bp ) = split;
next if m/CHR/;
push @loci, [ $chr, $bp ];
}
close $loci_in;
my $filename = shift @ARGV;
open( my $input, "<", $filename ) or die $!;
while (<$input>) {
next if m/bin/;
my ( $chr, $start, $end, $gene ) = split;
foreach my $locus (@loci) {
if ( $chr == $locus[0]
and $start <= $locus[1]
and $end >= $locus[1] )
{
print "$locus[0] $locus[1] $gene\n";
}
}
}
close($input);
I am getting the warning:
Global symbol "@locus" requires explicit package name at find_gene_2.pl line 29.
Can someone point out the error?