summaryrefslogtreecommitdiff
path: root/lib/English.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/English.pm')
-rw-r--r--lib/English.pm54
1 files changed, 42 insertions, 12 deletions
diff --git a/lib/English.pm b/lib/English.pm
index f38c313beb..1ebc3de11d 100644
--- a/lib/English.pm
+++ b/lib/English.pm
@@ -9,6 +9,7 @@ English - use nice English (or awk) names for ugly punctuation variables
=head1 SYNOPSIS
+ use English qw( -no_match_vars ) ; # Avoids regex performance penalty
use English;
...
if ($ERRNO =~ /denied/) { ... }
@@ -27,29 +28,52 @@ $INPUT_RECORD_SEPARATOR if you are using the English module.
See L<perlvar> for a complete list of these.
-=head1 BUGS
+=head1 PERFORMANCE
-This module provokes sizeable inefficiencies for regular expressions,
-due to unfortunate implementation details. If performance matters,
-consider avoiding English.
+This module can provoke sizeable inefficiencies for regular expressions,
+due to unfortunate implementation details. If performance matters in
+your application and you don't need $PREMATCH, $MATCH, or $POSTMATCH,
+try doing
+
+ use English qw( -no_match_vars ) ;
+
+. B<It is especially important to do this in modules to avoid penalizing
+all applications which use them.>
=cut
no warnings;
+my $globbed_match ;
+
# Grandfather $NAME import
sub import {
my $this = shift;
- my @list = @_;
+ my @list = grep { ! /^-no_match_vars$/ } @_ ;
local $Exporter::ExportLevel = 1;
+ if ( @_ == @list ) {
+ *EXPORT = \@COMPLETE_EXPORT ;
+ $globbed_match ||= (
+ eval q{
+ *MATCH = *& ;
+ *PREMATCH = *` ;
+ *POSTMATCH = *' ;
+ 1 ;
+ }
+ || do {
+ require Carp ;
+ Carp::croak "Can't create English for match leftovers: $@" ;
+ }
+ ) ;
+ }
+ else {
+ *EXPORT = \@MINIMAL_EXPORT ;
+ }
Exporter::import($this,grep {s/^\$/*/} @list);
}
-@EXPORT = qw(
+@MINIMAL_EXPORT = qw(
*ARG
- *MATCH
- *PREMATCH
- *POSTMATCH
*LAST_PAREN_MATCH
*INPUT_LINE_NUMBER
*NR
@@ -102,15 +126,21 @@ sub import {
@LAST_MATCH_END
);
+
+@MATCH_EXPORT = qw(
+ *MATCH
+ *PREMATCH
+ *POSTMATCH
+);
+
+@COMPLETE_EXPORT = ( @MINIMAL_EXPORT, @MATCH_EXPORT ) ;
+
# The ground of all being. @ARG is deprecated (5.005 makes @_ lexical)
*ARG = *_ ;
# Matching.
- *MATCH = *& ;
- *PREMATCH = *` ;
- *POSTMATCH = *' ;
*LAST_PAREN_MATCH = *+ ;
*LAST_MATCH_START = *-{ARRAY} ;
*LAST_MATCH_END = *+{ARRAY} ;