Hi,

Larry Wall wrote:
> On Fri, Sep 09, 2005 at 04:40:11PM +0200, Juerd wrote:
> : Ingo Blechschmidt skribis 2005-09-09 15:12 (+0200):
> : > I agree that the comma operator creates an anonymous array, but I
> : > do not agree that it behaves as if it has [] around it.
> : > 
> : > Creating an anonymous array does not require creating new
> : > containers --
> : 
> : So comma in scalar context creates an array of aliases? That would
> : be a welcome difference.
> 
> It might at that.  Though doubtless there is a downside I'm not seeing
> yet...

    ($foo, $bar) = ($grtz, $baka);
    say $foo, $bar;
    # <newbie>Hm, $foo and $bar are changed to $grtz respectively
    # $baka... So assigning to a list really assigns to the
    # elements of the list! So the comma operator constructs
    # a list of aliases, neat!

    # Now let's see whether the following works as well:
    ($foo, $bar)[0] = $grtz;
    # Ok, no error message.

    say $foo;
    # ...but why was $foo not changed?
    # I thought the comma operator constructs a list of
    # aliases...?</newbie>

Also note that the comma operator creating a list of aliases does *not*
affect regular [...] or assignment to an array:

    (1,2,3)[1]++;     # "Can't modify constant item 2"

    my @a = (1,2,3);  # @a's STORE method recognized that the RHS
                      # is an aggregate, so it created new containers.
    @a[1]++;          # No error
    say @a[1];        # 3

    [1,2,3][1]++;     # No error, &circumfix:<[ ]> assigned to an
                      # array internally, so new containers were
                      # created.

--Ingo

-- 
Linux, the choice of a GNU | Row, row, row your bits, gently down
generation on a dual AMD   | the stream...
Athlon!                    | 

Reply via email to