aboutsummaryrefslogtreecommitdiff
path: root/challenge-034/yet-ebreo/perl5/ch-2.pl
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-02-26 18:27:28 +0000
committerGitHub <noreply@github.com>2020-02-26 18:27:28 +0000
commit2d7574823cefd1e7a11072776b784fa88fe0fb52 (patch)
treec0a212d8299d2d93f4de77102f027a95ee24596f /challenge-034/yet-ebreo/perl5/ch-2.pl
parente2664a3f4c9d187c2d5f8559048b9af0f2e66550 (diff)
parent2640a0d64155ceb076579a0ad96f99a32c1a59aa (diff)
downloadperlweeklychallenge-club-2d7574823cefd1e7a11072776b784fa88fe0fb52.tar.gz
perlweeklychallenge-club-2d7574823cefd1e7a11072776b784fa88fe0fb52.tar.bz2
perlweeklychallenge-club-2d7574823cefd1e7a11072776b784fa88fe0fb52.zip
Merge pull request #1315 from Doomtrain14/master
Hello
Diffstat (limited to 'challenge-034/yet-ebreo/perl5/ch-2.pl')
-rw-r--r--challenge-034/yet-ebreo/perl5/ch-2.pl41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-034/yet-ebreo/perl5/ch-2.pl b/challenge-034/yet-ebreo/perl5/ch-2.pl
new file mode 100644
index 0000000000..b0c253f846
--- /dev/null
+++ b/challenge-034/yet-ebreo/perl5/ch-2.pl
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+my %table = (
+ add => \&add,
+ subtract => \&subtract,
+ multiply => \&multiply,
+ divide => \&divide
+);
+
+sub divide {
+ my ($m,$n) = @_;
+ say "Error: Divide by 0" if !$n;
+
+ return $m/$n;
+}
+
+sub add {
+ my ($m,$n) = @_;
+ return $m+$n;
+}
+
+sub subtract {
+ my ($m,$n) = @_;
+ return $m-$n;
+}
+
+sub multiply {
+ my ($m,$n) = @_;
+ return $m*$n;
+}
+
+my $commands = "add multiply subtract divide";
+my @operands = (43,6);
+for my $cmd ($commands=~/\w+/g) {
+ say "[$cmd]";
+ say $table{$cmd}->(@operands);
+} \ No newline at end of file