aboutsummaryrefslogtreecommitdiff
path: root/challenge-031/andrezgz/perl5/ch-1.pl
blob: 3da84bdbb84f329ec783a3651581b8e2e2ff3b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/perl

# https://perlweeklychallenge.org/blog/perl-weekly-challenge-031/
# Task #1
# Create a function to check divide by zero error
# without checking if the denominator is zero.

use strict;
use warnings;

sub is_division_by_zero {
    my ($num,$den) = @_;
    return if ( eval { $num = $num/$den; 1 } );
    return 1;
}

print 'Division by zero' if is_division_by_zero(1,0);