Hello drose2211,

For my point of view why not to use HASHES OF HASHES? I think is the best solution for your problem.

Sample of code:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %HoH = ( student1 => { quiz => "result", exam => "result", final => "result", }, student2 => { quiz => "result", exam => "result", final => "result", }, student3 => { quiz => "result", exam => "result", final => "result", }, ); print Dumper \%HoH; __END__ $ perl test.pl $VAR1 = { 'student3' => { 'quiz' => 'result', 'final' => 'result', 'exam' => 'result' }, 'student1' => { 'final' => 'result', 'quiz' => 'result', 'exam' => 'result' }, 'student2' => { 'exam' => 'result', 'quiz' => 'result', 'final' => 'result' } };

Regarding on how to process the data and store them read the doc on the link above, alternatively provide (a few lines) as a sample of your CSV file and we can help you.

Update: There are many many ways of resolving your problem. For a quick proposed solution something like that could be done using HASHES OF ARRAYS and HASHES OF HASHES. You can make the code sorter and more efficient with minor modifications but this should be enough to get you started.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use List::Util qw(sum); sub quizSub { return (sum(@_) / 300) * .10; } sub examSub { return (sum(@_) / 200) * .20; } sub finalSub { return (sum(@_) / 100) * .30; } my %HoA; while (<>) { chomp; my @data = split(/,/, ); my $name = shift @data; $HoA{$name} = [ @data ]; } continue { close ARGV if eof; } # print Dumper \%HoA; my %HoH; # print the whole thing sorted by number of members and name foreach my $key ( sort { @{$HoA{$b}} <=> @{$HoA{$a}} || $a cmp $b } keys %HoA ) { # print "$key: ", join(", ", sort @{ $HoA{$key} }), "\n"; my $quiz1 = shift @{ $HoA{$key} }; my $quiz2 = shift @{ $HoA{$key} }; my $quiz = quizSub($quiz1, $quiz2); $HoH{$key}{'quiz'} = $quiz; my $exam1 = shift @{ $HoA{$key} }; my $exam2 = shift @{ $HoA{$key} }; my $exam = examSub($exam1, $exam2); $HoH{$key}{'exam'} = $exam; my $final1 = shift @{ $HoA{$key} }; my $final2 = shift @{ $HoA{$key} }; my $final = finalSub($final1, $final2); $HoH{$key}{'final'} = $final; } print Dumper \%HoH; __END__ $ perl test.pl in.txt $VAR1 = { 'Student2' => { 'quiz' => '0.001', 'final' => '0.033', 'exam' => '0.007' }, 'Student3' => { 'final' => '0.033', 'exam' => '0.007', 'quiz' => '0.001' }, 'Student1' => { 'final' => '0.033', 'exam' => '0.007', 'quiz' => '0.001' } };

Sample of input data, based on the sample that you provided it:

$ cat in.txt Student1,1,2,3,4,5,6 Student2,1,2,3,4,5,6 Student3,1,2,3,4,5,6

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

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