Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Segmentation fault

by kibs (Initiate)
on Feb 08, 2012 at 11:54 UTC ( [id://952461]=perlquestion: print w/replies, xml ) Need Help??

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."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://952461]
Approved by Ratazong
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-23 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found