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;

In reply to Weighted averages by drose2211

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.