my @a = 1,2,3; my $a = 1,2,3;
These are
(my @a = 1), 2, 3; (my $a = 1), 2, 3;
if I understand precedence correctly. (S03)
right, sure. I vaguely remember something about comma instead of parens being the list constructor, but maybe it was just in my fantasy.
and thanks for the other clarifications too.
to summarize, I think a decent implementation of "splat" should do the following:
if the argument to unary * is... a normal value force list context and cast to 1-elem list a list nop an array cast to list an arrayref deref and cast to list
(I don't know if the use of "cast" is appropriate here. looks more like AST munging...).
(I don't like @a = []. It makes @a = ([]) be counter-intuitive (parens only group for precedence), and @a = [[]] feels VERY weird. Besides that, it makes @a = $b completely unpredictible if the type of $b is unknown. If it's an arrayref, @a gets all its elements, but if it's a normal value, @a gets only one element. That's a problem for general purpose modules/subs. I guess they could all use @a = [$b], but I find that ugly.)
in fact, S03 states:
"In list context, a scalar reference to an array does not flatten."
so I think @a = [1,2,3] should leave you with @a[0] = [1,2,3]. and you should use one of:
@a = *$b; @a = @$b; @a = $b[];
to make @a get all the elements of the arrayref in $b.
cheers, Aldo