From 4ec900b7ae56c5bffd86b2041d053224c1284bc4 Mon Sep 17 00:00:00 2001 From: Lars Thegler Date: Tue, 8 Oct 2019 14:27:28 +0200 Subject: Solutions for challenge 029 --- challenge-029/lars-thegler/perl5/.gitignore | 1 + challenge-029/lars-thegler/perl5/ch-1.pl | 33 +++++++++++++++++++++++++++++ challenge-029/lars-thegler/perl5/ch-2.pl | 17 +++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 challenge-029/lars-thegler/perl5/.gitignore create mode 100755 challenge-029/lars-thegler/perl5/ch-1.pl create mode 100755 challenge-029/lars-thegler/perl5/ch-2.pl 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); +} -- cgit