I'm getting a segmentation fault at varibale times in my program. I've had this problem before, on other basic formatting scripts on similar files. Basically this program is just reading in a giant text file, ~300 lines with 3000-5000 number data on each line separated by white space. This little script is just supposed to make sure that none of the lines have identical, non-zero data after the first six "id" fields. It usually crashes near the end of the first loop (comparing person 0 to persons 1-299), but often makes it to the early part of the second loop and sometimes further. I was getting a warning about using undefined variables when splitting the @file array lines since the last line was blank. I thought maybe I was overflowing some sort of warning buffer or something since I fixed that and got one file to run all the way through, but other files still aren't working!
-------------------------
use diagnostics;
open (IN, "$ARGV[0]");
@file = <IN>;
$waste = pop(@file); # was getting warning about undef last line
$waste = 0;
$len = @file;
$numIdent = 0;
for ($i = 0; $i < $len - 1; $i++) {
print "Comparing person $i of $len\n";
for ($j = $i + 1; $j < $len; $j++) {
$t1 = $file[$i];
$t2 = $file[$j];
@line1 = split(/\s+/, $t1);
@line2 = split(/\s+/, $t2);
$len1 = @line1;
$len2 = @line2;
if ($len1 != $len2) {
$message = "*** ABORT ***\nPersons " . $line1[0] . " " .
$line1[1] . " and " . $line2[0] . " " . $line2[1] .
" have different " . "number of markers";
die "$message\n";
}
$ident = identical($t1, $t2);
if ($ident == 1) {
$message = "Persons " . $line1[0] . " " . $line1[1] . " and " .
$line2[0] . " " . $line2[1] . " are identical and non-zero";
print "$message\n";
$numIdent++;
}
# @line1 = ();
# @line2 = ();
}
}
print "\n$numIdent total pairs of non-zero persons were identical\n";
close (IN);
-------------------------
GREATLY appreciate any advice! Thanks!
Matt
-------------------------
use diagnostics;
open (IN, "$ARGV[0]");
@file = <IN>;
$waste = pop(@file); # was getting warning about undef last line
$waste = 0;
$len = @file;
$numIdent = 0;
for ($i = 0; $i < $len - 1; $i++) {
print "Comparing person $i of $len\n";
for ($j = $i + 1; $j < $len; $j++) {
$t1 = $file[$i];
$t2 = $file[$j];
@line1 = split(/\s+/, $t1);
@line2 = split(/\s+/, $t2);
$len1 = @line1;
$len2 = @line2;
if ($len1 != $len2) {
$message = "*** ABORT ***\nPersons " . $line1[0] . " " .
$line1[1] . " and " . $line2[0] . " " . $line2[1] .
" have different " . "number of markers";
die "$message\n";
}
$ident = identical($t1, $t2);
if ($ident == 1) {
$message = "Persons " . $line1[0] . " " . $line1[1] . " and " .
$line2[0] . " " . $line2[1] . " are identical and non-zero";
print "$message\n";
$numIdent++;
}
# @line1 = ();
# @line2 = ();
}
}
print "\n$numIdent total pairs of non-zero persons were identical\n";
close (IN);
-------------------------
GREATLY appreciate any advice! Thanks!
Matt