aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-100/deadmarshal/perl/ch-1.pl32
-rw-r--r--challenge-100/deadmarshal/perl/ch-2.pl17
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-100/deadmarshal/perl/ch-1.pl b/challenge-100/deadmarshal/perl/ch-1.pl
new file mode 100644
index 0000000000..ac344fe24f
--- /dev/null
+++ b/challenge-100/deadmarshal/perl/ch-1.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature qw(say);
+
+die "No argument provided, arg should be a string. " unless @ARGV == 1;
+
+shift =~ m{(?<hour>\d{2}):(?<minute>\d{2})(?:\s+)?(?<am_pm>am|pm)?};
+
+unless (exists $+{am_pm}){
+if($+{hour} lt '12'){
+ say $+{hour}, ':', $+{minute}, 'am';
+}elsif($+{hour} gt '12'){
+ my $temp = $+{hour} - 12;
+ say '0', $temp, ':', $+{minute}, 'pm';
+}elsif($+{hour} eq '12'){
+ say $+{hour}, ':', $+{minute}, 'pm';
+}elsif($+{hour} eq '00'){
+ say $+{hour}, ':', $+{minute}, 'am';
+}
+}else{
+ if($+{hour} lt '12' && $+{am_pm} eq 'am'){
+ say $+{hour}, ':', $+{minute};
+ }elsif($+{hour} lt '12' && $+{am_pm} eq 'pm'){
+ my $temp = $+{hour} + 12;
+ say $temp, ':', $+{minute};
+ }elsif($+{hour} eq '12' && $+{am_pm} eq 'am'){
+ say '00', ':', $+{minute};
+ }elsif($+{hour} eq '12' && $+{am_pm} eq 'pm'){
+ say $+{hour}, ':', $+{minute};
+ }
+}
diff --git a/challenge-100/deadmarshal/perl/ch-2.pl b/challenge-100/deadmarshal/perl/ch-2.pl
new file mode 100644
index 0000000000..fcec41f90d
--- /dev/null
+++ b/challenge-100/deadmarshal/perl/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use List::Util qw(min);
+use feature 'say';
+use JSON::PP qw(decode_json);
+
+die "No argument provided. " unless @ARGV == 1;
+
+my $arrayref = decode_json shift;
+my $sum;
+
+foreach my $item (@$arrayref){
+ $sum += min @$item;
+}
+
+say $sum;