复制字符串

作者:Stephen "thundergnat" Schulze

此任务是关于复制字符串。在相关的情况下,区分复制字符串的内容与对现有字符串进行额外引用。

更多

http://rosettacode.org/wiki/Copy_a_string#Raku

源代码: copy-a-string.pl

use v6;

# There is no special handling needed to copy a string.
{
    my $original = 'Hello.';
    my $copy = $original;
    say $copy;            # prints "Hello."
    $copy = 'Goodbye.';
    say $copy;            # prints "Goodbye."
    say $original;        # prints "Hello."
}

# You can also bind a new variable to an existing one so that each refers
# to, and can modify the same string.
{
    my $original = 'Hello.';
    my $bound := $original;
    say $bound;           # prints "Hello."
    $bound = 'Goodbye.';
    say $bound;           # prints "Goodbye."
    say $original;        # prints "Goodbye."
}