aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-21 18:25:39 +0100
committerGitHub <noreply@github.com>2019-10-21 18:25:39 +0100
commit5b687d8c1cfc77a0a75070b80a571ed75e978423 (patch)
treee4afc77dea724bb4a96f7d62e3cc14843adb24b1
parentd40c1cc5b822fab79746640fa05b7a338e90bffc (diff)
parent9d0d2e2e7ae92c9fc63580a7a320b4ff71935669 (diff)
downloadperlweeklychallenge-club-5b687d8c1cfc77a0a75070b80a571ed75e978423.tar.gz
perlweeklychallenge-club-5b687d8c1cfc77a0a75070b80a571ed75e978423.tar.bz2
perlweeklychallenge-club-5b687d8c1cfc77a0a75070b80a571ed75e978423.zip
Merge pull request #822 from duanepowell/pwc31
Commit solutions for perl weekly challenge 031
-rwxr-xr-xchallenge-031/duane-powell/perl5/ch-1.pl26
-rwxr-xr-xchallenge-031/duane-powell/perl5/ch-2.pl28
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-031/duane-powell/perl5/ch-1.pl b/challenge-031/duane-powell/perl5/ch-1.pl
new file mode 100755
index 0000000000..9b4849ed3e
--- /dev/null
+++ b/challenge-031/duane-powell/perl5/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+# Create a function to check divide by zero error without checking if the denominator is zero.
+
+my %h = @ARGV;
+while ( my ($n, $d) = each (%h) ) {
+ my $o;
+ eval { $o = $n/$d };
+ if ( $@ ) {
+ print "$n/$d = division by zero.\n";
+ } else {
+ print "$n/$d = $o\n";
+ }
+}
+
+__END__
+
+./ch-1.pl 10 5 99 1 5 0 7 0 8 5
+8/5 = 1.6
+7/0 = division by zero.
+10/5 = 2
+99/1 = 99
+5/0 = division by zero.
+
diff --git a/challenge-031/duane-powell/perl5/ch-2.pl b/challenge-031/duane-powell/perl5/ch-2.pl
new file mode 100755
index 0000000000..68c589add4
--- /dev/null
+++ b/challenge-031/duane-powell/perl5/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Data::Dumper;
+
+# 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
+
+my ($dynamic_var, $value) = @ARGV;
+
+eval { $$dynamic_var = $value };
+print Data::Dumper->Dump([$dynamic_var],['User_defined_var']);
+print "$dynamic_var = $value\n";
+
+
+__END__
+
+./ch-2.pl number 10
+$User_defined_var = 'number';
+number = 10
+
+./ch-2.pl hello world
+$User_defined_var = 'hello';
+hello = world
+
+./ch-2.pl foo bar
+$User_defined_var = 'foo';
+foo = bar