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
The value of pattern match vars. after `next' #899
Comments
From inaba@st.rim.or.jpInline Patch--- cop.h.org Sun Mar 28 02:57:30 1999
+++ cop.h Thu Nov 25 00:54:29 1999
@@ -205,8 +205,9 @@
PL_stack_sp = PL_stack_base + cx->blk_oldsp, \
PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
PL_scopestack_ix = cx->blk_oldscopesp, \
- PL_retstack_ix = cx->blk_oldretsp, \
- PL_curpm = cx->blk_oldpm
+ PL_retstack_ix = cx->blk_oldretsp
+
+#define RESTOREPM(cxix) PL_curpm = cxstack[cxix+1].blk_oldpm
/* substitution context */
struct subst {
--- pp_ctl.c.org Sun Mar 28 02:56:24 1999
+++ pp_ctl.c Thu Nov 25 01:13:20 1999
@@ -1757,9 +1757,10 @@
if (cxix < 0)
DIE("Label not found for \"next %s\"", cPVOP->op_pv);
}
- if (cxix < cxstack_ix)
+ if (cxix < cxstack_ix) {
dounwind(cxix);
-
+ RESTOREPM(cxix);
+ }
TOPBLOCK(cx);
oldsave = PL_scopestack[PL_scopestack_ix - 1];
LEAVE_SCOPE(oldsave);
@@ -1782,9 +1783,10 @@
if (cxix < 0)
DIE("Label not found for \"redo %s\"", cPVOP->op_pv);
}
- if (cxix < cxstack_ix)
+ if (cxix < cxstack_ix){
dounwind(cxix);
-
+ RESTOREPM(cxix);
+ }
TOPBLOCK(cx);
oldsave = PL_scopestack[PL_scopestack_ix - 1];
LEAVE_SCOPE(oldsave);
@@ -1890,8 +1892,10 @@
cxix = dopoptosub(cxstack_ix);
if (cxix < 0)
DIE("Can't goto subroutine outside a subroutine");
- if (cxix < cxstack_ix)
+ if (cxix < cxstack_ix){
dounwind(cxix);
+ RESTOREPM(cxix);
+ }
TOPBLOCK(cx);
if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_ENTEREVAL)
DIE("Can't goto subroutine from an eval-string");
@@ -2168,6 +2172,7 @@
if (ix < 0)
ix = 0;
dounwind(ix);
+ RESTOREPM(ix);
TOPBLOCK(cx);
oldsave = PL_scopestack[PL_scopestack_ix];
LEAVE_SCOPE(oldsave); |
From [Unknown Contact. See original ticket]Inaba Hiroto writes:
What made you think so? What other block-local things behave like this? Ilya |
From [Unknown Contact. See original ticket]Ilya Zakharevich wrote:
I think $& etc. are block local like "{ local $var = $var; ... }". $x = "foo"; This code print "foo\nfoo\n". If the former code print "foo\nfoo\n", I think $& The string matched by the last successful pattern So I think the former code should print "bar\nbar\n" and current behavior |
From [Unknown Contact. See original ticket]Inaba Hiroto <inaba@st.rim.or.jp> wrote
I certainly see a bug here, but I'm not certain it's the same bug as you Here's a more thoroughly instrumented example: %perl -wl The issue seems to be that there are two scopes around, and it isn't The two scopes are (i) the whole of the for loop, so the variables %perl -wl Your example shows that we get behaviour (i) on the first loop, and Although I prefer (i) to (ii) as being more intuitive, the important Mike Guy |
From [Unknown Contact. See original ticket]M.J.T. Guy writes:
If what you want is consistency, you know where to find Python... :-( But it would be nice if lexicals introduced inside if(){} and Ilya |
From nobull@cpan.org
This should be addressed as a documentation bug. Should say The string matched by the last successful pattern in the current dynamic The phrase "This variable is ... dynamically scoped to the current BLOCK." Should be removed because it's not strictly true and doesn't add The wording of the description of all other match variables @+ @- $+ &` A more detailed explanation of the scoping rules should be placed in one |
From @gannett-ggreerOn Sun Aug 19 13:51:59 2007, nobull@cpan.org wrote:
This would be a good (easy?) fix for the Perl 5 Documentation Team. http://rt.perl.org/rt3/Ticket/Display.html?id=1833 -- |
From @cowensOn Sat, Jul 10, 2010 at 15:35, George Greer via RT
I am taking a look at it now. -- |
From @cowensOn Sun, Jul 11, 2010 at 12:35, Chas. Owens <chas.owens@gmail.com> wrote:
Well, I am still trying to suss out the rules so I can write the perl -E '"a"=~/a/;say compare with perl -E '"a"=~/a/;say -- |
From nobull@cpan.orgI don't think there is a reasonable explaination of why goto out of an For the purpose of documentation I think your best bet is a footnote What's more important is to make sure that the documentation makes it |
@demerphq does a doc patch for this make sense? |
@demerphq ping |
On Mon, 25 Apr 2022, 22:30 Karl Williamson, ***@***.***> wrote:
@demerphq <https://github.com/demerphq> ping
Will look soon.
Yves
… |
This section is used to document the majority of the regex variables, and previous language referring to them as "dynamically scoped" has been changed or simplified and a link to the new section provided to centralize the explanation. Strictly speaking $1 is globally scoped, but the data it access is dynamically scoped such that successful matches behave as though they localize a regex match state variable. (Maybe one day we will actually have such a variable exposed to the user.) This patch addss links to the relevant docs in perlsyn and perlvar to various places where it seemed appropriate, and also cleans up the wording for most cases to be similar or identical across all uses. It also cleans up a bit of related language in nearby paragraphs where it seemed to improve the readability of the docs. It also replaces the older kind of confusing example code for understanding the behavior and documents that "goto LABEL" does not play nicely with the dynamic scoping. This fixes Github Issue #899.
Patch pushed as #20791 |
This section is used to document the majority of the regex variables, and previous language referring to them as "dynamically scoped" has been changed or simplified and a link to the new section provided to centralize the explanation. Strictly speaking $1 is globally scoped, but the data it access is dynamically scoped such that successful matches behave as though they localize a regex match state variable. (Maybe one day we will actually have such a variable exposed to the user.) This patch adds links to the relevant docs in perlsyn and perlvar to various places where it seemed appropriate, and also cleans up the wording for most cases to be similar or identical across all uses. It also cleans up a bit of related language in nearby paragraphs where it seemed to improve the readability of the docs. It also replaces the older kind of confusing example code for understanding the behavior and documents that "goto LABEL" does not play nicely with the dynamic scoping. This fixes Github Issue #899.
This section is used to document the majority of the regex variables, and previous language referring to them as "dynamically scoped" has been changed or simplified and a link to the new section provided to centralize the explanation. Strictly speaking $1 is globally scoped, but the data it access is dynamically scoped such that successful matches behave as though they localize a regex match state variable. (Maybe one day we will actually have such a variable exposed to the user.) This patch adds links to the relevant docs in perlsyn and perlvar to various places where it seemed appropriate, and also cleans up the wording for most cases to be similar or identical across all uses. It also cleans up a bit of related language in nearby paragraphs where it seemed to improve the readability of the docs. It also replaces the older kind of confusing example code for understanding the behavior and documents that "goto LABEL" does not play nicely with the dynamic scoping. This fixes Github Issue #899.
This section is used to document the majority of the regex variables, and previous language referring to them as "dynamically scoped" has been changed or simplified and a link to the new section provided to centralize the explanation. Strictly speaking $1 is globally scoped, but the data it access is dynamically scoped such that successful matches behave as though they localize a regex match state variable. (Maybe one day we will actually have such a variable exposed to the user.) This patch adds links to the relevant docs in perlsyn and perlvar to various places where it seemed appropriate, and also cleans up the wording for most cases to be similar or identical across all uses. It also cleans up a bit of related language in nearby paragraphs where it seemed to improve the readability of the docs. It also replaces the older kind of confusing example code for understanding the behavior and documents that "goto LABEL" does not play nicely with the dynamic scoping. This fixes Github Issue Perl#899.
This section is used to document the majority of the regex variables, and previous language referring to them as "dynamically scoped" has been changed or simplified and a link to the new section provided to centralize the explanation. Strictly speaking $1 is globally scoped, but the data it access is dynamically scoped such that successful matches behave as though they localize a regex match state variable. (Maybe one day we will actually have such a variable exposed to the user.) This patch adds links to the relevant docs in perlsyn and perlvar to various places where it seemed appropriate, and also cleans up the wording for most cases to be similar or identical across all uses. It also cleans up a bit of related language in nearby paragraphs where it seemed to improve the readability of the docs. It also replaces the older kind of confusing example code for understanding the behavior and documents that "goto LABEL" does not play nicely with the dynamic scoping. This fixes Github Issue Perl#899.
This section is used to document the majority of the regex variables, and previous language referring to them as "dynamically scoped" has been changed or simplified and a link to the new section provided to centralize the explanation. Strictly speaking $1 is globally scoped, but the data it access is dynamically scoped such that successful matches behave as though they localize a regex match state variable. (Maybe one day we will actually have such a variable exposed to the user.) This patch adds links to the relevant docs in perlsyn and perlvar to various places where it seemed appropriate, and also cleans up the wording for most cases to be similar or identical across all uses. It also cleans up a bit of related language in nearby paragraphs where it seemed to improve the readability of the docs. It also replaces the older kind of confusing example code for understanding the behavior and documents that "goto LABEL" does not play nicely with the dynamic scoping. This fixes Github Issue Perl#899.
Migrated from rt.perl.org#1833 (status was 'open')
Searchable as RT1833$
The text was updated successfully, but these errors were encountered: