freelanceprogrammers.org Forum Index » Perl

compare 2 databases


View user's profile Post To page top
v_acuum Posted: Sun Apr 07, 2002 1:02 am


Joined: 07 Apr 2002

Posts: 1
compare 2 databases
I am trying to make a test marker

there are 2 databases

DB1- actual test
Question Number | Correct Answer | Bonus Answer | Weight
Q1 | A | True | 2
Q2 | C | True | 5
Q3 | B | False | 2
Q4 | D | True | 3

DB2- students test
Student | Question Number | Correct Answer | Bonus Answer
Chris | Q1 | A | True ---> answered `A` is correct = 2Pt, `True` is
correct = 2Pt, total=4Pts
Chris | Q2 | D | False ---> answered `D` is wrong = 0Pt, `False` is
wrong = 0Pt, total=0Pts
Chris | Q3 | C | False ---> answered `C` is wrong = 0Pt, `False` is
correct = 0Pt (has to get first part of the Q. Correct to get any
bonus), total=0Pts
Chris | Q4 | D | False ---> answered `D` is correct = 3Pt, `False` is
wrong = 0Pt, total=3Pts
---------------------
Jim | Q1 | C | True
Jim | Q2 | A | False
Jim | Q3 | B | False
Jim | Q4 | D | True
--------- ETC... --------

How can i match these two databases together so i can show final
scores
ie.
Student | Pts for Correct Answer | Pts for Bonus
Jim | 5 | 5 | 10
Chris | 5 | 2 | 7


I have this to work with, a previous answer to one of my questions in
the past:


foreach my $students(@Students) {
chomp $students;
my ($person,$questionNum,$answer,$bonus) = split(/|/,$students);
$pts{$person} = $question;
push(@$person,$pts{$person});
}

my %hash;
foreach $key (keys(%pts)) {
$TotalCorrectAnswers = 0;
foreach my $question(@$key) {
my @Info = grep(/$question/,@MasterTest);
my ($QuestionNumber,$CorrectAnswer,$BonusAnswer,$Weight) = split(/
|/,$Info[0]);
$TotalCorrectAnswers = ($TotalCorrectAnswers + $Weight);
}
$sortvalue = $TotalCorrectAnswers;
push @{$hash{$sortvalue}}, [$key,$CorrectAnswer,$BonusAnswer];
}

foreach my $sortvalue (keys %hash) {
for my $i (0..@{$hash{$sortvalue}} -1) {
$person = $hash{$sortvalue}[$i][0];
$CorrectAnswer = $hash{$sortvalue}[$i][1];
$BonusAnswer = $hash{$sortvalue}[$i][2];
print "$person - $CorrectAnswer - $BonusAnswer";
}
}


I am able to get the CorrectAnswer to sum up for each person, but
I can`t get the bonus answer to work, ie. Sum bonus if correct AND
first part of question is correct
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help