diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-10-27 03:47:36 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-27 03:47:36 +0000 |
| commit | 59dca7e69c56da36c5377a64c20f96502ded4ce8 (patch) | |
| tree | 937654ac1430a5eb65e627eb1e10e337ef49f840 | |
| parent | 69f385a5120f74c9788aeb5520f0ffc25a528550 (diff) | |
| parent | 2f70f5f3a8fc69bf5d2c4aa0dc823cfe3c6d0a16 (diff) | |
| download | perlweeklychallenge-club-59dca7e69c56da36c5377a64c20f96502ded4ce8.tar.gz perlweeklychallenge-club-59dca7e69c56da36c5377a64c20f96502ded4ce8.tar.bz2 perlweeklychallenge-club-59dca7e69c56da36c5377a64c20f96502ded4ce8.zip | |
Merge pull request #842 from jmaslak/joelle-31-1-1
Joelle's solutions in Raku and Perl to 31.1
| -rwxr-xr-x | challenge-031/joelle-maslak/perl5/ch-1.pl | 33 | ||||
| -rwxr-xr-x | challenge-031/joelle-maslak/perl6/ch-1.p6 | 28 |
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 + } + } +} + |
