Open ikegami opened 4 years ago
Note that perlop doesn't explicitly mention ->@{...}
, only that "the dereferencing cases (as opposed to method-calling cases) are somewhat extended by the postderef feature." The postderef feature is a no-op in 5.24+, so this part of the docs could clearly use some work.
That sentence is more referring to the postderef feature in the abstract, rather than the specific feature.pm argument. Perhaps it could be reworded to "postfix dereference syntax" like the referenced perlref section.
backref: https://stackoverflow.com/questions/61237808/is-postderef-syntax-on-hashes-supported
backbackref: conversation on irc.freenode.org#perl 2020-04-15T2:02:00 UTC-0700
Or conversely, re-allow %foo->{key}
. Some might prefer doing %foo->@{...}
over @foo{...}
. It's the inconsistency that's the problem.
Allowing %foo->{key}
would not make any sense, I can't fathom it was anything other than a bug to begin with. That is a dereference operation and a hash is not a reference, at best you could expect it to use the number of keys in the hash as a symbolic ref (not to mention that it's never worked on arrays).
You are gravely mistaken about what people expect :) Personally, I prefer limiting it to references, but it would not be contrary to expectations for it to work on %foo
, and it would be in the spirit of least surprise in some ways (and thus TIMTOWTDI).
The expectations of people that misunderstand Perl's syntax are not a good target for syntax extensions.
We're talking about what the syntax should be, so people's expectations are relevant. Furthermore, we're talking about syntax that's been valid for 20 years, so it's kinda disingenuous to say they are mistaken in their understanding. Finally, I didn't say people might expect %foo->@{...}
; I said people might prefer %foo->@{...}
, meaning it might be something worth providing.
While indeed efforts are made toward bugwards compatibility, it is still just that, and I know of no significant usage of this syntax that would warrant more than the deprecation and removal it had. Regarding its worth, it is certainly not worth providing a new syntax inconsistent with the rest of Perl that would create expectations of other random syntaxes by extension.
| a new syntax inconsistent with the rest of Perl
Except it's not. There's a 20 year history of non-references being accepted on the LHS of ->. Then there's keys(%h)
, push(@a, ...)
, etc. Hardly inconsistent! That's why I suggested it might be worth formalizing the concept.
I don't much care about this, but I found it intuitive as-is. I'm ok with the modification in behavior. To clarify the confusion: from my read of postderef
it's mainly some kind of acknowledgement that sigils are a failure/losing battle and we should try something else. It seems of limited use to provide,
my %foo = ( foo => 1, bar => 2 );
my $bar = \%foo;
$bar->@{qw(foo bar)};
As a stylistically better (though longer) alternative to
@$bar{qw(foo bar)};
But to have a discontinuity between a slice from a ref, and a slice from a hash like,
$bar->@{qw(foo bar)};
@foo{qw(foo bar)};
Perhaps I was wrong, but it seems like the advantage of postderef
was that sigils on use didn't have to change from the sigils on declaration. It seems like that read was wrong though and these serve a different function.
This is a bug report generated with the help of perlbug 1.41 running under perl 5.30.2.
The left side of
->
is supposed to be an expression that returns a reference.But
%foo->@{...}
works.Note that
%foo->{a}
used to work, but it was deemed to be a bug. It was deprecated in 5.12, and fixed in 5.22. The same should be done to%foo->@{...}
. I haven't tested any of the other postfix dereference syntaxes to see if they have the same problem.- ikegami