aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-031/e-choroba/perl5/ch-1.pl22
-rwxr-xr-xchallenge-031/e-choroba/perl5/ch-2.pl37
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