-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation of backslash operator inducing list context for its operand is missing #15932
Comments
From @hakonhaglandI could not find any documentation for the following behavior: $ perl -E '$s =\sort qw(a b c); say $$s' According to the documentation for sort, the behavior of sort in scalar $ perl -E '$s = sort qw(a b c); say "undef" if !defined $s' Apparently when using the backslash operator, sort does not consider I checked the following documentation: http://perldoc.perl.org/perldata.html#List-value-constructors See also: http://stackoverflow.com/q/42996519/2173773 Best regards, |
From zefram@fysh.orgHakon Haegland wrote:
Indeed, it is in list context. If we perform the sort statically, $s = \qw(a b c); and the refgen distributes, making this effectively $s = (\"a", \"b", \"c"); which ultimately behaves as $s = \"c";
No. Undefined behaviour means there is no specific thing that it There is no bug here, in either the behaviour or the documentation. -zefram |
The RT System itself - Status changed from 'new' to 'open' |
From @hakonhaglandThanks for the quick reply!
That is exactly what I am asking. Why is it list context? On the $ perl -E '$s =\sort qw(a b c); say $$s' I can make it list context by for example writing: $ perl -E '( 2017-03-25 23:37 GMT+01:00 Zefram via RT <perlbug-followup@perl.org>:
|
From Eirik-Berg.Hanssen@allverden.noOn Sat, Mar 25, 2017 at 11:36 PM, Zefram <zefram@fysh.org> wrote:
Well, the documentation is not wrong. But I'd argue it is lacking. Given how important context is when programming in Perl, I'm surprised I note that among the Symbolic Unary Operators, C<< \ >> is the only one That the others impose scalar context is consistent with the "default" That C<< + >> propagates context is implied (but IMO could better be That C<< \ >> imposes list context is not even implied by perlop. It seems to me Less Than Awesome that this exception for C<< \ >> is not Eirik |
From zefram@fysh.orgHakon Haegland wrote:
Because the refgen operator supplies list context to its operand. -zefram |
From zefram@fysh.orgEirik Berg Hanssen wrote:
Yes, good point. I agree that the context behaviour of \ in particular -zefram |
From @khwilliamsonOn Sun, 26 Mar 2017 01:10:47 -0700, zefram@fysh.org wrote:
Can someone suggest a patch? |
From @cpansproutOn Wed, 03 May 2017 09:25:15 -0700, khw wrote:
I am too busy right now to suggest a patch, but I can outline the behaviour, including details that are currently undocumented: \ gives its operand list context, regardless of its own context, but it behaves specially when it comes to sigilled items. \@foo and \%foo do not flatten the aggregate. Similarly, \&foo does not call the subroutine. Parentheses around an aggregate (\(@foo), \(%foo)) cause flattening, but make no difference to other sigils. Those parentheses only have that effect when they surround nothing else (except perhaps a unary + or trailing comma). So: \(@foo, @bar) # does not flatten either array -- Father Chrysostomos |
From zefram@fysh.orgDocumentation patched in commit 39dc9d1. -zefram |
@cpansprout - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for filing this report. You have helped make Perl better. With the release yesterday of Perl 5.28.0, this and 185 other issues have been Perl 5.28.0 may be downloaded via: If you find that the problem persists, feel free to reopen this ticket. |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#131061 (status was 'resolved')
Searchable as RT131061$
The text was updated successfully, but these errors were encountered: