Hi,
Juerd <juerd <at> convolution.nl> writes:
> Ingo Blechschmidt skribis 2005-09-06 21:24 (+0200):
> > > \(@array,) is [ @array ], NOT map { \$_ } @array
> > I'm not sure of the []s, remember &postcirumfix:<[ ]> creates *new*
> > containers:
>
> That was the point.
>
> > [EMAIL PROTECTED] = $bar;
> > (@array,)[0] = $bar;
>
> AFAIK, these are the same thing, because the left side of [0] is in
> Array context, which is a scalar context, in which comma creates a new
> anonymous array ref.
To prevent misconceptions: You think that both
[EMAIL PROTECTED] = $bar; # and
(@array,)[0] = $bar;
change @array[0] to $bar, right?
If so, I have to disagree. Consider:
(my $arrayref = [1,2,3])[1] = 42;
If &postcircumfix:<[ ]> did *not* create new containers, this
statement would fail ("Can't modify constant item 2") instead of
setting $arrayref[1] to 42.
Similarily,
(my $arrayref = [$foo])[0] = 42;
would not set $arrayref[0] to 42 and leave $foo untouched, but
would set $foo to 42. I don't think this is correct.
To clarify my view with code: I think &postcirumfix:<[ ]> could
be implemented like this:
sub *postcircumfix:<[ ]> ([EMAIL PROTECTED]) {
# Explicitly copy @elems:
my @array = @elems;
return [EMAIL PROTECTED];
}
And, presuming that I've understood you correctly, then you
would implement &postcirumfix:<[ ]> like this:
sub *postcircumfix:<[ ]> ([EMAIL PROTECTED]) {
# Do *not* copy @elems here
return [EMAIL PROTECTED];
}
(But note that I may be completely wrong, of course.)
--Ingo