aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoelle Maslak <jmaslak@antelope.net>2019-10-27 12:51:21 -0600
committerJoelle Maslak <jmaslak@antelope.net>2019-10-27 12:51:21 -0600
commit1e6fc0b5b79f567429b1c76bbbd0d0e1bb8cd517 (patch)
tree70ca4ae21eeaa3197757a7688712db871df7bc77
parentb06bfa34831dcbd0f6211c4a07b4cb0d8450d94a (diff)
downloadperlweeklychallenge-club-1e6fc0b5b79f567429b1c76bbbd0d0e1bb8cd517.tar.gz
perlweeklychallenge-club-1e6fc0b5b79f567429b1c76bbbd0d0e1bb8cd517.tar.bz2
perlweeklychallenge-club-1e6fc0b5b79f567429b1c76bbbd0d0e1bb8cd517.zip
Joelle's solutions to 31.2 in Raku and Perl.
-rwxr-xr-xchallenge-031/joelle-maslak/perl5/ch-2.pl19
-rwxr-xr-xchallenge-031/joelle-maslak/perl6/ch-2.p616
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-031/joelle-maslak/perl5/ch-2.pl b/challenge-031/joelle-maslak/perl5/ch-2.pl
new file mode 100755
index 0000000000..316e18ed0d
--- /dev/null
+++ b/challenge-031/joelle-maslak/perl5/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use v5.14;
+# use strict; Nope!
+use warnings;
+
+if ( @ARGV != 2 ) { die("Provide variable name and value") }
+
+# Note all sorts of bad things can still be done with this code - like a
+# user might pass in the name of an existing variable, might start a
+# variable name with a number, etc. We make it safer but not safe.
+
+my $varname = $ARGV[0];
+my $value = $ARGV[1];
+
+die "Invalid variable name" if $varname !~ m/^ \w+ $/s; # Doesn't catch everything
+
+$$varname = $value;
+say "\$$varname = $value";
+
diff --git a/challenge-031/joelle-maslak/perl6/ch-2.p6 b/challenge-031/joelle-maslak/perl6/ch-2.p6
new file mode 100755
index 0000000000..73cf0d97ee
--- /dev/null
+++ b/challenge-031/joelle-maslak/perl6/ch-2.p6
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl6
+use v6;
+
+use MONKEY-SEE-NO-EVAL;
+
+# Note all sorts of bad things can still be done with this code - like a
+# user might pass in the name of an existing variable, might start a
+# variable name with a number, etc.
+
+sub MAIN(Str:D $var-name, $value) {
+ die "Invalid variable name" if $var-name !~~ m/^ \w+ $/; # Doesn't catch everything
+ EVAL("my \$OUR::$var-name = { $value.perl }");
+ EVAL("say '\$$var-name is set to: ' ~ \$OUR::$var-name");
+}
+
+