can't parse numbers as numerical values from a file

Discussion in 'Perl' started by powdrsnow, Apr 21, 2008.

  1. powdrsnow

    powdrsnow

    Joined:
    Apr 21, 2008
    Messages:
    1
    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: Apr 21, 2008
    powdrsnow, Apr 21, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin McCormick

    Proper Way to Pass Numerical Values to a Function

    Martin McCormick, Oct 16, 2003, in forum: C Programming
    Replies:
    2
    Views:
    382
    Martin McCormick
    Oct 17, 2003
  2. Wei-Chao Hsu

    How to read numerical data from a file

    Wei-Chao Hsu, Jul 11, 2004, in forum: C Programming
    Replies:
    3
    Views:
    284
    Al Bowers
    Jul 11, 2004
  3. Subra
    Replies:
    25
    Views:
    1,222
    user923005
    Mar 8, 2007
  4. daku9999@gmail.com
    Replies:
    5
    Views:
    319
    daku9999@gmail.com
    Apr 1, 2009
  5. pood.forums@gmail.com

    Can't get my regexp to work to test if numerical

    pood.forums@gmail.com, Nov 2, 2007, in forum: Ruby
    Replies:
    3
    Views:
    113
    bbxx789_05ss@yahoo.com
    Nov 2, 2007
Loading...

Share This Page