Does the first 1 autovivify the arrayref in $x (as $x->[0] = 1 would) or must $x already have an array ref in it? What happens if I do shift @$x? Is $x->[0] now an alias to $z and the alias to $y disappears? Or (unlikely) does it effectively do @{$x} = @{$x}[1..($#$x-1)] which amounts to
$y = $z;
$z = $x->[2];
$x->[2] = $x->[3];
....
$x->[$#$x - 1] = $x->[$#$x];
pop @$x;
Fun and games!
The second example one seems very odd to me. To me, it reads as alias(push(@x, $y)) but I guess perl doesn't parse it as that. Why do this rather than just alias $x[-1] = $y or should that be alias $y = $x[-1]?
So you can use , or = to separate the aliased things? And you can put alias on either side of the =?
Anyway, time for bed. I dreamt about object pascal last night, I hope I don't dream about aliases to night! | [reply] [d/l] [select] |
You still misundestand how Data::Alias works, and you seem to see too much magic where there is none. Data::Alias does no parsing, perl does the parsing, so all syntax is just perl's syntax. Like I said in the description, "alias" itself is a nop. To perl, it's thin air. In fact, if you look at the operations executed (-MO=Concise,-exec), for example for alias push @x, $y:
3 <0> pushmark s
4 <#> gv[*x] s
5 <1> rv2av[t3] lKRM/1
6 <#> gvsv[*y] sM
7 <@> push[t5] vK/2
- <1> ex-list vK
See the call to alias? Nope, it isn't even there, apart from a miniscule stub "ex-list" (a nop). Alias just changes the semantics of whatever is inside it, and in a very simple way: whereever perl normally copies data, aliasing occurs instead.
So, let's analyze the cases. Take $x = alias [$y, $z] for example. What does it do? The [$y, $z] is just the array constructor which normally creates a new array, fills it with copies of $y and $z, and returns a reference to the array. Within the scope of "alias", it therefore creates a new array, fills it with aliases to $y and $z, and returns a reference to the array, which it then normally assigned to $x.
alias push @x, $y is indeed as you noted parsed as alias(push(@x, $y)). This push would normally add a copy of $y onto the end of @x, so within "alias" it adds an alias to $y onto the end of @x. This obviously differs from alias $x[-1] = $y which would overwrite the last element of @x with an alias to $y.
You finally mentioned using a comma... ($x, $y) involves no copying, therefore alias($x, $y) does nothing remarkable. It behaves 100% identical to plain ($x, $y).
All cleared up now? :-)
Time for me to get some sleep too.. zZ | [reply] [d/l] [select] |
alias { push(@x, y) }
would give a clearer indication of what is going on. It would also cause problems with scoping when you want to use my:-(
| [reply] [d/l] [select] |