aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-031/joelle-maslak/perl5/ch-1.pl33
-rwxr-xr-xchallenge-031/joelle-maslak/perl6/ch-1.p628
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-031/joelle-maslak/perl5/ch-1.pl b/challenge-031/joelle-maslak/perl5/ch-1.pl
new file mode 100755
index 0000000000..09afa38e3a
--- /dev/null
+++ b/challenge-031/joelle-maslak/perl5/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+use v5.24;
+use strict;
+use warnings;
+
+# Turn on method signatures
+use feature 'signatures';
+no warnings 'experimental::signatures';
+
+if ( @ARGV != 2 ) { die("Provide letters to use and (optionally) filename") }
+
+MAIN: {
+ if ( check_for_div_by_zero(@ARGV) ) {
+ say "Denominator is zero";
+ } else {
+ say "Denominator is not zero";
+ }
+}
+
+sub check_for_div_by_zero ( $top, $bottom ) {
+ local $@;
+ my $result =
+ eval { use warnings FATAL => 'all'; $top / $bottom }; # Make things like "1 / abc" fatal.
+
+ if ( defined($result) ) {
+ return;
+ } elsif ( $@ =~ /^Illegal division by zero / ) {
+ return 1;
+ } else {
+ die($@);
+ }
+}
+
diff --git a/challenge-031/joelle-maslak/perl6/ch-1.p6 b/challenge-031/joelle-maslak/perl6/ch-1.p6
new file mode 100755
index 0000000000..7d2b97aadf
--- /dev/null
+++ b/challenge-031/joelle-maslak/perl6/ch-1.p6
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl6
+use v6;
+
+#
+# Copyright © 2019 Joelle Maslak
+# All Rights Reserved - See License
+#
+
+sub MAIN($numerator, $denominator) {
+ if test-for-div-by-zero($numerator, $denominator) {
+ say "Denominator is zero";
+ } else {
+ say "Denominator is not zero";
+ }
+}
+
+sub test-for-div-by-zero($numerator, $denominator) {
+ ($numerator / $denominator).Int.sink;
+
+ return; # Not div by zero
+
+ CATCH {
+ when X::Numeric::DivideByZero {
+ return 1; # Div by zero
+ }
+ }
+}
+