aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-031/yet-ebreo/perl5/ch-1.pl17
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-031/yet-ebreo/perl5/ch-1.pl b/challenge-031/yet-ebreo/perl5/ch-1.pl
new file mode 100644
index 0000000000..ffe41c3a6e
--- /dev/null
+++ b/challenge-031/yet-ebreo/perl5/ch-1.pl
@@ -0,0 +1,17 @@
+#Create a function to check divide by zero error
+#without checking if the denominator is zero.
+use strict;
+use warnings;
+use feature 'say';
+
+sub div_zero_check {
+ my @div = @_;
+ my $r = eval "$_[0]/$_[1]";
+ $@ =~ /z/ ? -1 :$r ;
+}
+my $r;
+say ( (($r = div_zero_check(112,0)) < 0) ? "Division by zero detected" : $r );
+say ( (($r = div_zero_check(0,0)) < 0) ? "Division by zero detected" : $r );
+say ( (($r = div_zero_check(0,1)) < 0) ? "Division by zero detected" : $r );
+say ( (($r = div_zero_check(32,12)) < 0) ? "Division by zero detected" : $r );
+