aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-029/steven-wilson/perl5/ch-1.pl31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-029/steven-wilson/perl5/ch-1.pl b/challenge-029/steven-wilson/perl5/ch-1.pl
new file mode 100644
index 0000000000..4a122f9dbe
--- /dev/null
+++ b/challenge-029/steven-wilson/perl5/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+# Author: Steven Wilson
+# Date: 2019-10-09
+# Week: 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 strict;
+use warnings;
+use feature qw/ say /;
+
+my $cmd_line_arg = "Perl {Daily,Weekly,Monthly,Yearly} Challenge";
+say "The command line argument \"$cmd_line_arg\" should expand to:";
+
+if ( $cmd_line_arg =~ m/\{([\w\,]*)\}/ ) {
+ my @items = split /,/, $1;
+ for my $item (@items) {
+ my $string = $cmd_line_arg;
+ $string =~ s/\{[\w\,]*\}/$item/;
+ say $string;
+ }
+}
+