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

Re: [MacPerl] Multidimensional array question



Mark Manning/Simulacron I writes:
|	for( $i=0; $i<=$#myArray; $i++ ){
|		print $myArray[$i], "\n";
|		}

or

for( $i=0; $i<@myArray; $i++ ){

|	while( <THEFILE> ){
|		$myArray[++$#myArray] = $_;
|		}

or

	while( <THEFILE> ){
		push @myArray, $_;
		}

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

Sure they do, you just need to get the syntax right. Consider:

$myArray[1][2][3] = 'Hello, earth';

Then the following are all true:

$#myArray == 1 && @myArray == 2
$#{$myArray[1]} == 2 && @{$myArray[1]} == 3
$#{$myArray[1][2]} == 3 && @{$myArray[1][2]} == 4

Brian

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