aboutsummaryrefslogtreecommitdiff
path: root/challenge-031
diff options
context:
space:
mode:
authorJoelle Maslak <jmaslak@antelope.net>2019-10-26 18:46:28 -0600
committerJoelle Maslak <jmaslak@antelope.net>2019-10-26 18:46:28 -0600
commit2f70f5f3a8fc69bf5d2c4aa0dc823cfe3c6d0a16 (patch)
tree92df4a91e8a5a43ba44c7e69b98086ae81be0cc7 /challenge-031
parenteebcb87b5b57eef54424e41660dc5881e704cf57 (diff)
downloadperlweeklychallenge-club-2f70f5f3a8fc69bf5d2c4aa0dc823cfe3c6d0a16.tar.gz
perlweeklychallenge-club-2f70f5f3a8fc69bf5d2c4aa0dc823cfe3c6d0a16.tar.bz2
perlweeklychallenge-club-2f70f5f3a8fc69bf5d2c4aa0dc823cfe3c6d0a16.zip
Joelle's solutions in Raku and Perl to 31.1
Diffstat (limited to 'challenge-031')
-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
+ }
+ }
+}
+