aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-26 18:52:57 +0100
committerGitHub <noreply@github.com>2019-10-26 18:52:57 +0100
commit325129d29b036bc6a9a730f1a2e1332e7dfe6f46 (patch)
treede9bc70364fb65a69e0d2a9b38b24b54f4388e02
parent0c78b681329bd3719c057ce990e5fcf8c3338333 (diff)
parent59e05ebc5f9673f1885431d9a86bf32aa3040a5a (diff)
downloadperlweeklychallenge-club-325129d29b036bc6a9a730f1a2e1332e7dfe6f46.tar.gz
perlweeklychallenge-club-325129d29b036bc6a9a730f1a2e1332e7dfe6f46.tar.bz2
perlweeklychallenge-club-325129d29b036bc6a9a730f1a2e1332e7dfe6f46.zip
Merge pull request #840 from kolcon/master
Challenge 031 #1 LK
-rw-r--r--challenge-031/lubos-kolouch/perl5/ch-1.pl52
1 files changed, 52 insertions, 0 deletions
diff --git a/challenge-031/lubos-kolouch/perl5/ch-1.pl b/challenge-031/lubos-kolouch/perl5/ch-1.pl
new file mode 100644
index 0000000000..836dc75c8a
--- /dev/null
+++ b/challenge-031/lubos-kolouch/perl5/ch-1.pl
@@ -0,0 +1,52 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: ch-1.pl
+#
+# USAGE: ./ch-1.pl
+#
+# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-031/
+#
+# Create a function to check divide by zero error without checking if the denominator is zero.
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: Lubos Kolouch
+# ORGANIZATION:
+# VERSION: 1.0
+# CREATED: 10/26/2019 07:10:56 PM
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use feature qw/say/;
+use Try::Tiny;
+
+sub divide_test {
+ my ( $num, $div ) = @_;
+
+ my $result;
+
+ try {
+ $result = $num / $div;
+ }
+ catch {
+ $result = "ERROR";
+ }
+ finally {
+ return $result;
+ }
+}
+
+# TESTS
+use Test::More;
+
+is(divide_test( 0,0 ),"ERROR");
+is(divide_test( 1,0 ),"ERROR");
+isnt(divide_test( 1,1 ),"ERROR");
+
+done_testing;
+