-
Notifications
You must be signed in to change notification settings - Fork 540
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
overwriting with scalar $_ using foreach over array and inner wh ile loop #895
Comments
From Bernd.Koester@m.dasa.deUsing default scalar $_ (implicit) in an foreach loop over an array my @array=(1,2,3); FILE contains just one character (a). Bernd and Dirk Perl Info
|
From [Unknown Contact. See original ticket]Koester, Bernd writes: This is not a bug: man perlsyn ------------------------------------------------------------ The foreach modifier is an iterator: For each value in EXPR, it aliases man perlop ------------------------------------------------------------- If and ONLY if the input symbol is the only thing inside the conditional Hence the while loop assigns to $_ which is an alias into @array. No Mx. |
From [Unknown Contact. See original ticket]Martyn Pearce <m.pearce@inpharmatica.co.uk> wrote
But you haven't pointed out the key issue, that while never localises The development version (5.005_62) makes this more explicit: ---------------------pod/perlop.pod-------------------- I think the attached patch to perlsyn would also be useful. Mike Guy Inline Patch--- ./pod/perlsyn.pod.orig Fri Sep 17 21:23:08 1999
+++ ./pod/perlsyn.pod Fri Nov 26 16:02:15 1999
@@ -163,6 +163,8 @@
refers to the innermost enclosing loop. This may include dynamically
looking back your call-stack at run time to find the LABEL. Such
desperate behavior triggers a warning if you use the B<-w> flag.
+Unlike a C<foreach> statement, a C<while> statement never implicitly
+localises any variables.
If there is a C<continue> BLOCK, it is always executed just before the
conditional is about to be evaluated again, just like the third part of a
End of patch |
Migrated from rt.perl.org#1828 (status was 'resolved')
Searchable as RT1828$
The text was updated successfully, but these errors were encountered: