aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
+}