aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2019-10-26 19:48:52 +0200
committerLubos Kolouch <lubos@kolouch.net>2019-10-26 19:48:52 +0200
commit59e05ebc5f9673f1885431d9a86bf32aa3040a5a (patch)
treea81e568d914a9215b7b9839cc3da58974fc281be
parenteebcb87b5b57eef54424e41660dc5881e704cf57 (diff)
downloadperlweeklychallenge-club-59e05ebc5f9673f1885431d9a86bf32aa3040a5a.tar.gz
perlweeklychallenge-club-59e05ebc5f9673f1885431d9a86bf32aa3040a5a.tar.bz2
perlweeklychallenge-club-59e05ebc5f9673f1885431d9a86bf32aa3040a5a.zip
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;
+