-
Notifications
You must be signed in to change notification settings - Fork 560
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
what should be output of perl -we 'print do { foreach (1, 2) { 1; } }' #265
Comments
From [email protected]If this were true, then
would print 17. But it prints Useless use of a constant in void context at -e line 1. I consider this (no return of foreach) as a bug, and report it as such. Ilya |
From @schwernIf Data::Dumper is to be believed, it returns an empty string. $ perl -MData::Dumper -wle "@a = do { foreach (1,2) { 1; } }; print Dumper \@a" Different from an empty do block. $ perl -MData::Dumper -wle "@a = do { }; print Dumper \@a" This explains why do { 17; foreach ... } complains about a useless constant. A while loop returns 0. $ perl -MData::Dumper -wle '$foo = 42; sub foo { $bar = 2; $foo++; while ($bar--) { 1; Changing this behavior can cause serious backwards compat issues. Consider the 1) Have foreach be "null" so the statement before it is what is returned from the block. That will alter subroutines such as: sub foo { Currently this will return an empty string. If we change the foreach behavior, it will 2) Have foreach return its last evaluated expression in its block. Similar problem. Any subroutine ending in a foreach loop will suddenly start returning I suppose it should be documented, but at this point it would likely be better to simply |
From [email protected]On Tue Jul 15 19:20:10 2003, schwern wrote:
Actually, that has changed: in my perl-5.10.0, while loop returns an So the situation is more consistent now. It's almost ten years since the ticket was started, almost 6 years since |
[email protected] - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#1085 (status was 'resolved')
Searchable as RT1085$
The text was updated successfully, but these errors were encountered: