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