Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > can't parse numbers as numerical values from a file

Reply
Thread Tools

can't parse numbers as numerical values from a file

 
 
powdrsnow powdrsnow is offline
Junior Member
Join Date: Apr 2008
Posts: 1
 
      04-21-2008
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 by powdrsnow; 04-21-2008 at 05:59 AM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stripping non-numbers from a file parse without nested lists? daku9999@gmail.com Python 5 04-01-2009 08:20 PM
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
Finding 1000 largest numbers from a file having some billion numbers Subra C Programming 25 03-08-2007 01:31 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Proper Way to Pass Numerical Values to a Function Martin McCormick C Programming 2 10-17-2003 01:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57