diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-10-26 08:12:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-26 08:12:41 +0100 |
| commit | 0ef8fcc198744ade6097b992d0a735a9c27925bf (patch) | |
| tree | a9116831fc31ff1431ae8290aa3bf7c9188c1284 /challenge-031 | |
| parent | 8c06b83b502cb9b814551434d7941e77214b6e05 (diff) | |
| parent | 20e7482af4375fa8fd4858ce1fa85ca4d15773cc (diff) | |
| download | perlweeklychallenge-club-0ef8fcc198744ade6097b992d0a735a9c27925bf.tar.gz perlweeklychallenge-club-0ef8fcc198744ade6097b992d0a735a9c27925bf.tar.bz2 perlweeklychallenge-club-0ef8fcc198744ade6097b992d0a735a9c27925bf.zip | |
Merge pull request #837 from toshikFedotov/master
Added solutions by Anton Fedotov
Diffstat (limited to 'challenge-031')
| -rwxr-xr-x | challenge-031/anton-fedotov/task1-divide-by-zero.pl | 17 | ||||
| -rwxr-xr-x | challenge-031/anton-fedotov/task2-dyn-var.pl | 10 |
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-031/anton-fedotov/task1-divide-by-zero.pl b/challenge-031/anton-fedotov/task1-divide-by-zero.pl new file mode 100755 index 0000000000..6f475ca7cf --- /dev/null +++ b/challenge-031/anton-fedotov/task1-divide-by-zero.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +sub check_div_zero { + my ( $numerator, $denominator ) = @_; + return 'Can\'t divide by zero' if !eval{$numerator/$denominator}; + return $numerator/$denominator; +} + +my ($n, $den, $zero) = (7, 3, 0); +my $result = check_div_zero($n, $den); +say "Division $n by $den returns: $result"; +$result = check_div_zero($n, $zero); +say "Division $n by $zero returns: $result"; diff --git a/challenge-031/anton-fedotov/task2-dyn-var.pl b/challenge-031/anton-fedotov/task2-dyn-var.pl new file mode 100755 index 0000000000..56eaa65238 --- /dev/null +++ b/challenge-031/anton-fedotov/task2-dyn-var.pl @@ -0,0 +1,10 @@ +#!/usr/bin/env perl + +use warnings; +use v5.10; + +my $name = shift; +my $value = shift; +if (defined($value)) {$$name = $value} +else {$$name = 'I love Star Wars'} +say "Variable named $name have value: $$name"; |
