From 437925002a6c1e2ff5fa61ebf6ac6e4c364506c2 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic <philip.kaludercic@fau.de> Date: Thu, 11 Jan 2024 11:00:40 +0100 Subject: [PATCH] Check if there is any correct option for each question --- gen.pl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gen.pl b/gen.pl index d22b529..50b85e0 100755 --- a/gen.pl +++ b/gen.pl @@ -31,7 +31,7 @@ sub md { # pipe through $markdown sub add { return unless %last_option; - if (defined $last_option{"comment"}) { + if ($last_option{"comment"}) { $last_option{"comment"} = md($last_option{"comment"}); } @@ -44,9 +44,19 @@ while (<>) { } elsif (/^.$/) { add(); - die "end of block without a question at line $.\n" + die "end of block without a question at line $ARGV:$.\n" unless defined $question; + my $any = 0; + foreach my $opt (@options) { + # unless (defined $opt->{"correct"}) { + # die "undefined \"$question\" ($ARGV:$.)\n"; + # } + $any = 1 if (not (defined $opt->{"correct"})) or ($opt->{"correct"} eq JSON::true); + } + die "no correct option at \"$question\" ($ARGV)\n" + unless $any; + my %ent = ( "question" => md($question), -- GitLab