%foo is a hash, @foo{@keys} is a hash slice and $foo{key} is a hash element. It has nothing to do with @foo and $foo at this point (except that if they are global, they share a glob).
\%foo is a reference to the same hash which can be assigned to $foo. Then, $foo->{key} is that element again.
%foo->{key} is wrong. -> should only be used with references and classes. To either call a method on the reference if its referent is blessed (or the LHS is a class), or to access an element in the refered hash or array. %foo is not a reference, so the arrow should not be used with it.
Perl 6 will no longer use sigils to indicate how the variable is used. In Perl 5, we use a different sigil if we use the hash differently. That is: % to get the entire hash, @ to get a slice and $ to get a single element. In Perl 6, we use % for hashes, % for hashes and %for hashes. That meas %foo{key} will be valid.
Your %foo->{key} relies on a bug in Perl 5. The same, translated to Perl 6 would be %foo.{key}, which would rely on a feature in Perl 6. That feature is automatic referencing, so that what you wrote is in fact (\%foo).{key}.
%foo->{key} is unclear because no experienced Perl coder is used to seeing the arrow operator with something that is not a reference or a class. What about unexperienced Perl coders then? Well, they don't understand what it means, try to find out and find that it is not documented. They will take for granted that it works, probably not knowing that you really meant $foo{key}.
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
In reply to Re: %h->{foo} vs. $h{foo}..
by Juerd
in thread %h->{foo} vs. $h{foo}..
by smferris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |