Am Montag, 2. Mai 2005 21.27 schrieb Matthew Sacks: Hi Matthew,
it seems indeed strange... > I am reading somebody else's code, always a good learning process. The code > is about a telephone contact list. The intent of this line of code is > clear: 'does the logged in person have a cell phone, and does the cell > phone have the attribute line=dc' > > There is one confusing step in the syntax: > > if ((@{$info{$loggedin}}{cell}) and > (@{$info{$loggedin}}{line} eq 'dc')) > {stuff to > execute} We have two similar data structures, one of it is @{$info{$loggedin}}{line} eq 'dc' > When I read the condition, this is what I se > a) $loggedin is scalar > b) $loggedin is used as a hash key > c) info is a hash > d) since we retrieve on thing from the hash, there is a '$' in front of > info > e) $info{$loggedin} is enclosed inside @{} > f) @{} is a way of derefencing an array reference. > g) $info{$loggedin} is inside @{}, so we have @{$info{$loggedin}} > h) does @{$info{$loggedin}} evaluate to an array? That would confuse me > because {cell} imposes {} on an array? > i) does @{$info{$loggedin}}{cell} retrieve something from a hash? Also a > confusion, because of the @ This point confused me too, so I did: use strict; use warnings; use Data::Dumper; my %hash=(a=>'b'); my %info; my $loggedin=99; # :-) @{$info{$loggedin}}{line}='ec'; @{$info{$loggedin}}{cell}=1; print Dumper %hash; print Dumper %info; # this prints: $VAR1 = 'a'; $VAR2 = 'b'; $VAR1 = '99'; $VAR2 = { 'cell' => 1, 'line' => 'ec' }; The conclusion of this: The top level data structure is a hash with one key/value pair. But I can't see/explain _how_ the key is exactly coming from $loggedin... The gurus on the list will have the obvious answer. > j) Where am I going wrong???? My feeling is that the coder was somehow wrong, maybe he did not want this data structure, it's just the result of a typo. But it seems that it is functional because the right values are tested in the condition. I think the coder wanted a simple $info{$loggedin}->{line} = 'dc' (build a hash of hashes, but also with just one pair at the top level) Also and still confused, joe P.S. Just read Paul Kraus's Confusion - we're not alone :-) [...] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>