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
@{undef} inconsistently strict #6094
Comments
From @nwc10Created by @nwc10$ perl5.8.0 -lwe 'use strict; push @$a, "foo"; print $a' This isn't consistent. Why? Perl Info
|
From @eserteNicholas Clark (via RT) <perlbug@perl.org> writes:
$a and $b are special variables (for sort) and do not need to be Regards, -- Berlin Perl Mongers - http://berliner.pm.org |
From sburke@cpan.orgAt 10:10 2002-11-25 +0100, Slaven Rezic wrote:
I don't think the choice of variable name is what he means. I think he I feel like Perl is doing the right thing in all three cases, but I can't -- |
From @demerphqSean M. Burke said on 25 November 2002 10:35
At first I thought you were correct. The rule being "autovification on write Either all aspects of a read should not auto vivify (prepare for half the undef $a; to autovifiy $a wouldnt actually break any existing code as inorder to work if (@{$a||[]}) { Or the clumsier, $a=[] unless defined $a; Cheers, |
From @nwc10On Mon, Nov 25, 2002 at 10:26:43AM -0000, Orton, Yves wrote:
It seems that the current rule is autovivification is OK for element access which wasn't what I expected. One part of my brain knew that I'd had to code
or this: @$a = ...; should fail (ie autovivification for whole arrays not allowed)
I agree. I can't see anything wrong with your reasoning. I think that changing Nicholas Clark |
From @demerphqNicholas Clark said on 25 November 2002 11:57
$a||=[] Hmm, for some bizarre reason that one never occured to me. :-)
Exactly. Personally I think that $a->{a}{b} should not be created on a read
Well, I'm doubtful that this is the best strategy. I think autovivfy on push @{$hash{$key}},$item; So making autovivfy on read consistant makes more sense to me.
Doh. Of course. Either way im betting that code that depends on the above Yves |
From @rgsNicholas Clark <nick@ccl4.org> wrote:
$a //= []; # ;-)
strict 'refs' prohibits only symbolic references. It has no business My personal opinion on that last question is that new cases for autovivification |
From @demerphqRafael Garcia-Suarez said
I agree in general. But if its to make autovification more consistant and And personally i would like it if stuff like: unless (@{$hash{$key}}) { didn't raise an error when $hash{$key} is undef. If only cause its a pain to unless ( @{ $hash{$key} || [] } ) { does... Yves |
From @rgs"Orton, Yves" <yves.orton@mciworldcom.de> wrote:
I think that strictures shouldn't interfere with autovivification. The fact This crosses another known bug : $ perl -Mstrict=refs -le 'my The latest case should trigger an error (even if there's no autovivification (I've a patch to address this latest case, but it breaks some tests.) |
From @nwc10On Mon, Nov 25, 2002 at 02:23:28PM +0100, Rafael Garcia-Suarez wrote:
I agree that it's orthogonal. I found another inconsistency: $ perl -lwe 'use strict; print @$a' $ perl -lwe 'use strict; print foreach @$a'
I think I'm only asking that it be legal to do it without warnings under Nicholas Clark |
From @rgsNicholas Clark wrote:
Looking at pp_rv2av, and the other pp_rv2?v, the errors and warnings It's possible by inspecting the code to work out a full matrix opflags x scalar value : and then to imagine a more consistent behaviour. |
From perl-5.8.0@ton.iguana.beCreated by perl-5.8.0@ton.iguana.beWhy doesn't this actually work: perl -e '$x = ($u=undef)->{foo}' while this is (of course) fine: perl -e '$u = undef; $x = $u->{foo}' isn't the result of an assignment supposed to be a proper lvalue ? perldoc perlref definitely discusses autovivication in terms of This bug may be related to bug 18635: Perl Info
|
From @nwc10Created by @nwc10$ cat -n fail.pl Note the line number. How can it be anything *but* a *bug* that one sort of undefined value No "LVALUE" or "RVALUE" distinction here. Why is $b->[0] considered kosher, Nicholas Clark Perl Info
|
From Robin.Barker@npl.co.ukIndexing auto vivifies, plain derefencing doesn't.
Robin |
The RT System itself - Status changed from 'new' to 'open' |
From @nwc10On Thu, Mar 12, 2009 at 05:12:09PM -0000, Robin Barker wrote:
$ perl -Mstrict -le 'my $x; @{$x}; print $x' Yes, except plain dereferencing *does* in LVALUE context: $ perl -Mstrict -le 'my $x; 1 foreach @{$x}; print $x' Or as the argument to defined: $ perl -Mstrict -le 'my $x; defined @{$x}; print $x' So why are indexing and defined special? Nicholas Clark |
From chromatic@wgz.orgOn Thursday 12 March 2009 06:15:05 Nicholas Clark wrote:
Also note that the error message doesn't include the offending variable name. -- c |
From @ysthOn Thu, March 12, 2009 10:18 am, Nicholas Clark wrote:
My impression is that the general intent is that modification operations |
From @ysthOn Thu, March 12, 2009 6:15 am, Nicholas Clark wrote:
@$b does autovivify when it is modifying: $ perl -wl It makes sense to me that it does give an error when it is *not* |
From @davidnicolOn Thu, Mar 12, 2009 at 9:25 PM, Yitzchak Scott-Thoennes
and indexing only autovivs as an Lvalue, but strict doesn't mind. and the violation in @{$b->[0]} was misread by the OP; the same error $ perl -l |
From @cpansproutOn Mon Nov 25 05:28:08 2002, rafael wrote:
This isn’t directly related to the original ticket, and I know I’m Currently we have this consistency, which has nothing to do with Pint:perl.git sprout$ perl -le 'print @$x' Pint:perl.git sprout$ perl -Mstrict=refs -le 'print @$x' |
From @cpansproutOn Tue Aug 23 17:01:10 2011, sprout wrote:
An hour later, I’m having second thoughts. Just ignore what I wrote. |
From @cpansproutOn Thu Mar 12 06:15:02 2009, nicholas wrote:
This look an awful lot like bug #18635, which you reported. I don’t It’s basically the distinction between aelem (which autovivifies in |
Migrated from rt.perl.org#18635 (status was 'open')
Searchable as RT18635$
The text was updated successfully, but these errors were encountered: