-
Notifications
You must be signed in to change notification settings - Fork 578
foreach spuriously autovivifies #1196
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 [email protected]foreach (@h{a, b}) { } autovivifies $h{a} and $h{b}. Yes, I understand why it happens. Mike Guy % perl -V Characteristics of this binary (from libperl): |
From @schwern[mjtg <!--c--> <i>at</i> <!--a--> cus.cam.ac.uk - Thu Feb 17 18:57:54 2000]:
Issue still exists in 5.8.1 RC 2 |
From [email protected]Is it really a bug? I would expect these elements to be autovivified... |
From @smpetersOn Sun, Jun 15, 2008 at 6:02 AM, reneeb via RT
Unfortunately, it has pretty much agreed that it is a bug, but due to Steve Peters |
From @davidnicolOn 6/20/08, Steve Peters <steve@fisharerojo.org> wrote:
but not universally. The opposing POV holds that the non-autoviv of my %empty; |
From @iabynOn Fri, Jun 20, 2008 at 01:03:31PM -0500, David Nicol wrote:
Which would be pretty unfortunate if $empty{hooha} was a ref. -- |
From [email protected]In article <20080622132012.GM12186@iabyn.com>, davem@iabyn.com (Dave Mitchell)
Which is why you use do-BLOCK instead: some_function(do { $empty{hooha}; }); I don't think this behaviour is documented anywhere, though. /Bo Lindbergh |
From @ysthOn Sun, June 22, 2008 12:25 pm, Bo Lindbergh wrote:
Or some_function(scalar $empty{hooha}) |
From [email protected]Created by [email protected]This code: my %a; will die with "Bad 2". I don't believe the aliasing aspect This is particularly bad for tied hashes: foreach my $x ( $ENV{'TMPDIR'}, $ENV{'TMP'}, ... ) {} That will actually cause environment variables to spring to life. It is not good enough to create the element and delete it later; Perl Info
|
From @demerphq2009/3/26 Jason Noakes <perlbug-followup@perl.org>:
No, thats wrong. Aliasing SHOULD have this effect. Or else this wouldn't work: perl -e'my %x=(a=>1); $_='muhahaha' for $x{b}; use Data::Dumper; Its irritating i agree, but the list provided to foreach() is in Yves -- |
The RT System itself - Status changed from 'new' to 'open' |
From @davidnicolOn Fri, Mar 27, 2009 at 12:23 PM, demerphq <demerphq@gmail.com> wrote:
Yet, in Mr. Noakes' defense, perl -e'my %x=(a=>1); sub xy {$_[1]="muhahaha" }; xy $x{b}, does not autoviv $x{b}, demonstrating non-autivivving aliasing and |
From @smpetersOn Fri, Mar 27, 2009 at 1:52 PM, David Nicol <davidnicol@gmail.com> wrote:
This appears to be another case of "RT #2166: foreach spuriously Steve Peters |
From @gbarrOn Mar 27, 2009, at 1:52 PM, David Nicol wrote:
subs did at one time also autoviv but it was changed during 5.005 There are many places that auto-viv due to being in LVALUE (map and IMO, the fact that subs do not autoviv is the bug as they are the In the past I have used reverse to avoid the autoviv as it does not Graham. |
From @rgs2009/3/31 Graham Barr <gbarr@pobox.com>:
On that subject, and work to be done, see |
From @iabynI'm marking this ticket as rejected/wontfix, because no-one can agree on |
@iabyn - Status changed from 'open' to 'rejected' |
From @cpansproutOn Mon Sep 06 05:57:18 2010, davem wrote:
I have just discovered this ticket, as there is a to-do test for it, which I found when about to add a test for #115194 (a duplicate). I did not realise this was so controversial. The problem here is that I broke compatibility (and App::JobLog) when making foreach(pos $x || pos $y) work (by propagating the lvalue context to allow $_ assignment to set pos). Now foreach($h{k} || $h{l}) vivifies the elements, whereas it did not before. The obvious solution seemed to be to use defelem magic in foreach, as we already do for sub calls. Come to think of it, this has already been inconsistent, as constant folding will make for(1||$h{k}) vivify even before my changes. So I think we need to bite the bullet and decide that this is a bug that needs fixing. -- Father Chrysostomos |
From [email protected]I wrote:
I meant 0, not 1: $ perl5.10 -MData::Dumper -e 'for(${\0}||$h{k}) {} print Dumper \%h' |
From @iabynOn Thu, Jan 23, 2014 at 06:19:53PM -0800, Father Chrysostomos via RT wrote:
I don't like defelem magic: I think it introduces unnecessary overhead to -- |
From [email protected]Dave Mitchel wrote:
Is the overhead much greater than that occasioned by unnecessary viv-
How else can we fix the disparity between for(0||$h{k}) and |
From @iabynOn Fri, Jan 24, 2014 at 02:42:35PM -0000, Father Chrysostomos wrote:
Yes. Look at the timings for the following code (each time is for that sub f {} for (1..10_000_000) { Note that 1-element hash slices like @h{d} still autovivify when used as From the above, subtracting out the empty loop time: 4.77 s passing elements that already exist (and no, I don't understand why autovivifying is slightly faster than them
Do we even need to worry about it? It looks to me to be an obscure edge For the record, it think for ($h{k}) should auto-vivify $h{k} (and indeed it does) but more generally, I'm in favour the behaviour not changing from what it -- |
From @cpansproutOn Mon Jan 27 03:35:27 2014, davem wrote:
If I could change that (make PVLVs fast), would you be willing to change -- Father Chrysostomos |
@cpansprout - Status changed from 'rejected' to 'stalled' |
From @iabynOn Sun, Feb 09, 2014 at 11:16:03AM -0800, Father Chrysostomos via RT wrote:
Yes. -- |
The RT System itself - Status changed from 'stalled' to 'open' |
Migrated from rt.perl.org#2166 (status was 'open')
Searchable as RT2166$
The text was updated successfully, but these errors were encountered: