Perl script error

Hi all

I keep getting a segmentation fault error while running the script below.

#!/usr/bin/perl -w
use CGI ':standard';
use GD::Graph::pie;
use strict;
use warnings;

sub trim($)
{
        my $string = shift;
        $string =~ s/^\s+//;
        $string =~ s/\s+$//;
        return $string;
}


my ($ts, $filename, @array, $line, $arri , $k , $total);

open(DOMAINS, "< /mailstats/temp/domains.tmp") || die "Couldn't open. Please check permissions. \n";

$k = 0;
$total = 0;

while ($line = <DOMAINS>) {
$line = trim($line);
#chomp $line; # removes the carriage return
#@array = split(/ / , $line); # breaks the line up into fields

($array[1][$k], $array[0][$k], undef) = split(" ", $line);

$total = $total + $array[1][$k];

#print $array[0][$k] , "\
print $total , "\n";

my $mygraph = GD::Graph::pie->new(300, 300);
$mygraph->set(
    title       => 'Grading Policy for COP5555 course',
    '3d'          => 0,
) or warn $mygraph->error;

$mygraph->set_value_font(GD::gdMediumBoldFont);
my $myimage = $mygraph->plot(\@array) or die $mygraph->error;

#print "Content-type: image/png\n\n";
open(PICTURE, ">filesplittest.png") or die("Cannot open file for writing");
binmode PICTURE;
print PICTURE $myimage->png;
close PICTURE;
t" , $array[1][$k] , "\n";

## NOW PROCESS EACH LINE HERE


$k = $k + 1;
}
close DOMAINS;

now when I comment out the whole graph drawing block, I don't get a segmentation fault.

The data I am using is a lot of data. Can that be the issue?

If the data is the problem, is there any way I can optimize it?

I have tried inputting less data intro the text file, and it worked.

Regards

What is this line doing?

t" , $array[1][$k] , "\n";

Sorry about that, I didnt even notice that the forum (or my copy-paste) chopped of the leading part of that line

That line is part of a line higher up

The code should look like below

#print $array[0][$k] , "\t" , $array[1][$k] , "\n";

That was part of the output to see if the matrix gets created correctly.

Regards

From what I know a segmentation fault is an error caused by the operating system or a program that tries to read/write to memory that it's not supposed to. It is possible that the perl program is using too much memory and causing the error. My guess would be that the array you are building is growing too big.

That was my first guess as well. So I started playing around.

After I commented out the graph drawing, the segmentation fault went away.

That was probably because after I commented it out, it didn't need to read the array again

I am not sure about that though

Regards