--- "Randal L. Schwartz" <[EMAIL PROTECTED]> wrote:
> (aside to the rest of the experts: Perl doesn't have multidimensional
>  arrays, people.  Let's please stop confusing the newbies by calling
>  it that.)

A very good point. I hesitate to ask what how we *should* refer to it,
but the apparent multidimensionality of Perl's arrays is functional,
not structural. 

For the Nu-B's:

An array in Perl holds only scalars, and only in one dimension.
References, however, are scalars, and the syntax

  $array[$a][$b]

is actually a reduced/simplified way to say

  $array[$a]->[$b]

which means that $array[$a] is a reference to an array, 
and to go get the [$b] element out of that. This carries to subsequent
levels, and applies for hashes as well, so

  $this[0]{foo}[0]

is really 

  $this[0]->{foo}->[0]

To put that into slightly more easily parsed steps, you could get the
same general effect as

  my $cell = $this[0]{foo}[0];
 
by saying:

  my $ref1 = $this[0];     # the first "dimension" 
  my $ref2 = $ref1->{foo}; # the second, a hash this time
  my $cell = $ref2->[0];   # the zero element of @{ $ref2 }

except that this way requires more variables. The shortened syntax does
all this behind the scenes, but still goes through the general
gyrations to get to the same memory location.

Which is why

  $hash{"$a $b $c"} 

is sometimes much more efficient than

  $hash{$a}{$b}{$c}

The first version just has to do a string catenation and one lookup;
the second has to do three lookups.

(And as always, if I fumbled something, please tell me. =o)

Paul

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to