develooper Front page | perl.perl5.porters | Postings from November 2000

[PATCH 5.7.0] lexicals not recognized in a run-time (?{})

Thread Next
From:
Ilya Zakharevich
Date:
November 20, 2000 14:06
Subject:
[PATCH 5.7.0] lexicals not recognized in a run-time (?{})
Message ID:
20001120170609.A11780@monk.mps.ohio-state.edu
Previously, you could mention lexicals inside (?{}) in RExen only if
the REx was compiled at compile-time.  So if the REx included
interpolation, it would not work with lexicals.

Enjoy,
Ilya

--- ./pp_ctl.c~	Sun Nov  5 14:36:14 2000
+++ ./pp_ctl.c	Mon Nov 20 16:59:00 2000
@@ -2765,7 +2765,7 @@ Perl_sv_compile_2op(pTHX_ SV *sv, OP** s
     PL_op = &dummy;
     PL_op->op_type = OP_ENTEREVAL;
     PL_op->op_flags = 0;			/* Avoid uninit warning. */
-    PUSHBLOCK(cx, CXt_EVAL, SP);
+    PUSHBLOCK(cx, CXt_EVAL|(PL_curcop == &PL_compiling ? 0 : CXp_REAL), SP);
     PUSHEVAL(cx, 0, Nullgv);
     rop = doeval(G_SCALAR, startop);
     POPBLOCK(cx,PL_curpm);
--- ./t/op/pat.t-preeval	Mon Nov 20 16:37:15 2000
+++ ./t/op/pat.t	Mon Nov 20 17:01:20 2000
@@ -4,7 +4,7 @@
 # the format supported by op/regexp.t.  If you want to add a test
 # that does fit that format, add it to op/re_tests, not here.
 
-print "1..224\n";
+print "1..230\n";
 
 BEGIN {
     chdir 't' if -d 't';
@@ -545,10 +545,43 @@ $test++;
   print "ok $test\n";
   $test++;
 
+  local $lex_a = 2;
+  my $lex_a = 43;
+  my $lex_b = 17;
+  my $lex_c = 27;
+  my $lex_res = ($lex_b =~ qr/$lex_b(?{ $lex_c = $lex_a++ })/);
+  print "not " unless $lex_res eq '1';
+  print "ok $test\n";
+  $test++;
+  print "not " unless $lex_a eq '44';
+  print "ok $test\n";
+  $test++;
+  print "not " unless $lex_c eq '43';
+  print "ok $test\n";
+  $test++;
+
+
   no re "eval"; 
   $match = eval { /$a$c$a/ };
   print "not " 
     unless $b eq '14' and $@ =~ /Eval-group not allowed/ and not $match;
+  print "ok $test\n";
+  $test++;
+}
+
+{
+  local $lex_a = 2;
+  my $lex_a = 43;
+  my $lex_b = 17;
+  my $lex_c = 27;
+  my $lex_res = ($lex_b =~ qr/17(?{ $lex_c = $lex_a++ })/);
+  print "not " unless $lex_res eq '1';
+  print "ok $test\n";
+  $test++;
+  print "not " unless $lex_a eq '44';
+  print "ok $test\n";
+  $test++;
+  print "not " unless $lex_c eq '43';
   print "ok $test\n";
   $test++;
 }

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About