diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -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 |
6 files changed, 77 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index ba8194b15c..040286b6c4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,8 @@ go.mod go.sum tags +# Perl Inline module +_Inline + # Rust languageoutput directory target/ 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 |
