extra code in pp_concat, Take 2
[p5sagit/p5-mst-13.2.git] / lib / English.pm
CommitLineData
8990e307 1package English;
2
09e96b99 3our $VERSION = '1.03';
b75c8c73 4
8990e307 5require Exporter;
6@ISA = (Exporter);
7
f06db76b 8=head1 NAME
9
10English - use nice English (or awk) names for ugly punctuation variables
11
12=head1 SYNOPSIS
13
60ed1d8c 14 use English qw( -no_match_vars ) ; # Avoids regex performance penalty
f06db76b 15 use English;
16 ...
17 if ($ERRNO =~ /denied/) { ... }
18
19=head1 DESCRIPTION
20
21This module provides aliases for the built-in variables whose
22names no one seems to like to read. Variables with side-effects
23which get triggered just by accessing them (like $0) will still
24be affected.
25
26For those variables that have an B<awk> version, both long
27and short English alternatives are provided. For example,
28the C<$/> variable can be referred to either $RS or
29$INPUT_RECORD_SEPARATOR if you are using the English module.
30
31See L<perlvar> for a complete list of these.
32
60ed1d8c 33=head1 PERFORMANCE
f2545c07 34
60ed1d8c 35This module can provoke sizeable inefficiencies for regular expressions,
36due to unfortunate implementation details. If performance matters in
37your application and you don't need $PREMATCH, $MATCH, or $POSTMATCH,
38try doing
39
40 use English qw( -no_match_vars ) ;
41
42. B<It is especially important to do this in modules to avoid penalizing
43all applications which use them.>
f2545c07 44
f06db76b 45=cut
46
db376a24 47no warnings;
748a9306 48
60ed1d8c 49my $globbed_match ;
50
748a9306 51# Grandfather $NAME import
52sub import {
53 my $this = shift;
60ed1d8c 54 my @list = grep { ! /^-no_match_vars$/ } @_ ;
748a9306 55 local $Exporter::ExportLevel = 1;
60ed1d8c 56 if ( @_ == @list ) {
57 *EXPORT = \@COMPLETE_EXPORT ;
58 $globbed_match ||= (
59 eval q{
a33bf49b 60 *MATCH = *& ;
61 *PREMATCH = *` ;
62 *POSTMATCH = *' ;
60ed1d8c 63 1 ;
64 }
65 || do {
66 require Carp ;
09e96b99 67 Carp::croak("Can't create English for match leftovers: $@") ;
60ed1d8c 68 }
69 ) ;
70 }
71 else {
72 *EXPORT = \@MINIMAL_EXPORT ;
73 }
748a9306 74 Exporter::import($this,grep {s/^\$/*/} @list);
75}
a0d0e21e 76
60ed1d8c 77@MINIMAL_EXPORT = qw(
8990e307 78 *ARG
748a9306 79 *LAST_PAREN_MATCH
80 *INPUT_LINE_NUMBER
81 *NR
82 *INPUT_RECORD_SEPARATOR
83 *RS
84 *OUTPUT_AUTOFLUSH
85 *OUTPUT_FIELD_SEPARATOR
86 *OFS
87 *OUTPUT_RECORD_SEPARATOR
88 *ORS
89 *LIST_SEPARATOR
90 *SUBSCRIPT_SEPARATOR
91 *SUBSEP
92 *FORMAT_PAGE_NUMBER
93 *FORMAT_LINES_PER_PAGE
94 *FORMAT_LINES_LEFT
95 *FORMAT_NAME
96 *FORMAT_TOP_NAME
97 *FORMAT_LINE_BREAK_CHARACTERS
98 *FORMAT_FORMFEED
99 *CHILD_ERROR
100 *OS_ERROR
101 *ERRNO
d57fa8b6 102 *EXTENDED_OS_ERROR
748a9306 103 *EVAL_ERROR
104 *PROCESS_ID
105 *PID
106 *REAL_USER_ID
107 *UID
108 *EFFECTIVE_USER_ID
109 *EUID
110 *REAL_GROUP_ID
111 *GID
112 *EFFECTIVE_GROUP_ID
113 *EGID
114 *PROGRAM_NAME
115 *PERL_VERSION
116 *ACCUMULATOR
117 *DEBUGGING
118 *SYSTEM_FD_MAX
119 *INPLACE_EDIT
120 *PERLDB
121 *BASETIME
122 *WARNING
123 *EXECUTABLE_NAME
d57fa8b6 124 *OSNAME
66558a10 125 *LAST_REGEXP_CODE_RESULT
126 *EXCEPTIONS_BEING_CAUGHT
77ea4f6d 127 *LAST_SUBMATCH_RESULT
fe307981 128 @LAST_MATCH_START
129 @LAST_MATCH_END
8990e307 130);
131
60ed1d8c 132
133@MATCH_EXPORT = qw(
134 *MATCH
135 *PREMATCH
136 *POSTMATCH
137);
138
139@COMPLETE_EXPORT = ( @MINIMAL_EXPORT, @MATCH_EXPORT ) ;
140
fb73857a 141# The ground of all being. @ARG is deprecated (5.005 makes @_ lexical)
8990e307 142
8990e307 143 *ARG = *_ ;
144
145# Matching.
146
a33bf49b 147 *LAST_PAREN_MATCH = *+ ;
148 *LAST_SUBMATCH_RESULT = *^N ;
149 *LAST_MATCH_START = *-{ARRAY} ;
150 *LAST_MATCH_END = *+{ARRAY} ;
8990e307 151
152# Input.
153
a33bf49b 154 *INPUT_LINE_NUMBER = *. ;
155 *NR = *. ;
156 *INPUT_RECORD_SEPARATOR = */ ;
157 *RS = */ ;
8990e307 158
159# Output.
160
a33bf49b 161 *OUTPUT_AUTOFLUSH = *| ;
162 *OUTPUT_FIELD_SEPARATOR = *, ;
163 *OFS = *, ;
164 *OUTPUT_RECORD_SEPARATOR = *\ ;
165 *ORS = *\ ;
8990e307 166
167# Interpolation "constants".
168
a33bf49b 169 *LIST_SEPARATOR = *" ;
170 *SUBSCRIPT_SEPARATOR = *; ;
171 *SUBSEP = *; ;
8990e307 172
173# Formats
174
a33bf49b 175 *FORMAT_PAGE_NUMBER = *% ;
176 *FORMAT_LINES_PER_PAGE = *= ;
177 *FORMAT_LINES_LEFT = *- ;
178 *FORMAT_NAME = *~ ;
179 *FORMAT_TOP_NAME = *^ ;
180 *FORMAT_LINE_BREAK_CHARACTERS = *: ;
181 *FORMAT_FORMFEED = *^L ;
8990e307 182
183# Error status.
184
a33bf49b 185 *CHILD_ERROR = *? ;
186 *OS_ERROR = *! ;
187 *ERRNO = *! ;
188 *OS_ERROR = *! ;
189 *ERRNO = *! ;
190 *EXTENDED_OS_ERROR = *^E ;
191 *EVAL_ERROR = *@ ;
8990e307 192
193# Process info.
194
a33bf49b 195 *PROCESS_ID = *$ ;
196 *PID = *$ ;
197 *REAL_USER_ID = *< ;
198 *UID = *< ;
199 *EFFECTIVE_USER_ID = *> ;
200 *EUID = *> ;
201 *REAL_GROUP_ID = *( ;
202 *GID = *( ;
203 *EFFECTIVE_GROUP_ID = *) ;
204 *EGID = *) ;
205 *PROGRAM_NAME = *0 ;
8990e307 206
207# Internals.
208
a33bf49b 209 *PERL_VERSION = *^V ;
210 *ACCUMULATOR = *^A ;
211 *COMPILING = *^C ;
212 *DEBUGGING = *^D ;
213 *SYSTEM_FD_MAX = *^F ;
214 *INPLACE_EDIT = *^I ;
215 *PERLDB = *^P ;
216 *LAST_REGEXP_CODE_RESULT = *^R ;
217 *EXCEPTIONS_BEING_CAUGHT = *^S ;
218 *BASETIME = *^T ;
219 *WARNING = *^W ;
220 *EXECUTABLE_NAME = *^X ;
221 *OSNAME = *^O ;
8990e307 222
223# Deprecated.
224
a33bf49b 225# *ARRAY_BASE = *[ ;
226# *OFMT = *# ;
a33bf49b 227# *OLD_PERL_VERSION = *] ;
8990e307 228
2291;