Give (?{...}) a taste of its own medicine
Robin Houston [Tue, 8 May 2001 01:14:55 +0000 (02:14 +0100)]
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;
 }