This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse: make a complex pattern readable with /x
authorDavid Mitchell <davem@iabyn.com>
Thu, 23 Feb 2017 10:30:42 +0000 (10:30 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 5 Jun 2017 11:52:17 +0000 (12:52 +0100)
In sub re_unback().

It shouldn't change its functionality, but just add whitespace
and comments for readability.

lib/B/Deparse.pm

index 0a68828..47b557d 100644 (file)
@@ -4825,7 +4825,23 @@ sub re_unback {
     my($str) = @_;
 
     # the insane complexity here is due to the behaviour of "\c\"
-    $str =~ s/(^|[^\\]|\\c\\)(?<!\\c)\\(\\\\)*(?=[[:^print:]])/$1$2/g;
+    $str =~ s/
+                # these two lines ensure that the backslash we're about to
+                # remove isn't preceeded by something which makes it part
+                # of a \c
+
+                (^ | [^\\] | \\c\\)             # $1
+                (?<!\\c)
+
+                # the backslash to remove
+                \\
+
+                # keep pairs of backslashes
+                (\\\\)*                         # $2
+
+                # only remove if the thing following is a control char
+                (?=[[:^print:]])
+            /$1$2/xg;
     return $str;
 }