summaryrefslogtreecommitdiff
path: root/lib/English.pm
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-07-11 17:57:48 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-07-11 17:57:48 +0000
commit60ed1d8c6a1833ad712cafbcb926be21a03df470 (patch)
tree34088dc4a27bacd6ada9486934679bd7446614c4 /lib/English.pm
parenta9419b5523cf55175503760dcfdf0b3775a2952c (diff)
downloadperl-60ed1d8c6a1833ad712cafbcb926be21a03df470.tar.gz
integrate cfgperl changes#6224..6229 into mainline
p4raw-link: @6229 on //depot/cfgperl: 94f13a8fe911b4e5d658c1e8bb515599305c074c p4raw-link: @6224 on //depot/cfgperl: 9e7db0fd3029ee5d3ce957e842a66c057eacd303 p4raw-id: //depot/perl@6352 p4raw-deleted: from //depot/cfgperl@6351 'delete in' lib/lib.pm (@5608..) p4raw-integrated: from //depot/cfgperl@6351 'copy in' t/lib/english.t (@5586..) ext/Socket/Socket.pm (@5704..) README.hpux (@5972..) lib/English.pm (@6034..) p4raw-integrated: from //depot/cfgperl@6228 'copy in' op.c (@6226..) p4raw-branched: from //depot/cfgperl@6227 'branch in' lib/lib.pm.PL p4raw-integrated: from //depot/cfgperl@6227 'copy in' Makefile.SH (@6182..) MANIFEST (@6192..) p4raw-integrated: from //depot/cfgperl@6225 'merge in' embed.pl (@6221..)
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} ;