
BillKSmith
Veteran
Oct 17, 2017, 10:15 AM
Post #2 of 4
(3697 views)
|
Re: [ogit2] Data Structure Loop
[In reply to]
|
Can't Post
|
|
Your data structure does not compile. Based on the indenting, I made a guess at what is missing (Refer to comment in my code). If this is not correct, the rest of my code probably will not help you. Note: It is not possible to preserve the original order of the questions.
C:\Users\Bill\forums\guru>type ogit2.pl use strict; use warnings; my $data = { 'questions' => { 'textQuestion' => { 'status' => 'incorrect', 'direction' => "How many types of features does an owl have?", }, 'numericQuestion' => { 'status' => 'correct', 'direction' => "The interior angles of a triangle add up to? ", }, 'textQuestion' => { 'status' => 'correct', 'direction' => "Please spell the opposite of majestic ", }, 'multipleQuestion' => { 'status' => 'incorrect', 'direction' => "Which of these can be found in a swamp ", }, 'selectionQuestion' => { 'status' => 'correct', 'direction' => "Select the correct wood for building firewood ", } }, # I added this line to correct syntax 'groups' => { 'group' => { 'passingPercent' => '80', 'name' => 'Question Group 1', 'passingScore' => '80', 'totalQuestions' => '10', 'awardedScore' => '80.83', 'answeredQuestions' => '7', 'awardedPercent' => '80.83' } }, 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'quizSettings' => { 'maxScore' => '100', 'maxNormalizedScore' => '100', 'timeLimit' => '1200', 'passingPercent' => '0.8', 'quizType' => 'graded' }, 'xmlns' => 'http://results', 'version' => '1' }; while (my ( $question, $ans_ref ) = each %{$data->{questions}} ) { print "$question:\n"; print "status = $ans_ref->{status}\n"; print "direction = $ans_ref->{direction}\n"; print "\n\n"; } C:\Users\Bill\forums\guru>perl ogit2.pl numericQuestion: status = correct direction = The interior angles of a triangle add up to? textQuestion: status = correct direction = Please spell the opposite of majestic selectionQuestion: status = correct direction = Select the correct wood for building firewood multipleQuestion: status = incorrect direction = Which of these can be found in a swamp Good Luck, Bill
|