Segmentation fault in the below program

133 Views Asked by At

The below code is being called from a simple script like this. $test.line-validation();

    method line-validation is rw {
    my $file-data = slurp($!FileName, enc => "iso-8859-1");
    my @lines = $file-data.lines;
    my $start = now;
    for @lines -> $line {
        state $i = 1;
        my @splitLine = split('|', $line);
        if ($line.starts-with("H|") || $line.starts-with("T|")) {
            next;
        }
        my $lnObject = LineValidation.new( line => $line, FileType => $.FileType );
        $lnObject.ColumnIds = %.ColumnIds;
        my @promises;
        my @validationIds;
        for %.ValidationRules.keys -> $validationId {
            if (%.ValidationRules{$validationId}<ValidationType> eq 'COLUMN') {
                push @promises,  start {$lnObject.ColumnValidationFunction(%.ValidationRules{$validationId}<ValidationFunction>, %.ValidationRules{$validationId}<Arguments>, $.ValidationRules{$validationId}<Description>); 1};
                push @validationIds, $validationId;
            }
        }
        my @promise-output = await @promises;
        for @validationIds -> $valId {
            state $j = 0;
            my $result = @promise-output[$j];
            if ($result.Bool == True) {
                if (%.ResultSet{$valId}<count> :!exists) {
                    %.ResultSet{$valId}<count> = 1;
                } else {
                    %.ResultSet{$valId}<count> = %.ResultSet{$valId}<count> + 1;
                }
                my @prCol = (%.ValidationRules{$valId}<Arguments><column>, @.printColumns);
                if (%.ResultSet{$valId}<count> <= 10) {
                    %.ResultSet{$valId}.push: (sample => join('|', @splitLine[@prCol[*;*]].map: { if ($_.Bool == False ) { $_ = ''} else {$_ = $_;} }));
                }
                %.ResultSet{$valId}<ColumnList> = @prCol[*;*];
            }
            $j++;
        }
        $i++;
    }
    say "Line validation completed in {now - $start } time for $.lineCount lines";
}

The code was working fine earlier but when run using larger files, it just arbitrarily throws the error Segmentation fault and exists. I cannot determine where it is failing either.

0

There are 0 best solutions below