aboutsummaryrefslogtreecommitdiff
path: root/challenge-031/mark-senn/perl6/ch-2.p6
blob: 6ee3ff2722e066b9efaa19cadc011eed0d4444b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#
# Perl Weekly Challenge - 031
# Task #2
#
# Mark Senn, http://engineering.purdue.edu/~mark
# October 25, 2019
#
# From
# https://perlweeklychallenge.org/blog/perl-weekly-challenge-031#task-2
#     Create a script to demonstrate creating dynamic variable name,
#     assign a value to the variable and finally print the variable.
#     The variable name would be passed as command line argument.
#
# Perl 6 is in the process of being renamed Raku.
# Run using Raku v6.d;
use v6.d;

sub MAIN($name, $value)
{
    say "$name    $value";

    # Using
    #     my $$name = $value;
    # gave
    #     Cannot declare a variable by indirect name (use a hash instead?)
    #
    # Using
    #     ${$name} = $value;
    # gave
    #     Unsupported use of ${$name}; in Perl 6 please use $($name) for hard ref
    #     or $::($name) for symbolic ref
    #
    # Using
    #     my $::($name);
    # gave
    #     Cannot declare a variable by indirect name (use a hash instead?)
    my %hash;
    %hash{$name} = $value;
    %hash{$name}.say;
}