Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How do I do this??

by repson (Chaplain)
on Apr 08, 2001 at 15:04 UTC ( #70820=note: print w/ replies, xml ) Need Help??


in reply to How do I do this??

Just one thing with your program, as I recall with standard deviations you should have the average calculated over the whole data range, not just the elements that have come before.
Here is what I would do:

my @data; my $avg; while (<IN>) { chomp; my $tmp = [split /:/]; $avg += $tmp->[1]; push @data, $tmp; } $avg /= @data; my $std = 0; for (@data) { $std += abs($_->[1] - $avg) } $std /= @data; open(OUT, ">pa5c.dat") || die ("Can't open file $!\n"); for (@data) { my $grade; my $dev = ($_->[1] - $avg) / $std; if ($dev >= 1) { $grade = 'A' } elsif ($dev >= (1/3)) { $grade = 'B' } elsif ($dev >= (-1/3)) { $grade = 'C' } elsif ($dev > -1) { $grade = 'D' } else { $grade = 'E' } print OUT join(':', $_->[0], $_->[1], $grade) . "\n"; } close OUT;
Which produces records like
Smith:70:C Jones:74:B Rider:80:A


Comment on Re: How do I do this??
Select or Download Code
Replies are listed 'Best First'.
Re: Re: How do I do this??
by yabba on Apr 08, 2001 at 18:37 UTC
    Thanks a lot for your help!! I ran the program and it keeps saying: Illegal division by zero at $std /= @data; Does anyone know why??

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://70820]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2015-07-07 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls