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.

In reply to Re: Perl 6, differrence between ':=' and '=' by moritz
in thread Perl 6, differrence between ':=' and '=' by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.