aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-029/e-choroba/perl5/ch-1.pl39
-rwxr-xr-xchallenge-029/e-choroba/perl5/ch-2.pl23
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-029/e-choroba/perl5/ch-1.pl b/challenge-029/e-choroba/perl5/ch-1.pl
new file mode 100755
index 0000000000..c7de003078
--- /dev/null
+++ b/challenge-029/e-choroba/perl5/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+sub expand {
+ my ($string) = @_;
+ grep length, glob $string =~ s/(\s)/\\$1/gr
+}
+
+use Test::More tests => 5;
+use Test::Deep;
+
+cmp_deeply [expand('Perl {Daily,Weekly,Monthly,Yearly} Challenge')],
+ bag('Perl Daily Challenge',
+ 'Perl Weekly Challenge',
+ 'Perl Monthly Challenge',
+ 'Perl Yearly Challenge'),
+ 'Original example';
+
+cmp_deeply [expand('{a,,}')],
+ bag(qw( a )),
+ 'Empty results excluded';
+
+cmp_deeply [expand('a{b,c}{d,e}f{g,h,i}')],
+ bag('abdfg', 'abdfh', 'abdfi',
+ 'abefg', 'abefh', 'abefi',
+ 'acdfg', 'acdfh', 'acdfi',
+ 'acefg', 'acefh', 'acefi'),
+ 'Multiple brackets';
+
+cmp_deeply [expand('{{a,b}c,d}e')],
+ bag(qw( ace bce de )),
+ 'Nested brackets';
+
+cmp_deeply [expand('{{a,b}c,d}{g,}')],
+ bag(qw( acg ac bcg bc dg d )),
+ 'Everything combined';
+
diff --git a/challenge-029/e-choroba/perl5/ch-2.pl b/challenge-029/e-choroba/perl5/ch-2.pl
new file mode 100755
index 0000000000..ed756c8f2d
--- /dev/null
+++ b/challenge-029/e-choroba/perl5/ch-2.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use Inline 'C';
+
+use Test::More tests => 2;
+
+is factorial(20), 2432902008176640000;
+is greet('world'), 'Hello world!';
+
+__END__
+__C__
+
+long factorial (long n) {
+ long r = 1;
+ for (long i = 2; i <= n; i++) r *= i;
+ return r;
+}
+
+SV *greet (SV* name) {
+ return(newSVpvf("Hello %s!", SvPV(name, PL_na)));
+}