Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://70820]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2018-06-19 17:18 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.