commit 45c4136b399ead9c9c520f6240f5b55109c7d377 parent f68cedb8131accb9b05059759b1fa6deedac117f Author: Samir Parikh <noreply@samirparikh.com> Date: Tue, 28 Dec 2021 23:03:58 +0000 get additional test conditions to pass Diffstat:
M | wordy/Wordy.pm | | | 12 | ++++++++---- |
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/wordy/Wordy.pm b/wordy/Wordy.pm @@ -10,15 +10,19 @@ my $op_regex = qr/plus|minus|divided|multiplied/; sub answer { my ($question) = @_; - die "unknown operation" if ($question !~ m/^What/); + die "unknown operation" if ($question !~ m/^What is/); say $question; my @m = ($question =~ m/$pattern/g); + die "syntax error" unless (scalar @m); say "here is what I found"; say "->$_<-" foreach @m; say "total elements: ", scalar @m; - if (scalar @m == 1 && $m[0] =~ m/-?\d+/) { - say "I am returning $m[0]"; - return $m[0]; + if (scalar @m == 1) { + if ($question =~ m/-?\d+\?/) { # operand with no operation + return $m[0]; + } else { + die "unknown operation"; # operand with unknown operation + } } my @stack; foreach (@m) {