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
($_) = () fails to set $_ to undef #6659
Comments
From @epaCreated by @epaProgram: #!/usr/bin/perl Expected output: $x is not defined Actual output: $x is not defined Comments: In a list assignment, shouldn't any 'missing' elements get assigned Perl Info
|
From @epaA slightly better test case: #!/usr/bin/perl Output as before. |
From ben.goldberg@hotpop.com"Ed Avis (via RT)" wrote:
Actually, I would expect: $x is not defined Similar to how this: C:\> perl -e "'a' =~ /(1)/; $_ = 2 for $1" Produces: Modification of a read-only value attempted at -e line 1.
I'd consider this a bug. If you do local ($_) = (), then it should (Well, unless $_ is an alias to a tied value, in which case it should
*Assigned* undef, certainly. Whether that assign operation should succeed depends on what's being Anyway... your example code could be reduced to: perl -le "'a' =~ /(.)/; local ($1) = (); print $1" Which prints "a", instead of dieing with "Modification..." as I would -- |
From @epaOn 28 Jul 2003, Benjamin Goldberg wrote:
That would make _some_ sense - certainly better than the current I know that 'local' is really for saving and restoring the value, not local ($_) = (); could work some of the time and break some of the time, depending on Otherwise one would have to conclude that the above line of code is
I think that's fair enough, $1 is supposed to be read-only. And you
Yes, better, but still not great. If it's unpredictable which of the
Hmm. When you put it in those terms it seems more reasonable that the If localizing $_ is not sufficient to make sure you can safely assign -- |
From @rgsEd Avis (via RT) wrote:
In fact this bug can be reduced to : 'not ok' =~ /(.+)/; -->prints "not ok". in other words the localization of $_ is silently ignored when it's |
From @rgsRafael Garcia-Suarez wrote:
This patch appears to fix the bug, and, (a bit suprisingly), doesn't --- scope.c (revision 1484) Anyway this is a suboptimal fix ; I think that perl should be able (PS. I wouldn't trust this patch for 5.8.1 at this point.) |
From @chipdudeAccording to Rafael Garcia-Suarez:
I believe that it *is* localizing $_ properly (modulo the error Magical values are always localized in magical fashion (i.e. paying { local $/; <slurp> } When $_ is aliased to $1, C<local $_> should do the same level of |
From @rgsChip Salzenberg wrote:
Makes sense, since I remarked that my patch fixes also : $ perl5.8.0 -wle 'local $1=1;print $1' $ bleadperl -e 'local $1=1' ('bleadperl' being an alias to my patched perl) |
From @hvdsRafael Garcia-Suarez <rgarciasuarez@free.fr> wrote: Hmm, is SvREADONLY ever set on user-domain non-magical items? I wonder ugo |
From ctriv@dyndns.orgOn Mon, 4 Aug 2003 hv@crypt.org wrote:
Readonly::XS on CPAN does exactly that. -- |
From @chipdudeAccording to Hugo van der Sanden:
Any attempt to localize a user-set-readonly value should produce the |
From @rgshv@crypt.org wrote:
That should be safe, the line I changed is included in an if() statement : if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) { And with my patch : $ bleadperl -MScalar::Util=readonly -wle 'for (1) { print readonly $_; local $_ = 2; print ; print readonly $_ }' |
From @rgsChip Salzenberg wrote:
Er, if you want that C<for(1){local $_=2}> croaks, another patch is needed. |
From @chipdudeAccording to Rafael Garcia-Suarez:
Oh, yeah. Darn, I missed that possibility. Glad the patch works. |
From @rgsChip Salzenberg wrote:
After popular approval, I thanks-applied my patch as #20479. I even |
@rgs - Status changed from 'new' to 'resolved' |
Migrated from rt.perl.org#23141 (status was 'resolved')
Searchable as RT23141$
The text was updated successfully, but these errors were encountered: