Bill Gradwohl wrote:
I think I might be on to an explanation for the following line of code:
push( @{ $children{$f} }, $c );
If someone would be so kind as to verify this for me, I'd appreciate it.
1) push $c onto the array specified by @{$children{$f}}.
Yes.
2) $children{$f} must return a scalar array reference because the
surrounding @{..} expects a scalar array reference.
It doesn;t "return" anything, it "is" this or that. It needs to "be" and
array ref, but yes that is correct :)
3) $children{$f} causes the %children hash to be created via
autovivification.
Perhaps, maybe %children is created maybe $children{$f} is created as an
array ref. I'd try it and see.
This is another example of why one should always
use strict;
use warnings;
because that wouldn't even be a question if it was done properly
4) Once %children is created, $children{$f} is set equal to an array
reference which is what it must return.
Have you tried it?
perl -mstrict -MData::Dumper -wle 'my %x;push @{ $x{123} }, "abc";print
Dumper \%x;'
5) That array reference causes an anonymous array to be created via
autovivification, and the array reference points to that array.
Isn't this the same question as #4 ?
6) Therefore, for example, $children{Adam} is linked to an anonymous
array via the reference stored as the value for that key.
Correct, but again "Best practicces:
$children{'Adam'}
is indeed []
7) The push then pushes $c on to that anonymous array.
yes
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>