-
Notifications
You must be signed in to change notification settings - Fork 577
Is behaviour of lexicals which are auto-vivified after being strings correct? #7165
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 @jlokierCreated by @jlokierperl -le 'for (1..10) { my $x; Prints: 1, 1, A, B What a stonking great pair of surprises! Firstly, that $x can be both a string _and_ a reference at the same Secondly, that $$x is magically not destroyed and recreated, even To illustrate why it's dubious, try this: perl -le 'for (1..3) { my The output is: 17, 1, SCALAR(0x804c988), B Note how _now_ we are still auto-vivifying $$x and appending to it, There is some serious mystery in the Perl lexical variable It's nice that taking a reference to a lexical (\$x) keeps the lexical More illustrative is this code: perl -le 'for (1..3) { my A, B Oh. That looks a lot like the string is used as a hash key of some kind. Is there something I've not noticed in the documentation? Seriously, I understand Perl 5 has a _lot_ of oddities in the lexical In particular, "man perlsub" explains a lot about lexical variables The parameter list to my() may be assigned to if desired, which allows One could be forgiven for believing that it means C<undef>, not Btw, C<use strict 'refs'> does prevent these kind of assignments. It's -- Jamie Perl Info
|
From @jlokier
Doh! (Slaps face with a wet fish, then realises it was a brick shaped Ok, I made a mistake for the first time in my life. Please close the For the non-record, eyes only, I got hot and bothered when this test time perl -e 'my $y = "x"x10000; for (1..1000000) { my (What I meant of course was C<my $x=\my $y>). -- Jamie |
@rgs - Status changed from 'new' to 'resolved' |
From [email protected]In article <rt-3.0.8-27591-81224.5.31251743874563@perl.org>,
Not a bug. You are using symbolic references here, so you are manipulating the global "use strict" will "fix" this for you. It will error then. |
From @jlokier(Ton Hospel) via RT wrote:
Yes, thank you.
Yes, it was a failure to use strict for a quick one-liner that had me -- Jamie |
From @mjdominus
I don't see how it could have been, because your original message said:
It seems to me that the real problem here was that you were using Can't use string ("A") as a SCALAR ref while "strict refs" in use which I would have thought was a tipoff as to what was happening. |
From @mjdominus
Actually, that is quite an insightful remark. |
From @jlokierMark-Jason Dominus via RT wrote:
It did, after I'd hit send. Prior, I'd written C<my Fwiw, I do understand exactly what C<use strit 'refs'> is for. I am It didn't help that I'd just been shown some genuine weird behaviour That looked similar to what I was seeing with this report, hence The moral I take away: check bug report examples with C<use strict> Thanks for your time; may the next one be a real bug :) -- Jamie |
Migrated from rt.perl.org#27591 (status was 'resolved')
Searchable as RT27591$
The text was updated successfully, but these errors were encountered: