* Bill Gradwohl <[EMAIL PROTECTED]> [2006-01-11T09:08:15]
> while ( ($k,$v) = each %father ) {
>     push( @{ $children{$v} }, $k );
> }
> 
> It's the push line I'm having difficulty with. Here's what I understand:
> 
> The outermost {} can be removed to simplify it to : 
>       push( @$children{$v}, $k);

You understand incorrectly.

If it was  @{ $foo } you could simplify to @$foo, but you cannot
simplify what you see to what you said.

@{ $children{$v} } means:
  get the scalar stored in $children{$v} (which is an entry in
  %children) and dereference it as an array

In other words:

  my $entry = $children{$v};
  @$entry;

@$children{$v}, which you suggested, would mean:

  get the hash slice of all entries in the hash to which $children
  refers, containing the following keys: $v

In other words, with an only slight change in meaning:

  my $hashref = $children;
  my %hash = %$hashref;
  @hash{($v)};

-- 
rjbs

Attachment: pgpLcFGLnrHgf.pgp
Description: PGP signature

Reply via email to