aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-08-12 15:02:52 +0100
committerGitHub <noreply@github.com>2019-08-12 15:02:52 +0100
commit1decf8fab11977fe1349a22df5f8b1bda7b2c164 (patch)
treea64f0037992f01c0b3634bea2c63cdc298243109
parentc68da89f6f1840672d857f56360ea2bd89c80aaf (diff)
parent0663eb2e1461dbac548607661bfe48f096a066cf (diff)
downloadperlweeklychallenge-club-1decf8fab11977fe1349a22df5f8b1bda7b2c164.tar.gz
perlweeklychallenge-club-1decf8fab11977fe1349a22df5f8b1bda7b2c164.tar.bz2
perlweeklychallenge-club-1decf8fab11977fe1349a22df5f8b1bda7b2c164.zip
Merge pull request #507 from davorg/master
Added solutions to Challenge 21
-rw-r--r--challenge-021/dave-cross/perl5/ch-1.pl27
-rw-r--r--challenge-021/dave-cross/perl5/ch-2.pl22
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-021/dave-cross/perl5/ch-1.pl b/challenge-021/dave-cross/perl5/ch-1.pl
new file mode 100644
index 0000000000..ff73950dc2
--- /dev/null
+++ b/challenge-021/dave-cross/perl5/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+my ($curr, $last) = (1, 0);
+my $iter = 1;
+
+do {
+ # say $iter;
+ $last = $curr;
+ $curr += (1 / ( fact($iter++)));
+} until ($last == $curr);
+
+say $curr;
+
+sub fact {
+ my ($x) = @_;
+
+ my $fact = 1;
+ while ($x) {
+ $fact *= $x--;
+ }
+
+ return $fact;
+}
diff --git a/challenge-021/dave-cross/perl5/ch-2.pl b/challenge-021/dave-cross/perl5/ch-2.pl
new file mode 100644
index 0000000000..e0bd00d094
--- /dev/null
+++ b/challenge-021/dave-cross/perl5/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+use URI;
+
+if (!@ARGV) {
+ @ARGV = <DATA>;
+ chomp(@ARGV);
+}
+
+for (@ARGV) {
+ say URI->new($_)->canonical;
+}
+
+__DATA__
+HTTP://www.Example.com/
+http://www.example.com/a%c2%b1b
+http://www.example.com/%7Eusername/
+http://www.example.com:80/bar.html