diff options
| -rw-r--r-- | challenge-031/ndelucca/perl5/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-031/ndelucca/perl5/ch-2.pl | 19 |
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'; + |
