Bart Lateur wrote: > Hmm... the problem is, I think, that array references and ordinary > scalars are both scalars. > That's true, but they're scalars with different interfaces. In particular, an array ref can be dereferenced and provides an array in doing so. If an index can do this, then it's a multidimensional index. Of course, this isn't how it would actually be handled internally, since it's inefficient, but this is how its language interface would look. > What would be the difference between > > $a[2] > > and > > $a[[2]] > > anyway? Aren't these just the same? > Nearly! From the RFC: <quote> When a listref is used to index a list of lists, the returned list reference is automatically dereferenced: my @array( [0,1], [1,2]); my @a = @array[[0]]; # Returns (0,1), _not_ [0,1] </quote> Indexing with an integer doesn't have this feature. I considered proposing adding it (so that all list context assignments dereference the rvalue if it's a list ref), but I think it would lead to too many incompatibilities with P5. > If so, why not grab back into the old box, and get the syntax for > "multidimensional hashes" in perl4? > > single dimension: $hash{$item} > > 2 dimensions: $hash{$item1, $item2} > > Note that because of the '$' prefix, this cannot be confused with a > narray slice: > > hash slice, not multidimensionanl hash: @hash {$item1, îtem2} > > So, the similar syntax for ordinary arrays would then be: > > $array[2, 3] > > not $array[[2, 2]] > > Please feel free to corrct me if I'm wrong. > The difficulty with this is that it's not clear how to specify a multidimensional slice. An index is either multidimensional, *or* a slice, but not *both*.Thread Previous | Thread Next