E
elroyerni
Hi -
I have a array of a list of numbers:
7.9216
8.7583
12.675
0.8028
6.9230
1.1403
6.0083
0.1454
I wrote a sub-routine to add the list, but i'm getting these syntax
errors, and was wondering if someone could tell me what i'm doing
wrong. here's my code for the sub-routine:
sub sum_array {
my($sum) = 0; # initialize the sum to 0
foreach $i (@array_data) {
$sum = $sum + $i;
}
return($sum);
}
It's returning this error: isn't numeric in addition (+)
Also I'm trying to write a sub-routine that will go through each
element in the array and tell me how many elements in the array are
less than a given value. For example in the array above say i want to
return the amount of elements that are less than 5 seconds. From the
array above I'd return 3.Here's what I have so far:
sub less_five {
foreach $r(@array_data){
count=0;
while ($count<5)
{
$count++;
}
}
return($data);
}
Cant seem to get this to work.. Thanks for your help!
I have a array of a list of numbers:
7.9216
8.7583
12.675
0.8028
6.9230
1.1403
6.0083
0.1454
I wrote a sub-routine to add the list, but i'm getting these syntax
errors, and was wondering if someone could tell me what i'm doing
wrong. here's my code for the sub-routine:
sub sum_array {
my($sum) = 0; # initialize the sum to 0
foreach $i (@array_data) {
$sum = $sum + $i;
}
return($sum);
}
It's returning this error: isn't numeric in addition (+)
Also I'm trying to write a sub-routine that will go through each
element in the array and tell me how many elements in the array are
less than a given value. For example in the array above say i want to
return the amount of elements that are less than 5 seconds. From the
array above I'd return 3.Here's what I have so far:
sub less_five {
foreach $r(@array_data){
count=0;
while ($count<5)
{
$count++;
}
}
return($data);
}
Cant seem to get this to work.. Thanks for your help!