diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-12-17 18:23:53 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-12-17 18:23:53 +0000 |
| commit | cdebd0af75b2750d6073f96bc4df76807aebd060 (patch) | |
| tree | b1021dfb3ed6113aa59763a2652e5ff33c671a8c /challenge-029 | |
| parent | 8e2ca29751bbf4ce185f2b5766510334363c4293 (diff) | |
| download | perlweeklychallenge-club-cdebd0af75b2750d6073f96bc4df76807aebd060.tar.gz perlweeklychallenge-club-cdebd0af75b2750d6073f96bc4df76807aebd060.tar.bz2 perlweeklychallenge-club-cdebd0af75b2750d6073f96bc4df76807aebd060.zip | |
Add Perl solution to challenge 029
Diffstat (limited to 'challenge-029')
| -rw-r--r-- | challenge-029/paulo-custodio/README | 1 | ||||
| -rw-r--r-- | challenge-029/paulo-custodio/perl/ch-1.pl | 30 | ||||
| -rw-r--r-- | challenge-029/paulo-custodio/perl/ch-2.pl | 16 | ||||
| -rw-r--r-- | challenge-029/paulo-custodio/t/test-1.yaml | 22 | ||||
| -rw-r--r-- | challenge-029/paulo-custodio/t/test-2.yaml | 5 |
5 files changed, 74 insertions, 0 deletions
diff --git a/challenge-029/paulo-custodio/README b/challenge-029/paulo-custodio/README new file mode 100644 index 0000000000..87dc0b2fbd --- /dev/null +++ b/challenge-029/paulo-custodio/README @@ -0,0 +1 @@ +Solution by Paulo Custodio diff --git a/challenge-029/paulo-custodio/perl/ch-1.pl b/challenge-029/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..606ec245cf --- /dev/null +++ b/challenge-029/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +# Challenge 029 + +# Task #1 +# Write a script to demonstrate brace expansion. For example, script would take +# command line argument Perl {Daily,Weekly,Monthly,Yearly} Challenge and should +# expand it and print like below: +# +# Perl Daily Challenge +# Perl Weekly Challenge +# Perl Monthly Challenge +# Perl Yearly Challenge + +use Modern::Perl; + +sub print_expanded { + my($text) = @_; + if ($text =~ /[{]([^{}]*?)[}]/) { + my($before, $expand, $after) = ($`, $1, $'); + for my $arg (split(/,/, $expand)) { + print_expanded($before.$arg.$after); + } + } + else { + say $text; + } +} + +print_expanded("@ARGV"); diff --git a/challenge-029/paulo-custodio/perl/ch-2.pl b/challenge-029/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..c33fa95943 --- /dev/null +++ b/challenge-029/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +# Challenge 029 + +# Task #2 +# Write a script to demonstrate calling a C function. It could be any user +# defined or standard C function. + +use Modern::Perl; +use Inline C => <<'END'; + int sum(int a, int b) { + return a+b; + } +END + +say sum(@ARGV); diff --git a/challenge-029/paulo-custodio/t/test-1.yaml b/challenge-029/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..9caa126714 --- /dev/null +++ b/challenge-029/paulo-custodio/t/test-1.yaml @@ -0,0 +1,22 @@ +- setup: + cleanup: + args: "'Perl {Daily,Weekly,Monthly,Yearly} Challenge'" + input: + output: | + Perl Daily Challenge + Perl Weekly Challenge + Perl Monthly Challenge + Perl Yearly Challenge +- setup: + cleanup: + args: "'a{b{1,2},c{3,4}}d'" + input: + output: | + ab1d + ac3d + ab1d + ac4d + ab2d + ac3d + ab2d + ac4d diff --git a/challenge-029/paulo-custodio/t/test-2.yaml b/challenge-029/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..45d285dccc --- /dev/null +++ b/challenge-029/paulo-custodio/t/test-2.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: 2 3 + input: + output: 5 |
