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
    Likes Received:
    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: Apr 21, 2008
    powdrsnow, Apr 21, 2008
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.