diff options
author | Jeffrey Friedl <jfriedl@regex.info> | 2002-03-31 17:32:34 -0800 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2002-04-01 20:33:06 +0000 |
commit | 24e08cbad4d455c0ea0d5e7994d8469a9fc6790b (patch) | |
tree | bace44307ea3f6a826cf5a5da34d9a1f3491a8ee /lib/Text | |
parent | cf8feb78124b90756575c16fb087f9e129ee3a6d (diff) | |
download | perl-24e08cbad4d455c0ea0d5e7994d8469a9fc6790b.tar.gz |
getting rid of a few superfluous $&/$`
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
Diffstat (limited to 'lib/Text')
-rw-r--r-- | lib/Text/Balanced.pm | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Text/Balanced.pm b/lib/Text/Balanced.pm index 06e4fe1003..ee83e545dc 100644 --- a/lib/Text/Balanced.pm +++ b/lib/Text/Balanced.pm @@ -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)) { |