diff options
| author | E. Choroba <choroba@matfyz.cz> | 2019-10-24 22:55:57 +0200 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2019-10-24 22:55:57 +0200 |
| commit | d3b3f1332289bf3ea29fd7b46c6005110f4c99b1 (patch) | |
| tree | ec891134f066737f0e1bfe2b6fd993f53f3ada7b | |
| parent | 81c5875659fcfd79c885094d2a09517c06093cf4 (diff) | |
| download | perlweeklychallenge-club-d3b3f1332289bf3ea29fd7b46c6005110f4c99b1.tar.gz perlweeklychallenge-club-d3b3f1332289bf3ea29fd7b46c6005110f4c99b1.tar.bz2 perlweeklychallenge-club-d3b3f1332289bf3ea29fd7b46c6005110f4c99b1.zip | |
Add solutions to 031 (Division by zero + Dynamic variable name)
by E. Choroba
| -rwxr-xr-x | challenge-031/e-choroba/perl5/ch-1.pl | 22 | ||||
| -rwxr-xr-x | challenge-031/e-choroba/perl5/ch-2.pl | 37 |
2 files changed, 59 insertions, 0 deletions
diff --git a/challenge-031/e-choroba/perl5/ch-1.pl b/challenge-031/e-choroba/perl5/ch-1.pl new file mode 100755 index 0000000000..5409d28723 --- /dev/null +++ b/challenge-031/e-choroba/perl5/ch-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use Try::Tiny; + +sub division { + my ($numerator, $denominator) = @_; + try { + { safe => 1, result => $numerator / $denominator } + } catch { + { safe => 0, error => $_ } + } +} + +use Test::More tests => 4; + +ok division(1,2)->{safe}; +ok !division(1,0)->{safe}; + +is division(1,2)->{result}, 1/2; +like division(1,0)->{error}, qr/Illegal division by zero/; diff --git a/challenge-031/e-choroba/perl5/ch-2.pl b/challenge-031/e-choroba/perl5/ch-2.pl new file mode 100755 index 0000000000..ca9c5dc731 --- /dev/null +++ b/challenge-031/e-choroba/perl5/ch-2.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl +use warnings; +use strict; + +my $var_name = shift; +{ no strict; + ${ $var_name } = "Don't try this at home!"; + print "\$$var_name: ", $$var_name, "\n"; +} + +=head1 Some interesting values + +=over + +=item ! or ? + +Argument "Don't try this at home!" isn't numeric in scalar assignment + +=item & or + + +Modification of a read-only value attempted + +=item \ + + Don't try this at home! + Don't try this at home! + +No newline after the second line. + + +=item , + +Don't try this at home!Don't try this at home!Don't try this at home! + +=back + +=cut |
