Copy a string

Author: Salve J. Nilsen

This task is about copying a string. Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string.

More

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

Source code: 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."
}