develooper Front page | | Postings from September 2000

Re: RFC 204 (v2) Arrays: Use list reference for multidimensional array access

Thread Previous | Thread Next
Bart Lateur
September 25, 2000 14:53
Re: RFC 204 (v2) Arrays: Use list reference for multidimensional array access
Message ID:
On Fri, 22 Sep 2000 08:58:10 +1100, Jeremy Howard wrote:

>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.

That worries me. I'd like to avoid to repeat the fiasco of having the
same code have different kinds of behavious, depending on the contents
of a variable, as we have with symbolic references versus anonymous

What will this return?


It looks like a plain and simple array item, but what if $index is an
array ref?

>> What would be the difference between
>> $a[2]
>> and
>> $a[[2]]
>> anyway? Aren't these just the same?
>Nearly! From the RFC:
>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]

Puh. I'd prefer

	my @a = @$array[0];

which is shorter anyway.   ;-)  Currently, this does the wrong thing,
and I think that maybe the prefix precedence should be fixed so that


is the same as


Or doe people find it intuitive that this returns a slice of an array
pointed to by $ary?

>> 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*.

You are right in that. You cannot get a hash slice of a Perl4 style
"multidimensional" hash. A major stumbling block.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About