On 5/14/05, Larry Wall <[EMAIL PROTECTED]> wrote: > On Sat, May 14, 2005 at 01:36:22PM -0500, Rod Adams wrote: > : Larry Wall wrote: > : > : >On Sat, May 14, 2005 at 12:51:32PM -0500, Rod Adams wrote: > : > > : >: Unless, of course, there is some subtle difference between a 3-d hash > : >: and a hash of hashes of hashes that invalidates this. > : > > : >No difference, I hope. The multidimensional notation is meant > : >to extend to HoH and AoA transparently (as well as HoA and AoH). > : >Since a variable's dimensionality is always declared (and a container > : >object's dimensionality generated at "new" time), we shouldn't have > : >to worry about whether to add dimensions or autovivify a reference. > : >Either there's storage already allocated, or we autovivify. > : > > : > > : Hmm. So if I say: > : > : @a = [ { a => 1, b => 2}, { a => 3, b => 4 } ]; > : > : Can I then say: > : > : $x = @a[1;'b']; > : > : And get $x = 4? > > Probably not, but @a{1;'b'} might. I think what we've said before is > that .[] allows the optmimizer to assume numeric subscripting only, > while .{} is the more general form.
So, does this mean that I can do something like: @a = [ 1 .. 4 ]; $x = @a{2}; and have $x == 3? If so, is there any reason (other than clarity) to use the @a[] notation? The @ already indicates you have an array vs. the % which indicates hash. Is there a reason to have the subscripting notation also be different? I understand why it was different in P5, given that you needed to differentiate $x->[2] and $x->{2} and allow the reader to know whether $x was an arrayref or hashref. But, that need is gone from P6. (Isn't it?) Rob