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