Kevin Viel wrote:
Consider the following anonymous array of anonymous arrays:

my $a = [ [ 00 , 01 ]
        , [ 10 , 11 ]
        ] ;

I can print the first element of the first anonymous array:

print "$$a[ 0 ][ 0 ]\n" ;

or, equivalently, I can explicit use bracers to dereference it:

print "${$a}[ 0 ][ 0 ]\n" ;

OK

But they're 'braces' :)

Should I not need two pairs of bracers?

The 'missing' pair of braces is because you're using both of the two
different syntaxes for indexing a referenced array. The first element of
the outer array is either

  ${$a}[0]      (which can be written $$a[0] without ambiguity)

or

  $a->[0]

These are references to the first inner array, which can also be indexed
in either way. So we have four ways of reaching the first element of the
first inner array:

  ${${$a}[0]}[0]

  ${$a}[0]->[0]

  ${$a->[0]}[0]

  $a->[0]->[0]

In addition, Perl allows us to remove the arrow operator between pairs
of closing and opening brackets or braces - ][ or }{, so the second and
last options can be written

  ${$a}[0][0]

  $a->[0][0]

and so your code turns out to be the same as the first of these two. If
you use the same syntax for indexing in both cases then the second pair
of braces reappears. It is also the same as your final example below.

$a is a reference to the anonymous array.  The elements of the
> anonymous arrays are references to anonymous arrays, correct?

They are references to arrays, yes. They may be named arrays or
anonymous ones.

The following seems to achieve this result:

print "${${$a}[ 0 ]}[ 0 ]\n" ;
>
Is the outmost pair of bracers with the appropriate symbol ($, @, %) the
default?  If so, how does perl select the correct symbol?

I'm not sure what you mean here: you have explicit dollar signs in this
code for both dereferences. Perl has no default way of handling
references, but it will complain if you try to use a reference to one
type of data as something different.

I realize that it is seemingly moot, but it may help my understanding of
more complex structures, like hash of arrays or hash of hases.

Don't get to like them to the extent that you use them when your data
isn't shaped that way. They are a way of expressing hierarchical data
only.

HTH,

Rob



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to