aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Thegler <lth@fibia.dk>2019-10-08 14:27:28 +0200
committerLars Thegler <lth@fibia.dk>2019-10-08 14:27:28 +0200
commit4ec900b7ae56c5bffd86b2041d053224c1284bc4 (patch)
tree0298d792b0f64da9bf32ace50bc64109615ef2f6
parent3e58d49a42a3288e79d19b3176425b7ccc2bfb9d (diff)
downloadperlweeklychallenge-club-4ec900b7ae56c5bffd86b2041d053224c1284bc4.tar.gz
perlweeklychallenge-club-4ec900b7ae56c5bffd86b2041d053224c1284bc4.tar.bz2
perlweeklychallenge-club-4ec900b7ae56c5bffd86b2041d053224c1284bc4.zip
Solutions for challenge 029
-rw-r--r--challenge-029/lars-thegler/perl5/.gitignore1
-rwxr-xr-xchallenge-029/lars-thegler/perl5/ch-1.pl33
-rwxr-xr-xchallenge-029/lars-thegler/perl5/ch-2.pl17
3 files changed, 51 insertions, 0 deletions
diff --git a/challenge-029/lars-thegler/perl5/.gitignore b/challenge-029/lars-thegler/perl5/.gitignore
new file mode 100644
index 0000000000..7d9ecbe3b8
--- /dev/null
+++ b/challenge-029/lars-thegler/perl5/.gitignore
@@ -0,0 +1 @@
+_Inline/
diff --git a/challenge-029/lars-thegler/perl5/ch-1.pl b/challenge-029/lars-thegler/perl5/ch-1.pl
new file mode 100755
index 0000000000..11a903d08d
--- /dev/null
+++ b/challenge-029/lars-thegler/perl5/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+use Modern::Perl;
+
+# 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
+
+my $input = shift;
+
+# identify the braces in the input string
+my ($brace) = $input =~ m/\{(.+?)\}/;
+
+unless ($brace) {
+ say $input;
+ exit;
+}
+
+# split brace content into its expansions
+my @expansions = split ',', $brace;
+
+# replace the brace with the expansion
+for my $expansion (@expansions) {
+ ( my $output = $input ) =~ s/(\{.+?\})/$expansion/;
+ say $output;
+}
+
+# ideas for extension of the task:
+# - support for multiple braces in command line argument \ No newline at end of file
diff --git a/challenge-029/lars-thegler/perl5/ch-2.pl b/challenge-029/lars-thegler/perl5/ch-2.pl
new file mode 100755
index 0000000000..1f9877079c
--- /dev/null
+++ b/challenge-029/lars-thegler/perl5/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use Modern::Perl;
+
+# Write a script to demonstrate calling a C function. It could be any
+# user defined or standard C function.
+
+use Inline 'C';
+
+greet( shift // 'world' );
+
+__END__
+__C__
+
+void greet(char* name)
+{
+ printf("Hello, %s!\n", name);
+}