in reply to Re^2: How to reference to array keys?
in thread How to reference to array keys?
If I am thinking correctly it just checks for line that start with a "/". Right? Yes, Right!I see you have a link to some more info on references, I'll hit a few highlights specific to this code.
%recordState is a hash with basically 2 keys. In a complex data structure, everything is a reference until you get to the very last dimension where the data is. The value of $recordState{$record_id} is a reference to a another hash. The key to that hash is $OwnwerOrWaiting which is either set to "OWNER" or "WAITING" and the value is a reference to an array of input lines. Look at the output of Data::Dump and see the "key => value" pairs.
Also take a look at my dump loop, foreach my $recHashref ( values %recordState). There I didn't even use the $record_id key at all! I just get the values of the first dimension hash, where are references to the 2nd dimension hash. In the line
print "WAITING $_\n", for @{$recHashref->{WAITING}};
$recHashref is dereferenced and the WAITING key is accessed. The values of that key is a reference to an array of lines. I say that that whole thing, $recHashref->{WAITING} is an array reference that I want to dereference by enclosing it in another set of curly braces and putting an @ in front. Each line gets printed out. Note that I used the exact same code pattern for OWNER as for WAITING. There is only one OWNER and that could have been:
print "OWNER $recHashref->{OWNER}[0]\n"; which would mean give me the 0th line in the array pointed to by $recHashref->{OWNER}. There is a certain value in uniformity and so I did not handle the case of just one OWNER separately.
Maybe I confused you even more, but it this was remotely understandable, then the answer to you question above is that value of $recordState{$record_id}{$OwnerOrWaiting} is a reference to an array, which is dereferenced with the @ so that the current line can be pushed onto it.
It could very well be that the data structure can be simplified once I read more about what you are needing as an end result.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to reference to array keys?
by mmartin (Monk) on Jul 28, 2011 at 13:34 UTC | |
|
Re^4: How to reference to array keys?
by mmartin (Monk) on Jul 28, 2011 at 19:39 UTC | |
by jethro (Monsignor) on Jul 28, 2011 at 23:46 UTC | |
by mmartin (Monk) on Jul 29, 2011 at 13:24 UTC |