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

Re: [MacPerl] Multidimensional array question



At 10.41 -0500 1998.05.28, Mark Manning/Simulacron I wrote:
>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.  :-)

I am not sure I follow.  This works fine (not that I recommend it):

#!perl -wl
@array = (0..9, [0..9, [10..19, [20..30]]]);

# on-the-fly
print $array
 [$#array]
 [$#{$array[$#array]}]
 [$#{$array[$#array][$#{$array[$#array]}]}]
 [$#{$array[$#array][$#{$array[$#array]}]
   [$#{$array[$#array][$#{$array[$#array]}]}]}];

# making reference to each subarray first
$level{0} = \@array;
$level{1} = $level{0}[$#{$level{0}}];
$level{2} = $level{1}[$#{$level{1}}];
$level{3} = $level{2}[$#{$level{2}}];
print $array
  [$#{$level{0}}]
  [$#{$level{1}}]
  [$#{$level{2}}]
  [$#{$level{3}}];

# i know what i want!
print $array[10][10][10][10];

All of these access the same variable.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])



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