in reply to Perl 6, differrence between ':=' and '='

As chromatic already explained, := creates an alias, while = puts a value into a container.

What's more is that = also enforces a context, so for example assigning to an array variable causes it to upgrade the right-hand side to an array. Binding doesn't:

$ perl6 -e 'my @a = 1, 2, 3; push @a, 4; say ~@a' 1 2 3 4 $ perl6 -e 'my @a := 1, 2, 3; push @a, 4; say ~@a' Method '!fill' not found for invocant of class 'Int' in 'List::push' at line 2617:CORE.setting in main program body at line 1

The error message isn't good, but what happened is that I tried to push onto a list of values (not to an Array, because the binding replaced the array variable with a List). A List is read-only, so it blew up.

Assigning to arrays is also eager, whereas binding doesn't evaluate lists at all:

my @a = gather for 1..3 { .say; take $_; } say "printing now..."; say ~@a; # produces 1 2 3 printing now... 1 2 3

But with binding, you get lazy evaluation of the gather/take construct:

my @a := gather for 1..3 { .say; take $_; } say "printing now..."; say ~@a; # produces printing now... 1 2 3 1 2 3

Only on accessing list items are they evaluated as needed.

Perl 6 - links to (nearly) everything that is Perl 6.