I agree with thanos1983 that it looks like you're searching for some kind of nested data structure. Maybe you can try something and ask us how to improve it, or show us how you might expect the data to look like (but it would help if you understood how nested structures work for that). Anyway, there is a nice idiom to access elements in an array when each position has a special meaning, constant:

use strict; use warnings; use feature qw(say); use constant { STUDENT => 0, FIRST_QUIZ => 1, LAST_QUIZ => 3, FIRST_EXAM => 4, LAST_EXAM => 5, FINAL => 6, }; while (<DATA>) { my @fields = split /,/, $_; say "Student:", $fields[STUDENT]; say "Quizzes:", join ", ", @fields[FIRST_QUIZ..LAST_QUIZ]; say "Exams:", join ", ", @fields[FIRST_EXAM..LAST_EXAM]; say "Final:", $fields[FINAL]; say "-----" } __DATA__ Allen Bailey,90,95,80,98,76,89 Carole Daily,9,9,8,9,7,8 Evan Fairly,50,75,10,82,64,79
Student:Allen Bailey Quizzes:90, 95, 80 Exams:98, 76 Final:89 ----- Student:Carole Daily Quizzes:9, 9, 8 Exams:9, 7 Final:8 ----- Student:Evan Fairly Quizzes:50, 75, 10 Exams:82, 64 Final:79 -----
Here I have used Slices (@ meaning several elements at a time, and a list inside the [ ] rather than a single value, but you can define FIRST_QUIZ, SECOND_QUIZ and so on and access each element one by one if it's simpler to you.

Also in /\w*\s\w*/, the * means 0 or more. So that's "maybe a letter/digit or more, a space, maybe a letter/digit or more", in the end the condition is pretty much only "a space". This might work, but this doesn't look like much of a constraint. Maybe you want + instead of * ?


In reply to Re: Weighted averages by Eily
in thread 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.