drose2211 has asked for the wisdom of the Perl Monks concerning the following question:
I am attempting to find the weighted grades for 5 people with each having 6 scores. I made subroutines (untested) to calculate each of the different weights. The dilemma I am having is that all of my names and scores are currently in one array. My original thinking was that I would put make an array for the names, and an array for each persons exams, quizes, and final exam. Then running the scores through the subroutine. The problem is that it makes me think that I am creating a lot of extra arrays for something that could be condensed. My array is in a predictable order (name, score,score,score,score,score,score,name.....) Is there a way to take the first 3 scores run them through a subroutine and then put the other scores through their subroutines as well while keeping them in that array? Or is this just wishful thinking?
#usr/bin/perl use strict; use warnings; use feature qw(say); use List::Util qw(sum); open IN,'<',"part3.csv" or die "Can't open input file 'part3.csv': $!\ +n"; my $x; my @studentnames; sub quiz { return (sum(@_) / 300) * .10; } sub exam { return (sum(@_) / 200) * .20; } sub final { return (sum(@_) / 100) * .30; } while ($x = <IN>){ if ($x =~ /^\w*\s\w*/){ push @studentnames, +(split/,/, $x); } } foreach (@studentnames){ print "$_ \n"; } close IN;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Weighted averages
by Eily (Monsignor) on Jan 25, 2018 at 16:55 UTC | |
by drose2211 (Sexton) on Jan 25, 2018 at 17:25 UTC | |
by Eily (Monsignor) on Jan 25, 2018 at 17:40 UTC | |
by drose2211 (Sexton) on Jan 25, 2018 at 17:53 UTC | |
|
Re: Weighted averages
by thanos1983 (Parson) on Jan 25, 2018 at 16:26 UTC | |
by drose2211 (Sexton) on Jan 25, 2018 at 16:35 UTC | |
by thanos1983 (Parson) on Jan 25, 2018 at 17:04 UTC | |
by drose2211 (Sexton) on Jan 25, 2018 at 17:54 UTC | |
by thanos1983 (Parson) on Jan 25, 2018 at 18:05 UTC | |
|
Re: Weighted averages
by raymorris (Novice) on Jan 27, 2018 at 22:12 UTC |