can't parse numbers as numerical values from a file

Joined
Apr 21, 2008
Messages
1
Reaction score
0
Hello,

I have a basic question on how to read from a file that has numbers on it and i want to do some basic calculations.

i will provide a simple example of a file that i am opening in Perl.

file

bobby 10 9 7
chris 9 9 10
david 7 8 7

So what i am trying to do is add 3 numbers and find an average for each name but when I do a calculation and print, it shows like this:

output:
bobby (10 + 9 + 7)/3
chris (9 + 9 + 10)/3
david (7 + 8 + 7)/3

Obviously, what i would like to get is a number for each name.

this is my source code:

foreach $names (@raw_data)
{
chop($names);
($student_name,$points1,$points2, $points3)=split(' ',$names);
print "$student_name ($points + $points2 + $points3/3)\n";
}

i would appreciate if you can help me.
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top