Date: Sun, 9 Sep 2001 01:05:23 +0200 From: peter pilsl Subject: Re: sudhir: array references. Message-Id: <3b9aa444$1@e-post.inode.at> Sudhir Krishnan wrote: > Thanks for the response! > I've tried both setting and retrieving the values in the array as: > > a[i][j][k]=value; > and it seems to work. > is this implicitly the same as a->[i]->[i][k]; ? > no. $a[i][j][k] will work when @a is defined as array containing anonymous arrays. When $a is defined as anonymous array itself, you must use the '->' operator. @a=([1,2],[3,4]); $a[1][1]=4; # OK !! $a->[1][1]=4; # ERROR, cause $a is not defined yet, only @a $b=[[1,2],[3,4]]; $b->[1][1]=4; # OK !! $b[1][1]=4; # ERROR, cause @b ist not defined, only $b but the following is also possible: $a[1]->[1]=4; $b->[1]->[1]=4; You can use or ommit the '->' in the latter indeces as you like, but usage before the first index is strictly required _XOR_ strictly forbidden, depending how you defined your structure. When using $a[i][j][k] then perl will implecitely build a structure similar to my first example. > $#{$a} #DOES NOT WORK (I usually get -1) > > Would u happen to know why the 3rd case does not work? > Cause you use a structure like I used in my first example. cause $a is not a reference but @a is an array. You might try $#a instead and it will work. I recommend not let perl build your structures implecitely, but preset your structures (and preallocate if using large matricces) to make yourself clear about the structure. As I said in my last posting, I personally prefer the structure in the second example much more than the other, cause using references as parameters in functions is much easier than using arrays. best, peter -- peter pilsl pilsl_@goldfisch.at http://www.goldfisch.at