kibs has asked for the wisdom of the Perl Monks concerning the following question:

I am running an RRD perl script but giving me segmentation fault with the error below. Use of uninitialized value $tot_mem720 in addition (+) at ./rrd line 38. Line 38 is :
$tot_mem_sum = $tot_mem_sum + $tot_mem[$i];

Replies are listed 'Best First'.
Re: Segmentation fault
by Ratazong (Monsignor) on Feb 08, 2012 at 11:59 UTC
    Please check the value of $i. Most probably it has a wrong value, so $tot-Mem[$i] is somewhere "out of bounds".
      the $i is in the code below:
      # save the values from the 2-dimensional into a 1-dimensional array for $i ( 0 .. $#vals ) { $tot_mem[$count] = $vals[$i][1]; $count++; } my $tot_mem_sum = 0; # calculate the total of all values for $i ( 0 .. ($count-1) ) { $tot_mem_sum = $tot_mem_sum + $tot_mem[$i]; }
Re: Segmentation fault
by Utilitarian (Vicar) on Feb 08, 2012 at 13:44 UTC
    Your copy of the @vals array may be copying an undefined value so perhaps you should check the values before setting them in the new array.
    for my $i (0..$#vals){ $tot_mem[$i]=$vals[$i][1]?$vals[$i][1]:0; }
    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."