aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorndelucca <nazadelucca@gmail.com>2019-10-22 00:48:44 -0300
committerndelucca <nazadelucca@gmail.com>2019-10-22 00:48:44 -0300
commit55b82eb0568c94e29c9914cd69a714a79d34fb6f (patch)
treee1d7ab421a091981094347d56779a4c22dea94aa
parent3a07c75601b22087d31bab69cd4c731af727fba3 (diff)
downloadperlweeklychallenge-club-55b82eb0568c94e29c9914cd69a714a79d34fb6f.tar.gz
perlweeklychallenge-club-55b82eb0568c94e29c9914cd69a714a79d34fb6f.tar.bz2
perlweeklychallenge-club-55b82eb0568c94e29c9914cd69a714a79d34fb6f.zip
challenge-031/ndelucca
-rw-r--r--challenge-031/ndelucca/perl5/ch-1.pl19
-rw-r--r--challenge-031/ndelucca/perl5/ch-2.pl19
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-031/ndelucca/perl5/ch-1.pl b/challenge-031/ndelucca/perl5/ch-1.pl
new file mode 100644
index 0000000000..8759312c20
--- /dev/null
+++ b/challenge-031/ndelucca/perl5/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+# Create a function to check divide by zero error without checking if the denominator is zero.
+
+use strict;
+use warnings;
+
+sub divide_with_zero_check{
+
+ my ($num,$den) = @_;
+
+ return eval { $num / $den } // $@;
+
+}
+
+# print divide_with_zero_check(10,5); # 2
+# print divide_with_zero_check(10,0); # Illegal division by zero
+# print divide_with_zero_check(15,0); # Illegal division by zero
+# print divide_with_zero_check(15,3); # 5
diff --git a/challenge-031/ndelucca/perl5/ch-2.pl b/challenge-031/ndelucca/perl5/ch-2.pl
new file mode 100644
index 0000000000..c806ff72b8
--- /dev/null
+++ b/challenge-031/ndelucca/perl5/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+# Create a script to demonstrate creating dynamic variable name, assign a value to the variable and finally print the variable.
+# The variable name would be passed as command line argument.
+
+use strict;
+use warnings;
+
+my $name = shift || die "Choose a variable name!";
+my $value = int rand(10000);
+
+no strict 'refs';
+
+$$name = $value;
+print "Variable name: $name\nVariable value: $$name\n";
+
+# Looks the other way, hoping nobody notices...
+use strict 'refs';
+