summaryrefslogtreecommitdiff
path: root/perly.h
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2011-10-12 14:01:50 +0100
committerDavid Mitchell <davem@iabyn.com>2012-06-13 13:25:50 +0100
commitd63c20f27b4a88c274844b2b635deb3c6588cccd (patch)
tree419e8d46117855aa07627636841d9a7208f0320e /perly.h
parent2866decb530d50f622ad6853fed7f30562e474ce (diff)
downloadperl-d63c20f27b4a88c274844b2b635deb3c6588cccd.tar.gz
make qr/(?{})/ behave with closures
With this commit, qr// with a literal (compile-time) code block will Do the Right Thing as regards closures and the scope of lexical vars; in particular, the following now creates three regexes that match 1, 2 and 3: for my $i (0..2) { push @r, qr/^(??{$i})$/; } "1" =~ $r[1]; # matches Previously, $i would be evaluated as undef in all 3 patterns. This is achieved by wrapping the compilation of the pattern within a new anonymous CV, which is then attached to the pattern. At run-time pp_qr() clones the CV as well as copying the REGEXP; and when the code block is executed, it does so using the pad of the cloned CV. Which makes everything come out all right in the wash. The CV is stored in a new field of the REGEXP, called qr_anoncv. Note that run-time qr//s are still not fixed, e.g. qr/$foo(?{...})/; nor is it yet fixed where the qr// is embedded within another pattern: continuing with the code example from above, my $i = 99; "1" =~ $r[1]; # bare qr: matches: correct! "X99" =~ /X$r[1]/; # embedded qr: matches: whoops, it's still seeing the wrong $i
Diffstat (limited to 'perly.h')
-rw-r--r--perly.h13
1 files changed, 6 insertions, 7 deletions
diff --git a/perly.h b/perly.h
index fa47196067..8ebae6ec8a 100644
--- a/perly.h
+++ b/perly.h
@@ -5,13 +5,12 @@
*/
#ifdef PERL_CORE
-
-/* A Bison parser, made by GNU Bison 2.4.1. */
+/* A Bison parser, made by GNU Bison 2.4.3. */
/* Skeleton interface for Bison's Yacc-like parsers in C
- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
- Free Software Foundation, Inc.
+ Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -216,7 +215,7 @@
typedef union YYSTYPE
{
-/* Line 1676 of yacc.c */
+/* Line 1685 of yacc.c */
I32 ival; /* __DEFAULT__ (marker for regen_perly.pl;
must always be 1st union member) */
@@ -236,7 +235,7 @@ typedef union YYSTYPE
-/* Line 1676 of yacc.c */
+/* Line 1685 of yacc.c */
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -248,6 +247,6 @@ typedef union YYSTYPE
/* Generated from:
- * ff01d43de6f749eba3bfeffd39928772fe7e1bebe039506b8465c05941209aa8 perly.y
+ * 27cce68ad4844f1b8053bfc11206fb9f559e08be6cefd4a986aaa606c0e5fb38 perly.y
* 53f57d7143a42b3c008841a14d158bcf9cab64b2904b07ef5e95051fe9a8a875 regen_perly.pl
* ex: set ro: */