On 02.08.2015 06:43, Gabor Szabo wrote:

On Fri, Jul 31, 2015 at 4:16 PM, Moritz Lenz <mor...@faui2k3.org
<mailto:mor...@faui2k3.org>> wrote:

    On 07/31/2015 03:02 PM, Gabor Szabo wrote:

        The following code (with comments) is confusing me.
        Can someone give some explanation please?
        Specifically the difference between

        my @x = <a b>;

    It's the assignment to the Array variable that makes the Array here;
    < > by itself just creates a Parcel:

    $ ./perl6-m -e 'say <a b>.^name'
    $ ./perl6-m -e 'say (my @ = <a b> ).^name'

        # we can assign that array to a scalar variable and it is still
        and array
        my $y = @x;

    that's because assignment to $ isn't coercive in the same way as
    assignment to @ or %.

    It just wraps things into a Scalar, which is normally invisible.

    But, you can observe the difference still>

    my @a = <a b>;
    my $s = @a'

    for @a { } # two iterations
    for $s { } # one iteration

Thanks though this just shows I still don't get the whole sigil and
Array thing in Perl 6.
I thought you can put an array in a $ -ish variable and that will still
be a real array, but
now I see it is not an array.

It's an Array inside a Scalar.

If you want to extract it from the scalar, use the @ again, this time as a prefix:

for @$s { } # two iterations again.


Reply via email to