[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Multidimensional array question



>Now the drawback:  So far as I know, multidimensional arrays do not
>contain a "$#" variable for anything other than the first entry of an
>array.  Thus:
>
>	$myArray[$#myArray][$#subScript1][$#subScript2]
>
>do not exist.  Chris?  Paul?  Matthias?  Am I wrong about this?  If so -
>let me know too.  :-)

Hmmm... allow me to take a shot at this.

how about...

$myArray[$#myArray][$#{$myArray[$#myArray]}][$#{$myArray[$#{$myArray[$#myArray]}
]}]

which looks like...
		$myArray[$#myArray]
	    [$#{$myArray[$#myArray]}]
[$#{$myArray[$#{$myArray[$#myArray]}]}]

if you line up the sqare brackets.

:)

why?  as far as I know, $myArray[ somenumber ] refers to an array reference,
and $myArray[ somenumber ][ anothernumber] is another array reference.  And
$myArray[ somenumber ][ anothernumber ][ whenisthisgonnaend ] is a scalar.
So I'll refer to the last indexed value of the array reference.

Knowing the above, you can probably predict the results of this code snippet.

===== code snippet =====
@thisray = (
   [0, 1, 2],
   [a, b, c, d],
   [0, 1, 2, 3, 4, 5]
   );

print $#thisray, "\n";
print $#{$thisray[0]}, "\n";
print $#{$thisray[1]}, "\n";
print $#{$thisray[2]}, "\n";
===== end code snippet =====

-- Gene



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch