getting rid of a few superfluous $&/$`
Jeffrey Friedl [Mon, 1 Apr 2002 01:32:34 +0000 (17:32 -0800)]
Message-Id: <200204010932.g319WY886939@ventrue.corp.yahoo.com>

(with more-backward-compat than just using @- and @+, also by Jeffrey)

(The version number of Text::Balanced intentionally not
increased since Damian will make a new release after 5.8)

p4raw-id: //depot/perl@15668

lib/Pod/Html.pm
lib/Text/Balanced.pm

index 1ae81c9..179b80b 100644 (file)
@@ -1255,9 +1255,9 @@ sub process_pre {
     $rest = $$text;
 
     # insert spaces in place of tabs
-    $rest =~ s#.*#
-           my $line = $&;
-           1 while $line =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
+    $rest =~ s#(.+)#
+           my $line = $1;
+            1 while $line =~ s/(\t+)/' ' x ((length($1) * 8) - $-[0] % 8)/e;
            $line;
        #eg;
 
index 06e4fe1..ee83e54 100644 (file)
@@ -30,6 +30,15 @@ $VERSION = '1.89';
 
 Exporter::export_ok_tags('ALL');
 
+##
+## These shenanagins are to avoid using $& in perl5.6+
+##
+my $GetMatchedText = ($] < 5.006) ? eval 'sub { $& } '
+                                  : eval 'sub { 
+                                           substr($_[0], $-[0], $+[0] - $-[0])
+                                          }';
+
+
 # PROTOTYPES
 
 sub _match_bracketed($$$$$$);
@@ -328,7 +337,8 @@ sub _match_tagged   # ($$$$$$$)
 
        if (!defined $rdel)
        {
-               $rdelspec = $&;
+               $rdelspec = &$GetMatchedText($$textref);
+
                unless ($rdelspec =~ s/\A([[(<{]+)($XMLNAME).*/ quotemeta "$1\/$2". revbracket($1) /oes)
                {
                        _failmsg "Unable to construct closing tag to match: $rdel",
@@ -911,7 +921,8 @@ sub extract_multiple (;$$$$)        # ($text, $functions_ref, $max_fields, $ignoreunkno
                                elsif (ref($func) eq 'Text::Balanced::Extractor')
                                        { @bits = $field = $func->extract($$textref) }
                                elsif( $$textref =~ m/\G$func/gc )
-                                       { @bits = $field = defined($1) ? $1 : $& }
+                                       { @bits = $field = defined($1) ? $1 : &$GetMatchedText($$textref) }
+                                       # substr() on previous line is "$&", without the pain
                                $pref ||= "";
                                if (defined($field) && length($field))
                                {