-1
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(min max);
use Set::IntervalTree;
use GenomeLookupUtil;

my $chromCol = 0;
my $startCol = 0;
my $endCol   = 0;
if($ARGV[2] eq "VSC") {
    $chromCol = 0;
    $startCol = 1;
    $endCol   = 2;
} else {
    $chromCol = 1;
    $startCol = 2;
    $endCol   = 3;
}

open (IN2,"$ARGV[0]") || die "counldn't open";
print STDERR "Read mask file \n";
my @masklines   = ();
my $i           = 0;
my %mask_hash   = ();
my $current_chr = '01';
my $current_snp_ranges = Set::IntervalTree->new();
while (<IN2>){
    my @masklines = split ("\t", $_);
    if ($masklines[1] ne $current_chr) {
            $mask_hash{$current_chr} = $current_snp_ranges;
            $current_snp_ranges = Set::IntervalTree->new();
    }

    $current_chr = $masklines[$chromCol];
    $current_snp_ranges->insert(
        [ $masklines[$startCol], $masklines[$endCol] ],
          $masklines[$startCol], 
          $masklines[$endCol]
    );
}
$mask_hash{$current_chr} = $current_snp_ranges;
close (IN2);

When I am running code with unnecessary arguments which is a file its showing error as

Use of uninitialized value in subroutine entry at mytest.pl line 47, <IN2> line 100.

I have initialized all the variable and top of that I am not using any subroutine also in my code. Line 47 is

$current_snp_ranges->insert(
      [ $masklines[$startCol], $masklines[$endCol] ],
        $masklines[$startCol], 
        $masklines[$endCol]
);
TLP
  • 66,756
  • 10
  • 92
  • 149
Syed
  • 19
  • 1
  • 6

1 Answers1

2

The uninitialized value in subroutine entry at mytest.pl line 47, line 100 suggests that the previous 99 lines of input data were OK. So what is line 100 of the input data? Could it be a blank line, possibly at the end of the file?

Earlier in the code there is my @masklines=split ("\t",$_); but with no checks that the array received enough data to support the attempts on line 47 to extract values from the array. Perhaps line 100 has fewer tab separated fields than expected.

I would suggest adding code after my @masklines=split ("\t",$_); similar to:

if ( $#masklines < $endCol ) {
    print "Too few fields in line: $_";
}
else {
    ... the rest of the code within the while statement
}

Update: The question was worded to suggest only one line gave the error. However, There is no check that the split extracts the required number of fields. It is good practice to write defensive code that checks for bad input data. To help find the problem, you could try adding series of print statements before line 47, such as:

print "startcol $startCol\n";
print "endcol $endCol\n";
print "masklines-startCol $masklines[$startCol]\n";
print "masklines-endCol $masklines[$endCol]\n";

Making them separate lines will give the uninitialized variable on simpler lines helping to understand the source of the problem.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
  • I just showed one line of example!! All lines are showing this erros!! Files are tap separated and seems fine to me. – Syed May 07 '13 at 14:32
  • Yes, Thanks but I guess that its not problem here this time !! – Syed May 07 '13 at 14:53
  • 7
    @Syed but you do not know what the answer is! Your first comment says "and seems fine to me" your second comment says "I guess that its not problem". Use the computer to check the data and tell you what it is doing and what it has found. Guessing wastes your time and the time of everyone who tries to help you. – AdrianHHH May 07 '13 at 14:58