The dilemma I am having is that all of my names and scores are currently in one array.That is indeed your problem. Let's fix that. In fact you have a bunch of students. To represent "a bunch of" we use an array: @students = (); Each student has a final exam grade and probably a student ID:
Each student also has a bunch of quizzes. "A bunch of" is called an array, so:@students = ( { 'id' => 123, 'final'=> 94 }, { 'id' => 321 'final'=> 90 } );
@students = ( { 'id' => 123, 'final'=> 94, 'quiz' => [ 88, 45, 91 ] }, { 'id' => 321, 'final'=> 90, 'quiz' => [ 81, 93, 90 ] } );
Now that our Perl data structure accurately represents the real world, the code to manipulate it is straightforward.
"Bad programmers worry about the code. Good programmers worry about data structures and their relationships." Linus Torvalds
Note - the single quotes around the hash keys such as 'final' aren't required. That's just my personal preference for style, since barewords aren't good in *general* I don't like having something that *looks* like a bareword.In reply to Re: Weighted averages
by raymorris
in thread Weighted averages
by drose2211
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |