At 01:00 AM 6/18/01 -0500, Teresa Raymond wrote:
>I'm sorry, but I mean could you explain the syntax of the whole line.

Always ask the list, not an individual respondent.  I may be gone for a 
month in Antarctica or something.

>>At 10:08 PM 6/17/01 -0500, you wrote:
>>>Could you please explain this syntax?  Why does people not have a $ sign?
>>
>>Because it didn't in the code you posted.  I was following your syntax, 
>>which made 'people' a literal key.
>>
>>>>  foreach my $person (@{$state{$city}{$street}{people}}) {

Okay, here's a syntax-reading explanation:

         foreach my $person (@{$state{$city}{$street}{people}})

reads as

         foreach my $person (LIST)

i.e., set a lexical variable $person to each member of LIST in turn for the 
duration of a block to follow.  The scope of $person will be that 
block.  Now, what is LIST?

         @{$state{$city}{$street}{people}}

reads as

         @{something returning reference to ARRAY}

What returns the arrayref?

         $state{$city}{$street}{people}

Which can be written (using the knowledge that arrows are implied between 
adjacent curlies and square brackets) as

         $state{$city}->{$street}->{people}

Because the arrows are evaluated left-to-right, we dissect them 
right-to-left, hence

         Something returning hashref->{people}

We are getting the element whose key is 'people' from a hash referenced by 
something.  By what?

         $state{$city}->{$street}

Which by the same token is:

         Something returning hashref->{$street}

We are getting the element whose key is $street from a hash referenced by 
something.  By what?

         $state{$city}

That is the element whose key is $city from the hash %state.  Now we can 
put it all together:

         foreach my $person (@{$state{$city}{$street}{people}})  means:

Set the lexical $person in turn to each of the members of the array 
referenced by the element with key 'people' in the hash referenced by the 
element with key $street in the hash referenced by the element $city in the 
hash %state.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com

Reply via email to