-
Notifications
You must be signed in to change notification settings - Fork 580
Infinite loop 'while( each { 1=>'a' } )' #14706
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
Comments
From @KES777This is a bug report for perl from kes-kes@yandex.ru, #!/usr/bin/perl use Modern::Perl; my $val = { 1 => 'a' }; #test 1 OK #test 2 OK (Why this work if "Type of argument to each on reference must be unblessed hashref or arrayref at ./test.pl line 18." #test 3 FAIL not Expected #test4 OK as Expected (see perldoc each) #test 5 FAIL not expected (infinite loop) #test 6 FAIL not Expected (infinite loop) __END__ May you tell me please where I can view status of this BUG report? Flags: Site configuration information for perl 5.18.2: Configured by Debian Project at Thu Mar 27 18:28:21 UTC 2014. Summary of my perl5 (revision 5 version 18 subversion 2) configuration: Locally applied patches: @INC for perl 5.18.2: Environment for perl 5.18.2: |
From @KES777Subject: Infinite loop 'while( each { 1=>'a' } ) This is a bug report for perl from kes-kes@yandex.ru, #!/usr/bin/perl use Modern::Perl; my $val = { 1 => 'a' }; #test 1 OK #test 2 OK (Why this work if "Type of argument to each on reference must be unblessed hashref or arrayref at ./test.pl line 18." #test 3 FAIL not Expected #test4 OK as Expected (see perldoc each) #test 5 FAIL not expected (infinite loop) #test 6 FAIL not Expected (infinite loop) __END__ May you tell me please where I can view status of this BUG report? Configured by Debian Project at Thu Mar 27 18:28:21 UTC 2014. Summary of my perl5 (revision 5 version 18 subversion 2) configuration: Locally applied patches: --- --- |
From @jkeenanOn Sat May 16 00:56:18 2015, kes-kes@yandex.ua wrote:
To report a possible error in Perl itself, you should submit the bug report in a manner in which other possible causes of the error are excluded. Modern::Perl is a library which, if I recall correctly, tries to provide a lot of functionality which has become popular among Perl programmers in the last decade, but it is nonetheless a library which might handle situations differently from Perl itself. So, for the balance of my response, I'm going to proceed as if you had *not* said 'use Modern::Perl'. But I will assume at least Perl 5.18.2 -- the version from which you are filing this bug report -- and I will assume 'use strict;' and 'use warnings;'.
This first gets a warning and then a failure message: Type of argument to each on reference must be unblessed hashref or arrayref at 125205.pl line 18. See: 'perldoc -f each'. The way you are using 'each' above is neither on a hash nor on an array but on its third, experimental version: "a scalar EXPR, which must hold reference to an unblessed hash or array." Your expression does not hold a reference; hence the error.
Since I have to go AFK now, I'll leave analysis of these two cases to others. Thank you very much. -- |
The RT System itself - Status changed from 'new' to 'open' |
From [email protected]kes-kes@yandex.ua wrote:
It works because this isn't "each on reference". It's the old-style
This creates a fresh hash each time round the loop, via the {} constructor
Same again, this time using each on the reference. -zefram |
From @demerphqOn 16 May 2015 at 09:56, KES <perlbug-followup@perl.org> wrote:
As far as I can tell, and I think Zefram agrees, this is not a bug. Yves |
From @kentfredric
At best, one could potentially submit documentation for perlfunc/each to -- *KENTNL* - https://metacpan.org/author/KENTNL |
From @jkeenanSince this is not a bug in Perl, I am taking the ticket for the purpose of closing it within 7 days unless there is further discussion. -- |
From @KES777
I do not agree with you. for( keys { 1 => 'a', 2 => 'b' } ) { As you say this must also creates a fresh hash, but it does not.
Becase 'each' access internal iterator of hash in same manner as 'keys'/'values' do. You can use this iterator. 1. What is the benifit of recalculating argument of 'each' for every 'while' iteration? 2. Does this broken in compare to 5.12? print shift split ' ', '1 2'; 3. Can I force hash for ( 1 => 'a', 2 => 'b' ) without temporary variable? maybe like: or force to not calculate 'each's EXPR on 'while' iterations: |
From [email protected]KES wrote:
Different case. A while loop evaluates its conditional expression each
It creates a fresh hash once per execution of the whole foreach loop.
That's what it does, wasteful or not. Except that technically we don't
This refers to the well-known side effect that the keys and values You can see this resetting effect by comparing these two loops: $ perl -lwe '%a=(a=>1,b=>2,c=>3); while ($_ = each %a) { print $_; }' This means that there is practical utility in that `wasteful' behaviour
The keys operator does all the hash iteration in one go. With the choice
It is fundamental to the while operator that it evaluates the conditional my $h = { 1 => "a", 2 => "b" };
shift is another of the operators to which the experimental implicit
That doesn't quite make sense, because you don't have a hash constructor
is precisely possible, using a module from CPAN: use Memoize::Once qw(once); See also the quite similar Memoize::Lift. However, these operators cause -zefram |
From @KES777Ok, thank you for your explanation. 18.05.2015, 19:37, "Zefram via RT" <perlbug-followup@perl.org>:
|
@iabyn - Status changed from 'open' to 'rejected' |
From @ap* KES <kes-kes@yandex.ua> [2015-05-18 19:20]:
No. That would require a combination of several special cases, and that “Any language that doesn't occasionally surprise the novice Now you know how it works. So just store it in a variable and move on. Regards, |
Migrated from rt.perl.org#125205 (status was 'rejected')
Searchable as RT125205$
The text was updated successfully, but these errors were encountered: