Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How do I do this??

by repson (Chaplain)
on Apr 08, 2001 at 15:04 UTC ( [id://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'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found