Re: References to hash elements?
[email protected] (Luke Palmer)
| Newsgroups | perl.perl6.internals,perl.ponie.dev |
|---|---|
| Message-ID | <[email protected]> |
Simon Cozens writes:
> > $a = $hash{bar};
>
> Here you used the copy constructor before taking the reference. It might look
> like an assignment operator, but it isn't. You're better off thinking that
> assignment doesn't exist. It's a copy constructor. It makes the PMC referred
> to by $a a copy of the PMC in $hash{bar}. Their values may be "equal" but
> they're two different PMCs.
>
> > $b = \$hash{bar};
>
> Here you didn't make a copy before taking the reference. No copy, only one
> PMC. It all works.
Indeed, and this separate PMC is probably the best way to think about
it, since we have in Perl 6:
$a := %hash{bar};
The operator C<:=> is just like a PMC C<set> as opposed to an C<assign>.
If, after this statement, one says:
$a = "baz";
One should expect that C<%hash{bar}> would turn into "baz";
Luke