Give (?{...}) a taste of its own medicine
authorRobin Houston <robin@cpan.org>
Tue, 8 May 2001 01:14:55 +0000 (02:14 +0100)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 7 May 2001 23:22:48 +0000 (23:22 +0000)
Message-ID: <20010508011455.A32162@penderel>

p4raw-id: //depot/perl@10027

ext/B/B/Deparse.pm

index 959bb37..ae4043b 100644 (file)
@@ -2930,7 +2930,36 @@ sub uninterp {
 # the same, but treat $|, $), $( and $ at the end of the string differently
 sub re_uninterp {
     my($str) = @_;
-    $str =~ s/(^|\G|[^\\])((?:\\\\)*)([\$\@](?!\||\)|\(|$)|\\[uUlLQE])/$1$2\\$3/g;
+
+    use re "eval";
+    # Matches any string which is balanced with respect to {braces}
+    my $bal = qr(
+      (?:
+       [^\\{}]
+      | \\\\
+      | \\[{}]
+      | \{(??{$bal})\}
+      )*
+    )x;
+
+    $str =~ s/
+         ( ^|\G                  # $1
+          | [^\\]
+          )
+
+          (                       # $2
+            (?:\\\\)*
+          )
+
+          (                       # $3
+            (\(\?\??\{$bal\}\))   # $4
+          | [\$\@]
+            (?!\||\)|\(|$)
+          | \\[uUlLQE]
+          )
+
+       /length($4) ? "$1$2$4" : "$1$2\\$3"/xeg;
+
     return $str;
 }