perlvar >
5.14.1
との差分
perlvar 5.14.1 と 5.40.0 の差分
1 | 1 | |
2 | =encoding | |
2 | =encoding utf8 | |
3 | 3 | |
4 | 4 | =head1 NAME |
5 | 5 | |
6 | 6 | =begin original |
7 | 7 | |
8 | 8 | perlvar - Perl predefined variables |
9 | 9 | |
10 | 10 | =end original |
11 | 11 | |
12 | 12 | perlvar - Perl で定義済みの変数 |
13 | 13 | |
14 | 14 | =head1 DESCRIPTION |
15 | 15 | |
16 | 16 | =head2 The Syntax of Variable Names |
17 | 17 | |
18 | 18 | (変数名の文法) |
19 | 19 | |
20 | 20 | =begin original |
21 | 21 | |
22 | Variable names in Perl can have several formats. Usually, they | |
22 | Variable names in Perl can have several formats. Usually, they | |
23 | 23 | must begin with a letter or underscore, in which case they can be |
24 | 24 | arbitrarily long (up to an internal limit of 251 characters) and |
25 | 25 | may contain letters, digits, underscores, or the special sequence |
26 | C<::> or C<'>. In this case, the part before the last C<::> or | |
26 | C<::> or C<'>. In this case, the part before the last C<::> or | |
27 | 27 | C<'> is taken to be a I<package qualifier>; see L<perlmod>. |
28 | A Unicode letter that is not ASCII is not considered to be a letter | |
29 | unless S<C<"use utf8">> is in effect, and somewhat more complicated | |
30 | rules apply; see L<perldata/Identifier parsing> for details. | |
28 | 31 | |
29 | 32 | =end original |
30 | 33 | |
31 | 34 | Perl の変数名は様々な形があります。 |
32 | 35 | 通常、変数名は英文字か下線で始まらなければならず、 |
33 | 36 | 任意の長さ(内部制限の 251 文字まで)を取ることができ、 |
34 | 37 | 英文字、数字、下線、特別な文字列である C<::> と C<'> を含むことができます。 |
35 | この場合、最後の C<::> または C<'> の前は | |
38 | この場合、最後の C<::> または C<'> の前は I<パッケージ限定子> として | |
36 | ||
39 | 扱われます; L<perlmod> を参照して下さい。 | |
37 | ||
40 | ASCII ではない Unicode 文字は、S<C<"use utf8">> が有効でない限り | |
41 | 文字として扱われません; そしていくらかより複雑な規則が適用されます; | |
42 | 詳しくは L<perldata/Identifier parsing> を参照してください。 | |
38 | 43 | |
39 | 44 | =begin original |
40 | 45 | |
41 | Perl variable names may also be a sequence of digits | |
46 | Perl variable names may also be a sequence of digits, a single | |
42 | punctuation | |
47 | punctuation character, or the two-character sequence: C<^> (caret or | |
48 | CIRCUMFLEX ACCENT) followed by any one of the characters C<[][A-Z^_?\]>. | |
49 | These names are all reserved for | |
43 | 50 | special uses by Perl; for example, the all-digits names are used |
44 | 51 | to hold data captured by backreferences after a regular expression |
45 | match. | |
52 | match. | |
46 | names: It understands C<^X> (caret C<X>) to mean the control-C<X> | |
47 | character. For example, the notation C<$^W> (dollar-sign caret | |
48 | C<W>) is the scalar variable whose name is the single character | |
49 | control-C<W>. This is better than typing a literal control-C<W> | |
50 | into your program. | |
51 | 53 | |
52 | 54 | =end original |
53 | 55 | |
54 | Perl の変数は、数字の列または一文字の句読点 | |
56 | Perl の変数は、数字の列または一文字の句読点文字、2 文字並び( | |
55 | ||
57 | C<^> (キャレット、CIRCUMFLEX ACCENT) に引き続いて C<[][A-Z^_?\]> の文字の一つ) | |
56 | ||
58 | の場合もあります。 | |
59 | これらの名前は全て Perl によって特別な用途のために予約されています; | |
57 | 60 | 例えば、全て数字の名前は正規表現マッチの後の後方参照のデータを |
58 | 61 | 保持するために用いられます。 |
59 | Perl には一文字のコントロール文字の名前のための特別な文法があります。 | |
60 | C<^X>(キャレット C<X>)は control-C<X> キャラクタを意味します。 | |
61 | 例えば、C<$^W>(ドル記号 キャレット C<W>)は control-C<W> 一文字の | |
62 | 名前をもつスカラ変数です。 | |
63 | これはプログラム中にリテラルな control-C<W> をタイプするより | |
64 | 良いです。 | |
65 | 62 | |
66 | 63 | =begin original |
67 | 64 | |
68 | Since Perl 5.6, Perl variable names may be alphanumeric | |
65 | Since Perl v5.6.0, Perl variable names may also be alphanumeric strings | |
69 | ||
66 | preceded by a caret. These must all be written using the demarcated | |
70 | ||
67 | variable form using curly braces such as C<${^Foo}>; | |
71 | are not optional. C<${^Foo}> denotes the scalar variabl | |
68 | the braces are B<not> optional. C<${^Foo}> denotes the scalar variable | |
72 | name is a control-C<F> followed by two C<o>'s. | |
69 | whose name is considered to be a control-C<F> followed by two C<o>'s. | |
70 | (See L<perldata/"Demarcated variable names using braces"> for more | |
71 | information on this form of spelling a variable name or specifying | |
72 | access to an element of an array or a hash). | |
73 | These variables are | |
73 | 74 | reserved for future special uses by Perl, except for the ones that |
74 | begin with C<^_> (c | |
75 | begin with C<^_> (caret-underscore). No | |
75 | ||
76 | name that begins with C<^_> will acquire a special | |
76 | 77 | meaning in any future version of Perl; such names may therefore be |
77 | used safely in programs. C<$^_> itself, however, I<is> reserved. | |
78 | used safely in programs. C<$^_> itself, however, I<is> reserved. | |
78 | 79 | |
79 | 80 | =end original |
80 | 81 | |
81 | Perl 5.6 から、 | |
82 | Perl v5.6.0 から、キャレットが前置された、英数字からなる文字列の変数名も | |
82 | ||
83 | 使えます。 | |
83 | これら | |
84 | これらは C<${^Foo}> のような中かっこを使った | |
84 | ||
85 | 区切り付き変数形式で書かれなければなりません; | |
86 | 括弧はオプション B<ではありません>。 | |
85 | 87 | C<${^Foo}> はコントロール-C<F> の後に二つ C<o> が続く名前を持つ |
86 | スカラ変数 | |
88 | スカラ変数と考えられます。 | |
89 | (変数名をこの形式で書くことや配列やハッシュの要素へのアクセスを指定する | |
90 | さらなる情報については | |
91 | L<perldata/"Demarcated variable names using braces"> を参照してください。) | |
87 | 92 | これらの変数は Perl によって特別な用途のために予約されていますが、 |
88 | C<^_> ( | |
93 | C<^_> (キャレット-下線)で始まるものは例外です。 | |
89 | C<^_> で始まる | |
94 | C<^_> で始まる名前は Perl の将来のバージョンで特別な意味を | |
90 | ||
95 | 持つことはありません; 従ってこれらの名前はプログラム中で安全に使用できます。 | |
91 | 従ってこれらの名前はプログラム中で安全に使用できます。 | |
92 | 96 | 但し、C<$^_> そのものは I<予約されます>。 |
93 | 97 | |
94 | 98 | =begin original |
95 | 99 | |
96 | ||
100 | Note that you also B<must> use the demarcated form to access subscripts | |
101 | of variables of this type when interpolating, for instance to access the | |
102 | first element of the C<@{^CAPTURE}> variable inside of a double quoted | |
103 | string you would write C<"${^CAPTURE[0]}"> and NOT C<"${^CAPTURE}[0]"> | |
104 | which would mean to reference a scalar variable named C<${^CAPTURE}> and | |
105 | not index 0 of the magic C<@{^CAPTURE}> array which is populated by the | |
106 | regex engine. | |
107 | ||
108 | =end original | |
109 | ||
110 | この種類の変数の添え字にアクセスするためにも境界を定める形式を | |
111 | B<使わなければならない> ことに注意してください; | |
112 | 例えば、ダブルクォート文字列の中で | |
113 | C<@{^CAPTURE}> 変数の最初の要素にアクセスするには、 | |
114 | C<"${^CAPTURE}[0]"> ではなく C<"${^CAPTURE[0]}"> と書きます; | |
115 | 前者は C<${^CAPTURE}> という名前のスカラ変数へのリファレンスで、 | |
116 | 正規表現エンジンによって設定された C<@{^CAPTURE}> マジック配列の | |
117 | インデックス 0 ではありません。 | |
118 | ||
119 | =begin original | |
120 | ||
121 | Perl identifiers that begin with digits or | |
97 | 122 | punctuation characters are exempt from the effects of the C<package> |
98 | 123 | declaration and are always forced to be in package C<main>; they are |
99 | also exempt from C<strict 'vars'> errors. A few other names are also | |
124 | also exempt from C<strict 'vars'> errors. A few other names are also | |
100 | 125 | exempt in these ways: |
101 | 126 | |
102 | 127 | =end original |
103 | 128 | |
104 | 数字、 | |
129 | 数字、句読点で始まる Perl の識別子は C<package> 宣言の | |
105 | ||
130 | 効果から逃れて、常に C<main> パッケージにあるものとして扱われます。 | |
106 | ||
131 | さらに以下のものも逃れます: | |
107 | 132 | |
108 | ||
133 | ENV STDIN | |
109 | ||
134 | INC STDOUT | |
110 | ||
135 | ARGV STDERR | |
111 | ||
136 | ARGVOUT | |
112 | ||
137 | SIG | |
113 | 138 | |
114 | 139 | =begin original |
115 | 140 | |
116 | 141 | In particular, the special C<${^_XYZ}> variables are always taken |
117 | 142 | to be in package C<main>, regardless of any C<package> declarations |
118 | 143 | presently in scope. |
119 | 144 | |
120 | 145 | =end original |
121 | 146 | |
122 | 147 | 特に、新しい特別な C<${^_XYZ}> 変数はスコープ内の C<package> 宣言に関わらず |
123 | 148 | 常に C<main> パッケージとして扱われます。 |
124 | 149 | |
125 | 150 | =head1 SPECIAL VARIABLES |
126 | 151 | |
127 | 152 | (特殊変数) |
128 | 153 | |
129 | 154 | =begin original |
130 | 155 | |
131 | The following names have special meaning to Perl. Most punctuation | |
156 | The following names have special meaning to Perl. Most punctuation | |
132 | 157 | names have reasonable mnemonics, or analogs in the shells. |
133 | 158 | Nevertheless, if you wish to use long variable names, you need only say: |
134 | 159 | |
135 | 160 | =end original |
136 | 161 | |
137 | 162 | 以下の名前は Perl では特別な意味を持ちます。 |
138 | 163 | 記号的な名前の多くは記憶法があるか、シェルでの類推が可能です。 |
139 | 164 | それでも長い名前を使用したい場合には |
140 | 165 | |
141 | ||
166 | use English; | |
142 | 167 | |
143 | 168 | =begin original |
144 | 169 | |
145 | at the top of your program. This aliases all the short names to the long | |
170 | at the top of your program. This aliases all the short names to the long | |
146 | names in the current package. Some even have medium names, generally | |
171 | names in the current package. Some even have medium names, generally | |
147 | borrowed from B<awk>. | |
172 | borrowed from B<awk>. For more info, please see L<English>. | |
148 | C<$PREMATCH>, C<$MATCH>, or C<$POSTMATCH> it's best to use the C<English> | |
149 | module without them: | |
150 | 173 | |
151 | 174 | =end original |
152 | 175 | |
153 | 176 | とプログラムの最初に書いてください。 |
154 | 177 | これは、すべての短い名前の別名として、 |
155 | 178 | カレントパッケージで長い名前を付けるものです。 |
156 | 179 | B<awk> から持ってきた中間的な名前を持っているものもあります。 |
157 | ||
180 | さらなる情報については、どうか L<English> を参照してください。 | |
158 | C<$POSTMATCH> が必要ないなら、これらなしで C<English> モジュールを使うのが | |
159 | 最善です: | |
160 | 181 | |
161 | use English '-no_match_vars'; | |
162 | ||
163 | 182 | =begin original |
164 | 183 | |
165 | Before you continue, note the sort order for variables. In general, we | |
184 | Before you continue, note the sort order for variables. In general, we | |
166 | 185 | first list the variables in case-insensitive, almost-lexigraphical |
167 | 186 | order (ignoring the C<{> or C<^> preceding words, as in C<${^UNICODE}> |
168 | 187 | or C<$^T>), although C<$_> and C<@_> move up to the top of the pile. |
169 | 188 | For variables with the same identifier, we list it in order of scalar, |
170 | 189 | array, hash, and bareword. |
171 | 190 | |
172 | 191 | =end original |
173 | 192 | |
174 | 193 | 先に進む前に、変数のソート順に注意してください。 |
175 | 194 | 一般的に、変数を大文字小文字を無視して、ほとんど辞書順に並んでいます |
176 | (C<${^UNICODE}> や C<$^T> 先頭についている C<{> や C<^> は | |
195 | (C<${^UNICODE}> や C<$^T> のように、先頭についている C<{> や C<^> は | |
177 | C<$_> と C<@_> は先頭に来ます。 | |
196 | 無視します)が、C<$_> と C<@_> は先頭に来ます。 | |
178 | 197 | 同じ識別子を持つ変数については、スカラ、配列、ハッシュ、裸の単語の順に |
179 | 198 | 並べています。 |
180 | 199 | |
181 | 200 | =head2 General Variables |
182 | 201 | |
183 | 202 | (一般変数) |
184 | 203 | |
185 | 204 | =over 8 |
186 | 205 | |
187 | 206 | =item $ARG |
188 | 207 | |
189 | 208 | =item $_ |
190 | 209 | X<$_> X<$ARG> |
191 | 210 | |
192 | 211 | =begin original |
193 | 212 | |
194 | The default input and pattern-searching space. The following pairs are | |
213 | The default input and pattern-searching space. The following pairs are | |
195 | 214 | equivalent: |
196 | 215 | |
197 | 216 | =end original |
198 | 217 | |
199 | 218 | デフォルトの入力とパターン検索のスペース。 |
200 | 219 | 以下の 2つは同値です: |
201 | 220 | |
202 | ||
221 | =begin original | |
203 | while (defined($_ = <>)) {...} | |
204 | 222 | |
205 | ||
223 | while (<>) {...} # equivalent only in while! | |
206 | ||
224 | while (defined($_ = <>)) {...} | |
207 | 225 | |
208 | ||
226 | =end original | |
209 | $_ =~ tr/a-z/A-Z/ | |
210 | 227 | |
211 | ||
228 | while (<>) {...} # while の中でのみ等価! | |
212 | ||
229 | while (defined($_ = <>)) {...} | |
213 | 230 | |
231 | /^Subject:/ | |
232 | $_ =~ /^Subject:/ | |
233 | ||
234 | tr/a-z/A-Z/ | |
235 | $_ =~ tr/a-z/A-Z/ | |
236 | ||
237 | chomp | |
238 | chomp($_) | |
239 | ||
214 | 240 | =begin original |
215 | 241 | |
216 | 242 | Here are the places where Perl will assume C<$_> even if you don't use it: |
217 | 243 | |
218 | 244 | =end original |
219 | 245 | |
220 | 246 | あなたが使いたくなくても Perl が C<$_> を仮定する場合がいくつかあります: |
221 | 247 | |
222 | 248 | =over 3 |
223 | 249 | |
224 | 250 | =item * |
225 | 251 | |
226 | 252 | =begin original |
227 | 253 | |
228 | 254 | The following functions use C<$_> as a default argument: |
229 | 255 | |
230 | 256 | =end original |
231 | 257 | |
232 | 258 | 以下の関数は C<$_> をデフォルト引数として使います: |
233 | 259 | |
234 | 260 | =begin original |
235 | 261 | |
236 | abs, alarm, chomp, chop, chr, chroot, | |
262 | abs, alarm, chomp, chop, chr, chroot, | |
237 | ||
263 | cos, defined, eval, evalbytes, exp, fc, glob, hex, int, lc, | |
264 | lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, printf, | |
238 | 265 | quotemeta, readlink, readpipe, ref, require, reverse (in scalar context only), |
239 | rmdir, sin, split (o | |
266 | rmdir, say, sin, split (for its second | |
267 | argument), sqrt, stat, study, uc, ucfirst, | |
240 | 268 | unlink, unpack. |
241 | 269 | |
242 | 270 | =end original |
243 | 271 | |
244 | abs, alarm, chomp, chop, chr, chroot, | |
272 | abs, alarm, chomp, chop, chr, chroot, | |
245 | ||
273 | cos, defined, eval, evalbytes, exp, fc, glob, hex, int, lc, | |
274 | lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, printf, | |
246 | 275 | quotemeta, readlink, readpipe, ref, require, reverse (スカラコンテキストのみ), |
247 | rmdir, sin, split (の 2 番目の引数), | |
276 | rmdir, say, sin, split (の 2 番目の引数), | |
248 | u | |
277 | sqrt, stat, study, uc, ucfirst, | |
278 | unlink, unpack | |
249 | 279 | |
250 | 280 | =item * |
251 | 281 | |
252 | 282 | =begin original |
253 | 283 | |
254 | 284 | All file tests (C<-f>, C<-d>) except for C<-t>, which defaults to STDIN. |
255 | 285 | See L<perlfunc/-X> |
256 | 286 | |
257 | 287 | =end original |
258 | 288 | |
259 | デフォルトが STDIN である C<-t> を除く全てのファイルテスト(C<-f>, C<-d>) | |
289 | デフォルトが STDIN である C<-t> を除く全てのファイルテスト(C<-f>, C<-d>)。 | |
260 | 290 | L<perlfunc/-X> を参照してください。 |
261 | 291 | |
262 | 292 | =item * |
263 | 293 | |
264 | 294 | =begin original |
265 | 295 | |
266 | 296 | The pattern matching operations C<m//>, C<s///> and C<tr///> (aka C<y///>) |
267 | 297 | when used without an C<=~> operator. |
268 | 298 | |
269 | 299 | =end original |
270 | 300 | |
271 | 301 | C<=~> 演算子なしで用いられたパターンマッチ演算 C<m//>, C<s///>, C<tr///> |
272 | 302 | (またの名を C<y///>)。 |
273 | 303 | |
274 | 304 | =item * |
275 | 305 | |
276 | 306 | =begin original |
277 | 307 | |
278 | 308 | The default iterator variable in a C<foreach> loop if no other |
279 | 309 | variable is supplied. |
280 | 310 | |
281 | 311 | =end original |
282 | 312 | |
283 | C<foreach> ループでの他の変数が補われなかった場合のデフォルトの | |
313 | C<foreach> ループでの他の変数が補われなかった場合のデフォルトの繰り返し変数。 | |
284 | 繰り返し変数。 | |
285 | 314 | |
286 | 315 | =item * |
287 | 316 | |
288 | 317 | =begin original |
289 | 318 | |
290 | 319 | The implicit iterator variable in the C<grep()> and C<map()> functions. |
291 | 320 | |
292 | 321 | =end original |
293 | 322 | |
294 | 323 | C<grep()> 関数と C<map()> 関数の暗黙の繰り返し変数。 |
295 | 324 | |
296 | 325 | =item * |
297 | 326 | |
298 | 327 | =begin original |
299 | 328 | |
300 | 329 | The implicit variable of C<given()>. |
301 | 330 | |
302 | 331 | =end original |
303 | 332 | |
304 | 333 | C<given()> の暗黙の変数。 |
305 | 334 | |
306 | 335 | =item * |
307 | 336 | |
308 | 337 | =begin original |
309 | 338 | |
310 | The default place to put | |
339 | The default place to put the next value or input record | |
340 | when a C<< <FH> >>, C<readline>, C<readdir> or C<each> | |
311 | 341 | operation's result is tested by itself as the sole criterion of a C<while> |
312 | test. Outside a C<while> test, this will not happen. | |
342 | test. Outside a C<while> test, this will not happen. | |
313 | 343 | |
314 | 344 | =end original |
315 | 345 | |
316 | C<< <FH> >> が単独で C<while> テストで | |
346 | C<< <FH> >>, C<readline>, C<readdir>, C<each> が単独で C<while> テストで | |
317 | ||
347 | テストされた場合の、次の値や入力レコードを入れるデフォルトの場所。 | |
318 | 348 | C<while> テスト以外ではこれは起こりません。 |
319 | 349 | |
320 | 350 | =back |
321 | 351 | |
322 | 352 | =begin original |
323 | 353 | |
324 | ||
354 | C<$_> is a global variable. | |
325 | side-effects. As of perl 5.9.1, you can now use a lexical version of | |
326 | C<$_> by declaring it in a file or in a block with C<my>. Moreover, | |
327 | declaring C<our $_> restores the global C<$_> in the current scope. | |
328 | 355 | |
329 | 356 | =end original |
330 | 357 | |
331 | C<$_> はグローバル変数 | |
358 | C<$_> はグローバル変数です。 | |
332 | perl 5.9.1 から、ファイルやブロックで C<my> で宣言することで、 | |
333 | レキシカル版の C<$_> が使えます。 | |
334 | さらに、C<our $_> という宣言は現在のスコープでグローバルな C<$_> を | |
335 | 再構築します。 | |
336 | 359 | |
337 | 360 | =begin original |
338 | 361 | |
362 | However, between perl v5.10.0 and v5.24.0, it could be used lexically by | |
363 | writing C<my $_>. Making C<$_> refer to the global C<$_> in the same scope | |
364 | was then possible with C<our $_>. This experimental feature was removed and is | |
365 | now a fatal error, but you may encounter it in older code. | |
366 | ||
367 | =end original | |
368 | ||
369 | しかし、perl v5.10.0 から v5.24.0 の間、 | |
370 | C<my $_> と書くことでこれをレキシカルに使うことが出来ました。 | |
371 | 同じスコープで C<$_> がグローバルな C<$_> を参照するのは | |
372 | C<our $_> で可能になっていました。 | |
373 | この実験的機能は削除されて今では致命的エラーですが、 | |
374 | 古いコードで見かけるかも知れません。 | |
375 | ||
376 | =begin original | |
377 | ||
339 | 378 | Mnemonic: underline is understood in certain operations. |
340 | 379 | |
341 | 380 | =end original |
342 | 381 | |
343 | 382 | 記憶法: 下線はある操作を覚えるためのもの。 |
344 | 383 | |
345 | 384 | =item @ARG |
346 | 385 | |
347 | 386 | =item @_ |
348 | 387 | X<@_> X<@ARG> |
349 | 388 | |
350 | 389 | =begin original |
351 | 390 | |
352 | 391 | Within a subroutine the array C<@_> contains the parameters passed to |
353 | that subroutine. Inside a subroutine, C<@_> is the default array for | |
392 | that subroutine. Inside a subroutine, C<@_> is the default array for | |
354 | the array operators C<p | |
393 | the array operators C<pop> and C<shift>. | |
355 | 394 | |
356 | 395 | =end original |
357 | 396 | |
358 | 397 | サブルーチンに入るときには、配列 C<@_> はサブルーチンに渡された |
359 | 398 | パラメータです。 |
360 | サブルーチンの内部では、C<@_> は配列演算子 C<push>, C< | |
399 | サブルーチンの内部では、C<@_> は配列演算子 C<push>, C<shift> の | |
361 | ||
400 | デフォルト配列です。 | |
362 | 401 | |
363 | 402 | =begin original |
364 | 403 | |
365 | 404 | See L<perlsub>. |
366 | 405 | |
367 | 406 | =end original |
368 | 407 | |
369 | 408 | L<perlsub> を参照して下さい。 |
370 | 409 | |
371 | 410 | =item $LIST_SEPARATOR |
372 | 411 | |
373 | 412 | =item $" |
374 | 413 | X<$"> X<$LIST_SEPARATOR> |
375 | 414 | |
376 | 415 | =begin original |
377 | 416 | |
378 | 417 | When an array or an array slice is interpolated into a double-quoted |
379 | 418 | string or a similar context such as C</.../>, its elements are |
380 | separated by this value. Default is a space. For example, this: | |
419 | separated by this value. Default is a space. For example, this: | |
381 | 420 | |
382 | 421 | =end original |
383 | 422 | |
384 | 423 | 配列や配列スライスがダブルクォートされた文字列あるいは C</.../> のような |
385 | 424 | 同様のコンテキスト展開されたとき、その要素はこの値で分割されます。 |
386 | 425 | デフォルトは空白です。 |
387 | 426 | 例えば、以下のものは: |
388 | 427 | |
389 | ||
428 | print "The array is: @array\n"; | |
390 | 429 | |
391 | 430 | =begin original |
392 | 431 | |
393 | 432 | is equivalent to this: |
394 | 433 | |
395 | 434 | =end original |
396 | 435 | |
397 | 436 | 以下と等価です: |
398 | 437 | |
399 | ||
438 | print "The array is: " . join($", @array) . "\n"; | |
400 | 439 | |
401 | 440 | =begin original |
402 | 441 | |
403 | 442 | Mnemonic: works in double-quoted context. |
404 | 443 | |
405 | 444 | =end original |
406 | 445 | |
407 | 446 | 記憶法: ダブルクォートされた内容に対して動作します。 |
408 | 447 | |
409 | 448 | =item $PROCESS_ID |
410 | 449 | |
411 | 450 | =item $PID |
412 | 451 | |
413 | 452 | =item $$ |
414 | 453 | X<$$> X<$PID> X<$PROCESS_ID> |
415 | 454 | |
416 | 455 | =begin original |
417 | 456 | |
418 | The process number of the Perl running this script. | |
457 | The process number of the Perl running this script. Though you I<can> set | |
419 | ||
458 | this variable, doing so is generally discouraged, although it can be | |
459 | invaluable for some testing purposes. It will be reset automatically | |
420 | 460 | across C<fork()> calls. |
421 | 461 | |
422 | 462 | =end original |
423 | 463 | |
424 | スクリプトを実行している Perl のプロセス番号です。 | |
464 | このスクリプトを実行している Perl のプロセス番号です。 | |
425 | この変数は | |
465 | この変数に値を設定することは I<可能> ですが、そうすることは一般的に | |
426 | ||
466 | 非推奨です; しかしこれは一部のテストの目的には計り知れない価値があります。 | |
467 | C<fork()> 呼び出しがあると自動的にリセットされます。 | |
427 | 468 | |
428 | 469 | =begin original |
429 | 470 | |
430 | Note for Linux | |
471 | Note for Linux and Debian GNU/kFreeBSD users: Before Perl v5.16.0 perl | |
431 | ||
472 | would emulate POSIX semantics on Linux systems using LinuxThreads, a | |
432 | ||
473 | partial implementation of POSIX Threads that has since been superseded | |
433 | ||
474 | by the Native POSIX Thread Library (NPTL). | |
434 | you may use the CPAN module C<Linux::Pid>. | |
435 | 475 | |
436 | 476 | =end original |
437 | 477 | |
438 | Linux ユーザー | |
478 | Linux および Debian GNU/kFreeBSD ユーザーに対する注意: Perl v5.16.0 より | |
439 | ||
479 | 前では perl は LinuxThreads を使って Linux システムで POSIX の意味論を | |
440 | ||
480 | エミュレートしていました; これは POSIX Threads の部分的な実装で、 | |
441 | ||
481 | Native POSIX Thread Library (NPTL) で置き換えられました。 | |
442 | もし内在する C<getpid()> を呼び出したい場合は、CPAN モジュール | |
443 | C<Linux::Pid> が使えます。 | |
444 | 482 | |
445 | 483 | =begin original |
446 | 484 | |
447 | ||
485 | LinuxThreads is now obsolete on Linux, and caching C<getpid()> | |
486 | like this made embedding perl unnecessarily complex (since you'd have | |
487 | to manually update the value of $$), so now C<$$> and C<getppid()> | |
488 | will always return the same values as the underlying C library. | |
448 | 489 | |
449 | 490 | =end original |
450 | 491 | |
451 | ||
492 | LinuxThreads は Linux では古いもので、このように C<getpid()> を | |
493 | キャッシュすると組み込み perl が不必要に複雑になります ($$ の値を手動で | |
494 | 更新する必要があるからです); それで今では C<$$> と C<getppid()> は常に | |
495 | 基礎となる C ライブラリと同じ値を返します。 | |
452 | 496 | |
453 | =item $REAL_GROUP_ID | |
454 | ||
455 | =item $GID | |
456 | ||
457 | =item $( | |
458 | X<$(> X<$GID> X<$REAL_GROUP_ID> | |
459 | ||
460 | 497 | =begin original |
461 | 498 | |
462 | ||
499 | Debian GNU/kFreeBSD systems also used LinuxThreads up until and | |
463 | ||
500 | including the 6.0 release, but after that moved to FreeBSD thread | |
464 | ||
501 | semantics, which are POSIX-like. | |
465 | C<getgid()>, and the subsequent ones by C<getgroups()>, one of which may be | |
466 | the same as the first number. | |
467 | 502 | |
468 | 503 | =end original |
469 | 504 | |
470 | ||
505 | Debian GNU/kFreeBSD システムは 6.0 リリースまで LinuxThreads を | |
471 | ||
506 | 使っていましたが、その後は POSIX 風の FreeBSD スレッドの意味論に | |
472 | ||
507 | 移行しました。 | |
473 | 最初の数値は、C<getgid()> で返されるものです。 | |
474 | その後に C<getgroups()> が返す値が続き、その中の 1 つは、 | |
475 | 最初の値と同じかもしれません。 | |
476 | 508 | |
477 | 509 | =begin original |
478 | 510 | |
479 | ||
511 | To see if your system is affected by this discrepancy check if | |
480 | ||
512 | C<getconf GNU_LIBPTHREAD_VERSION | grep -q NPTL> returns a false | |
481 | ||
513 | value. NTPL threads preserve the POSIX semantics. | |
482 | that this is different to the effective gid (C<$)>) which does take a | |
483 | list. | |
484 | 514 | |
485 | 515 | =end original |
486 | 516 | |
487 | ||
517 | あなたのシステムがこの非一貫性の影響を受けるかどうかを調べるには、 | |
488 | ||
518 | C<getconf GNU_LIBPTHREAD_VERSION | grep -q NPTL> が偽を返すかどうかを | |
489 | ||
519 | チェックしてください。 | |
490 | ||
520 | NTPL スレッドは POSIX の意味論を保存します。 | |
491 | これはリストが得られる実行 GID (C<$)>) とは違うことに注意してください。 | |
492 | 521 | |
493 | 522 | =begin original |
494 | 523 | |
495 | ||
524 | Mnemonic: same as shells. | |
496 | time by using C<POSIX::setgid()>. Changes to C<$(> require a check to C<$!> | |
497 | to detect any possible errors after an attempted change. | |
498 | 525 | |
499 | 526 | =end original |
500 | 527 | |
501 | ||
528 | 記憶法: シェルと同じ。 | |
502 | C<$(> を変更した場合は、変更しようとしたときに起こりうるエラーを検出するために | |
503 | C<$!> をチェックする必要があります。 | |
504 | 529 | |
505 | =begin original | |
506 | ||
507 | Mnemonic: parentheses are used to I<group> things. The real gid is the | |
508 | group you I<left>, if you're running setgid. | |
509 | ||
510 | =end original | |
511 | ||
512 | 記憶法: 括弧は、I<グループ化>に使われます。 | |
513 | setgid で実行中であれば、実 gid は I<left> した、つまり離れたグループです。 | |
514 | ||
515 | =item $EFFECTIVE_GROUP_ID | |
516 | ||
517 | =item $EGID | |
518 | ||
519 | =item $) | |
520 | X<$)> X<$EGID> X<$EFFECTIVE_GROUP_ID> | |
521 | ||
522 | =begin original | |
523 | ||
524 | The effective gid of this process. If you are on a machine that | |
525 | supports membership in multiple groups simultaneously, gives a space | |
526 | separated list of groups you are in. The first number is the one | |
527 | returned by C<getegid()>, and the subsequent ones by C<getgroups()>, | |
528 | one of which may be the same as the first number. | |
529 | ||
530 | =end original | |
531 | ||
532 | 本プロセスの実効 gid を示します。 | |
533 | 同時に複数のグループに所属できるマシンでは、 | |
534 | 所属するグループをスペースで区切ったリストが得られます。 | |
535 | 最初の数値は、C<getegid()> で返されるものです。 | |
536 | その後に C<getgroups()> が返す値が続き、その中の 1 つは、 | |
537 | 最初の値と同じかもしれません。 | |
538 | ||
539 | =begin original | |
540 | ||
541 | Similarly, a value assigned to C<$)> must also be a space-separated | |
542 | list of numbers. The first number sets the effective gid, and | |
543 | the rest (if any) are passed to C<setgroups()>. To get the effect of an | |
544 | empty list for C<setgroups()>, just repeat the new effective gid; that is, | |
545 | to force an effective gid of 5 and an effectively empty C<setgroups()> | |
546 | list, say C< $) = "5 5" >. | |
547 | ||
548 | =end original | |
549 | ||
550 | 同様に、C<$)> へ代入する値はスペースで区切られた数値の | |
551 | リストでなければなりません。 | |
552 | 最初の数値は実効 gid を設定し、残りの数値は(もしあれば) C<setgroups()> に | |
553 | 渡されます。 | |
554 | C<setgroups()> に空リストを渡したい場合は、単に新しい実効 gid を | |
555 | 繰り返してください。 | |
556 | つまり、実効 gid を 5 にして、C<setgroups()> に空リストを渡したい場合は、 | |
557 | C< $) = "5 5" > としてください。 | |
558 | ||
559 | =begin original | |
560 | ||
561 | You can change both the effective gid and the real gid at the same | |
562 | time by using C<POSIX::setgid()> (use only a single numeric argument). | |
563 | Changes to C<$)> require a check to C<$!> to detect any possible errors | |
564 | after an attempted change. | |
565 | ||
566 | =end original | |
567 | ||
568 | C<POSIX::setgid()> を使って、実効 GID と実 GID を同時に変更できます。 | |
569 | (1 つの数値引数だけが使えます)。 | |
570 | C<$)> を変更した場合は、変更時に起こりうるエラーを検出するために C<$!> の | |
571 | チェックが必要です。 | |
572 | ||
573 | =begin original | |
574 | ||
575 | C<< $< >>, C<< $> >>, C<$(> and C<$)> can be set only on | |
576 | machines that support the corresponding I<set[re][ug]id()> routine. C<$(> | |
577 | and C<$)> can be swapped only on machines supporting C<setregid()>. | |
578 | ||
579 | =end original | |
580 | ||
581 | C<< $< >>, C<< $> >>, C<$(>, C<$)> は、実行するマシンで、 | |
582 | 対応する I<set[re][ug]id()> ルーティンがサポートされているときにのみ | |
583 | 設定可能です。 | |
584 | C<$(> と C<$)> の交換は、 | |
585 | C<setregid()> がサポートされているマシンでのみ可能です。 | |
586 | ||
587 | =begin original | |
588 | ||
589 | Mnemonic: parentheses are used to I<group> things. The effective gid | |
590 | is the group that's I<right> for you, if you're running setgid. | |
591 | ||
592 | =end original | |
593 | ||
594 | 記憶法: 括弧は、I<グループ化>に使われます。 | |
595 | setgid で実行中であれば、実効 gid は right な、つまり正しいグループです。 | |
596 | ||
597 | 530 | =item $PROGRAM_NAME |
598 | 531 | |
599 | 532 | =item $0 |
600 | 533 | X<$0> X<$PROGRAM_NAME> |
601 | 534 | |
602 | 535 | =begin original |
603 | 536 | |
604 | 537 | Contains the name of the program being executed. |
605 | 538 | |
606 | 539 | =end original |
607 | 540 | |
608 | 541 | 実行されているプログラムの名前を示します。 |
609 | 542 | |
610 | 543 | =begin original |
611 | 544 | |
612 | 545 | On some (but not all) operating systems assigning to C<$0> modifies |
613 | the argument area that the C<ps> program sees. On some platforms you | |
546 | the argument area that the C<ps> program sees. On some platforms you | |
614 | 547 | may have to use special C<ps> options or a different C<ps> to see the |
615 | changes. Modifying the C<$0> is more useful as a way of indicating the | |
548 | changes. Modifying the C<$0> is more useful as a way of indicating the | |
616 | 549 | current program state than it is for hiding the program you're |
617 | 550 | running. |
618 | 551 | |
619 | 552 | =end original |
620 | 553 | |
621 | 554 | 一部の(しかし全てではありません)オペレーティングシステムでは |
622 | 555 | C<$0> に代入を行なうことで B<ps> プログラムが見る引数エリアを修正します。 |
623 | 556 | プラットフォームによっては、この変更を見るために 特殊な C<ps> オプションや、 |
624 | 557 | 他の C<ps> を使う必要があるものもあります。 |
625 | 558 | C<$0> の修正は、実行しているプログラムを隠すよりは、 |
626 | 559 | 実行中のプログラムの状態を表示するときに、使うとよいでしょう。 |
627 | 560 | |
628 | 561 | =begin original |
629 | 562 | |
630 | 563 | Note that there are platform-specific limitations on the maximum |
631 | length of C<$0>. In the most extreme case it may be limited to the | |
564 | length of C<$0>. In the most extreme case it may be limited to the | |
632 | 565 | space occupied by the original C<$0>. |
633 | 566 | |
634 | 567 | =end original |
635 | 568 | |
636 | 569 | C<$0> の最大長にはプラットフォーム固有の制限があることに注意してください。 |
637 | 570 | 最も極端な場合では、元の C<$0> で占められているサイズに制限されます。 |
638 | 571 | |
639 | 572 | =begin original |
640 | 573 | |
641 | 574 | In some platforms there may be arbitrary amount of padding, for |
642 | 575 | example space characters, after the modified name as shown by C<ps>. |
643 | 576 | In some platforms this padding may extend all the way to the original |
644 | 577 | length of the argument area, no matter what you do (this is the case |
645 | 578 | for example with Linux 2.2). |
646 | 579 | |
647 | 580 | =end original |
648 | 581 | |
649 | 582 | プラットフォームによっては、任意の量のパッディングがある場合があります; |
650 | 583 | 例えば、C<ps> で見られる修正された名前の後の空白文字です。 |
651 | 584 | プラットフォームによっては、このパッディングは、あなたが何をしたかに |
652 | 585 | 関わらず、元の引数のエリア全体に拡張されるものもあります |
653 | 586 | (例えば、これは Linux 2.2 の場合です)。 |
654 | 587 | |
655 | 588 | =begin original |
656 | 589 | |
657 | 590 | Note for BSD users: setting C<$0> does not completely remove "perl" |
658 | from the ps(1) output. For example, setting C<$0> to C<"foobar"> may | |
591 | from the ps(1) output. For example, setting C<$0> to C<"foobar"> may | |
659 | 592 | result in C<"perl: foobar (perl)"> (whether both the C<"perl: "> prefix |
660 | 593 | and the " (perl)" suffix are shown depends on your exact BSD variant |
661 | and version). This is an operating system feature, Perl cannot help it. | |
594 | and version). This is an operating system feature, Perl cannot help it. | |
662 | 595 | |
663 | 596 | =end original |
664 | 597 | |
665 | 598 | BSD ユーザーへの注意: C<$0> に値をセットしても、ps(1) の出力から |
666 | 599 | 完全に "perl" の文字列は取り除かれません。 |
667 | 600 | 例えば、C<$0> に C<"foobar"> と設定すると、C<"perl: foobar (perl)"> という |
668 | 601 | 結果になります |
669 | 602 | (C<"perl: "> 接頭辞と" (perl)" 接尾辞が表示されるかどうかは 、正確な |
670 | 603 | BSD の種類とバージョンに依存します)。 |
671 | 604 | これはオペレーティングシステムの機能で、Perl は何もできません。 |
672 | 605 | |
673 | 606 | =begin original |
674 | 607 | |
675 | 608 | In multithreaded scripts Perl coordinates the threads so that any |
676 | 609 | thread may modify its copy of the C<$0> and the change becomes visible |
677 | to ps(1) (assuming the operating system plays along). Note that | |
610 | to ps(1) (assuming the operating system plays along). Note that | |
678 | 611 | the view of C<$0> the other threads have will not change since they |
679 | 612 | have their own copies of it. |
680 | 613 | |
681 | 614 | =end original |
682 | 615 | |
683 | 616 | マルチスレッドスクリプトでは、どのスレッドも自身の C<$0> のコピーを |
684 | 617 | 変更できて、その変更が(OS が対応しているとして) ps(1) で見えるように、 |
685 | 618 | Perl がスレッドを調整します。 |
686 | 619 | 他のスレッドが持っている C<$0> の見え方は(各自が自身のコピーを |
687 | 620 | 持っているので)変わらないことに注意してください。 |
688 | 621 | |
689 | 622 | =begin original |
690 | 623 | |
691 | 624 | If the program has been given to perl via the switches C<-e> or C<-E>, |
692 | 625 | C<$0> will contain the string C<"-e">. |
693 | 626 | |
694 | 627 | =end original |
695 | 628 | |
696 | 629 | プログラムが perl に C<-e> または C<-E> オプション経由で与えられた場合、 |
697 | 630 | C<$0> には文字列 C<"-e"> を含みます。 |
698 | 631 | |
699 | 632 | =begin original |
700 | 633 | |
701 | On Linux as of perl 5.14 the legacy process name will be set with | |
634 | On Linux as of perl v5.14.0 the legacy process name will be set with | |
702 | 635 | C<prctl(2)>, in addition to altering the POSIX name via C<argv[0]> as |
703 | perl has done since version 4.000. Now system utilities that read the | |
636 | perl has done since version 4.000. Now system utilities that read the | |
704 | 637 | legacy process name such as ps, top and killall will recognize the |
705 | name you set when assigning to C<$0>. The string you supply will be | |
638 | name you set when assigning to C<$0>. The string you supply will be | |
706 | 639 | cut off at 16 bytes, this is a limitation imposed by Linux. |
707 | 640 | |
708 | 641 | =end original |
709 | 642 | |
710 | Linux では perl 5.14 以降、perl がバージョン 4.000 以降行っていた | |
643 | Linux では perl v5.14.0 以降、perl がバージョン 4.000 以降行っていた | |
711 | 644 | C<argv[0]> 経由での POSIX 名の置き換えに加えて、 |
712 | 645 | レガシープロセス名は C<prctl(2)> で設定されます。 |
713 | 646 | 今では ps, top, killall のようにレガシープロセス名を読むユーティリティは |
714 | 647 | C<$0> に代入することに設定される名前を認識します。 |
715 | 648 | 指定した文字列は 16 バイトに切り詰められます; これは Linux による |
716 | 649 | 制限です。 |
717 | 650 | |
718 | 651 | =begin original |
719 | 652 | |
653 | Wide characters are invalid in C<$0> values. For historical reasons, | |
654 | though, Perl accepts them and encodes them to UTF-8. When this | |
655 | happens a wide-character warning is triggered. | |
656 | ||
657 | =end original | |
658 | ||
659 | ワイド文字は C<$0> の値としては不正です。 | |
660 | しかし、歴史的な理由により、Perl はこれを受け入れて、UTF-8 に | |
661 | エンコードします。 | |
662 | これが起きると、wide-character 警告が引き起こされます。 | |
663 | ||
664 | =begin original | |
665 | ||
720 | 666 | Mnemonic: same as B<sh> and B<ksh>. |
721 | 667 | |
722 | 668 | =end original |
723 | 669 | |
724 | 670 | 記憶法: B<sh> や B<ksh> と同じ。 |
725 | 671 | |
726 | =item $ | |
672 | =item $REAL_GROUP_ID | |
727 | 673 | |
728 | =item $ | |
674 | =item $GID | |
729 | 675 | |
730 | =item $ | |
676 | =item $( | |
731 | X<$ | |
677 | X<$(> X<$GID> X<$REAL_GROUP_ID> | |
732 | 678 | |
733 | 679 | =begin original |
734 | 680 | |
735 | The | |
681 | The real gid of this process. If you are on a machine that supports | |
736 | ||
682 | membership in multiple groups simultaneously, gives a space separated | |
683 | list of groups you are in. The first number is the one returned by | |
684 | C<getgid()>, and the subsequent ones by C<getgroups()>, one of which may be | |
685 | the same as the first number. | |
737 | 686 | |
738 | 687 | =end original |
739 | 688 | |
740 | ||
689 | 本プロセスの実 gid を示します。 | |
741 | ||
690 | 同時に複数のグループに所属できるマシンでは、所属するグループをスペースで | |
691 | 区切ったリストが得られます。 | |
692 | 最初の数値は、C<getgid()> で返されるものです; その後に C<getgroups()> が | |
693 | 返す値が続き、その中の 1 つは、最初の値と同じかもしれません。 | |
742 | 694 | |
743 | $foo{$a,$b,$c} | |
744 | ||
745 | 695 | =begin original |
746 | 696 | |
747 | it | |
697 | However, a value assigned to C<$(> must be a single number used to | |
698 | set the real gid. So the value given by C<$(> should I<not> be assigned | |
699 | back to C<$(> without being forced numeric, such as by adding zero. Note | |
700 | that this is different to the effective gid (C<$)>) which does take a | |
701 | list. | |
748 | 702 | |
749 | 703 | =end original |
750 | 704 | |
751 | ||
705 | しかし、C<$(> に代入された値は実際の gid に設定された値の | |
706 | 一つでなければなりません。 | |
707 | 従って、 C<$(> で与えられた値はゼロを足すことによって | |
708 | 数値化することなく C<$(> に書き戻すべきではありません。 | |
709 | これはリストが得られる実行 GID (C<$)>) とは違うことに注意してください。 | |
752 | 710 | |
753 | ||
711 | =begin original | |
754 | 712 | |
713 | You can change both the real gid and the effective gid at the same | |
714 | time by using C<POSIX::setgid()>. Changes | |
715 | to C<$(> require a check to C<$!> | |
716 | to detect any possible errors after an attempted change. | |
717 | ||
718 | =end original | |
719 | ||
720 | C<POSIX::setgid()> を使って、実 GID と実効 GID の両方を同時に変更できます。 | |
721 | C<$(> を変更した場合は、変更しようとしたときに起こりうるエラーを検出するために | |
722 | C<$!> をチェックする必要があります。 | |
723 | ||
755 | 724 | =begin original |
756 | 725 | |
757 | ||
726 | Mnemonic: parentheses are used to I<group> things. The real gid is the | |
727 | group you I<left>, if you're running setgid. | |
758 | 728 | |
759 | 729 | =end original |
760 | 730 | |
761 | ||
731 | 記憶法: 括弧は、I<グループ化>に使われます。 | |
762 | し | |
732 | setgid で実行中であれば、実 gid は I<left> した、つまり離れたグループです。 | |
763 | 733 | |
764 | ||
734 | =item $EFFECTIVE_GROUP_ID | |
765 | 735 | |
736 | =item $EGID | |
737 | ||
738 | =item $) | |
739 | X<$)> X<$EGID> X<$EFFECTIVE_GROUP_ID> | |
740 | ||
766 | 741 | =begin original |
767 | 742 | |
768 | ||
743 | The effective gid of this process. If you are on a machine that | |
744 | supports membership in multiple groups simultaneously, gives a space | |
745 | separated list of groups you are in. The first number is the one | |
746 | returned by C<getegid()>, and the subsequent ones by C<getgroups()>, | |
747 | one of which may be the same as the first number. | |
769 | 748 | |
770 | 749 | =end original |
771 | 750 | |
772 | ||
751 | 本プロセスの実効 gid を示します。 | |
773 | ||
752 | 同時に複数のグループに所属できるマシンでは、所属するグループをスペースで | |
753 | 区切ったリストが得られます。 | |
754 | 最初の数値は、C<getegid()> で返されるものです; その後に C<getgroups()> が | |
755 | 返す値が続き、その中の 1 つは、最初の値と同じかもしれません。 | |
774 | 756 | |
775 | ||
757 | =begin original | |
776 | 758 | |
759 | Similarly, a value assigned to C<$)> must also be a space-separated | |
760 | list of numbers. The first number sets the effective gid, and | |
761 | the rest (if any) are passed to C<setgroups()>. To get the effect of an | |
762 | empty list for C<setgroups()>, just repeat the new effective gid; that is, | |
763 | to force an effective gid of 5 and an effectively empty C<setgroups()> | |
764 | list, say C< $) = "5 5" >. | |
765 | ||
766 | =end original | |
767 | ||
768 | 同様に、C<$)> へ代入する値はスペースで区切られた数値の | |
769 | リストでなければなりません。 | |
770 | 最初の数値は実効 gid を設定し、残りの数値は(もしあれば) C<setgroups()> に | |
771 | 渡されます。 | |
772 | C<setgroups()> に空リストを渡したい場合は、単に新しい実効 gid を | |
773 | 繰り返してください; つまり、実効 gid を 5 にして、C<setgroups()> に空リストを | |
774 | 渡したい場合は、C< $) = "5 5" > としてください。 | |
775 | ||
777 | 776 | =begin original |
778 | 777 | |
779 | ||
778 | You can change both the effective gid and the real gid at the same | |
780 | ||
779 | time by using C<POSIX::setgid()> (use only a single numeric argument). | |
780 | Changes to C<$)> require a check to C<$!> to detect any possible errors | |
781 | after an attempted change. | |
781 | 782 | |
782 | 783 | =end original |
783 | 784 | |
784 | ||
785 | C<POSIX::setgid()> を使って、実効 GID と実 GID を同時に変更できます | |
785 | ||
786 | (1 つの数値引数だけが使えます)。 | |
786 | C<$ | |
787 | C<$)> を変更した場合は、変更時に起こりうるエラーを検出するために C<$!> の | |
788 | チェックが必要です。 | |
787 | 789 | |
788 | 790 | =begin original |
789 | 791 | |
790 | C | |
792 | C<< $< >>, C<< $> >>, C<$(> and C<$)> can be set only on | |
791 | in | |
793 | machines that support the corresponding I<set[re][ug]id()> routine. C<$(> | |
794 | and C<$)> can be swapped only on machines supporting C<setregid()>. | |
792 | 795 | |
793 | 796 | =end original |
794 | 797 | |
795 | ||
798 | C<< $< >>, C<< $> >>, C<$(>, C<$)> は、実行するマシンで、 | |
799 | 対応する I<set[re][ug]id()> ルーティンがサポートされているときにのみ | |
800 | 設定可能です。 | |
801 | C<$(> と C<$)> の交換は、 | |
802 | C<setregid()> がサポートされているマシンでのみ可能です。 | |
796 | 803 | |
797 | 804 | =begin original |
798 | 805 | |
799 | Mnemonic: | |
806 | Mnemonic: parentheses are used to I<group> things. The effective gid | |
807 | is the group that's I<right> for you, if you're running setgid. | |
800 | 808 | |
801 | 809 | =end original |
802 | 810 | |
803 | 記憶法: | |
811 | 記憶法: 括弧は、I<グループ化>に使われます。 | |
804 | ||
812 | setgid で実行中であれば、実効 gid は right な、つまり正しいグループです。 | |
805 | 813 | |
806 | 814 | =item $REAL_USER_ID |
807 | 815 | |
808 | 816 | =item $UID |
809 | 817 | |
810 | 818 | =item $< |
811 | 819 | X<< $< >> X<$UID> X<$REAL_USER_ID> |
812 | 820 | |
813 | 821 | =begin original |
814 | 822 | |
815 | The real uid of this process. You can change both the real uid and the | |
823 | The real uid of this process. You can change both the real uid and the | |
816 | effective uid at the same time by using C<POSIX::setuid()>. Since | |
824 | effective uid at the same time by using C<POSIX::setuid()>. Since | |
817 | 825 | changes to C<< $< >> require a system call, check C<$!> after a change |
818 | 826 | attempt to detect any possible errors. |
819 | 827 | |
820 | 828 | =end original |
821 | 829 | |
822 | 830 | 本プロセスの実 uid を示します。 |
823 | 831 | C<POSIX::setuid()> を使って、実効 UID と実 UID を同時に変更できます。 |
824 | 832 | C<< $< >> の変更にはシステムコールが必要なので、起こりうるエラーを |
825 | 833 | 検出するために C<$!> のチェックが必要です。 |
826 | 834 | |
827 | 835 | =begin original |
828 | 836 | |
829 | 837 | Mnemonic: it's the uid you came I<from>, if you're running setuid. |
830 | 838 | |
831 | 839 | =end original |
832 | 840 | |
833 | 841 | 記憶法: setuid で実行中であれば、そこ「から」来た uid です。 |
834 | 842 | |
835 | 843 | =item $EFFECTIVE_USER_ID |
836 | 844 | |
837 | 845 | =item $EUID |
838 | 846 | |
839 | 847 | =item $> |
840 | 848 | X<< $> >> X<$EUID> X<$EFFECTIVE_USER_ID> |
841 | 849 | |
842 | 850 | =begin original |
843 | 851 | |
844 | The effective uid of this process. For example: | |
852 | The effective uid of this process. For example: | |
845 | 853 | |
846 | 854 | =end original |
847 | 855 | |
848 | 856 | 本プロセスの実効 uid を示します。 |
849 | 857 | 例えば: |
850 | 858 | |
851 | ||
859 | =begin original | |
852 | ($<,$>) = ($>,$<); # swap real and effective uids | |
853 | 860 | |
861 | $< = $>; # set real to effective uid | |
862 | ($<,$>) = ($>,$<); # swap real and effective uids | |
863 | ||
864 | =end original | |
865 | ||
866 | $< = $>; # 実 uid に実効 uid を設定 | |
867 | ($<,$>) = ($>,$<); # 実 uid と実効 uid を交換 | |
868 | ||
854 | 869 | =begin original |
855 | 870 | |
856 | 871 | You can change both the effective uid and the real uid at the same |
857 | time by using C<POSIX::setuid()>. Changes to C<< $> >> require a check | |
872 | time by using C<POSIX::setuid()>. Changes to C<< $> >> require a check | |
858 | 873 | to C<$!> to detect any possible errors after an attempted change. |
859 | 874 | |
860 | 875 | =end original |
861 | 876 | |
862 | 877 | C<POSIX::setuid()> を使って、実効 UID と実 UID を同時に変更できます。 |
863 | 878 | C<< $> >> を変更した場合は、変更時に起こりうるエラーを検出するために |
864 | 879 | C<$!> のチェックが必要です。 |
865 | 880 | |
866 | 881 | =begin original |
867 | 882 | |
868 | 883 | C<< $< >> and C<< $> >> can be swapped only on machines |
869 | 884 | supporting C<setreuid()>. |
870 | 885 | |
871 | 886 | =end original |
872 | 887 | |
873 | 888 | C<< $< >> と C<< $> >> の交換は、C<setreuid()> をサポートしている |
874 | 889 | マシンでのみ可能です。 |
875 | 890 | |
876 | 891 | =begin original |
877 | 892 | |
878 | 893 | Mnemonic: it's the uid you went I<to>, if you're running setuid. |
879 | 894 | |
880 | 895 | =end original |
881 | 896 | |
882 | 897 | 記憶法: setuid で実行中であれば、そこ I<へ> 行く uid です。 |
883 | 898 | |
884 | =item $ | |
899 | =item $SUBSCRIPT_SEPARATOR | |
885 | 900 | |
886 | =item $ | |
901 | =item $SUBSEP | |
887 | X<$a> X<$b> | |
888 | 902 | |
889 | = | |
903 | =item $; | |
904 | X<$;> X<$SUBSEP> X<SUBSCRIPT_SEPARATOR> | |
890 | 905 | |
891 | Special package variables when using C<sort()>, see L<perlfunc/sort>. | |
892 | Because of this specialness C<$a> and C<$b> don't need to be declared | |
893 | (using C<use vars>, or C<our()>) even when using the C<strict 'vars'> | |
894 | pragma. Don't lexicalize them with C<my $a> or C<my $b> if you want to | |
895 | be able to use them in the C<sort()> comparison block or function. | |
896 | ||
897 | =end original | |
898 | ||
899 | C<sort()> を使うときの特殊パッケージ変数です; L<perlfunc/sort> を | |
900 | 参照してください。 | |
901 | この特殊性により、C<$a> と C<$b> は、たとえ C<strict 'vars'> プラグマを | |
902 | 使っているときでも (C<use vars> や C<our()> を使って) 宣言する必要が | |
903 | ありません。 | |
904 | これを C<sort()> 比較ブロックや関数で使えるようにしたい場合は、 | |
905 | C<my $a> や C<my $b> としてレキシカル化しないでください。 | |
906 | ||
907 | =item $COMPILING | |
908 | ||
909 | =item $^C | |
910 | X<$^C> X<$COMPILING> | |
911 | ||
912 | 906 | =begin original |
913 | 907 | |
914 | The | |
908 | The subscript separator for multidimensional array emulation. If you | |
915 | ||
909 | refer to a hash element as | |
916 | when being compiled, such as for example to C<AUTOLOAD> at compile | |
917 | time rather than normal, deferred loading. Setting | |
918 | C<$^C = 1> is similar to calling C<B::minus_c>. | |
919 | 910 | |
920 | 911 | =end original |
921 | 912 | |
922 | ||
913 | 多次元配列のエミュレートのための添え字の区切文字。 | |
923 | ||
914 | ハッシュの要素を | |
924 | なくコンパイル時に実行するといった、コンパイル時の振る舞いを | |
925 | 変えるために用います。 | |
926 | C<$^C = 1> に設定することは C<B::minus_c> を呼び出すのと似ています。 | |
927 | 915 | |
928 | ||
916 | $foo{$x,$y,$z} | |
929 | 917 | |
930 | This variable was added in Perl 5.6. | |
931 | ||
932 | =end original | |
933 | ||
934 | この変数は Perl 5.6 で追加されました。 | |
935 | ||
936 | =item $DEBUGGING | |
937 | ||
938 | =item $^D | |
939 | X<$^D> X<$DEBUGGING> | |
940 | ||
941 | 918 | =begin original |
942 | 919 | |
943 | ||
920 | it really means | |
944 | command-line equivalent, you can use numeric or symbolic values, eg | |
945 | C<$^D = 10> or C<$^D = "st">. | |
946 | 921 | |
947 | 922 | =end original |
948 | 923 | |
949 | ||
924 | のようにして参照すると、実際には以下のようになります | |
950 | 読み書き可能です。 | |
951 | コマンドラインによる等価な機能と同様に、数値とシンボル値が使えます | |
952 | (例: C<$^D = 10> または C<$^D = "st">)。 | |
953 | 925 | |
954 | ||
926 | $foo{join($;, $x, $y, $z)} | |
955 | 927 | |
956 | Mnemonic: value of B<-D> switch. | |
957 | ||
958 | =end original | |
959 | ||
960 | 記憶法: B<-D> スイッチの値。 | |
961 | ||
962 | =item ${^ENCODING} | |
963 | X<${^ENCODING}> | |
964 | ||
965 | 928 | =begin original |
966 | 929 | |
967 | ||
930 | But don't put | |
968 | the source code to Unicode. Thanks to this variable your Perl script | |
969 | does not have to be written in UTF-8. Default is I<undef>. The direct | |
970 | manipulation of this variable is highly discouraged. | |
971 | 931 | |
972 | 932 | =end original |
973 | 933 | |
974 | ||
934 | しかし、以下のようにしてはいけません | |
975 | I<オブジェクトリファレンス> 。 | |
976 | この変数のおかげで、Perl スクリプトを UTF-8 で書く必要がありません。 | |
977 | デフォルトは I<undef> です。 | |
978 | この変数を直接操作することはとても推奨できません。 | |
979 | 935 | |
980 | 936 | =begin original |
981 | 937 | |
982 | ||
938 | @foo{$x,$y,$z} # a slice--note the @ | |
983 | 939 | |
984 | 940 | =end original |
985 | 941 | |
986 | ||
942 | @foo{$x,$y,$z} # スライス -- @ に注意 | |
987 | 943 | |
988 | =item %ENV | |
989 | X<%ENV> | |
990 | ||
991 | 944 | =begin original |
992 | 945 | |
993 | ||
946 | which means | |
994 | value in C<ENV> changes the environment for any child processes | |
995 | you subsequently C<fork()> off. | |
996 | 947 | |
997 | 948 | =end original |
998 | 949 | |
999 | ||
950 | これは以下の意味になります | |
1000 | C<ENV> に値を設定することで、 | |
1001 | 以後に C<fork()> した子プロセスの環境変数を変更します。 | |
1002 | 951 | |
1003 | ||
952 | ($foo{$x},$foo{$y},$foo{$z}) | |
1004 | 953 | |
1005 | =item $^F | |
1006 | X<$^F> X<$SYSTEM_FD_MAX> | |
1007 | ||
1008 | 954 | =begin original |
1009 | 955 | |
1010 | ||
956 | Default is "\034", the same as SUBSEP in B<awk>. If your keys contain | |
1011 | ||
957 | binary data there might not be any safe value for C<$;>. | |
1012 | descriptors are not. Also, during an C<open()>, system file descriptors are | |
1013 | preserved even if the C<open()> fails (ordinary file descriptors are | |
1014 | closed before the C<open()> is attempted). The close-on-exec | |
1015 | status of a file descriptor will be decided according to the value of | |
1016 | C<$^F> when the corresponding file, pipe, or socket was opened, not the | |
1017 | time of the C<exec()>. | |
1018 | 958 | |
1019 | 959 | =end original |
1020 | 960 | |
1021 | ||
961 | デフォルトは "\034" で、C<awk> の SUBSEP と同じです。 | |
1022 | ||
962 | 使おうとしている key の値がバイナリのデータを含むならば、 | |
1023 | ||
963 | C<$;> に設定する安全な値などはないことになります。 | |
1024 | また、C<open()> の実行中は、システムファイル記述子は、 | |
1025 | たとえ C<open()> が失敗しても、保存されます。 | |
1026 | (通常のファイル記述子は、C<open()> が実行される前にクローズされます。) | |
1027 | ファイル記述子の close-on-exec のステータスは、C<exec()> 時ではなく、 | |
1028 | 対応するファイル、パイプソケットの open 時の C<$^F> の値によって | |
1029 | 決められます。 | |
1030 | 964 | |
1031 | =item @F | |
1032 | X<@F> | |
1033 | ||
1034 | 965 | =begin original |
1035 | 966 | |
1036 | ||
967 | Consider using "real" multidimensional arrays as described | |
1037 | ||
968 | in L<perllol>. | |
1038 | is package-specific, and must be declared or given a full package name | |
1039 | if not in package main when running under C<strict 'vars'>. | |
1040 | 969 | |
1041 | 970 | =end original |
1042 | 971 | |
1043 | ||
972 | L<perllol> で記述している「本物の」多次元配列を使うようにしてください。 | |
1044 | 含みます。 | |
1045 | B<-a> オプションについては L<perlrun> を参照してください。 | |
1046 | この配列はパッケージ固有であり、もし C<strict 'vars'> で実行していて | |
1047 | パッケージ main 以外の場合は完全なパッケージ名で定義したり与えたり | |
1048 | しなければなりません。 | |
1049 | 973 | |
1050 | =item ${^GLOBAL_PHASE} | |
1051 | X<${^GLOBAL_PHASE}> | |
1052 | ||
1053 | 974 | =begin original |
1054 | 975 | |
1055 | ||
976 | Mnemonic: comma (the syntactic subscript separator) is a semi-semicolon. | |
1056 | 977 | |
1057 | 978 | =end original |
1058 | 979 | |
1059 | ||
980 | 記憶法: コンマ (構文上の添え字区切り文字) はセミ-セミコロンなのです。 | |
1060 | 981 | |
1061 | = | |
982 | =item $a | |
1062 | 983 | |
1063 | ||
984 | =item $b | |
985 | X<$a> X<$b> | |
1064 | 986 | |
1065 | =end original | |
1066 | ||
1067 | 取り得る値は: | |
1068 | ||
1069 | =over 8 | |
1070 | ||
1071 | =item CONSTRUCT | |
1072 | ||
1073 | 987 | =begin original |
1074 | 988 | |
1075 | ||
989 | Special package variables when using C<sort()>, see L<perlfunc/sort>. | |
1076 | ||
990 | Because of this specialness C<$a> and C<$b> don't need to be declared | |
1077 | u | |
991 | (using C<use vars>, or C<our()>) even when using the C<strict 'vars'> | |
1078 | ||
992 | pragma. Don't lexicalize them with C<my $a> or C<my $b> if you want to | |
1079 | ||
993 | be able to use them in the C<sort()> comparison block or function. | |
1080 | 994 | |
1081 | 995 | =end original |
1082 | 996 | |
1083 | C< | |
997 | C<sort()> を使うときの特殊パッケージ変数です; L<perlfunc/sort> を | |
1084 | ||
998 | 参照してください。 | |
1085 | C< | |
999 | この特殊性により、C<$a> と C<$b> は、たとえ C<strict 'vars'> プラグマを | |
1086 | ||
1000 | 使っているときでも (C<use vars> や C<our()> を使って) 宣言する必要が | |
1087 | ||
1001 | ありません。 | |
1002 | これを C<sort()> 比較ブロックや関数で使えるようにしたい場合は、 | |
1003 | C<my $a> や C<my $b> としてレキシカル化しないでください。 | |
1088 | 1004 | |
1089 | =item | |
1005 | =item %ENV | |
1006 | X<%ENV> | |
1090 | 1007 | |
1091 | 1008 | =begin original |
1092 | 1009 | |
1093 | Th | |
1010 | The hash C<%ENV> contains your current environment. Setting a | |
1094 | C< | |
1011 | value in C<ENV> changes the environment for any child processes | |
1095 | ||
1012 | you subsequently C<fork()> off. | |
1096 | 1013 | |
1097 | 1014 | =end original |
1098 | 1015 | |
1099 | ||
1016 | ハッシュ C<%ENV> には、その時点の環境変数が設定されています。 | |
1100 | ||
1017 | C<ENV> に値を設定することで、 | |
1101 | ||
1018 | 以後に C<fork()> した子プロセスの環境変数を変更します。 | |
1102 | 1019 | |
1103 | 1020 | =begin original |
1104 | 1021 | |
1105 | ||
1022 | As of v5.18.0, both keys and values stored in C<%ENV> are stringified. | |
1106 | C<BEGIN>-blocks, as those are executed during compile-time of any | |
1107 | compilation unit, not just the top-level program. A new, localised | |
1108 | compile-time entered at run-time, for example by constructs as | |
1109 | C<eval "use SomeModule"> are not global interpreter phases, and | |
1110 | therefore aren't reflected by C<${^GLOBAL_PHASE}>. | |
1111 | 1023 | |
1112 | 1024 | =end original |
1113 | 1025 | |
1114 | C< | |
1026 | v5.18.0 から、C<%ENV> に補完されたキーと値の両方は文字列化されます。 | |
1115 | ありません; これらは単にトップレベルプログラムではなく、任意のコンパイル | |
1116 | ユニットのコンパイル中に実行されます。 | |
1117 | 例えば C<eval "use SomeModule"> のように、実行時に入った | |
1118 | 新しいローカル化されたコンパイル時はグローバルなインタプリタフェーズではなく、 | |
1119 | 従って C<${^GLOBAL_PHASE}> に反映されません。 | |
1120 | 1027 | |
1121 | ||
1028 | my $foo = 1; | |
1029 | $ENV{'bar'} = \$foo; | |
1030 | if( ref $ENV{'bar'} ) { | |
1031 | say "Pre 5.18.0 Behaviour"; | |
1032 | } else { | |
1033 | say "Post 5.18.0 Behaviour"; | |
1034 | } | |
1122 | 1035 | |
1123 | 1036 | =begin original |
1124 | 1037 | |
1125 | ||
1038 | Previously, only child processes received stringified values: | |
1126 | 1039 | |
1127 | 1040 | =end original |
1128 | 1041 | |
1129 | ||
1042 | 以前は、子プロセスのみが文字列化された値を受け取っていました: | |
1130 | 1043 | |
1131 | ||
1044 | my $foo = 1; | |
1045 | $ENV{'bar'} = \$foo; | |
1132 | 1046 | |
1133 | ||
1047 | # Always printed 'non ref' | |
1048 | system($^X, '-e', | |
1049 | q/print ( ref $ENV{'bar'} ? 'ref' : 'non ref' ) /); | |
1134 | 1050 | |
1135 | Similar to "CHECK", but for C<INIT>-blocks, not C<CHECK> blocks. | |
1136 | ||
1137 | =end original | |
1138 | ||
1139 | "CHECK" と似ていますが、C<CHECK> ブロックではなく C<INIT> ブロック。 | |
1140 | ||
1141 | =item RUN | |
1142 | ||
1143 | 1051 | =begin original |
1144 | 1052 | |
1145 | Th | |
1053 | This happens because you can't really share arbitrary data structures with | |
1054 | foreign processes. | |
1146 | 1055 | |
1147 | 1056 | =end original |
1148 | 1057 | |
1149 | ||
1058 | これは、外部プロセスと本当に任意のデータ構造を共有することができないために | |
1059 | 起きます。 | |
1150 | 1060 | |
1151 | =item EN | |
1061 | =item $OLD_PERL_VERSION | |
1152 | 1062 | |
1153 | = | |
1063 | =item $] | |
1064 | X<$]> X<$OLD_PERL_VERSION> | |
1154 | 1065 | |
1155 | Execution of any C<END> blocks. | |
1156 | ||
1157 | =end original | |
1158 | ||
1159 | C<END> ブロックの実行。 | |
1160 | ||
1161 | =item DESTRUCT | |
1162 | ||
1163 | 1066 | =begin original |
1164 | 1067 | |
1165 | ||
1068 | The revision, version, and subversion of the Perl interpreter, represented | |
1069 | as a decimal of the form 5.XXXYYY, where XXX is the version / 1e3 and YYY | |
1070 | is the subversion / 1e6. For example, Perl v5.10.1 would be "5.010001". | |
1166 | 1071 | |
1167 | 1072 | =end original |
1168 | 1073 | |
1169 | ||
1074 | 5.XXXYYY 型式の小数で表現される Perl インタプリタの | |
1075 | revision, version, subversion | |
1076 | (XXX は version / 1e3、 YYY は subversion / 1e6)。 | |
1077 | 例えば、、Perl v5.10.1 は "5.010001" です。 | |
1170 | 1078 | |
1171 | =back | |
1172 | ||
1173 | 1079 | =begin original |
1174 | 1080 | |
1175 | ||
1081 | This variable can be used to determine whether the Perl interpreter | |
1176 | ||
1082 | executing a script is in the right range of versions: | |
1177 | not a global interpreter phase. | |
1178 | 1083 | |
1179 | 1084 | =end original |
1180 | 1085 | |
1181 | ||
1086 | スクリプトの最初で、そのスクリプトを実行しているインタプリタのバージョンが | |
1182 | な | |
1087 | 適切な範囲内にあるかを調べる、といったことができます: | |
1183 | グローバルなインタプリタフェーズではないからです。 | |
1184 | 1088 | |
1185 | ||
1089 | warn "No PerlIO!\n" if "$]" < 5.008; | |
1186 | 1090 | |
1187 | Not every program has to go through each of the possible phases, but | |
1188 | transition from one phase to another can only happen in the order | |
1189 | described in the above list. | |
1190 | ||
1191 | =end original | |
1192 | ||
1193 | 全てのプログラムが可能な全てのフェーズを通らなければならないわけでは | |
1194 | ありませんが、あるフェーズから他のフェーズへの移行は上述の | |
1195 | 順でのみ起こります。 | |
1196 | ||
1197 | 1091 | =begin original |
1198 | 1092 | |
1199 | ||
1093 | When comparing C<$]>, numeric comparison operators should be used, but the | |
1094 | variable should be stringified first to avoid issues where its original | |
1095 | numeric value is inaccurate. | |
1200 | 1096 | |
1201 | 1097 | =end original |
1202 | 1098 | |
1203 | ||
1099 | C<$]> を比較するとき、数値比較演算子が使われるべきですが、 | |
1100 | 元の数値が不正確な場合の問題を避けるために、まず文字列化するべきです。 | |
1204 | 1101 | |
1205 | BEGIN { print "compile-time: ${^GLOBAL_PHASE}\n" } | |
1206 | ||
1207 | INIT { print "init-time: ${^GLOBAL_PHASE}\n" } | |
1208 | ||
1209 | CHECK { print "check-time: ${^GLOBAL_PHASE}\n" } | |
1210 | ||
1211 | { | |
1212 | package Print::Phase; | |
1213 | ||
1214 | sub new { | |
1215 | my ($class, $time) = @_; | |
1216 | return bless \$time, $class; | |
1217 | } | |
1218 | ||
1219 | sub DESTROY { | |
1220 | my $self = shift; | |
1221 | print "$$self: ${^GLOBAL_PHASE}\n"; | |
1222 | } | |
1223 | } | |
1224 | ||
1225 | print "run-time: ${^GLOBAL_PHASE}\n"; | |
1226 | ||
1227 | my $runtime = Print::Phase->new( | |
1228 | "lexical variables are garbage collected before END" | |
1229 | ); | |
1230 | ||
1231 | END { print "end-time: ${^GLOBAL_PHASE}\n" } | |
1232 | ||
1233 | our $destruct = Print::Phase->new( | |
1234 | "package variables are garbage collected after END" | |
1235 | ); | |
1236 | ||
1237 | 1102 | =begin original |
1238 | 1103 | |
1239 | ||
1104 | See also the documentation of L<C<use VERSION>|perlfunc/use VERSION> and | |
1105 | C<require VERSION> for a convenient way to fail if the running Perl | |
1106 | interpreter is too old. | |
1240 | 1107 | |
1241 | 1108 | =end original |
1242 | 1109 | |
1243 | ||
1110 | 実行する Perl インタプリタが古すぎる場合に終了する便利な方法に | |
1111 | ついては L<C<use VERSION>|perlfunc/use VERSION> と | |
1112 | C<require VERSION> のドキュメントも | |
1113 | 参照して下さい。 | |
1244 | 1114 | |
1245 | compile-time: START | |
1246 | check-time: CHECK | |
1247 | init-time: INIT | |
1248 | run-time: RUN | |
1249 | lexical variables are garbage collected before END: RUN | |
1250 | end-time: END | |
1251 | package variables are garbage collected after END: DESTRUCT | |
1252 | ||
1253 | 1115 | =begin original |
1254 | 1116 | |
1255 | ||
1117 | See L</$^V> for a representation of the Perl version as a L<version> | |
1118 | object, which allows more flexible string comparisons. | |
1256 | 1119 | |
1257 | 1120 | =end original |
1258 | 1121 | |
1259 | ||
1122 | より柔軟な文字列比較が可能な L<version> オブジェクトとしての | |
1123 | Perl バージョン表現については L</$^V> を参照してください。 | |
1260 | 1124 | |
1261 | =item $^H | |
1262 | X<$^H> | |
1263 | ||
1264 | 1125 | =begin original |
1265 | 1126 | |
1266 | ||
1127 | The main advantage of C<$]> over C<$^V> is that it works the same on any | |
1267 | ||
1128 | version of Perl. The disadvantages are that it can't easily be compared | |
1129 | to versions in other formats (e.g. literal v-strings, "v1.2.3" or | |
1130 | version objects) and numeric comparisons are subject to the binary | |
1131 | floating point representation; it's good for numeric literal version | |
1132 | checks and bad for comparing to a variable that hasn't been | |
1133 | sanity-checked. | |
1268 | 1134 | |
1269 | 1135 | =end original |
1270 | 1136 | |
1271 | ||
1137 | C<$^V> に対する C<$]> の主な利点は、どのバージョンの Perl でも同様に | |
1272 | ||
1138 | 動作することです。 | |
1139 | 欠点は、他の型式のバージョン (例えばリテラルな v-文字列、"v1.2.3"、 | |
1140 | バージョンオブジェクト) と簡単に比較できず、数値比較はバイナリ | |
1141 | 浮動小数点表現になりがちです; 数値リテラルバージョンチェックとしては | |
1142 | 良いですが、正気チェックをされていない変数と比較するには良くないです。 | |
1273 | 1143 | |
1274 | 1144 | =begin original |
1275 | 1145 | |
1276 | Th | |
1146 | The C<$OLD_PERL_VERSION> form was added in Perl v5.20.0 for historical | |
1277 | e | |
1147 | reasons but its use is discouraged. (If your reason to use C<$]> is to | |
1278 | ||
1148 | run code on old perls then referring to it as C<$OLD_PERL_VERSION> would | |
1149 | be self-defeating.) | |
1279 | 1150 | |
1280 | 1151 | =end original |
1281 | 1152 | |
1282 | ||
1153 | C<$OLD_PERL_VERSION> 型式は歴史的理由により Perl v5.20.0 に追加されましたが、 | |
1283 | ||
1154 | この使用は非推奨です。 | |
1284 | ||
1155 | (C<$]> を使う理由が古い perl でコードを実行することなら、これを | |
1156 | C<$OLD_PERL_VERSION> して参照すると自滅することになります。) | |
1285 | 1157 | |
1286 | 1158 | =begin original |
1287 | 1159 | |
1288 | ||
1160 | Mnemonic: Is this version of perl in the right bracket? | |
1289 | (e.g., eval body, required file, subroutine body, loop body, or conditional | |
1290 | block), the existing value of C<$^H> is saved, but its value is left unchanged. | |
1291 | When the compilation of the block is completed, it regains the saved value. | |
1292 | Between the points where its value is saved and restored, code that | |
1293 | executes within BEGIN blocks is free to change the value of C<$^H>. | |
1294 | 1161 | |
1295 | 1162 | =end original |
1296 | 1163 | |
1297 | Perl | |
1164 | 記憶法: Perl のバージョンは、正しい範囲 (right bracket) にあるか。 | |
1298 | ファイル、サブルーチンの中身、loop の中身、条件付きブロック)の | |
1299 | パーズを開始するとき、現在の C<$^H> の値は保存されますが、値は | |
1300 | 変更されません。 | |
1301 | ブロックのコンパイルが終わると、保存された値が戻されます。 | |
1302 | 値の保存と回復の間の地点で、BEGIN ブロックの中で実行されるコードは自由に | |
1303 | C<$^H> の値を変更できます。 | |
1304 | 1165 | |
1305 | = | |
1166 | =item $SYSTEM_FD_MAX | |
1306 | 1167 | |
1307 | ||
1168 | =item $^F | |
1308 | ||
1169 | X<$^F> X<$SYSTEM_FD_MAX> | |
1309 | 1170 | |
1310 | =end original | |
1311 | ||
1312 | この振る舞いはレキシカルスコープを持ち、その中で使えます。 | |
1313 | 例としては C<use strict> があります。 | |
1314 | ||
1315 | 1171 | =begin original |
1316 | 1172 | |
1317 | The | |
1173 | The maximum system file descriptor, ordinarily 2. System file | |
1318 | d | |
1174 | descriptors are passed to C<exec()>ed processes, while higher file | |
1175 | descriptors are not. Also, during an | |
1176 | C<open()>, system file descriptors are | |
1177 | preserved even if the C<open()> fails (ordinary file descriptors are | |
1178 | closed before the C<open()> is attempted). The close-on-exec | |
1179 | status of a file descriptor will be decided according to the value of | |
1180 | C<$^F> when the corresponding file, pipe, or socket was opened, not the | |
1181 | time of the C<exec()>. | |
1319 | 1182 | |
1320 | 1183 | =end original |
1321 | 1184 | |
1322 | ||
1185 | システムが使用するファイル記述子の最大値を示し、通常は 2 です。 | |
1323 | ||
1186 | システムファイル記述子は、C<exec()> されたプロセスに渡されますが、 | |
1187 | それ以降のファイル記述子は渡されません。 | |
1188 | また、C<open()> の実行中は、システムファイル記述子は、 | |
1189 | たとえ C<open()> が失敗しても、保存されます | |
1190 | (通常のファイル記述子は、C<open()> が実行される前にクローズされます)。 | |
1191 | ファイル記述子の close-on-exec のステータスは、C<exec()> 時ではなく、 | |
1192 | 対応するファイル、パイプソケットの open 時の C<$^F> の値によって | |
1193 | 決められます。 | |
1324 | 1194 | |
1325 | ||
1195 | =item @F | |
1196 | X<@F> | |
1326 | 1197 | |
1327 | sub foo { | |
1328 | BEGIN { add_100() } | |
1329 | bar->baz($boon); | |
1330 | } | |
1331 | ||
1332 | 1198 | =begin original |
1333 | 1199 | |
1334 | Con | |
1200 | The array C<@F> contains the fields of each line read in when autosplit | |
1335 | ||
1201 | mode is turned on. See L<perlrun|perlrun/-a> for the B<-a> switch. This | |
1336 | ||
1202 | array is package-specific, and must be declared or given a full package | |
1337 | ||
1203 | name if not in package main when running under C<strict 'vars'>. | |
1338 | 1204 | |
1339 | 1205 | =end original |
1340 | 1206 | |
1341 | ||
1207 | 自動 split モードが有効の場合、配列 C<@F> には読み込んだ行のフィールドを | |
1342 | ||
1208 | 含みます。 | |
1343 | ||
1209 | B<-a> オプションについては L<perlrun|perlrun/-a> を参照してください。 | |
1344 | ||
1210 | この配列はパッケージ固有であり、もし C<strict 'vars'> で実行していて | |
1345 | ||
1211 | パッケージ main 以外の場合は完全なパッケージ名で定義したり与えたり | |
1212 | しなければなりません。 | |
1346 | 1213 | |
1347 | =begin original | |
1348 | ||
1349 | Substitution of C<BEGIN { add_100() }> block with: | |
1350 | ||
1351 | =end original | |
1352 | ||
1353 | C<BEGIN { add_100() }> ブロックを以下のように変更すると: | |
1354 | ||
1355 | BEGIN { require strict; strict->import('vars') } | |
1356 | ||
1357 | =begin original | |
1358 | ||
1359 | demonstrates how C<use strict 'vars'> is implemented. Here's a conditional | |
1360 | version of the same lexical pragma: | |
1361 | ||
1362 | =end original | |
1363 | ||
1364 | どのように C<use strict 'vars'> が実装されているかがわかります。 | |
1365 | 以下は同じレキシカルプラグマの条件付き版です: | |
1366 | ||
1367 | BEGIN { require strict; strict->import('vars') if $condition } | |
1368 | ||
1369 | =begin original | |
1370 | ||
1371 | This variable was added in Perl 5.003. | |
1372 | ||
1373 | =end original | |
1374 | ||
1375 | この変数は Perl 5.003 で追加されました。 | |
1376 | ||
1377 | =item %^H | |
1378 | X<%^H> | |
1379 | ||
1380 | =begin original | |
1381 | ||
1382 | The C<%^H> hash provides the same scoping semantic as C<$^H>. This makes it | |
1383 | useful for implementation of lexically scoped pragmas. See L<perlpragma>. | |
1384 | ||
1385 | =end original | |
1386 | ||
1387 | C<%^H> ハッシュは C<$^H> と同じスコープを持ちます。 | |
1388 | これはレキシカルスコープを持つプラグマを実装するのに便利です。 | |
1389 | L<perlpragma> を参照してください。 | |
1390 | ||
1391 | =begin original | |
1392 | ||
1393 | This variable was added in Perl 5.6. | |
1394 | ||
1395 | =end original | |
1396 | ||
1397 | この変数は Perl 5.6 で追加されました。 | |
1398 | ||
1399 | 1214 | =item @INC |
1400 | 1215 | X<@INC> |
1401 | 1216 | |
1402 | 1217 | =begin original |
1403 | 1218 | |
1404 | 1219 | The array C<@INC> contains the list of places that the C<do EXPR>, |
1405 | C<require>, or C<use> constructs look for their library files. It | |
1220 | C<require>, or C<use> constructs look for their library files. It | |
1406 | 1221 | initially consists of the arguments to any B<-I> command-line |
1407 | 1222 | switches, followed by the default Perl library, probably |
1408 | F</usr/local/lib/perl> | |
1223 | F</usr/local/lib/perl>. | |
1409 | ||
1224 | Prior to Perl 5.26, C<.> -which represents the current directory, was included | |
1410 | ||
1225 | in C<@INC>; it has been removed. This change in behavior is documented | |
1411 | ||
1226 | in L<C<PERL_USE_UNSAFE_INC>|perlrun/PERL_USE_UNSAFE_INC> and it is | |
1412 | ||
1227 | not recommended that C<.> be re-added to C<@INC>. | |
1228 | If you need to modify C<@INC> at runtime, you should use the C<use lib> pragma | |
1229 | to get the machine-dependent library properly loaded as well: | |
1413 | 1230 | |
1414 | 1231 | =end original |
1415 | 1232 | |
1416 | 1233 | 配列 C<@INC> には、C<do EXPR>, C<require>, C<use> によってライブラリファイルを |
1417 | 1234 | 探すときに評価する場所のリストが納められています。 |
1418 | 初期状態では、コマンドラインスイッチ B<-I> の引数と | |
1235 | 初期状態では、コマンドラインスイッチ B<-I> の引数とデフォルトの | |
1419 | ||
1236 | Perl ライブラリディレクトリ (おそらく F</usr/local/lib/perl5>) を | |
1420 | ||
1237 | 順につなげたものです。 | |
1421 | ||
1238 | Perl 5.26 より前では、カレントディレクトリを表す C<.> | |
1422 | ||
1239 | が C<@INC> に含まれていました; これは削除されました。 | |
1423 | ||
1240 | この振る舞いの変更は | |
1241 | L<C<PERL_USE_UNSAFE_INC>|perlrun/PERL_USE_UNSAFE_INC> に文書化されていて、 | |
1242 | C<@INC> に C<.> を再追加するのは推奨されません。 | |
1243 | 実行時に C<@INC> 変更する必要がある場合は、マシン依存のライブラリも正しく | |
1424 | 1244 | 読み込むために C<use lib> を使うべきです: |
1425 | 1245 | |
1426 | ||
1246 | use lib '/mypath/libdir/'; | |
1427 | ||
1247 | use SomeMod; | |
1428 | 1248 | |
1429 | 1249 | =begin original |
1430 | 1250 | |
1431 | 1251 | You can also insert hooks into the file inclusion system by putting Perl |
1432 | code directly into C<@INC>. Those hooks may be subroutine references, | |
1252 | code directly into C<@INC>. Those hooks may be subroutine references, | |
1433 | references or blessed objects. See L<perlfunc/require> for details. | |
1253 | array references or blessed objects. See L<perlfunc/require> for details. | |
1434 | 1254 | |
1435 | 1255 | =end original |
1436 | 1256 | |
1437 | 1257 | Perl のコードを直接 C<@INC> に入れることで、ファイルインクルード機構に |
1438 | 1258 | フックを挿入できます。 |
1439 | 1259 | このフックはサブルーチンリファレンス、配列リファレンス、bless された |
1440 | 1260 | オブジェクトが可能です。 |
1441 | 1261 | 詳細については L<perlfunc/require> を参照してください。 |
1442 | 1262 | |
1443 | 1263 | =item %INC |
1444 | 1264 | X<%INC> |
1445 | 1265 | |
1446 | 1266 | =begin original |
1447 | 1267 | |
1448 | 1268 | The hash C<%INC> contains entries for each filename included via the |
1449 | C<do>, C<require>, or C<use> operators. The key is the filename | |
1269 | C<do>, C<require>, or C<use> operators. The key is the filename | |
1450 | 1270 | you specified (with module names converted to pathnames), and the |
1451 | value is the location of the file found. The C<require> | |
1271 | value is the location of the file found. The C<require> | |
1452 | 1272 | operator uses this hash to determine whether a particular file has |
1453 | 1273 | already been included. |
1454 | 1274 | |
1455 | 1275 | =end original |
1456 | 1276 | |
1457 | 1277 | ハッシュ C<%INC> は、C<do>, C<require>, C<use> 演算子によって |
1458 | 1278 | インクルードされた、個々のファイル名をエントリとして持っています。 |
1459 | 1279 | key は指定したファイル名(モジュール名はパス名に変換されます)で、 |
1460 | 1280 | value は見つかった場所となっています。 |
1461 | 1281 | C<require> 演算子は、指定されたファイル名が既に |
1462 | 1282 | インクルードされているかを、このハッシュを使って調べます。 |
1463 | 1283 | |
1464 | 1284 | =begin original |
1465 | 1285 | |
1466 | 1286 | If the file was loaded via a hook (e.g. a subroutine reference, see |
1467 | 1287 | L<perlfunc/require> for a description of these hooks), this hook is |
1468 | by default inserted into C<%INC> in place of a filename. Note, however, | |
1288 | by default inserted into C<%INC> in place of a filename. Note, however, | |
1469 | 1289 | that the hook may have set the C<%INC> entry by itself to provide some more |
1470 | 1290 | specific info. |
1471 | 1291 | |
1472 | 1292 | =end original |
1473 | 1293 | |
1474 | 1294 | ファイルがフック(つまりサブルーチンリファレンス; フックに関する |
1475 | 1295 | 説明については L<perlfunc/require> を参照してください)経由で読み込まれた |
1476 | 1296 | 場合、このフックはデフォルトではファイル名の代わりに C<%INC> に挿入されます。 |
1477 | 1297 | しかし、フックはさらなる特定の情報を提供するために、自身で C<%INC> エントリを |
1478 | 1298 | セットするかもしれないことに注意してください。 |
1479 | 1299 | |
1300 | =item $INC | |
1301 | X<$INC> | |
1302 | ||
1303 | =begin original | |
1304 | ||
1305 | As of 5.37.7 when an C<@INC> hook is executed the index of the C<@INC> | |
1306 | array that holds the hook will be localized into the C<$INC> variable. | |
1307 | When the hook returns the integer successor of its value will be used to | |
1308 | determine the next index in C<@INC> that will be checked, thus if it is | |
1309 | set to -1 (or C<undef>) the traversal over the C<@INC> array will be | |
1310 | restarted from its beginning. | |
1311 | ||
1312 | =end original | |
1313 | ||
1314 | 5.37.7 から、C<@INC> フックが実行されるとき、フックを保持する | |
1315 | C<@INC> 配列のインデックスは C<$INC> 変数にローカル化されます。 | |
1316 | フックが整数を返すとき、その値の継承はチェックされる C<@INC> の | |
1317 | 次のインデックスを決定するために使われます; | |
1318 | 従って、もしそれが -1 (または C<undef>)に設定されるなら、 | |
1319 | C<@INC> 配列上の走査は最初から再開されます。 | |
1320 | ||
1321 | =begin original | |
1322 | ||
1323 | Normally traversal through the C<@INC> array is from beginning to end | |
1324 | (C<0 .. $#INC>), and if the C<@INC> array is modified by the hook the | |
1325 | iterator may be left in a state where newly added entries are skipped. | |
1326 | Changing this value allows an C<@INC> hook to rewrite the C<@INC> array | |
1327 | and tell Perl where to continue afterwards. See L<perlfunc/require> for | |
1328 | details on C<@INC> hooks. | |
1329 | ||
1330 | =end original | |
1331 | ||
1332 | 通常、C<@INC> 配列のトラバースは最初から最後まで | |
1333 | (C<0 .. $#INC>) であり、C<@INC> 配列がフックによって変更された場合、 | |
1334 | 反復子は新しく追加されたエントリが読み飛ばされる状態のままになる | |
1335 | 可能性があります。 | |
1336 | この値を変更すると、C<@INC> フックが C<@INC> 配列を書き換え、 | |
1337 | 後でどこに進むかを Perl に指示できます。 | |
1338 | C<@INC> フックの詳細については L<perlfunc/require> を参照してください。 | |
1339 | ||
1480 | 1340 | =item $INPLACE_EDIT |
1481 | 1341 | |
1482 | 1342 | =item $^I |
1483 | 1343 | X<$^I> X<$INPLACE_EDIT> |
1484 | 1344 | |
1485 | 1345 | =begin original |
1486 | 1346 | |
1487 | The current value of the inplace-edit extension. Use C<undef> to disable | |
1347 | The current value of the inplace-edit extension. Use C<undef> to disable | |
1488 | 1348 | inplace editing. |
1489 | 1349 | |
1490 | 1350 | =end original |
1491 | 1351 | |
1492 | 1352 | 置き換え編集の拡張子の値を示します。 |
1493 | 1353 | 置き換え編集を禁止するためには、C<undef> を設定します。 |
1494 | 1354 | |
1495 | 1355 | =begin original |
1496 | 1356 | |
1497 | 1357 | Mnemonic: value of B<-i> switch. |
1498 | 1358 | |
1499 | 1359 | =end original |
1500 | 1360 | |
1501 | 1361 | 記憶法: B<-i> スイッチの値。 |
1502 | 1362 | |
1363 | =item @ISA | |
1364 | X<@ISA> | |
1365 | ||
1366 | =begin original | |
1367 | ||
1368 | Each package contains a special array called C<@ISA> which contains a list | |
1369 | of that class's parent classes, if any. This array is simply a list of | |
1370 | scalars, each of which is a string that corresponds to a package name. The | |
1371 | array is examined when Perl does method resolution, which is covered in | |
1372 | L<perlobj>. | |
1373 | ||
1374 | =end original | |
1375 | ||
1376 | それぞれのパッケージには C<@ISA> という名前の特殊配列があります; | |
1377 | これは (もしあれば) そのクラスの親クラスのリストです。 | |
1378 | この変数は単なるスカラのリストで、それぞれはパッケージ名に対応する | |
1379 | 文字列です。 | |
1380 | この配列は Perl がメソッド解決を行うときにチェックされます; これは | |
1381 | L<perlobj> に記述しています。 | |
1382 | ||
1383 | =begin original | |
1384 | ||
1385 | To load packages while adding them to C<@ISA>, see the L<parent> pragma. The | |
1386 | discouraged L<base> pragma does this as well, but should not be used except | |
1387 | when compatibility with the discouraged L<fields> pragma is required. | |
1388 | ||
1389 | =end original | |
1390 | ||
1391 | パッケージを読み込むために C<@ISA> に追加するには、L<parent> プラグマを | |
1392 | 参照してください。 | |
1393 | 非推奨の L<base> プラグマは同じことをしますが、 | |
1394 | 非推奨の L<fields> プラグマとの互換性が必要な場合を除いて、 | |
1395 | 使うべきではありません。 | |
1396 | ||
1503 | 1397 | =item $^M |
1504 | 1398 | X<$^M> |
1505 | 1399 | |
1506 | 1400 | =begin original |
1507 | 1401 | |
1508 | 1402 | By default, running out of memory is an untrappable, fatal error. |
1509 | 1403 | However, if suitably built, Perl can use the contents of C<$^M> |
1510 | as an emergency memory pool after C<die()>ing. Suppose that your Perl | |
1404 | as an emergency memory pool after C<die()>ing. Suppose that your Perl | |
1511 | 1405 | were compiled with C<-DPERL_EMERGENCY_SBRK> and used Perl's malloc. |
1512 | 1406 | Then |
1513 | 1407 | |
1514 | 1408 | =end original |
1515 | 1409 | |
1516 | 1410 | デフォルトでは、メモリ不足はトラップできない致命的エラーとなります。 |
1517 | 1411 | しかし、もし適切に構築されていれば、Perl は C<$^M> の中身を |
1518 | 1412 | C<die()> した後の緊急用メモリとして使えます。 |
1519 | 1413 | Perl が C<-DPERL_EMERGENCY_SBRK> 付きでコンパイルされ、 |
1520 | 1414 | Perl の malloc を使うと仮定します。そして、 |
1521 | 1415 | |
1522 | ||
1416 | $^M = 'a' x (1 << 16); | |
1523 | 1417 | |
1524 | 1418 | =begin original |
1525 | 1419 | |
1526 | would allocate a 64K buffer for use in an emergency. See the | |
1420 | would allocate a 64K buffer for use in an emergency. See the | |
1527 | ||
1421 | L<INSTALL> file in the Perl distribution for information on how to | |
1528 | add custom C compilation flags when compiling perl. To discourage casual | |
1422 | add custom C compilation flags when compiling perl. To discourage casual | |
1529 | 1423 | use of this advanced feature, there is no L<English|English> long name for |
1530 | 1424 | this variable. |
1531 | 1425 | |
1532 | 1426 | =end original |
1533 | 1427 | |
1534 | 1428 | とすると緊急用の 64K のバッファを割り当てます。 |
1535 | 1429 | perl をコンパイルするときに独自の C コンパイルフラグを追加する |
1536 | 1430 | 方法についての情報は、Perl 配布パッケージに含まれている |
1537 | ||
1431 | L<INSTALL> ファイルを参照して下さい。 | |
1538 | 1432 | この拡張機能を気軽に使えないようにするために、 |
1539 | 1433 | この変数には L<English|English> の長い名前はありません。 |
1540 | 1434 | |
1541 | 1435 | =begin original |
1542 | 1436 | |
1543 | 1437 | This variable was added in Perl 5.004. |
1544 | 1438 | |
1545 | 1439 | =end original |
1546 | 1440 | |
1547 | 1441 | この変数は Perl 5.004 で追加されました。 |
1548 | 1442 | |
1549 | =item $ | |
1443 | =item ${^MAX_NESTED_EVAL_BEGIN_BLOCKS} | |
1550 | 1444 | |
1551 | =item $^O | |
1552 | X<$^O> X<$OSNAME> | |
1553 | ||
1554 | 1445 | =begin original |
1555 | 1446 | |
1556 | Th | |
1447 | This variable determines the maximum number C<eval EXPR>/C<BEGIN> or | |
1557 | ||
1448 | C<require>/C<BEGIN> block nesting that is allowed. This means it also | |
1558 | see | |
1449 | controls the maximum nesting of C<use> statements as well. | |
1559 | 1450 | |
1560 | 1451 | =end original |
1561 | 1452 | |
1562 | この Per | |
1453 | この変数は、C<eval EXPR>/C<BEGIN> や C<require>/C<BEGIN> | |
1563 | ||
1454 | ブロックのネストの許される最大数を決定します。 | |
1455 | つまり、C<use> 文のネストの最大数も制御します。 | |
1564 | 1456 | |
1565 | 1457 | =begin original |
1566 | 1458 | |
1567 | The | |
1459 | The default of 1000 should be sufficiently large for normal working | |
1568 | and | |
1460 | purposes, and if you must raise it then you should be conservative | |
1461 | with your choice or you may encounter segfaults from exhaustion of | |
1462 | the C stack. It seems unlikely that real code has a use depth above | |
1463 | 1000, but we have left this configurable just in case. | |
1569 | 1464 | |
1570 | 1465 | =end original |
1571 | 1466 | |
1572 | ||
1467 | デフォルトの 1000 は、通常の作業目的に十分な大きさであるはずです; | |
1573 | ||
1468 | 値を大きくする必要がある場合は、慎重に選択する必要があります; | |
1574 | ||
1469 | そうしないと、C スタックの枯渇によって segfault が発生する可能性があります。 | |
1470 | 実際のコードが 1000 を超える使用深度を持つ可能性は低いと思われますが、 | |
1471 | 念のためこれを設定できるようにしてあります。 | |
1575 | 1472 | |
1576 | 1473 | =begin original |
1577 | 1474 | |
1578 | ||
1475 | When set to C<0> then C<BEGIN> blocks inside of C<eval EXPR> or | |
1579 | C< | |
1476 | C<require EXPR> are forbidden entirely and will trigger an exception | |
1580 | ||
1477 | which will terminate the compilation and in the case of C<require> | |
1581 | ||
1478 | will throw an exception, or in the case of C<eval> return the error in | |
1582 | ||
1479 | C<$@> as usual. | |
1583 | 1480 | |
1584 | 1481 | =end original |
1585 | 1482 | |
1586 | ||
1483 | C<0> に設定すると、C<eval EXPR> や C<require EXPR> 内の | |
1587 | C< | |
1484 | C<BEGIN> ブロックは完全に禁止され、コンパイルを終了する | |
1588 | ||
1485 | 例外を引き起こします; | |
1589 | ||
1486 | C<require> の場合は例外を投げ、C<eval> の場合は通常どおり | |
1487 | C<$@> にエラーを返します。 | |
1590 | 1488 | |
1591 | 1489 | =begin original |
1592 | 1490 | |
1593 | ||
1491 | Consider the code | |
1594 | 1492 | |
1595 | 1493 | =end original |
1596 | 1494 | |
1597 | ||
1495 | 次のコードを考えます: | |
1598 | 1496 | |
1599 | ||
1497 | perl -le'sub f { eval "BEGIN { f() }"; } f()' | |
1600 | X<${^OPEN}> | |
1601 | 1498 | |
1602 | 1499 | =begin original |
1603 | 1500 | |
1604 | ||
1501 | each invocation of C<f()> will consume considerable C stack, and this | |
1605 | ||
1502 | variable is used to cause code like this to die instead of exhausting | |
1606 | ||
1503 | the C stack and triggering a segfault. Needless to say code like this is | |
1504 | unusual, it is unlikely you will actually need to raise the setting. | |
1505 | However it may be useful to set it to 0 for a limited time period to | |
1506 | prevent BEGIN{} blocks from being executed during an C<eval EXPR>. | |
1607 | 1507 | |
1608 | 1508 | =end original |
1609 | 1509 | |
1610 | ||
1510 | C<f()> の各呼び出しはかなりの C スタックを消費し、この変数は、 | |
1611 | ||
1511 | このようなコードが C スタックを使い果たして segfault を | |
1612 | ||
1512 | 引き起こすのではなく、die させるために使われます。 | |
1513 | このようなコードが普通ではないことは言うまでもありませんが、実際に | |
1514 | 設定を上げる必要があることはあまりありません。 | |
1515 | ただし、C<eval EXPR> 中に BEGIN{} ブロックが実行されないようにするために、 | |
1516 | 限られた時間だけ 0 に設定すると便利な場合があります。 | |
1613 | 1517 | |
1614 | 1518 | =begin original |
1615 | 1519 | |
1616 | ||
1520 | Note that setting this to 1 would NOT affect code like this: | |
1617 | 1521 | |
1618 | 1522 | =end original |
1619 | 1523 | |
1620 | この | |
1524 | これの 1 への設定は、次のようなコードには影響しません: | |
1621 | 1525 | |
1622 | ||
1526 | BEGIN { $n += 1; BEGIN { $n += 2; BEGIN { $n += 4 } } } | |
1623 | 1527 | |
1624 | =item $^P | |
1625 | X<$^P> X<$PERLDB> | |
1626 | ||
1627 | 1528 | =begin original |
1628 | 1529 | |
1629 | The | |
1530 | The reason is that BEGIN blocks are executed immediately after they are | |
1630 | ||
1531 | completed, thus the innermost will execute before the ones which contain | |
1532 | it have even finished compiling, and the depth will not go above 1. In | |
1533 | fact the above code is equivalent to | |
1631 | 1534 | |
1632 | 1535 | =end original |
1633 | 1536 | |
1634 | ||
1537 | その理由は、BEGIN ブロックは完了した直後に実行されるためです; | |
1635 | ||
1538 | したがって、最も内側のブロックは、それを含むブロックがコンパイルを | |
1636 | ||
1539 | 完了する前に実行され、深さは 1 を超えません。 | |
1540 | 実際、前述のコードは次と等価です: | |
1637 | 1541 | |
1638 | = | |
1542 | BEGIN { $n+=4 } | |
1543 | BEGIN { $n+=2 } | |
1544 | BEGIN { $n+=1 } | |
1639 | 1545 | |
1640 | =item 0x01 | |
1641 | ||
1642 | 1546 | =begin original |
1643 | 1547 | |
1644 | ||
1548 | which makes it obvious why a ${^MAX_EVAL_BEGIN_DEPTH} of 1 would not | |
1549 | block this code. | |
1645 | 1550 | |
1646 | 1551 | =end original |
1647 | 1552 | |
1648 | ||
1553 | これは、なぜ ${^MAX_EVAL_BEGIN_DEPTH} を 1 にすることが | |
1554 | このコードをブロックしないかを分かりやすくします。 | |
1649 | 1555 | |
1650 | =item 0x02 | |
1651 | ||
1652 | 1556 | =begin original |
1653 | 1557 | |
1654 | ||
1558 | Only C<BEGIN>'s executed inside of an C<eval> or C<require> (possibly via | |
1655 | ||
1559 | C<use>) are affected. | |
1656 | 1560 | |
1657 | 1561 | =end original |
1658 | 1562 | |
1659 | ||
1563 | C<eval> または (C<use> 経由を含む) C<require> の内側で実行された | |
1660 | ||
1564 | C<BEGIN> のみが影響を受けます。 | |
1661 | さらに、(0x400 のように) ソースコードを保存します。 | |
1662 | 1565 | |
1663 | =item | |
1566 | =item $OSNAME | |
1664 | 1567 | |
1665 | = | |
1568 | =item $^O | |
1569 | X<$^O> X<$OSNAME> | |
1666 | 1570 | |
1667 | Switch off optimizations. | |
1668 | ||
1669 | =end original | |
1670 | ||
1671 | 最適化を行いません。 | |
1672 | ||
1673 | =item 0x08 | |
1674 | ||
1675 | 1571 | =begin original |
1676 | 1572 | |
1677 | ||
1573 | The name of the operating system under which this copy of Perl was | |
1574 | built, as determined during the configuration process. For examples | |
1575 | see L<perlport/PLATFORMS>. | |
1678 | 1576 | |
1679 | 1577 | =end original |
1680 | 1578 | |
1681 | ||
1579 | この Perl が構築されたオペレーティングシステムの名前です; | |
1580 | これは設定プロセス中に決定されます。 | |
1581 | 例えば L<perlport/PLATFORMS> を参照してください。 | |
1682 | 1582 | |
1683 | =item 0x10 | |
1684 | ||
1685 | 1583 | =begin original |
1686 | 1584 | |
1687 | ||
1585 | The value is identical to C<$Config{'osname'}>. See also L<Config> | |
1586 | and the B<-V> command-line switch documented in L<perlrun|perlrun/-V>. | |
1688 | 1587 | |
1689 | 1588 | =end original |
1690 | 1589 | |
1691 | ||
1590 | この値は C<$Config{'osname'}> と同じです。 | |
1591 | L<Config> と、L<perlrun|perlrun/-V> で文書化されている | |
1592 | B<-V> コマンドラインスイッチも参照して下さい。 | |
1692 | 1593 | |
1693 | =item 0x20 | |
1694 | ||
1695 | 1594 | =begin original |
1696 | 1595 | |
1697 | ||
1596 | In Windows platforms, C<$^O> is not very helpful: since it is always | |
1597 | C<MSWin32>, it doesn't tell the difference between | |
1598 | 95/98/ME/NT/2000/XP/CE/.NET. Use C<Win32::GetOSName()> or | |
1599 | Win32::GetOSVersion() (see L<Win32> and L<perlport>) to distinguish | |
1600 | between the variants. | |
1698 | 1601 | |
1699 | 1602 | =end original |
1700 | 1603 | |
1701 | ||
1604 | Windows プラットフォームでは、C<$^O> はあまり役に立ちません: これは常に | |
1605 | C<MSWin32> となり、95/98/ME/NT/2000/XP/CE/.NET の違いを示していないからです。 | |
1606 | これらを区別するためには、C<Win32::GetOSName()> や Win32::GetOSVersion() を | |
1607 | 使ってください (L<Win32> と L<perlport> を参照してください)。 | |
1702 | 1608 | |
1703 | =item 0x40 | |
1704 | ||
1705 | 1609 | =begin original |
1706 | 1610 | |
1707 | ||
1611 | This variable was added in Perl 5.003. | |
1708 | 1612 | |
1709 | 1613 | =end original |
1710 | 1614 | |
1711 | ||
1615 | この変数は Perl 5.003 で追加されました。 | |
1712 | 1616 | |
1713 | =item | |
1617 | =item %SIG | |
1618 | X<%SIG> | |
1714 | 1619 | |
1715 | 1620 | =begin original |
1716 | 1621 | |
1717 | ||
1622 | The hash C<%SIG> contains signal handlers for signals. For example: | |
1718 | 1623 | |
1719 | 1624 | =end original |
1720 | 1625 | |
1721 | C< | |
1626 | ハッシュ C<%SIG> にはシグナルのためのシグナルハンドラが含まれています。 | |
1627 | 例えば: | |
1722 | 1628 | |
1723 | =item 0x100 | |
1724 | ||
1725 | 1629 | =begin original |
1726 | 1630 | |
1727 | ||
1631 | sub handler { # 1st argument is signal name | |
1632 | my($sig) = @_; | |
1633 | print "Caught a SIG$sig--shutting down\n"; | |
1634 | close(LOG); | |
1635 | exit(0); | |
1636 | } | |
1728 | 1637 | |
1729 | 1638 | =end original |
1730 | 1639 | |
1731 | ||
1640 | sub handler { # 最初の引数はシグナル名 | |
1641 | my($sig) = @_; | |
1642 | print "Caught a SIG$sig--shutting down\n"; | |
1643 | close(LOG); | |
1644 | exit(0); | |
1645 | } | |
1732 | 1646 | |
1733 | =item 0x200 | |
1734 | ||
1735 | 1647 | =begin original |
1736 | 1648 | |
1737 | ||
1649 | $SIG{'INT'} = \&handler; | |
1738 | ||
1650 | $SIG{'QUIT'} = \&handler; | |
1651 | ... | |
1652 | $SIG{'INT'} = 'DEFAULT'; # restore default action | |
1653 | $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT | |
1739 | 1654 | |
1740 | 1655 | =end original |
1741 | 1656 | |
1742 | ||
1657 | $SIG{'INT'} = \&handler; | |
1743 | ||
1658 | $SIG{'QUIT'} = \&handler; | |
1659 | ... | |
1660 | $SIG{'INT'} = 'DEFAULT'; # デフォルトの動作を復元 | |
1661 | $SIG{'QUIT'} = 'IGNORE'; # SIGQUIT を無視 | |
1744 | 1662 | |
1745 | =item 0x400 | |
1746 | ||
1747 | 1663 | =begin original |
1748 | 1664 | |
1749 | Save source code lines into C<@{"_<$filename"}>. | |
1750 | ||
1751 | =end original | |
1752 | ||
1753 | ソースコードの行数を C<@{"_<$filename"}> に保存します。 | |
1754 | ||
1755 | =back | |
1756 | ||
1757 | =begin original | |
1758 | ||
1759 | Some bits may be relevant at compile-time only, some at | |
1760 | run-time only. This is a new mechanism and the details may change. | |
1761 | See also L<perldebguts>. | |
1762 | ||
1763 | =end original | |
1764 | ||
1765 | 無名サブルーチンに対して、 | |
1766 | コンパイルされた位置を基にした参考名を提供します。 | |
1767 | L<perldebguts> も参照してください。 | |
1768 | ||
1769 | =item %SIG | |
1770 | X<%SIG> | |
1771 | ||
1772 | =begin original | |
1773 | ||
1774 | The hash C<%SIG> contains signal handlers for signals. For example: | |
1775 | ||
1776 | =end original | |
1777 | ||
1778 | ハッシュ C<%SIG> にはシグナルのためのシグナルハンドラが含まれています。 | |
1779 | 例えば: | |
1780 | ||
1781 | sub handler { # 1st argument is signal name | |
1782 | my($sig) = @_; | |
1783 | print "Caught a SIG$sig--shutting down\n"; | |
1784 | close(LOG); | |
1785 | exit(0); | |
1786 | } | |
1787 | ||
1788 | $SIG{'INT'} = \&handler; | |
1789 | $SIG{'QUIT'} = \&handler; | |
1790 | ... | |
1791 | $SIG{'INT'} = 'DEFAULT'; # restore default action | |
1792 | $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT | |
1793 | ||
1794 | =begin original | |
1795 | ||
1796 | 1665 | Using a value of C<'IGNORE'> usually has the effect of ignoring the |
1797 | signal, except for the C<CHLD> signal. See L<perlipc> for more about | |
1666 | signal, except for the C<CHLD> signal. See L<perlipc> for more about | |
1798 | this special case. | |
1667 | this special case. Using an empty string or C<undef> as the value has | |
1668 | the same effect as C<'DEFAULT'>. | |
1799 | 1669 | |
1800 | 1670 | =end original |
1801 | 1671 | |
1802 | 1672 | C<'IGNORE'> という値は通常はシグナルの効果を無視するために使いますが、 |
1803 | 1673 | C<CHLD> シグナルは例外です。 |
1804 | 1674 | この特別な場合に関する詳細は L<perlipc> を参照して下さい。 |
1675 | 値として空文字列や C<undef> を使うのは C<'DEFAULT'> と同じ効果です。 | |
1805 | 1676 | |
1806 | 1677 | =begin original |
1807 | 1678 | |
1808 | 1679 | Here are some other examples: |
1809 | 1680 | |
1810 | 1681 | =end original |
1811 | 1682 | |
1812 | 1683 | 以下にその他の例を示します: |
1813 | 1684 | |
1814 | 1685 | =begin original |
1815 | 1686 | |
1816 | ||
1687 | $SIG{"PIPE"} = "Plumber"; # assumes main::Plumber (not | |
1817 | ||
1688 | # recommended) | |
1818 | ||
1689 | $SIG{"PIPE"} = \&Plumber; # just fine; assume current | |
1819 | ||
1690 | # Plumber | |
1691 | $SIG{"PIPE"} = *Plumber; # somewhat esoteric | |
1692 | $SIG{"PIPE"} = Plumber(); # oops, what did Plumber() | |
1693 | # return?? | |
1820 | 1694 | |
1821 | 1695 | =end original |
1822 | 1696 | |
1823 | 1697 | $SIG{"PIPE"} = "Plumber"; # main::Plumber を仮定します(非推奨) |
1824 | 1698 | $SIG{"PIPE"} = \&Plumber; # 問題なし; カレントの Plumber を仮定します |
1825 | 1699 | $SIG{"PIPE"} = *Plumber; # 少々難解 |
1826 | 1700 | $SIG{"PIPE"} = Plumber(); # げげ、Plumber() は何を返すの?? |
1827 | 1701 | |
1828 | 1702 | =begin original |
1829 | 1703 | |
1830 | 1704 | Be sure not to use a bareword as the name of a signal handler, |
1831 | 1705 | lest you inadvertently call it. |
1832 | 1706 | |
1833 | 1707 | =end original |
1834 | 1708 | |
1835 | 裸の単語をシグナルハンドラの名前として使わないようにしてください | |
1709 | 裸の単語をシグナルハンドラの名前として使わないようにしてください; | |
1836 | 1710 | 不注意で呼び出すのを避けるためです。 |
1837 | 1711 | |
1838 | 1712 | =begin original |
1839 | 1713 | |
1714 | Using a string that doesn't correspond to any existing function or a | |
1715 | glob that doesn't contain a code slot is equivalent to C<'IGNORE'>, | |
1716 | but a warning is emitted when the handler is being called (the warning | |
1717 | is not emitted for the internal hooks described below). | |
1718 | ||
1719 | =end original | |
1720 | ||
1721 | 既存の関数に対応しない文字列や、コードスロットを含んでいないグロブを | |
1722 | 使うのは、C<'IGNORE'> と等価ですが、ハンドラが呼び出されると警告が | |
1723 | 発生します(後述する内部フックでは警告は発生しません)。 | |
1724 | ||
1725 | =begin original | |
1726 | ||
1840 | 1727 | If your system has the C<sigaction()> function then signal handlers |
1841 | are installed using it. This means you get reliable signal handling. | |
1728 | are installed using it. This means you get reliable signal handling. | |
1842 | 1729 | |
1843 | 1730 | =end original |
1844 | 1731 | |
1845 | システムに sigaction() 関数がある場合は、シグナルハンドラ | |
1732 | システムに sigaction() 関数がある場合は、シグナルハンドラはそれを使って | |
1846 | インストールされ | |
1733 | インストールされます。 | |
1847 | 1734 | これにより、信頼性のあるシグナルハンドリングが可能になります。 |
1848 | 1735 | |
1849 | 1736 | =begin original |
1850 | 1737 | |
1851 | The default delivery policy of signals changed in Perl 5.8.0 from | |
1738 | The default delivery policy of signals changed in Perl v5.8.0 from | |
1852 | immediate (also known as "unsafe") to deferred, also known as | |
1739 | immediate (also known as "unsafe") to deferred, also known as "safe | |
1853 | ||
1740 | signals". See L<perlipc> for more information. | |
1854 | 1741 | |
1855 | 1742 | =end original |
1856 | 1743 | |
1857 | デフォルトのシグナル配送ポリシーは Perl 5.8.0 に即時("unsafe"としても | |
1744 | デフォルトのシグナル配送ポリシーは Perl v5.8.0 に即時("unsafe"としても | |
1858 | 1745 | 知られます)から保留(「安全なシグナル」としても知られます)に変更されました。 |
1859 | 1746 | さらなる情報については L<perlipc> を参照してください。 |
1860 | 1747 | |
1861 | 1748 | =begin original |
1862 | 1749 | |
1863 | Certain internal hooks can be also set using the C<%SIG> hash. The | |
1750 | Certain internal hooks can be also set using the C<%SIG> hash. The | |
1864 | 1751 | routine indicated by C<$SIG{__WARN__}> is called when a warning |
1865 | message is about to be printed. The warning message is passed as the | |
1752 | message is about to be printed. The warning message is passed as the | |
1866 | first argument. The presence of a C<__WARN__> hook causes the | |
1753 | first argument. The presence of a C<__WARN__> hook causes the | |
1867 | ordinary printing of warnings to C<STDERR> to be suppressed. You can | |
1754 | ordinary printing of warnings to C<STDERR> to be suppressed. You can | |
1868 | 1755 | use this to save warnings in a variable, or turn warnings into fatal |
1869 | 1756 | errors, like this: |
1870 | 1757 | |
1871 | 1758 | =end original |
1872 | 1759 | |
1873 | 1760 | ある種の内部フックも %SIG ハッシュを使ってセットされます。 |
1874 | 1761 | 警告メッセージを表示しようとするときに C<$SIG{__WARN__}> で |
1875 | 1762 | 示されたルーチンが呼び出されます。 |
1876 | 1763 | 警告メッセージは最初の引数として渡されます。 |
1877 | 1764 | C<__WARN__> フックがあると、通常の C<STDERR> への警告の出力は行われません。 |
1878 | 1765 | これを使って、警告メッセージを変数にいれたり、 |
1879 | 1766 | あるいは以下のようにして警告を致命的エラーに変えたり出来ます: |
1880 | 1767 | |
1881 | ||
1768 | local $SIG{__WARN__} = sub { die $_[0] }; | |
1882 | ||
1769 | eval $proggie; | |
1883 | 1770 | |
1884 | 1771 | =begin original |
1885 | 1772 | |
1886 | As the C<'IGNORE'> hook is not supported by C<__WARN__>, | |
1773 | As the C<'IGNORE'> hook is not supported by C<__WARN__>, its effect is | |
1887 | disable warnings using the | |
1774 | the same as using C<'DEFAULT'>. You can disable warnings using the | |
1775 | empty subroutine: | |
1888 | 1776 | |
1889 | 1777 | =end original |
1890 | 1778 | |
1891 | C<__WARN__> では C<'IGNORE'> フックには対応していないので、 | |
1779 | C<__WARN__> では C<'IGNORE'> フックには対応していないので、 | |
1892 | ||
1780 | この効果は C<'DEFAULT'> を使うのと同じです。 | |
1781 | 空サブルーチンを使って警告を無効に出来ます: | |
1893 | 1782 | |
1894 | ||
1783 | local $SIG{__WARN__} = sub {}; | |
1895 | 1784 | |
1896 | 1785 | =begin original |
1897 | 1786 | |
1898 | 1787 | The routine indicated by C<$SIG{__DIE__}> is called when a fatal |
1899 | exception is about to be thrown. The error message is passed as the | |
1788 | exception is about to be thrown. The error message is passed as the | |
1900 | first argument. When a C<__DIE__> hook routine returns, the exception | |
1789 | first argument. When a C<__DIE__> hook routine returns, the exception | |
1901 | 1790 | processing continues as it would have in the absence of the hook, |
1902 | unless the hook routine itself exits via a C<goto>, a loop exit, | |
1791 | unless the hook routine itself exits via a C<goto &sub>, a loop exit, | |
1903 | C<die()>. The C<__DIE__> handler is explicitly disabled during | |
1792 | or a C<die()>. The C<__DIE__> handler is explicitly disabled during | |
1904 | call, so that you can die from a C<__DIE__> handler. Similarly | |
1793 | the call, so that you can die from a C<__DIE__> handler. Similarly | |
1905 | C<__WARN__>. | |
1794 | for C<__WARN__>. | |
1906 | 1795 | |
1907 | 1796 | =end original |
1908 | 1797 | |
1909 | 1798 | C<$SIG{__DIE__}> で示されるルーチンは |
1910 | 1799 | 致命的な例外がまさに投げられようとするときに呼び出されます。 |
1911 | 1800 | エラーメッセージは最初の引数として渡されます。 |
1912 | C<__DIE__> フックから戻ると、 | |
1801 | C<__DIE__> フックから戻ると、例外処理はフックがなかったかのように | |
1913 | ||
1802 | 再開されますが、フックルーチン自体が C<goto &sub>、ループ終了、 | |
1914 | ||
1803 | C<die()> によって終了した場合を除きます。 | |
1915 | 終了した場合を除きます。 | |
1916 | 1804 | C<__DIE__> ハンドラは呼び出し中は明示的に無効になりますので、 |
1917 | 1805 | C<__DIE__> ハンドラから die できます。 |
1918 | 1806 | C<__WARN__> も同様です。 |
1919 | 1807 | |
1920 | 1808 | =begin original |
1921 | 1809 | |
1922 | ||
1810 | The C<$SIG{__DIE__}> hook is called even inside an C<eval()>. It was | |
1923 | eve | |
1811 | never intended to happen this way, but an implementation glitch made | |
1924 | ||
1812 | this possible. This used to be deprecated, as it allowed strange action | |
1925 | ||
1813 | at a distance like rewriting a pending exception in C<$@>. Plans to | |
1926 | i | |
1814 | rectify this have been scrapped, as users found that rewriting a | |
1927 | p | |
1815 | pending exception is actually a useful feature, and not a bug. | |
1928 | deprecated. | |
1929 | 1816 | |
1930 | 1817 | =end original |
1931 | 1818 | |
1932 | ||
1819 | C<$SIG{__DIE__}> は eval() の中でも呼び出されます。 | |
1933 | ||
1820 | これは決してこのようになることを意図したものではありませんでしたが、 | |
1934 | ||
1821 | 実装上のミスでこれが可能になっていました。 | |
1935 | こ | |
1822 | これは以前廃止予定でした; C<$@> で保留されている例外を書き換えるといった | |
1936 | ||
1823 | 変わった行動を離れた場所でできるようにしていたからです。 | |
1937 | ||
1824 | これを修正する計画は破棄されました; | |
1938 | ||
1825 | 保留されている例外を書き換えるというのは実際有用な機能であることがわかり、 | |
1826 | またバグではないからです。 | |
1939 | 1827 | |
1940 | 1828 | =begin original |
1941 | 1829 | |
1830 | The C<$SIG{__DIE__}> doesn't support C<'IGNORE'>; it has the same | |
1831 | effect as C<'DEFAULT'>. | |
1832 | ||
1833 | =end original | |
1834 | ||
1835 | C<$SIG{__DIE__}> は C<'IGNORE'> に対応していません; | |
1836 | これは C<'DEFAULT'> と同じ効果です。 | |
1837 | ||
1838 | =begin original | |
1839 | ||
1942 | 1840 | C<__DIE__>/C<__WARN__> handlers are very special in one respect: they |
1943 | may be called to report (probable) errors found by the parser. In such | |
1841 | may be called to report (probable) errors found by the parser. In such | |
1944 | 1842 | a case the parser may be in inconsistent state, so any attempt to |
1945 | 1843 | evaluate Perl code from such a handler will probably result in a |
1946 | segfault. This means that warnings or errors that result from parsing | |
1844 | segfault. This means that warnings or errors that result from parsing | |
1947 | 1845 | Perl should be used with extreme caution, like this: |
1948 | 1846 | |
1949 | 1847 | =end original |
1950 | 1848 | |
1951 | C<__DIE__> と C<__WARN__> のハンドラは一つの点で非常に特別です | |
1849 | C<__DIE__> と C<__WARN__> のハンドラは一つの点で非常に特別です: | |
1952 | パー | |
1850 | パーサによってエラー(であろうもの)を報告するために呼び出されることがある | |
1953 | 1851 | ことです。 |
1954 | このような場合、パー | |
1852 | このような場合、パーサは不安定な状態になっているかもしれないので、 | |
1955 | 1853 | ハンドラから Perl コードを評価しようとするとセグメンテーションフォールトが |
1956 | 1854 | 発生するかもしれません。 |
1957 | Perl のパー | |
1855 | Perl のパース中の警告やエラーは、以下のように非常に注意して扱うべきです; | |
1958 | 1856 | |
1959 | ||
1857 | require Carp if defined $^S; | |
1960 | ||
1858 | Carp::confess("Something wrong") if defined &Carp::confess; | |
1961 | ||
1859 | die "Something wrong, but could not load Carp to give " | |
1962 | ||
1860 | . "backtrace...\n\t" | |
1861 | . "To see backtrace try starting Perl with -MCarp switch"; | |
1963 | 1862 | |
1964 | 1863 | =begin original |
1965 | 1864 | |
1966 | ||
1967 | 1865 | Here the first line will load C<Carp> I<unless> it is the parser who |
1968 | called the handler. The second line will print backtrace and die if | |
1866 | called the handler. The second line will print backtrace and die if | |
1969 | C<Carp> was available. The third line will be executed only if C<Carp> was | |
1867 | C<Carp> was available. The third line will be executed only if C<Carp> was | |
1970 | 1868 | not available. |
1971 | 1869 | |
1972 | 1870 | =end original |
1973 | 1871 | |
1974 | 一行目は、 | |
1872 | 一行目は、パーサが C<ハンドラ> を I<呼び出したのでなければ> C<Carp> を | |
1975 | ||
1873 | 読み込みます。 | |
1976 | C<二行目> は、Carp が使えるならバックとレースを表示して die します。 | |
1874 | C<二行目> は、C<Carp> が使えるならバックとレースを表示して die します。 | |
1977 | 三行目は Carp が使えないときにのみ実行されます。 | |
1875 | 三行目は C<Carp> が使えないときにのみ実行されます。 | |
1978 | 1876 | |
1979 | 1877 | =begin original |
1980 | 1878 | |
1981 | 1879 | Having to even think about the C<$^S> variable in your exception |
1982 | handlers is simply wrong. C<$SIG{__DIE__}> as currently implemented | |
1880 | handlers is simply wrong. C<$SIG{__DIE__}> as currently implemented | |
1983 | invites grievous and difficult to track down errors. Avoid it | |
1881 | invites grievous and difficult to track down errors. Avoid it | |
1984 | 1882 | and use an C<END{}> or CORE::GLOBAL::die override instead. |
1985 | 1883 | |
1986 | 1884 | =end original |
1987 | 1885 | |
1988 | 1886 | 例外ハンドラの中で C<$^S> を使おうなどとは考えてもいけません。 |
1989 | 1887 | 現在の実装の C<$SIG{__DIE__}> は面倒を引き寄せ、エラーの追跡を困難にします。 |
1990 | これの代わりに C<END{}> を使うか、CORE::GLOBAL::die を | |
1888 | これの代わりに C<END{}> を使うか、CORE::GLOBAL::die を | |
1889 | オーバーライドしてください。 | |
1991 | 1890 | |
1992 | 1891 | =begin original |
1993 | 1892 | |
1994 | 1893 | See L<perlfunc/die>, L<perlfunc/warn>, L<perlfunc/eval>, and |
1995 | 1894 | L<warnings> for additional information. |
1996 | 1895 | |
1997 | 1896 | =end original |
1998 | 1897 | |
1999 | 1898 | 追加の情報については L<perlfunc/die>, L<perlfunc/warn>, L<perlfunc/eval>, |
2000 | 1899 | L<warnings> を参照して下さい。 |
2001 | 1900 | |
2002 | =item | |
1901 | =item %{^HOOK} | |
1902 | X<%{^HOOK}> | |
2003 | 1903 | |
2004 | =item $^T | |
2005 | X<$^T> X<$BASETIME> | |
2006 | ||
2007 | 1904 | =begin original |
2008 | 1905 | |
2009 | Th | |
1906 | This hash contains coderefs which are called when various perl keywords | |
2010 | ||
1907 | which are hard or impossible to wrap are called. The keys of this hash | |
2011 | and | |
1908 | are named after the keyword that is being hooked, followed by two | |
1909 | underbars and then a phase term; either "before" or "after". | |
2012 | 1910 | |
2013 | 1911 | =end original |
2014 | 1912 | |
2015 | ||
1913 | このハッシュには、ラップが困難または不可能なさまざまな | |
2016 | ||
1914 | perl キーワードが呼び出されたときに呼び出される | |
1915 | コードリファレンスが含まれています。 | |
1916 | このハッシュのキーは、フックされているキーワードにちなんで | |
1917 | 名前が付けられ、その後に二つのアンダーバーとフェーズ用語 | |
1918 | ("before" または "after")が続きます。 | |
2017 | 1919 | |
2018 | =item ${^TAINT} | |
2019 | X<${^TAINT}> | |
2020 | ||
2021 | 1920 | =begin original |
2022 | 1921 | |
2023 | ||
1922 | Perl will throw an error if you attempt modify a key which is not | |
2024 | ||
1923 | documented to exist, or if you attempt to store anything other than a | |
2025 | ||
1924 | code reference or undef in the hash. If you wish to use an object to | |
1925 | implement a hook you can use currying to embed the object into an | |
1926 | anonymous code reference. | |
2026 | 1927 | |
2027 | 1928 | =end original |
2028 | 1929 | |
2029 | ||
1930 | 存在することが文書化されていないキーを変更しようとしたり、 | |
2030 | ||
1931 | コードリファレンスや undef 以外のものをハッシュに | |
2031 | ||
1932 | 保存しようとしたりすると、Perl はエラーを投げます。 | |
1933 | フックを実装するためにオブジェクトを使用したい場合は、カリー化を | |
1934 | 使って、オブジェクトに匿名コードリファレンスを埋め込むことができます。 | |
2032 | 1935 | |
2033 | 1936 | =begin original |
2034 | 1937 | |
2035 | ||
1938 | Currently there is only one keyword which can be hooked, C<require>, but | |
1939 | it is expected that in future releases there will be additional keywords | |
1940 | with hook support. | |
2036 | 1941 | |
2037 | 1942 | =end original |
2038 | 1943 | |
2039 | ||
1944 | 現在、フック可能なキーワードは C<require> のみですが、将来のリリースでは | |
1945 | フックに対応するキーワードが追加される予定です。 | |
2040 | 1946 | |
1947 | =over 4 | |
1948 | ||
1949 | =item require__before | |
1950 | ||
2041 | 1951 | =begin original |
2042 | 1952 | |
2043 | Thi | |
1953 | The routine indicated by C<${^HOOK}{require__before}> is called by | |
1954 | C<require> B<before> it checks C<%INC>, looks up C<@INC>, calls INC | |
1955 | hooks, or compiles any code. It is called with a single argument, the | |
1956 | filename for the item being required (package names are converted to | |
1957 | paths). It may alter this filename to change what file is loaded. If | |
1958 | the hook dies during execution then it will block the require from executing. | |
2044 | 1959 | |
2045 | 1960 | =end original |
2046 | 1961 | |
2047 | ||
1962 | C<${^HOOK}{require__before}> で示されるルーチンは、 | |
1963 | C<%INC> をチェックしたり、C<@INC> を検索したり、 | |
1964 | INC フックを呼び出したり、任意のコードをコンパイルしたりする | |
1965 | B<前> に C<require> によって呼び出されます。 | |
1966 | このルーチンは単一の引数で呼び出されます; | |
1967 | require されるアイテムのファイル名です (パッケージ名はパスに変換されます)。 | |
1968 | このファイル名を変更して、ロードされるファイルを変更できます。 | |
1969 | 実行中にフックが die すると、require の実行がブロックされます。 | |
2048 | 1970 | |
2049 | =item ${^UNICODE} | |
2050 | X<${^UNICODE}> | |
2051 | ||
2052 | 1971 | =begin original |
2053 | 1972 | |
2054 | ||
1973 | In order to make it easy to perform an action with shared state both | |
2055 | ||
1974 | before and after the require keyword was executed the C<require__before> | |
2056 | ||
1975 | hook may return a "post-action" coderef which will in turn be executed when | |
1976 | the C<require> completes. This coderef will be executed regardless as to | |
1977 | whether the require completed succesfully or threw an exception. It will | |
1978 | be called with the filename that was required. You can check %INC to | |
1979 | determine if the require was successful. Any other return from the | |
1980 | C<require__before> hook will be silently ignored. | |
2057 | 1981 | |
2058 | 1982 | =end original |
2059 | 1983 | |
2060 | ||
1984 | require キーワードが実行される前と後の両方で共有状態のアクションを | |
2061 | ||
1985 | 簡単に実行できるようにするために、C<require__before> フックは、 | |
2062 | ||
1986 | C<require> が完了したときに順番に実行される「アクション後」の | |
1987 | コードリファレンスを返すことができます。 | |
1988 | このコードリファレンスは、require が正常に完了したか、 | |
1989 | 例外が投げられたかにかかわらず実行されます。 | |
1990 | これは、require されたファイル名と共に呼び出されます。 | |
1991 | %INC をチェックして、require が成功したかどうかを判断できます。 | |
1992 | C<require__before> フックからのその他の戻り値は、暗黙に無視されます。 | |
2063 | 1993 | |
2064 | 1994 | =begin original |
2065 | 1995 | |
2066 | ||
1996 | C<require__before> hooks are called in FIFO order, and if the hook | |
1997 | returns a code reference those code references will be called in FILO | |
1998 | order. In other words if A requires B requires C, then | |
1999 | C<require__before> will be called first for A, then B and then C, and | |
2000 | the post-action code reference will executed first for C, then B and | |
2001 | then finally A. | |
2067 | 2002 | |
2068 | 2003 | =end original |
2069 | 2004 | |
2070 | ||
2005 | C<require__before> フックは FIFO 順に呼び出され、フックが | |
2006 | コードリファレンスを返す場合、それらのコードリファレンスは | |
2007 | FILO 順に呼び出されます。 | |
2008 | つまり、A が B を require し、B が C を require する場合、 | |
2009 | C<require__before> が最初に A に対して呼び出され、次に B, C の順に | |
2010 | 呼び出され、アクション後のコードリファレンスが最初に C に対して実行され、 | |
2011 | 次に B、最後に A の順に実行されます。 | |
2071 | 2012 | |
2072 | 2013 | =begin original |
2073 | 2014 | |
2074 | ||
2015 | Well behaved code should ensure that when setting up a | |
2016 | C<require__before> hook that any prior installed hook will be called, | |
2017 | and that their return value, if a code reference, will be called as | |
2018 | well. See L<perlfunc/require> for an example implementation. | |
2075 | 2019 | |
2076 | 2020 | =end original |
2077 | 2021 | |
2078 | ||
2022 | 適切に動作するコードでは、C<require__before> フックを設定するときに、 | |
2023 | 以前にインストールされたフックが呼び出され、コードリファレンスの場合は | |
2024 | その戻り値も呼び出されるようにする必要があります。 | |
2025 | 実装例については、L<perlfunc/require> を参照してください。 | |
2079 | 2026 | |
2080 | =item | |
2027 | =item require__after | |
2081 | X<${^UTF8CACHE}> | |
2082 | 2028 | |
2083 | 2029 | =begin original |
2084 | 2030 | |
2085 | Th | |
2031 | The routine indicated by C<${^HOOK}{require__after}> is called by | |
2086 | ||
2032 | C<require> B<after> the require completes. It is called with a single | |
2087 | a | |
2033 | argument, the filename for the item being required (package names are | |
2034 | converted to paths). It is executed when the C<require> completes, | |
2035 | either via exception or via completion of the require statement, and you | |
2036 | can check C<%INC> to determine if the require was successful. | |
2088 | 2037 | |
2089 | 2038 | =end original |
2090 | 2039 | |
2091 | ||
2040 | C<${^HOOK}{require__after}> で示されるルーチンは、require が完了した | |
2092 | ||
2041 | B<後> に C<require> によって呼び出されます。 | |
2093 | ||
2042 | このルーチンは単一の引数で呼び出されます; | |
2043 | require されるアイテムのファイル名です (パッケージ名はパスに変換されます)。 | |
2044 | このルーチンは、例外または require 文の完了によって | |
2045 | C<require> が完了したときに実行されます; | |
2046 | C<%INC> をチェックして、require が成功したかどうかを判断できます。 | |
2094 | 2047 | |
2095 | 2048 | =begin original |
2096 | 2049 | |
2097 | Th | |
2050 | The C<require__after> hook is called for each required file in FILO | |
2051 | order. In other words if A requires B requires C, then C<require__after> | |
2052 | will be called first for C, then B and then A. | |
2098 | 2053 | |
2099 | 2054 | =end original |
2100 | 2055 | |
2101 | ||
2056 | C<require__after> フックは、require されたファイルごとに FILO 順で | |
2057 | 呼び出されます。 | |
2058 | つまり、A が B を require し、B が C を require する場合、 | |
2059 | C<require__after> が最初に C に対して呼び出され、次に B、次に A に対して | |
2060 | 呼び出されます。 | |
2102 | 2061 | |
2103 | = | |
2062 | =back | |
2104 | X<${^UTF8LOCALE}> | |
2105 | 2063 | |
2106 | = | |
2064 | =item $BASETIME | |
2107 | 2065 | |
2108 | ||
2066 | =item $^T | |
2109 | ||
2067 | X<$^T> X<$BASETIME> | |
2110 | adjust-utf8ness-to-locale mode (as when run with the C<-CL> command-line | |
2111 | switch); see L<perlrun> for more info on this. | |
2112 | 2068 | |
2113 | =end original | |
2114 | ||
2115 | この変数は、起動時に perl によって UTF-8 ロケールが検出されたかどうかを | |
2116 | 示します。 | |
2117 | この情報は(C<-CL> コマンドラインスイッチで起動されることによって) | |
2118 | 「utf8 性をロケールに合わせる」モードのときに perl によって使われます; | |
2119 | これに関するさらなる情報は L<perlrun> を参照してください。 | |
2120 | ||
2121 | 2069 | =begin original |
2122 | 2070 | |
2123 | Thi | |
2071 | The time at which the program began running, in seconds since the | |
2072 | epoch (beginning of 1970). The values returned by the B<-M>, B<-A>, | |
2073 | and B<-C> filetests are based on this value. | |
2124 | 2074 | |
2125 | 2075 | =end original |
2126 | 2076 | |
2127 | ||
2077 | プログラムを実行開始した時刻を、紀元 (1970年の始め) からの秒数で | |
2078 | 示したものです。 | |
2079 | ファイルテスト B<-M>、B<-A>、B<-C> で返される値は、この値に基づいています。 | |
2128 | 2080 | |
2129 | 2081 | =item $PERL_VERSION |
2130 | 2082 | |
2131 | 2083 | =item $^V |
2132 | 2084 | X<$^V> X<$PERL_VERSION> |
2133 | 2085 | |
2086 | =for comment | |
2087 | These are documented in the generated file lib/Config.pod. This looks | |
2088 | like as good a place as any to give notice that they are documented. | |
2089 | ||
2134 | 2090 | =begin original |
2135 | 2091 | |
2136 | 2092 | The revision, version, and subversion of the Perl interpreter, |
2137 | represented as a | |
2093 | represented as a L<version> object. | |
2138 | 2094 | |
2139 | 2095 | =end original |
2140 | 2096 | |
2141 | ||
2097 | L<version> オブジェクトとして表現される Perl インタプリタの | |
2098 | revision, version, subversion。 | |
2142 | 2099 | |
2143 | 2100 | =begin original |
2144 | 2101 | |
2145 | This variable first appeared in perl 5.6.0; earlier versions of perl | |
2102 | This variable first appeared in perl v5.6.0; earlier versions of perl | |
2146 | will see an undefined value. Before perl 5.10.0 C<$^V> was represented | |
2103 | will see an undefined value. Before perl v5.10.0 C<$^V> was represented | |
2147 | as a v-string. | |
2104 | as a v-string rather than a L<version> object. | |
2148 | 2105 | |
2149 | 2106 | =end original |
2150 | 2107 | |
2151 | この変数は perl 5.6.0 で最初に現れました; それより前のバージョンでは | |
2108 | この変数は perl v5.6.0 で最初に現れました; それより前のバージョンでは | |
2152 | 2109 | 未定義値となります。 |
2153 | perl 5.10.0 以前では C<$^V> は v | |
2110 | perl v5.10.0 以前では C<$^V> は L<version> オブジェクトではなく | |
2111 | v-string 形式で表現されます。 | |
2154 | 2112 | |
2155 | 2113 | =begin original |
2156 | 2114 | |
2157 | 2115 | C<$^V> can be used to determine whether the Perl interpreter executing |
2158 | a script is in the right range of versions. For example: | |
2116 | a script is in the right range of versions. For example: | |
2159 | 2117 | |
2160 | 2118 | =end original |
2161 | 2119 | |
2162 | 2120 | C<$^V> はスクリプトを実行している Perl インタプリタのバージョンが |
2163 | 2121 | 正しい範囲に入っているかを調べるのに使えます。 |
2164 | 例: | |
2122 | 例えば: | |
2165 | 2123 | |
2166 | ||
2124 | warn "Hashes not randomized!\n" if !$^V or $^V lt v5.8.1 | |
2167 | 2125 | |
2168 | 2126 | =begin original |
2169 | 2127 | |
2170 | ||
2128 | While version objects overload stringification, to portably convert | |
2171 | C< | |
2129 | C<$^V> into its string representation, use C<sprintf()>'s C<"%vd"> | |
2130 | conversion, which works for both v-strings or version objects: | |
2172 | 2131 | |
2173 | 2132 | =end original |
2174 | 2133 | |
2175 | C<$^V> を文字列表現に変換するに | |
2134 | 移植性がある形で C<$^V> を文字列表現に変換するために、 | |
2135 | バージョンオブジェクトは文字列化をオーバーロードしますが、 | |
2136 | v-文字列とバージョンオブジェクトの療養で動作する | |
2137 | C<sprintf()> の C<"%vd"> 変換を使ってください。 | |
2176 | 2138 | |
2177 | printf "version is v%vd\n", $^V; # Perl's version | |
2178 | ||
2179 | 2139 | =begin original |
2180 | 2140 | |
2181 | ||
2141 | printf "version is v%vd\n", $^V; # Perl's version | |
2182 | for a convenient way to fail if the running Perl interpreter is too old. | |
2183 | 2142 | |
2184 | 2143 | =end original |
2185 | 2144 | |
2186 | ||
2145 | printf "version is v%vd\n", $^V; # Perl のバージョン | |
2187 | ついては C<use VERSION> と C<require VERSION> のドキュメントを | |
2188 | 参照して下さい。 | |
2189 | 2146 | |
2190 | 2147 | =begin original |
2191 | 2148 | |
2192 | See | |
2149 | See the documentation of C<use VERSION> and C<require VERSION> | |
2150 | for a convenient way to fail if the running Perl interpreter is too old. | |
2193 | 2151 | |
2194 | 2152 | =end original |
2195 | 2153 | |
2196 | Perl | |
2154 | 実行する Perl インタプリタが古すぎる場合に終了する便利な方法については | |
2155 | C<use VERSION> と C<require VERSION> のドキュメントを参照して下さい。 | |
2197 | 2156 | |
2198 | 2157 | =begin original |
2199 | 2158 | |
2200 | ||
2159 | See also C<L</$]>> for a decimal representation of the Perl version. | |
2201 | 2160 | |
2202 | 2161 | =end original |
2203 | 2162 | |
2204 | ||
2163 | Perl バージョンの 10 進表現については C<L</$]>> も参照して下さい。 | |
2205 | 2164 | |
2206 | 2165 | =begin original |
2207 | 2166 | |
2208 | ||
2167 | The main advantage of C<$^V> over C<$]> is that, for Perl v5.10.0 or | |
2168 | later, it overloads operators, allowing easy comparison against other | |
2169 | version representations (e.g. decimal, literal v-string, "v1.2.3", or | |
2170 | objects). The disadvantage is that prior to v5.10.0, it was only a | |
2171 | literal v-string, which can't be easily printed or compared, whereas | |
2172 | the behavior of C<$]> is unchanged on all versions of Perl. | |
2209 | 2173 | |
2210 | 2174 | =end original |
2211 | 2175 | |
2212 | ||
2176 | Perl 5.10.0 以降での、C<$]> に対する C<$^V> の主な利点は、これは演算子を | |
2177 | オーバーロードするので、他のバージョン表現 (例えば 10 進数、 | |
2178 | リテラルな v-文字列、"v1.2.3"、オブジェクト)との比較が簡単であることです。 | |
2179 | v5.10.0 より前での欠点は、これは単なるリテラルな v-文字列であるため、 | |
2180 | 簡単に表示したり比較したり出来ないことです; 一方、 | |
2181 | C<$]> の振る舞いは全てのバージョンの Perl で変化しません。 | |
2213 | 2182 | |
2214 | =item ${^WIN32_SLOPPY_STAT} | |
2215 | X<${^WIN32_SLOPPY_STAT}> X<sitecustomize> X<sitecustomize.pl> | |
2216 | ||
2217 | 2183 | =begin original |
2218 | 2184 | |
2219 | ||
2185 | Mnemonic: use ^V for a version object. | |
2220 | not try to open the file. This means that the link count cannot be | |
2221 | determined and file attributes may be out of date if additional | |
2222 | hardlinks to the file exist. On the other hand, not opening the file | |
2223 | is considerably faster, especially for files on network drives. | |
2224 | 2186 | |
2225 | 2187 | =end original |
2226 | 2188 | |
2227 | ||
2189 | 記憶法: ^V をバージョンオブジェクトに使います。 | |
2228 | オープンしようとはしません。 | |
2229 | これは、このファイルへの追加のハードリンクが存在する場合、リンクカウントを | |
2230 | 決定できませんし、ファイル属性が古いものになるかもしれないことを | |
2231 | 意味します。 | |
2232 | 一方、ファイルを開かないので、(特にファイルがネットワークドライブにある | |
2233 | 場合は)大幅に高速です。 | |
2234 | 2190 | |
2235 | =begin original | |
2236 | ||
2237 | This variable could be set in the F<sitecustomize.pl> file to | |
2238 | configure the local Perl installation to use "sloppy" C<stat()> by | |
2239 | default. See the documentation for B<-f> in | |
2240 | L<perlrun|perlrun/"Command Switches"> for more information about site | |
2241 | customization. | |
2242 | ||
2243 | =end original | |
2244 | ||
2245 | デフォルトで「ずさんな」C<stat()> を使うために、この変数は、ローカルな | |
2246 | Perl を設定するための F<sitecustomize.pl> で設定できます。 | |
2247 | サイトカスタマイズに関するさらなる情報については | |
2248 | L<perlrun|perlrun/"Command Switches"> の B<-f> を参照してください。 | |
2249 | ||
2250 | =begin original | |
2251 | ||
2252 | This variable was added in Perl 5.10. | |
2253 | ||
2254 | =end original | |
2255 | ||
2256 | この変数は Perl 5.10 で追加されました。 | |
2257 | ||
2258 | 2191 | =item $EXECUTABLE_NAME |
2259 | 2192 | |
2260 | 2193 | =item $^X |
2261 | 2194 | X<$^X> X<$EXECUTABLE_NAME> |
2262 | 2195 | |
2263 | 2196 | =begin original |
2264 | 2197 | |
2265 | 2198 | The name used to execute the current copy of Perl, from C's |
2266 | 2199 | C<argv[0]> or (where supported) F</proc/self/exe>. |
2267 | 2200 | |
2268 | 2201 | =end original |
2269 | 2202 | |
2270 | 2203 | Perl バイナリ自身が実行された時の名前を C の argv[0] または (対応していれば) |
2271 | 2204 | F</proc/self/exe> から持ってきたものです。 |
2272 | 2205 | |
2273 | 2206 | =begin original |
2274 | 2207 | |
2275 | 2208 | Depending on the host operating system, the value of C<$^X> may be |
2276 | 2209 | a relative or absolute pathname of the perl program file, or may |
2277 | 2210 | be the string used to invoke perl but not the pathname of the |
2278 | perl program file. Also, most operating systems permit invoking | |
2211 | perl program file. Also, most operating systems permit invoking | |
2279 | 2212 | programs that are not in the PATH environment variable, so there |
2280 | is no guarantee that the value of C<$^X> is in PATH. For VMS, the | |
2213 | is no guarantee that the value of C<$^X> is in PATH. For VMS, the | |
2281 | 2214 | value may or may not include a version number. |
2282 | 2215 | |
2283 | 2216 | =end original |
2284 | 2217 | |
2285 | 2218 | ホスト OS に依存して、C<$^X> の値は perl プログラムファイルの絶対パスかも |
2286 | 2219 | しれませんし、相対パスかもしれませんし、perl を起動するために使われる |
2287 | 2220 | 文字列ではありますが perl プログラムファイルのパス名ではないかもしれません。 |
2288 | 2221 | また、ほとんどの OS は PATH 環境変数にない位置のプログラムを起動することを |
2289 | 2222 | 許しているので、C<$^X> の値が PATH にある保証はありません。 |
2290 | 2223 | VMS では、この値はバージョン番号を含む場合も含まない場合もあります。 |
2291 | 2224 | |
2292 | 2225 | =begin original |
2293 | 2226 | |
2294 | 2227 | You usually can use the value of C<$^X> to re-invoke an independent |
2295 | 2228 | copy of the same perl that is currently running, e.g., |
2296 | 2229 | |
2297 | 2230 | =end original |
2298 | 2231 | |
2299 | 2232 | 通常は、現在実行中のものと同じ perl の独立したコピーを再起動するために |
2300 | 2233 | C<$^X> の値を使えます; つまり: |
2301 | 2234 | |
2302 | ||
2235 | @first_run = `$^X -le "print int rand 100 for 1..100"`; | |
2303 | 2236 | |
2304 | 2237 | =begin original |
2305 | 2238 | |
2306 | 2239 | But recall that not all operating systems support forking or |
2307 | 2240 | capturing of the output of commands, so this complex statement |
2308 | 2241 | may not be portable. |
2309 | 2242 | |
2310 | 2243 | =end original |
2311 | 2244 | |
2312 | 2245 | しかし、全ての OS が fork やコマンドの出力の捕捉に対応しているわけでは |
2313 | 2246 | ないので、この複雑な文は移植性がないかもしれないことを忘れないでください。 |
2314 | 2247 | |
2315 | 2248 | =begin original |
2316 | 2249 | |
2317 | 2250 | It is not safe to use the value of C<$^X> as a path name of a file, |
2318 | 2251 | as some operating systems that have a mandatory suffix on |
2319 | 2252 | executable files do not require use of the suffix when invoking |
2320 | a command. To convert the value of C<$^X> to a path name, use the | |
2253 | a command. To convert the value of C<$^X> to a path name, use the | |
2321 | 2254 | following statements: |
2322 | 2255 | |
2323 | 2256 | =end original |
2324 | 2257 | |
2325 | C<$^X> の値をファイルのパス名として使うのは安全ではありません; | |
2258 | C<$^X> の値をファイルのパス名として使うのは安全ではありません; 実行ファイルに | |
2326 | ||
2259 | 固定の接尾辞があり、コマンドの起動時には接尾辞が不要な OS もあるからです。 | |
2327 | あるからです。 | |
2328 | 2260 | C<$^X> の値をパス名に変換するには、以下のコードを使ってください: |
2329 | 2261 | |
2330 | ||
2262 | =begin original | |
2331 | use Config; | |
2332 | my $this_perl = $^X; | |
2333 | if ($^O ne 'VMS') { | |
2334 | $this_perl .= $Config{_exe} | |
2335 | unless $this_perl =~ m/$Config{_exe}$/i; | |
2336 | } | |
2337 | 2263 | |
2264 | # Build up a set of file names (not command names). | |
2265 | use Config; | |
2266 | my $this_perl = $^X; | |
2267 | if ($^O ne 'VMS') { | |
2268 | $this_perl .= $Config{_exe} | |
2269 | unless $this_perl =~ m/$Config{_exe}$/i; | |
2270 | } | |
2271 | ||
2272 | =end original | |
2273 | ||
2274 | # (コマンド名ではなく)ファイル名を構築する。 | |
2275 | use Config; | |
2276 | my $this_perl = $^X; | |
2277 | if ($^O ne 'VMS') { | |
2278 | $this_perl .= $Config{_exe} | |
2279 | unless $this_perl =~ m/$Config{_exe}$/i; | |
2280 | } | |
2281 | ||
2338 | 2282 | =begin original |
2339 | 2283 | |
2340 | 2284 | Because many operating systems permit anyone with read access to |
2341 | 2285 | the Perl program file to make a copy of it, patch the copy, and |
2342 | 2286 | then execute the copy, the security-conscious Perl programmer |
2343 | 2287 | should take care to invoke the installed copy of perl, not the |
2344 | copy referenced by C<$^X>. The following statements accomplish | |
2288 | copy referenced by C<$^X>. The following statements accomplish | |
2345 | 2289 | this goal, and produce a pathname that can be invoked as a |
2346 | 2290 | command or referenced as a file. |
2347 | 2291 | |
2348 | 2292 | =end original |
2349 | 2293 | |
2350 | 多くの OS が Perl のプログラムファイルのコピーを作って、コピーに | |
2294 | 多くの OS が Perl のプログラムファイルのコピーを作って、コピーにパッチを当て、 | |
2351 | ||
2295 | それを実行するための読み込み権限を全員に与えているので、セキュリティ | |
2352 | ||
2296 | 意識のある Perl プログラマは C<$^X> で参照されているコピーではなく、 | |
2353 | 2297 | インストールされている perl を起動するように気をつけるべきです。 |
2354 | 2298 | 以下のコードはこの目的を達成し、コマンドとして起動したりファイルとして |
2355 | 2299 | 参照するためのパス名を作成します。 |
2356 | 2300 | |
2357 | ||
2301 | use Config; | |
2358 | ||
2302 | my $secure_perl_path = $Config{perlpath}; | |
2359 | ||
2303 | if ($^O ne 'VMS') { | |
2360 | ||
2304 | $secure_perl_path .= $Config{_exe} | |
2361 | ||
2305 | unless $secure_perl_path =~ m/$Config{_exe}$/i; | |
2362 | ||
2306 | } | |
2363 | 2307 | |
2364 | 2308 | =back |
2365 | 2309 | |
2366 | 2310 | =head2 Variables related to regular expressions |
2367 | 2311 | |
2368 | 2312 | (正規表現に関する変数) |
2369 | 2313 | |
2370 | 2314 | =begin original |
2371 | 2315 | |
2372 | 2316 | Most of the special variables related to regular expressions are side |
2373 | effects. Perl sets these variables when it has | |
2317 | effects. Perl sets these variables when it has completed a match | |
2374 | you should check the match result before using them. | |
2318 | successfully, so you should check the match result before using them. | |
2319 | For instance: | |
2375 | 2320 | |
2376 | 2321 | =end original |
2377 | 2322 | |
2378 | 2323 | 正規表現に関連する特殊変数のほとんどは副作用です。 |
2379 | 2324 | Perl はマッチングに成功したときにこれらの変数を設定するので、変数を |
2380 | 2325 | 使う前にマッチングの結果をチェックするべきです。 |
2381 | 2326 | 例えば: |
2382 | 2327 | |
2383 | ||
2328 | if( /P(A)TT(ER)N/ ) { | |
2384 | ||
2329 | print "I found $1 and $2\n"; | |
2385 | ||
2330 | } | |
2386 | 2331 | |
2387 | 2332 | =begin original |
2388 | 2333 | |
2389 | These variables are read-only and dynamically | |
2334 | These variables are read-only and behave similarly to a dynamically | |
2390 | othe | |
2335 | scoped variable, with only a few exceptions which are explicitly | |
2336 | documented as behaving otherwise. See the following section for more | |
2337 | details. | |
2391 | 2338 | |
2392 | 2339 | =end original |
2393 | 2340 | |
2394 | これらの変数は | |
2341 | これらの変数は、異なる振る舞いを明示的に記しているいくつかの例外を除いて、 | |
2342 | 読み込み専用で動的スコープを持つ変数と同様に振る舞います。 | |
2395 | 2343 | |
2344 | =head3 Scoping Rules of Regex Variables | |
2345 | X<Scoping Rules of Regex Variables> | |
2346 | ||
2347 | (正規表現変数のスコープ規則) | |
2348 | ||
2396 | 2349 | =begin original |
2397 | 2350 | |
2398 | ||
2351 | Regular expression variables allow the programmer to access the state of | |
2399 | the | |
2352 | the most recent I<successful> regex match in the current dynamic scope. | |
2400 | by this bit of code: | |
2401 | 2353 | |
2402 | 2354 | =end original |
2403 | 2355 | |
2404 | 正規表現変数の動的 | |
2356 | 正規表現変数を使うと、プログラマは現在の動的スコープ内で最後に | |
2405 | ||
2357 | I<成功した> 正規表現マッチングの状態にアクセスできます。 | |
2406 | 2358 | |
2407 | ||
2359 | =begin original | |
2408 | my $inner = 'Mutt and Jeff'; | |
2409 | 2360 | |
2410 | ||
2361 | The variables themselves are global and unscoped, but the data they | |
2362 | access is scoped similarly to dynamically scoped variables, in that | |
2363 | every successful match behaves as though it localizes a global state | |
2364 | object to the current block or file scope. | |
2365 | (See L<perlsyn/"Compound Statements"> for more details on dynamic | |
2366 | scoping and the C<local> keyword.) | |
2411 | 2367 | |
2412 | ||
2368 | =end original | |
2413 | 2369 | |
2414 | ||
2370 | 変数自体はグローバルでスコープはありませんが、変数がアクセスする | |
2415 | ||
2371 | データは動的スコープ変数と同様にスコープがあります; | |
2416 | ||
2372 | つまり、マッチングが成功するたびに、グローバル状態オブジェクトが | |
2373 | 現在のブロックまたはファイルスコープにローカル化されたかのように | |
2374 | 動作します。 | |
2375 | (動的スコープと C<local> キーワードの詳細については、 | |
2376 | L<perlsyn/"Compound Statements"> を参照してください。) | |
2417 | 2377 | |
2418 | ||
2378 | =begin original | |
2419 | show_n() if $inner =~ m/$pattern/; | |
2420 | } | |
2421 | 2379 | |
2422 | ||
2380 | A I<successful match> includes any successful match performed by the | |
2423 | ||
2381 | search and replace operator C<s///> as well as those performed by the | |
2382 | C<m//> operator. | |
2424 | 2383 | |
2384 | =end original | |
2385 | ||
2386 | I<成功したマッチング> には、C<m//> 演算子によって実行されたものに加えて、 | |
2387 | 検索および置換演算子 C<s///> によって実行されたすべての成功した | |
2388 | マッチングが含まれます。 | |
2389 | ||
2425 | 2390 | =begin original |
2426 | 2391 | |
2427 | ||
2392 | Consider the following code: | |
2428 | and C<$2> are from the match against C<$outer>. Inside the C<INNER> | |
2429 | block, the values of C<$1> and C<$2> are from the match against | |
2430 | C<$inner>, but only until the end of the block (i.e. the dynamic | |
2431 | scope). After the C<INNER> block completes, the values of C<$1> and | |
2432 | C<$2> return to the values for the match against C<$outer> even though | |
2433 | we have not made another match: | |
2434 | 2393 | |
2435 | 2394 | =end original |
2436 | 2395 | |
2437 | ||
2396 | 次のコードを考えます: | |
2438 | C<$outer> に対するマッチングからのものになります。 | |
2439 | C<INNER> ブロックの内側では、C<$1> と C<$2> の値は C<$inner> での | |
2440 | マッチングからのものになりますが、ブロックの最後までです (つまり、 | |
2441 | 動的スコープを持ちます)。 | |
2442 | C<INNER> ブロックの終了後、C<$1> と C<$2> の値は、他のマッチングがなくても | |
2443 | C<$outer> に対するマッチングからのものになります: | |
2444 | 2397 | |
2445 | ||
2398 | my @state; | |
2446 | ||
2399 | sub matchit { | |
2447 | ||
2400 | push @state, $1; # pushes "baz" | |
2401 | my $str = shift; | |
2402 | $str =~ /(zat)/; # matches "zat" | |
2403 | push @state, $1; # pushes "zat" | |
2404 | } | |
2448 | 2405 | |
2406 | { | |
2407 | $str = "foo bar baz blorp zat"; | |
2408 | $str =~ /(foo)/; # matches "foo" | |
2409 | push @state, $1; # pushes "foo" | |
2410 | { | |
2411 | $str =~ /(pizza)/; # does NOT match | |
2412 | push @state, $1; # pushes "foo" | |
2413 | $str =~ /(bar)/; # matches "bar" | |
2414 | push @state, $1; # pushes "bar" | |
2415 | $str =~ /(baz)/; # matches "baz" | |
2416 | matchit($str); # see above | |
2417 | push @state, $1; # pushes "baz" | |
2418 | } | |
2419 | $str =~ s/noodles/rice/; # does NOT match | |
2420 | push @state, $1; # pushes "foo" | |
2421 | $str =~ s/(blorp)/zwoop/; # matches "blorp" | |
2422 | push @state, $1; # pushes "blorp" | |
2423 | } | |
2424 | # the following prints "foo, foo, bar, baz, zat, baz, foo, blorp" | |
2425 | print join ",", @state; | |
2426 | ||
2449 | 2427 | =begin original |
2450 | 2428 | |
2451 | ||
2429 | Notice that each successful match in the exact same scope overrides the | |
2452 | ||
2430 | match context of the previous successful match, but that unsuccessful | |
2453 | e | |
2431 | matches do not. Also note that in an inner nested scope the previous | |
2454 | ||
2432 | state from an outer dynamic scope persists until it has been overriden | |
2455 | ||
2433 | by another successful match, but that when the inner nested scope exits | |
2456 | ||
2434 | whatever match context was in effect before the inner successful match | |
2435 | is restored when the scope concludes. | |
2457 | 2436 | |
2458 | 2437 | =end original |
2459 | 2438 | |
2460 | ||
2439 | まったく同じスコープ内でマッチングが成功するたびに、以前の成功した | |
2461 | ||
2440 | マッチングのマッチングコンテキストは上書きされますが、失敗したマッチングは | |
2462 | ||
2441 | 上書きされないことに注意してください。 | |
2463 | ||
2442 | また、内側のネストされたスコープでは、外側の動的スコープからの | |
2464 | ||
2443 | 以前の状態は、別の成功したマッチングによって上書きされるまで持続しますが、 | |
2465 | ||
2444 | 内側のネストされたスコープが終了すると、内側の成功したマッチングが終了する | |
2445 | 前に有効であったマッチングコンテキストが復元されます。 | |
2466 | 2446 | |
2467 | ||
2447 | =begin original | |
2468 | 2448 | |
2449 | It is a known issue that C<goto LABEL> may interact poorly with the | |
2450 | dynamically scoped match context. This may not be fixable, and is | |
2451 | considered to be one of many good reasons to avoid C<goto LABEL>. | |
2452 | ||
2453 | =end original | |
2454 | ||
2455 | C<goto LABEL> が動的スコープマッチングコンテキストとうまく | |
2456 | 相互作用しない可能性があることは既知の問題です。 | |
2457 | これは修正できない可能性があり、C<goto LABEL> を避ける多くの正当な | |
2458 | 理由の一つと考えられています。 | |
2459 | ||
2460 | =head3 Performance issues | |
2461 | ||
2462 | (性能問題) | |
2463 | ||
2469 | 2464 | =begin original |
2470 | 2465 | |
2471 | T | |
2466 | Traditionally in Perl, any use of any of the three variables C<$`>, C<$&> | |
2472 | ||
2467 | or C<$'> (or their C<use English> equivalents) anywhere in the code, caused | |
2473 | ||
2468 | all subsequent successful pattern matches to make a copy of the matched | |
2469 | string, in case the code might subsequently access one of those variables. | |
2470 | This imposed a considerable performance penalty across the whole program, | |
2471 | so generally the use of these variables has been discouraged. | |
2474 | 2472 | |
2475 | 2473 | =end original |
2476 | 2474 | |
2477 | ||
2475 | Perl では伝統的に、C<$`>, C<$&>, C<$'> (または C<use English> での | |
2478 | コードの | |
2476 | 等価物) をコードのどこかで使うと、コードが引き続いてこれらの変数に | |
2477 | アクセスするかもしれないので、引き続くすべての成功したパターンマッチングで | |
2478 | マッチングした文字列のコピーを作ります。 | |
2479 | これはプログラム全体に対してかなりの性能上の負荷を掛けるので、一般的に | |
2480 | これらの変数の使用は非推奨です。 | |
2479 | 2481 | |
2480 | 2482 | =begin original |
2481 | 2483 | |
2482 | ||
2484 | In Perl 5.6.0 the C<@-> and C<@+> dynamic arrays were introduced that | |
2483 | ||
2485 | supply the indices of successful matches. So you could for example do | |
2484 | ||
2486 | this: | |
2485 | 2487 | |
2486 | 2488 | =end original |
2487 | 2489 | |
2488 | Perl 5. | |
2490 | Perl 5.6.0 では、マッチングに成功したインデックスを提供する C<@-> と | |
2489 | C< | |
2491 | C<@+> 動的配列が導入されました。 | |
2490 | ||
2492 | それで、たとえばこのようにできます: | |
2491 | 2493 | |
2494 | $str =~ /pattern/; | |
2495 | ||
2496 | print $`, $&, $'; # bad: performance hit | |
2497 | ||
2498 | print # good: no performance hit | |
2499 | substr($str, 0, $-[0]), | |
2500 | substr($str, $-[0], $+[0]-$-[0]), | |
2501 | substr($str, $+[0]); | |
2502 | ||
2503 | =begin original | |
2504 | ||
2505 | In Perl 5.10.0 the C</p> match operator flag and the C<${^PREMATCH}>, | |
2506 | C<${^MATCH}>, and C<${^POSTMATCH}> variables were introduced, that allowed | |
2507 | you to suffer the penalties only on patterns marked with C</p>. | |
2508 | ||
2509 | =end original | |
2510 | ||
2511 | Perl 5.10.0 で C</p> マッチング演算子フラグと C<${^PREMATCH}>, | |
2512 | C<${^MATCH}>, C<${^POSTMATCH}> 変数が導入され、C</p> でマークされた | |
2513 | パターンのみが負荷を被るようにできるようになりました。 | |
2514 | ||
2515 | =begin original | |
2516 | ||
2517 | In Perl 5.18.0 onwards, perl started noting the presence of each of the | |
2518 | three variables separately, and only copied that part of the string | |
2519 | required; so in | |
2520 | ||
2521 | =end original | |
2522 | ||
2523 | Perl 5.18.0 以降では、perl は三つの変数の存在を別々に注意するようになり、 | |
2524 | 必要な部分文字列のみをコピーするようになりました; 従って、次の場合は | |
2525 | ||
2526 | $`; $&; "abcdefgh" =~ /d/ | |
2527 | ||
2528 | =begin original | |
2529 | ||
2530 | perl would only copy the "abcd" part of the string. That could make a big | |
2531 | difference in something like | |
2532 | ||
2533 | =end original | |
2534 | ||
2535 | perl は文字列のうち "abcd" の部分のみをコピーします。 | |
2536 | これは次のようなものとは大きな違いになります | |
2537 | ||
2538 | $str = 'x' x 1_000_000; | |
2539 | $&; # whoops | |
2540 | $str =~ /x/g # one char copied a million times, not a million chars | |
2541 | ||
2542 | =begin original | |
2543 | ||
2544 | In Perl 5.20.0 a new copy-on-write system was enabled by default, which | |
2545 | finally fixes most of the performance issues with these three variables, and | |
2546 | makes them safe to use anywhere. | |
2547 | ||
2548 | =end original | |
2549 | ||
2550 | Perl 5.20.0 では新しいコピーオンライトシステムがデフォルトで有効になり、 | |
2551 | これらの変数に関するほとんどの性能問題は最終的に修正され、 | |
2552 | これらをどこで使っても安全になりました。 | |
2553 | ||
2554 | =begin original | |
2555 | ||
2556 | The C<Devel::NYTProf> and C<Devel::FindAmpersand> modules can help you | |
2557 | find uses of these problematic match variables in your code. | |
2558 | ||
2559 | =end original | |
2560 | ||
2561 | C<Devel::NYTProf> と C<Devel::FindAmpersand> のモジュールは、コード中に | |
2562 | これらの問題のあるマッチング変数の使用を探す助けになります。 | |
2563 | ||
2492 | 2564 | =over 8 |
2493 | 2565 | |
2494 | 2566 | =item $<I<digits>> ($1, $2, ...) |
2495 | X<$1> X<$2> X<$3> | |
2567 | X<$1> X<$2> X<$3> X<$I<digits>> | |
2496 | 2568 | |
2497 | 2569 | =begin original |
2498 | 2570 | |
2571 | ||
2499 | 2572 | Contains the subpattern from the corresponding set of capturing |
2500 | parentheses from the last successful pattern match | |
2573 | parentheses from the last successful pattern match in the current | |
2501 | ||
2574 | dynamic scope. (See L</Scoping Rules of Regex Variables>.) | |
2502 | 2575 | |
2503 | 2576 | =end original |
2504 | 2577 | |
2505 | 最後に成功したパターンマッチングで対応する括弧の | |
2578 | 現在の動的スコープで、最後に成功したパターンマッチングで対応する括弧の | |
2506 | 文字列が入ってい | |
2579 | サブパターンにマッチングした文字列が入っています。 | |
2507 | ||
2580 | (L</Scoping Rules of Regex Variables> を参照してください。) | |
2508 | 2581 | |
2509 | 2582 | =begin original |
2510 | 2583 | |
2511 | ||
2584 | Note there is a distinction between a capture buffer which matches | |
2585 | the empty string a capture buffer which is optional. Eg, C<(x?)> and | |
2586 | C<(x)?> The latter may be undef, the former not. | |
2512 | 2587 | |
2513 | 2588 | =end original |
2514 | 2589 | |
2515 | ||
2590 | 空文字列にマッチングする捕捉バッファと、オプションの捕捉バッファの | |
2591 | 違いに注意してください。 | |
2592 | 例えば、C<(x?)> と C<(x)?> では、後者は undef かもしれませんが、 | |
2593 | 前者は違います。 | |
2516 | 2594 | |
2517 | 2595 | =begin original |
2518 | 2596 | |
2597 | These variables are read-only. | |
2598 | ||
2599 | =end original | |
2600 | ||
2601 | これらの変数はすべて読み込み専用です。 | |
2602 | ||
2603 | =begin original | |
2604 | ||
2519 | 2605 | Mnemonic: like \digits. |
2520 | 2606 | |
2521 | 2607 | =end original |
2522 | 2608 | |
2523 | ||
2609 | 記憶法: \(数字) のようなもの。 | |
2524 | 2610 | |
2611 | =item @{^CAPTURE} | |
2612 | X<@{^CAPTURE}> X<@^CAPTURE> | |
2613 | ||
2614 | =begin original | |
2615 | ||
2616 | An array which exposes the contents of the capture buffers, if any, of | |
2617 | the last successful pattern match, not counting patterns matched | |
2618 | in nested blocks that have been exited already. | |
2619 | ||
2620 | =end original | |
2621 | ||
2622 | 最後に成功したパターンマッチングの (もしあれば) 捕捉バッファの内容を | |
2623 | 露出させた配列; 既に終了したネストしたブロックの中でマッチングしたパターンは | |
2624 | 考慮しません。 | |
2625 | ||
2626 | =begin original | |
2627 | ||
2628 | Note that the 0 index of C<@{^CAPTURE}> is equivalent to C<$1>, the 1 index | |
2629 | is equivalent to C<$2>, etc. | |
2630 | ||
2631 | =end original | |
2632 | ||
2633 | C<@{^CAPTURE}> の添え字 0 は C<$1> と等価、 | |
2634 | 添え字 1 は C<$2> と等価、などであることに注意してください。 | |
2635 | ||
2636 | if ("foal"=~/(.)(.)(.)(.)/) { | |
2637 | print join "-", @{^CAPTURE}; | |
2638 | } | |
2639 | ||
2640 | =begin original | |
2641 | ||
2642 | should output "f-o-a-l". | |
2643 | ||
2644 | =end original | |
2645 | ||
2646 | これは "f-o-a-l" を出力します。 | |
2647 | ||
2648 | =begin original | |
2649 | ||
2650 | See also L<<< /$<I<digits>> ($1, $2, ...) >>>, L</%{^CAPTURE}> and | |
2651 | L</%{^CAPTURE_ALL}>. | |
2652 | ||
2653 | =end original | |
2654 | ||
2655 | L<<< /$<I<数字>> ($1, $2, ...) >>>, L</%{^CAPTURE}>, | |
2656 | L</%{^CAPTURE_ALL}> も参照してください。 | |
2657 | ||
2658 | =begin original | |
2659 | ||
2660 | Note that unlike most other regex magic variables there is no single | |
2661 | letter equivalent to C<@{^CAPTURE}>. Also be aware that when | |
2662 | interpolating subscripts of this array you B<must> use the demarcated | |
2663 | variable form, for instance | |
2664 | ||
2665 | =end original | |
2666 | ||
2667 | その他のほとんどの正規表現マジカル変数と異なり、 | |
2668 | C<@{^CAPTURE}> と等価な単一文字変数はないことに注意してください。 | |
2669 | また、この配列の添え字を変数展開するときは、境界を定める変数形式を | |
2670 | B<使わなければならない> ことにも注意してください; 例えば: | |
2671 | ||
2672 | print "${^CAPTURE[0]}" | |
2673 | ||
2674 | =begin original | |
2675 | ||
2676 | see L<perldata/"Demarcated variable names using braces"> for more | |
2677 | information on this form and its uses. | |
2678 | ||
2679 | =end original | |
2680 | ||
2681 | この形式とその使用法に関するさらなる情報については | |
2682 | L<perldata/"Demarcated variable names using braces"> を参照してください。 | |
2683 | ||
2684 | =begin original | |
2685 | ||
2686 | This variable was added in 5.25.7 | |
2687 | ||
2688 | =end original | |
2689 | ||
2690 | これは 5.25.7 で追加されました。 | |
2691 | ||
2692 | =begin original | |
2693 | ||
2694 | If you need access to this functionality in older Perls you can use this | |
2695 | function immediately after your regexp. | |
2696 | ||
2697 | =end original | |
2698 | ||
2699 | 古い Perl でこの機能にアクセスする必要がある場合は、 | |
2700 | 正規表現の直後にこの関数を使えます。 | |
2701 | ||
2702 | sub get_captures { | |
2703 | no strict 'refs'; | |
2704 | ||
2705 | my $last_idx = scalar(@-) - 1; | |
2706 | my @arr = 1 .. $last_idx; | |
2707 | my @ret = map { $$_; } @arr; | |
2708 | ||
2709 | return @ret; | |
2710 | } | |
2711 | ||
2525 | 2712 | =item $MATCH |
2526 | 2713 | |
2527 | 2714 | =item $& |
2528 | 2715 | X<$&> X<$MATCH> |
2529 | 2716 | |
2530 | 2717 | =begin original |
2531 | 2718 | |
2532 | The string matched by the last successful pattern match | |
2719 | The string matched by the last successful pattern match. | |
2533 | ||
2720 | (See L</Scoping Rules of Regex Variables>.) | |
2534 | BLOCK). | |
2535 | 2721 | |
2536 | 2722 | =end original |
2537 | 2723 | |
2538 | 最後に成功したパターンマッチでマッチした文字列 | |
2724 | 最後に成功したパターンマッチでマッチした文字列。 | |
2539 | ||
2725 | (L</Scoping Rules of Regex Variables> を参照してください。) | |
2540 | 勘定に入れません)。 | |
2541 | 2726 | |
2542 | 2727 | =begin original |
2543 | 2728 | |
2544 | ||
2729 | See L</Performance issues> above for the serious performance implications | |
2545 | ||
2730 | of using this variable (even once) in your code. | |
2546 | penalty, you can extract the same substring by using L</@->. Starting | |
2547 | with Perl 5.10, you can use the </p> match flag and the C<${^MATCH}> | |
2548 | variable to do the same thing for particular match operations. | |
2549 | 2731 | |
2550 | 2732 | =end original |
2551 | 2733 | |
2552 | この変数を | |
2734 | この変数を(一度でも)使うことによる重大な性能の問題については前述した | |
2553 | ||
2735 | L</Performance issues> を参照してください。 | |
2554 | このペナルティを避けるために、同じ部分文字列を L</@-> を使って | |
2555 | 抽出できます。 | |
2556 | Perl 5.10 から、C</p> マッチングフラグと C<${^MATCH}> 変数を | |
2557 | 特定のマッチング演算子について同じことをするために使えます。 | |
2558 | 2736 | |
2559 | 2737 | =begin original |
2560 | 2738 | |
2561 | This variable is read-only and dynamically | |
2739 | This variable is read-only, and its value is dynamically scoped. | |
2562 | 2740 | |
2563 | 2741 | =end original |
2564 | 2742 | |
2565 | この変数は読み込み専用で動的スコープを持ちます。 | |
2743 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2566 | 2744 | |
2567 | 2745 | =begin original |
2568 | 2746 | |
2569 | 2747 | Mnemonic: like C<&> in some editors. |
2570 | 2748 | |
2571 | 2749 | =end original |
2572 | 2750 | |
2573 | 2751 | 記憶法: あるエディタの C<&> ようなもの。 |
2574 | 2752 | |
2575 | 2753 | =item ${^MATCH} |
2576 | 2754 | X<${^MATCH}> |
2577 | 2755 | |
2578 | 2756 | =begin original |
2579 | 2757 | |
2580 | ||
2758 | It is only guaranteed to return a defined value when the pattern was | |
2581 | ||
2759 | compiled or executed with the C</p> modifier. | |
2582 | to return a defined value when the pattern was compiled or executed with | |
2583 | the C</p> modifier. | |
2584 | 2760 | |
2585 | 2761 | =end original |
2586 | 2762 | |
2587 | ||
2763 | パターンが C</p> 修飾子付きでコンパイルまたは実行された場合、 | |
2588 | ||
2764 | 定義された値が返ることだけが保証されます。 | |
2589 | 場合にのみ定義された値を返すことが保証されます。 | |
2590 | 2765 | |
2591 | 2766 | =begin original |
2592 | 2767 | |
2593 | This | |
2768 | This is similar to C<$&> (C<$MATCH>) except that to use it you must | |
2769 | use the C</p> modifier when executing the pattern, and it does not incur | |
2770 | the performance penalty associated with that variable. | |
2594 | 2771 | |
2595 | 2772 | =end original |
2596 | 2773 | |
2597 | こ | |
2774 | これは C<$&> (C<$MATCH>) と同様ですが、 | |
2775 | パターンを実行するときに C</p> 修飾子を使わなければならず、 | |
2776 | この変数と関連付けられた性能上のペナルティを被りません。 | |
2598 | 2777 | |
2599 | 2778 | =begin original |
2600 | 2779 | |
2601 | ||
2780 | See L</Performance issues> above. | |
2602 | 2781 | |
2603 | 2782 | =end original |
2604 | 2783 | |
2605 | ||
2784 | 前述した L</Performance issues> を参照してください。 | |
2606 | 2785 | |
2786 | =begin original | |
2787 | ||
2788 | This variable was added in Perl v5.10.0. | |
2789 | ||
2790 | =end original | |
2791 | ||
2792 | この変数は Perl v5.10.0 で追加されました。 | |
2793 | ||
2794 | =begin original | |
2795 | ||
2796 | This variable is read-only, and its value is dynamically scoped. | |
2797 | ||
2798 | =end original | |
2799 | ||
2800 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2801 | ||
2607 | 2802 | =item $PREMATCH |
2608 | 2803 | |
2609 | 2804 | =item $` |
2610 | X<$`> X<$PREMATCH> | |
2805 | X<$`> X<$PREMATCH> | |
2611 | 2806 | |
2612 | 2807 | =begin original |
2613 | 2808 | |
2614 | 2809 | The string preceding whatever was matched by the last successful |
2615 | pattern match | |
2810 | pattern match. (See L</Scoping Rules of Regex Variables>). | |
2616 | enclosed by the current BLOCK. | |
2617 | 2811 | |
2618 | 2812 | =end original |
2619 | 2813 | |
2620 | 最後の成功したパターンマッチ | |
2814 | 最後の成功したパターンマッチでマッチした部分の前の文字列。 | |
2621 | ||
2815 | (L</Scoping Rules of Regex Variables> を参照してください)。 | |
2622 | マッチした部分の前の文字列。 | |
2623 | 2816 | |
2624 | 2817 | =begin original |
2625 | 2818 | |
2626 | ||
2819 | See L</Performance issues> above for the serious performance implications | |
2627 | ||
2820 | of using this variable (even once) in your code. | |
2628 | penalty, you can extract the same substring by using L</@->. Starting | |
2629 | with Perl 5.10, you can use the </p> match flag and the | |
2630 | C<${^PREMATCH}> variable to do the same thing for particular match | |
2631 | operations. | |
2632 | 2821 | |
2633 | 2822 | =end original |
2634 | 2823 | |
2635 | この変数を | |
2824 | この変数を(一度でも)使うことによる重大な性能の問題については前述した | |
2636 | ||
2825 | L</Performance issues> を参照してください。 | |
2637 | このペナルティを避けるために、同じ部分文字列を L</@-> を使って | |
2638 | 抽出できます。 | |
2639 | Perl 5.10 から、C</p> マッチングフラグと C<${^PREMATCH}> 変数を | |
2640 | 特定のマッチング演算子について同じことをするために使えます。 | |
2641 | 2826 | |
2642 | 2827 | =begin original |
2643 | 2828 | |
2644 | This variable is read-only and dynamically | |
2829 | This variable is read-only, and its value is dynamically scoped. | |
2645 | 2830 | |
2646 | 2831 | =end original |
2647 | 2832 | |
2648 | この変数は読み込み専用で動的スコープを持ちます。 | |
2833 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2649 | 2834 | |
2650 | 2835 | =begin original |
2651 | 2836 | |
2652 | 2837 | Mnemonic: C<`> often precedes a quoted string. |
2653 | 2838 | |
2654 | 2839 | =end original |
2655 | 2840 | |
2656 | 2841 | 記憶法: C<`> は多くの場合クォートされた文字列の前にある。 |
2657 | 2842 | |
2658 | 2843 | =item ${^PREMATCH} |
2659 | X<$ | |
2844 | X<${^PREMATCH}> | |
2660 | 2845 | |
2661 | 2846 | =begin original |
2662 | 2847 | |
2663 | ||
2848 | It is only guaranteed to return a defined value when the pattern was | |
2664 | ||
2849 | executed with the C</p> modifier. | |
2665 | to return a defined value when the pattern was compiled or executed with | |
2666 | the C</p> modifier. | |
2667 | 2850 | |
2668 | 2851 | =end original |
2669 | 2852 | |
2670 | ||
2853 | パターンが C</p> 修飾子付きでコンパイルまたは実行された場合、 | |
2671 | ||
2854 | 定義された値が返ることだけが保証されます。 | |
2672 | 場合にのみ定義された値を返すことが保証されます。 | |
2673 | 2855 | |
2674 | 2856 | =begin original |
2675 | 2857 | |
2676 | This | |
2858 | This is similar to C<$`> ($PREMATCH) except that to use it you must | |
2859 | use the C</p> modifier when executing the pattern, and it does not incur | |
2860 | the performance penalty associated with that variable. | |
2677 | 2861 | |
2678 | 2862 | =end original |
2679 | 2863 | |
2680 | こ | |
2864 | これは C<$`> ($PREMATCH) と同様ですが、 | |
2865 | パターンを実行するときに C</p> 修飾子を使わなければならず、 | |
2866 | この変数と関連付けられた性能上のペナルティを被りません。 | |
2681 | 2867 | |
2682 | 2868 | =begin original |
2683 | 2869 | |
2684 | ||
2870 | See L</Performance issues> above. | |
2685 | 2871 | |
2686 | 2872 | =end original |
2687 | 2873 | |
2688 | ||
2874 | 前述した L</Performance issues> を参照してください。 | |
2689 | 2875 | |
2876 | =begin original | |
2877 | ||
2878 | This variable was added in Perl v5.10.0. | |
2879 | ||
2880 | =end original | |
2881 | ||
2882 | この変数は Perl v5.10.0 で追加されました。 | |
2883 | ||
2884 | =begin original | |
2885 | ||
2886 | This variable is read-only, and its value is dynamically scoped. | |
2887 | ||
2888 | =end original | |
2889 | ||
2890 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2891 | ||
2690 | 2892 | =item $POSTMATCH |
2691 | 2893 | |
2692 | 2894 | =item $' |
2693 | X<$'> X<$POSTMATCH> X< | |
2895 | X<$'> X<$POSTMATCH> X<@-> | |
2694 | 2896 | |
2695 | 2897 | =begin original |
2696 | 2898 | |
2697 | 2899 | The string following whatever was matched by the last successful |
2698 | pattern match ( | |
2900 | pattern match. (See L</Scoping Rules of Regex Variables>). Example: | |
2699 | enclosed by the current BLOCK). Example: | |
2700 | 2901 | |
2701 | 2902 | =end original |
2702 | 2903 | |
2703 | 最後の成功したパターンマッチ | |
2904 | 最後の成功したパターンマッチでマッチした部分に続く文字列。 | |
2704 | ||
2905 | (L</Scoping Rules of Regex Variables> を参照してください)。 | |
2705 | マッチした部分に続く文字列。 | |
2706 | 2906 | 例: |
2707 | 2907 | |
2708 | ||
2908 | =begin original | |
2709 | /def/; | |
2710 | print "$`:$&:$'\n"; # prints abc:def:ghi | |
2711 | 2909 | |
2910 | local $_ = 'abcdefghi'; | |
2911 | /def/; | |
2912 | print "$`:$&:$'\n"; # prints abc:def:ghi | |
2913 | ||
2914 | =end original | |
2915 | ||
2916 | local $_ = 'abcdefghi'; | |
2917 | /def/; | |
2918 | print "$`:$&:$'\n"; # abc:def:ghi を表示 | |
2919 | ||
2712 | 2920 | =begin original |
2713 | 2921 | |
2714 | ||
2922 | See L</Performance issues> above for the serious performance implications | |
2715 | ||
2923 | of using this variable (even once) in your code. | |
2716 | To avoid this penalty, you can extract the same substring by | |
2717 | using L</@->. Starting with Perl 5.10, you can use the </p> match flag | |
2718 | and the C<${^POSTMATCH}> variable to do the same thing for particular | |
2719 | match operations. | |
2720 | 2924 | |
2721 | 2925 | =end original |
2722 | 2926 | |
2723 | この変数を | |
2927 | この変数を(一度でも)使うことによる重大な性能の問題については前述した | |
2724 | ||
2928 | L</Performance issues> を参照してください。 | |
2725 | このペナルティを避けるために、同じ部分文字列を L</@-> を使って | |
2726 | 抽出できます。 | |
2727 | Perl 5.10 から、C</p> マッチングフラグと C<${^POSTMATCH}> 変数を | |
2728 | 特定のマッチング演算子について同じことをするために使えます。 | |
2729 | 2929 | |
2730 | 2930 | =begin original |
2731 | 2931 | |
2732 | This variable is read-only and dynamically | |
2932 | This variable is read-only, and its value is dynamically scoped. | |
2733 | 2933 | |
2734 | 2934 | =end original |
2735 | 2935 | |
2736 | この変数は読み込み専用で動的スコープを持ちます。 | |
2936 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2737 | 2937 | |
2738 | 2938 | =begin original |
2739 | 2939 | |
2740 | 2940 | Mnemonic: C<'> often follows a quoted string. |
2741 | 2941 | |
2742 | 2942 | =end original |
2743 | 2943 | |
2744 | 2944 | 記憶法: C<'> は多くの場合クォートされた文字列の後にある。 |
2745 | 2945 | |
2746 | 2946 | =item ${^POSTMATCH} |
2747 | X<${^POSTMATCH}> | |
2947 | X<${^POSTMATCH}> | |
2748 | 2948 | |
2749 | 2949 | =begin original |
2750 | 2950 | |
2751 | ||
2951 | It is only guaranteed to return a defined value when the pattern was | |
2752 | ||
2952 | compiled or executed with the C</p> modifier. | |
2753 | to return a defined value when the pattern was compiled or executed with | |
2754 | the C</p> modifier. | |
2755 | 2953 | |
2756 | 2954 | =end original |
2757 | 2955 | |
2758 | ||
2956 | パターンが C</p> 修飾子付きでコンパイルまたは実行された場合、 | |
2759 | ||
2957 | 定義された値が返ることだけが保証されます。 | |
2760 | 場合にのみ定義された値を返すことが保証されます。 | |
2761 | 2958 | |
2762 | 2959 | =begin original |
2763 | 2960 | |
2764 | This | |
2961 | This is similar to C<$'> (C<$POSTMATCH>) except that to use it you must | |
2962 | use the C</p> modifier when executing the pattern, and it does not incur | |
2963 | the performance penalty associated with that variable. | |
2765 | 2964 | |
2766 | 2965 | =end original |
2767 | 2966 | |
2768 | こ | |
2967 | これは C<$'> (C<$POSTMATCH>) と同様ですが、 | |
2968 | パターンを実行するときに C</p> 修飾子を使わなければならず、 | |
2969 | この変数と関連付けられた性能上のペナルティを被りません。 | |
2769 | 2970 | |
2770 | 2971 | =begin original |
2771 | 2972 | |
2772 | ||
2973 | See L</Performance issues> above. | |
2773 | 2974 | |
2774 | 2975 | =end original |
2775 | 2976 | |
2776 | ||
2977 | 前述した L</Performance issues> を参照してください。 | |
2777 | 2978 | |
2979 | =begin original | |
2980 | ||
2981 | This variable was added in Perl v5.10.0. | |
2982 | ||
2983 | =end original | |
2984 | ||
2985 | この変数は Perl v5.10.0 で追加されました。 | |
2986 | ||
2987 | =begin original | |
2988 | ||
2989 | This variable is read-only, and its value is dynamically scoped. | |
2990 | ||
2991 | =end original | |
2992 | ||
2993 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2994 | ||
2778 | 2995 | =item $LAST_PAREN_MATCH |
2779 | 2996 | |
2780 | 2997 | =item $+ |
2781 | 2998 | X<$+> X<$LAST_PAREN_MATCH> |
2782 | 2999 | |
2783 | 3000 | =begin original |
2784 | 3001 | |
2785 | The text matched by the | |
3002 | The text matched by the highest used capture group of the last | |
3003 | successful search pattern. (See L</Scoping Rules of Regex Variables>). | |
3004 | It is logically equivalent to the highest | |
3005 | numbered capture variable (C<$1>, C<$2>, ...) which has a defined value. | |
3006 | ||
3007 | ||
3008 | =end original | |
3009 | ||
3010 | 最後に検索されたパターンの最大の使われたの捕捉グループにマッチした文字列。 | |
3011 | (L</Scoping Rules of Regex Variables> を参照してください)。 | |
3012 | これは、定義されている最大の番号の捕捉変数 | |
3013 | (C<$1>, C<$2>, ...) と論理的に等価です。 | |
3014 | ||
3015 | =begin original | |
3016 | ||
2786 | 3017 | This is useful if you don't know which one of a set of alternative patterns |
2787 | matched. For example: | |
3018 | matched. For example: | |
2788 | 3019 | |
2789 | 3020 | =end original |
2790 | 3021 | |
2791 | ||
3022 | わからないような場合に使うと便利です。 | |
2792 | ||
3023 | 例えば: | |
2793 | わからないような場合に使うと便利です。たとえば: | |
2794 | 3024 | |
2795 | ||
3025 | /Version: (.*)|Revision: (.*)/ && ($rev = $+); | |
2796 | 3026 | |
2797 | 3027 | =begin original |
2798 | 3028 | |
2799 | This variable is read-only and dynamically | |
3029 | This variable is read-only, and its value is dynamically scoped. | |
2800 | 3030 | |
2801 | 3031 | =end original |
2802 | 3032 | |
2803 | この変数は読み込み専用で動的スコープを持ちます。 | |
3033 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2804 | 3034 | |
2805 | 3035 | =begin original |
2806 | 3036 | |
2807 | 3037 | Mnemonic: be positive and forward looking. |
2808 | 3038 | |
2809 | 3039 | =end original |
2810 | 3040 | |
2811 | 3041 | 記憶法: ポジティブで前向き。 |
2812 | 3042 | |
2813 | 3043 | =item $LAST_SUBMATCH_RESULT |
2814 | 3044 | |
2815 | 3045 | =item $^N |
2816 | 3046 | X<$^N> X<$LAST_SUBMATCH_RESULT> |
2817 | 3047 | |
2818 | 3048 | =begin original |
2819 | 3049 | |
2820 | 3050 | The text matched by the used group most-recently closed (i.e. the group |
2821 | with the rightmost closing parenthesis) of the last successful | |
3051 | with the rightmost closing parenthesis) of the last successful match. | |
2822 | p | |
3052 | (See L</Scoping Rules of Regex Variables>). | |
2823 | 3053 | |
2824 | 3054 | =end original |
2825 | 3055 | |
2826 | 最近のマッチングに成功した検索パターンのうち、一番最近に閉じられた | |
3056 | 最近のマッチングに成功した検索パターンのうち、一番最近に閉じられた使われた | |
2827 | ||
3057 | グループ(つまり、一番右の閉じかっこのグループ)にマッチングしたテキスト。 | |
2828 | ||
3058 | (L</Scoping Rules of Regex Variables> を参照してください)。 | |
2829 | 3059 | |
2830 | 3060 | =begin original |
2831 | 3061 | |
3062 | This is subtly different from C<$+>. For example in | |
3063 | ||
3064 | =end original | |
3065 | ||
3066 | これは C<$+> とわずかに異なります。 | |
3067 | 例えば次のものは | |
3068 | ||
3069 | "ab" =~ /^((.)(.))$/ | |
3070 | ||
3071 | =begin original | |
3072 | ||
3073 | we have | |
3074 | ||
3075 | =end original | |
3076 | ||
3077 | 次の結果になります | |
3078 | ||
3079 | $1,$^N have the value "ab" | |
3080 | $2 has the value "a" | |
3081 | $3,$+ have the value "b" | |
3082 | ||
3083 | =begin original | |
3084 | ||
2832 | 3085 | This is primarily used inside C<(?{...})> blocks for examining text |
2833 | recently matched. For example, to effectively capture text to a variable | |
3086 | recently matched. For example, to effectively capture text to a variable | |
2834 | 3087 | (in addition to C<$1>, C<$2>, etc.), replace C<(...)> with |
2835 | 3088 | |
2836 | 3089 | =end original |
2837 | 3090 | |
2838 | 3091 | これは主として最近マッチしたテキストを調べるために C<(?{...})> ブロックの |
2839 | 3092 | 中で使われます。 |
2840 | 3093 | 例えば、(C<$1>, C<$2> などに加えて) テキストを変数に効率的に捕捉するには、 |
2841 | 3094 | C<(...)> を以下で置き換えます: |
2842 | 3095 | |
2843 | ||
3096 | (?:(...)(?{ $var = $^N })) | |
2844 | 3097 | |
2845 | 3098 | =begin original |
2846 | 3099 | |
2847 | 3100 | By setting and then using C<$var> in this way relieves you from having to |
2848 | 3101 | worry about exactly which numbered set of parentheses they are. |
2849 | 3102 | |
2850 | 3103 | =end original |
2851 | 3104 | |
2852 | 3105 | C<$var> をこの方法で設定してから使うことで、かっこの組の番号について |
2853 | 3106 | 気にしなくてすむようになります。 |
2854 | 3107 | |
2855 | 3108 | =begin original |
2856 | 3109 | |
2857 | This variable | |
3110 | This variable is read-only, and its value is dynamically scoped. | |
2858 | 3111 | |
2859 | 3112 | =end original |
2860 | 3113 | |
2861 | この変数は | |
3114 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2862 | 3115 | |
2863 | 3116 | =begin original |
2864 | 3117 | |
3118 | This variable was added in Perl v5.8.0. | |
3119 | ||
3120 | =end original | |
3121 | ||
3122 | この変数は Perl v5.8.0 で追加されました。 | |
3123 | ||
3124 | =begin original | |
3125 | ||
2865 | 3126 | Mnemonic: the (possibly) Nested parenthesis that most recently closed. |
2866 | 3127 | |
2867 | 3128 | =end original |
2868 | 3129 | |
2869 | 3130 | 記憶法: もっとも最近閉じられた、(おそらく) ネストした (Nested) かっこ。 |
2870 | 3131 | |
2871 | 3132 | =item @LAST_MATCH_END |
2872 | 3133 | |
2873 | 3134 | =item @+ |
2874 | 3135 | X<@+> X<@LAST_MATCH_END> |
2875 | 3136 | |
2876 | 3137 | =begin original |
2877 | 3138 | |
2878 | 3139 | This array holds the offsets of the ends of the last successful |
2879 | ||
3140 | match and any matching capture buffers that the pattern contains. | |
2880 | ||
3141 | (See L</Scoping Rules of Regex Variables>) | |
2881 | is the same value as what the C<pos> function returns when called | |
2882 | on the variable that was matched against. The I<n>th element | |
2883 | of this array holds the offset of the I<n>th submatch, so | |
2884 | C<$+[1]> is the offset past where C<$1> ends, C<$+[2]> the offset | |
2885 | past where C<$2> ends, and so on. You can use C<$#+> to determine | |
2886 | how many subgroups were in the last successful match. See the | |
2887 | examples given for the C<@-> variable. | |
2888 | 3142 | |
2889 | 3143 | =end original |
2890 | 3144 | |
2891 | この配列は、 | |
3145 | この配列は、最後に成功したマッチングの末尾へのオフセットと、 | |
2892 | ||
3146 | パターンが含むすべてのマッチング捕捉バッファを保持します。 | |
3147 | (L</Scoping Rules of Regex Variables> を参照してください。) | |
3148 | ||
3149 | =begin original | |
3150 | ||
3151 | The number of elements it contains will be one more than the number | |
3152 | of capture buffers in the pattern, regardless of which capture buffers | |
3153 | actually matched. You can use this to determine how many capture | |
3154 | buffers there are in the pattern. (As opposed to C<@-> which may | |
3155 | have fewer elements.) | |
3156 | ||
3157 | =end original | |
3158 | ||
3159 | 含まれる要素の数は、どの捕捉バッファが実際にマッチングしたかに関係なく、 | |
3160 | パターン内の捕捉バッファの数よりも一つ多くなります。 | |
3161 | これを使って、パターン内に捕捉バッファがいくつあるかを決定できます。 | |
3162 | (要素の数が少なくなる C<@-> とは対照的です)。 | |
3163 | ||
3164 | =begin original | |
3165 | ||
3166 | C<$+[0]> is the offset into the string of the end of the entire match. | |
3167 | This is the same value as what the C<pos> function returns when called | |
3168 | on the variable that was matched against. The I<n>th element of this | |
3169 | array holds the offset of the I<n>th submatch, so C<$+[1]> is the offset | |
3170 | past where C<$1> ends, C<$+[2]> the offset past where C<$2> ends, and so | |
3171 | on. You can use C<$#+> to determine how many subgroups were in the last | |
3172 | successful match. See the examples given for the C<@-> variable. | |
3173 | ||
3174 | =end original | |
3175 | ||
2893 | 3176 | C<$+[0]> はマッチ全体の文字列の最後へのオフセットです。 |
2894 | これはマッチした変数に対して C<pos> 関数を呼び出したときの | |
3177 | これはマッチした変数に対して C<pos> 関数を呼び出したときの返り値と同じです。 | |
2895 | 返り値と同じです。 | |
2896 | 3178 | この配列の I<n> 番目の要素は I<n> 番目のサブマッチのオフセットを |
2897 | 保持してい | |
3179 | 保持しているので、C<$+[1]> は過去の C<$1> の終わりのオフセット、C<$+[2]> は | |
2898 | C<$ | |
3180 | C<$2> のオフセット、という形になります。 | |
2899 | C<$#+> は最後に成功したマッチでいくつサブグループがあるかを | |
3181 | C<$#+> は最後に成功したマッチでいくつサブグループがあるかを決定するのに | |
2900 | ||
3182 | 使えます。 | |
2901 | 3183 | C<@-> 変数の例を参照して下さい。 |
2902 | 3184 | |
2903 | 3185 | =begin original |
2904 | 3186 | |
2905 | This variable | |
3187 | This variable is read-only, and its value is dynamically scoped. | |
2906 | 3188 | |
2907 | 3189 | =end original |
2908 | 3190 | |
2909 | この変数は | |
3191 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2910 | 3192 | |
3193 | =begin original | |
3194 | ||
3195 | This variable was added in Perl v5.6.0. | |
3196 | ||
3197 | =end original | |
3198 | ||
3199 | この変数は Perl v5.6.0 で追加されました。 | |
3200 | ||
3201 | =item %{^CAPTURE} | |
3202 | ||
2911 | 3203 | =item %LAST_PAREN_MATCH |
2912 | 3204 | |
2913 | 3205 | =item %+ |
2914 | X<%+> X<%LAST_PAREN_MATCH> | |
3206 | X<%+> X<%LAST_PAREN_MATCH> X<%{^CAPTURE}> | |
2915 | 3207 | |
2916 | 3208 | =begin original |
2917 | 3209 | |
2918 | 3210 | Similar to C<@+>, the C<%+> hash allows access to the named capture |
2919 | 3211 | buffers, should they exist, in the last successful match in the |
2920 | currently active dynamic scope. | |
3212 | currently active dynamic scope. (See L</Scoping Rules of Regex Variables>). | |
2921 | 3213 | |
2922 | 3214 | =end original |
2923 | 3215 | |
2924 | 3216 | C<@+> と同様、C<%+> ハッシュは、現在アクティブな動的スコープで最後に成功した |
2925 | 3217 | マッチングの名前付き捕捉バッファ(存在すれば)へのアクセスを可能にします。 |
3218 | (L</Scoping Rules of Regex Variables> を参照してください)。 | |
2926 | 3219 | |
2927 | 3220 | =begin original |
2928 | 3221 | |
2929 | 3222 | For example, C<$+{foo}> is equivalent to C<$1> after the following match: |
2930 | 3223 | |
2931 | 3224 | =end original |
2932 | 3225 | |
2933 | 3226 | 例えば、C<$+{foo}> は以下のマッチングの後の C<$1> と等価です: |
2934 | 3227 | |
2935 | ||
3228 | 'foo' =~ /(?<foo>foo)/; | |
2936 | 3229 | |
2937 | 3230 | =begin original |
2938 | 3231 | |
2939 | 3232 | The keys of the C<%+> hash list only the names of buffers that have |
2940 | 3233 | captured (and that are thus associated to defined values). |
2941 | 3234 | |
2942 | 3235 | =end original |
2943 | 3236 | |
2944 | 3237 | C<%+> ハッシュのキーは捕捉された(従って定義された値と結びついている) |
2945 | 3238 | バッファの名前のみの一覧です。 |
2946 | 3239 | |
2947 | 3240 | =begin original |
2948 | 3241 | |
3242 | If multiple distinct capture groups have the same name, then | |
3243 | C<$+{NAME}> will refer to the leftmost defined group in the match. | |
3244 | ||
3245 | =end original | |
3246 | ||
3247 | 同じ名前の複数の異なる補足グループがある場合、 | |
3248 | C<$+{NAME}> はマッチングの中で一番左側に定義されているグループを | |
3249 | 参照します。 | |
3250 | ||
3251 | =begin original | |
3252 | ||
2949 | 3253 | The underlying behaviour of C<%+> is provided by the |
2950 | 3254 | L<Tie::Hash::NamedCapture> module. |
2951 | 3255 | |
2952 | 3256 | =end original |
2953 | 3257 | |
2954 | 3258 | C<%+> の基礎となる振る舞いは L<Tie::Hash::NamedCapture> モジュールで |
2955 | 3259 | 提供されています。 |
2956 | 3260 | |
2957 | 3261 | =begin original |
2958 | 3262 | |
2959 | 3263 | B<Note:> C<%-> and C<%+> are tied views into a common internal hash |
2960 | associated with the last successful regular expression. Therefore mixing | |
3264 | associated with the last successful regular expression. Therefore mixing | |
2961 | 3265 | iterative access to them via C<each> may have unpredictable results. |
2962 | 3266 | Likewise, if the last successful match changes, then the results may be |
2963 | 3267 | surprising. |
2964 | 3268 | |
2965 | 3269 | =end original |
2966 | 3270 | |
2967 | 3271 | B<注意:> C<%-> and C<%+> は最後に成功した正規表現と関連付けられた共通の |
2968 | 3272 | 内部ハッシュと tie されたビューです。 |
2969 | 従って、C<each> 経由で混ざった反復アクセスを行うと、予測不能の結果と | |
3273 | 従って、C<each> 経由で混ざった反復アクセスを行うと、予測不能の結果となります。 | |
2970 | なります。 | |
2971 | 3274 | 同様に、最後に成功したマッチングを変更すると、結果は驚くべきものとなります。 |
2972 | 3275 | |
2973 | 3276 | =begin original |
2974 | 3277 | |
2975 | This variable was added in Perl 5.10. | |
3278 | This variable was added in Perl v5.10.0. The C<%{^CAPTURE}> alias was | |
3279 | added in 5.25.7. | |
2976 | 3280 | |
2977 | 3281 | =end original |
2978 | 3282 | |
2979 | この変数は Perl 5.10 で追加されました。 | |
3283 | この変数は Perl v5.10.0 で追加されました。 | |
3284 | C<%{^CAPTURE}> の別名は 5.25.7 で追加されました。 | |
2980 | 3285 | |
2981 | 3286 | =begin original |
2982 | 3287 | |
2983 | This variable is read-only and dynamically | |
3288 | This variable is read-only, and its value is dynamically scoped. | |
2984 | 3289 | |
2985 | 3290 | =end original |
2986 | 3291 | |
2987 | この変数は読み込み専用で動的スコープを持ちます。 | |
3292 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
2988 | 3293 | |
2989 | 3294 | =item @LAST_MATCH_START |
2990 | 3295 | |
2991 | 3296 | =item @- |
2992 | 3297 | X<@-> X<@LAST_MATCH_START> |
2993 | 3298 | |
2994 | 3299 | =begin original |
2995 | 3300 | |
3301 | This array holds the offsets of the beginnings of the last successful | |
3302 | match and any capture buffers it contains. | |
3303 | (See L</Scoping Rules of Regex Variables>). | |
3304 | ||
3305 | =end original | |
3306 | ||
3307 | この配列は、最後に成功したマッチングの先頭へのオフセットと、 | |
3308 | パターンが含むすべてのマッチング捕捉バッファを保持します。 | |
3309 | (L</Scoping Rules of Regex Variables> を参照してください。) | |
3310 | ||
3311 | =begin original | |
3312 | ||
3313 | The number of elements it contains will be one more than the number of | |
3314 | the highest capture buffers (also called a subgroup) that actually | |
3315 | matched something. (As opposed to C<@+> which may have more elements.) | |
3316 | ||
3317 | =end original | |
3318 | ||
3319 | 含まれる要素の数は、実際に何かにマッチングした最も高い捕捉バッファ | |
3320 | (サブグループとも呼ばれる)の数よりも一つ多くなります | |
3321 | (要素の数が多くなる C<@+> とは対照的です)。 | |
3322 | ||
3323 | =begin original | |
3324 | ||
2996 | 3325 | C<$-[0]> is the offset of the start of the last successful match. |
2997 | C<$-[ | |
3326 | C<$-[I<n>]> is the offset of the start of the substring matched by | |
2998 | 3327 | I<n>-th subpattern, or undef if the subpattern did not match. |
2999 | 3328 | |
3000 | 3329 | =end original |
3001 | 3330 | |
3002 | 3331 | C<$-[0]> は最後に成功したマッチの先頭のオフセットです。 |
3003 | C<$-[ | |
3332 | C<$-[I<n>]> は I<n> 番目のサブパターンにマッチした部分文字列の先頭の | |
3004 | ||
3333 | オフセットです; サブパターンがマッチしなかった場合は undef です。 | |
3005 | 3334 | |
3006 | 3335 | =begin original |
3007 | 3336 | |
3008 | Thus, after a match against C<$_>, C<$&> coincides with | |
3337 | Thus, after a match against C<$_>, C<$&> coincides with | |
3009 | $+[0] - $-[0]>. Similarly, $I<n> coincides | |
3338 | C<substr $_, $-[0], $+[0] - $-[0]>. Similarly, C<$I<n>> coincides | |
3010 | $+[n] - $-[n]> if C<$-[n]> is defined, and | |
3339 | with C<substr $_, $-[n], $+[n] - $-[n]> if C<$-[n]> is defined, and | |
3011 | C<substr $_, $-[$#-], $+[$#-] - $-[$#-]>. | |
3340 | C<$+> coincides with C<substr $_, $-[$#-], $+[$#-] - $-[$#-]>. | |
3012 | ||
3341 | One can use C<$#-> to find the last matched subgroup in the last | |
3013 | C<$#+>, the number of subgroups | |
3342 | successful match. Contrast with C<$#+>, the number of subgroups | |
3014 | ||
3343 | in the regular expression. | |
3015 | 3344 | |
3016 | 3345 | =end original |
3017 | 3346 | |
3018 | 従って C<$_> のマッチの後、C<$ | |
3347 | 従って C<$_> のマッチの後、C<$I<n>> は | |
3019 | 一致します。 | |
3348 | C<substr $_, $-[0], $+[0] - $-[0]> と一致します。 | |
3020 | 3349 | 同様に、$I<n> は、C<$-[n]> が定義されていれば |
3021 | 3350 | C<substr $_, $-[n], $+[n] - $-[n]> と一致し、 |
3022 | $+ は C<substr $_, $-[$#-], $+[$#-] - $-[$#-]> と一致します。 | |
3351 | C<$+> は C<substr $_, $-[$#-], $+[$#-] - $-[$#-]> と一致します。 | |
3023 | 3352 | C<$#-> は直前に成功したマッチで最後のマッチしたサブグループを |
3024 | 3353 | 探すのに使えます。 |
3025 | 3354 | 正規表現でのサブグループの数である C<$#+> と対照的です。 |
3026 | C<@+> と比較してください。 | |
3027 | 3355 | |
3028 | 3356 | =begin original |
3029 | 3357 | |
3030 | This array holds the offsets of the beginnings of the last | |
3031 | successful submatches in the currently active dynamic scope. | |
3032 | 3358 | C<$-[0]> is the offset into the string of the beginning of the |
3033 | entire match. The I<n>th element of this array holds the offset | |
3359 | entire match. The I<n>th element of this array holds the offset | |
3034 | 3360 | of the I<n>th submatch, so C<$-[1]> is the offset where C<$1> |
3035 | 3361 | begins, C<$-[2]> the offset where C<$2> begins, and so on. |
3036 | 3362 | |
3037 | 3363 | =end original |
3038 | 3364 | |
3039 | この配列は現在アクティブな動的スコープ内で最後に成功した | |
3040 | サブマッチの先頭位置のオフセットを保持します。 | |
3041 | 3365 | C<$-[0]> はマッチ全体の先頭の文字列へのオフセットです。 |
3042 | 3366 | この配列の I<n> 番目の要素は I<n> 番目のサブマッチへの |
3043 | 3367 | オフセットを保持しますので、C<$-[1]> は C<$1> の先頭への |
3044 | 3368 | オフセット、C<$-[2]> は C<$2> の先頭へのオフセット、などとなります。 |
3045 | 3369 | |
3046 | 3370 | =begin original |
3047 | 3371 | |
3048 | 3372 | After a match against some variable C<$var>: |
3049 | 3373 | |
3050 | 3374 | =end original |
3051 | 3375 | |
3052 | 3376 | ある変数 C<$var> でマッチした後、以下のようになります。 |
3053 | 3377 | |
3054 | 3378 | =over 5 |
3055 | 3379 | |
3056 | 3380 | =item C<$`> is the same as C<substr($var, 0, $-[0])> |
3057 | 3381 | |
3058 | (C<$`> は C<substr($var, 0, $-[0])> と同じです | |
3382 | (C<$`> は C<substr($var, 0, $-[0])> と同じです) | |
3059 | 3383 | |
3060 | 3384 | =item C<$&> is the same as C<substr($var, $-[0], $+[0] - $-[0])> |
3061 | 3385 | |
3062 | (C<$&> は C<substr($var, $-[0], $+[0] - $-[0])> と同じです | |
3386 | (C<$&> は C<substr($var, $-[0], $+[0] - $-[0])> と同じです) | |
3063 | 3387 | |
3064 | 3388 | =item C<$'> is the same as C<substr($var, $+[0])> |
3065 | 3389 | |
3066 | (C<$'> は C<substr($var, $+[0])> と同じです | |
3390 | (C<$'> は C<substr($var, $+[0])> と同じです) | |
3067 | 3391 | |
3068 | 3392 | =item C<$1> is the same as C<substr($var, $-[1], $+[1] - $-[1])> |
3069 | 3393 | |
3070 | (C<$1> は C<substr($var, $-[1], $+[1] - $-[1])> と同じです | |
3394 | (C<$1> は C<substr($var, $-[1], $+[1] - $-[1])> と同じです) | |
3071 | 3395 | |
3072 | 3396 | =item C<$2> is the same as C<substr($var, $-[2], $+[2] - $-[2])> |
3073 | 3397 | |
3074 | (C<$2> は C<substr($var, $-[2], $+[2] - $-[2])> と同じです | |
3398 | (C<$2> は C<substr($var, $-[2], $+[2] - $-[2])> と同じです) | |
3075 | 3399 | |
3076 | 3400 | =item C<$3> is the same as C<substr($var, $-[3], $+[3] - $-[3])> |
3077 | 3401 | |
3078 | (C<$3> は C<substr $var, $-[3], $+[3] - $-[3])> と同じです | |
3402 | (C<$3> は C<substr $var, $-[3], $+[3] - $-[3])> と同じです) | |
3079 | 3403 | |
3080 | 3404 | =back |
3081 | 3405 | |
3082 | 3406 | =begin original |
3083 | 3407 | |
3084 | This variable | |
3408 | This variable is read-only, and its value is dynamically scoped. | |
3085 | 3409 | |
3086 | 3410 | =end original |
3087 | 3411 | |
3088 | この変数は | |
3412 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
3089 | 3413 | |
3090 | = | |
3414 | =begin original | |
3091 | 3415 | |
3416 | This variable was added in Perl v5.6.0. | |
3417 | ||
3418 | =end original | |
3419 | ||
3420 | この変数は Perl v5.6.0 で追加されました。 | |
3421 | ||
3422 | =item %{^CAPTURE_ALL} | |
3423 | X<%{^CAPTURE_ALL}> | |
3424 | ||
3092 | 3425 | =item %- |
3093 | X<%-> | |
3426 | X<%-> | |
3094 | 3427 | |
3095 | 3428 | =begin original |
3096 | 3429 | |
3097 | Similar to C<%+>, this variable allows access to the named capture | |
3430 | Similar to C<%+>, this variable allows access to the named capture | |
3098 | in the last successful match in the currently active dynamic | |
3431 | groups in the last successful match in the currently active dynamic | |
3099 | ||
3432 | scope. (See L</Scoping Rules of Regex Variables>). To each capture group | |
3100 | ||
3433 | name found in the regular expression, it associates a reference to an | |
3101 | ||
3434 | array containing the list of values captured by all buffers with that | |
3102 | where they appear. | |
3435 | name (should there be several of them), in the order where they appear. | |
3103 | 3436 | |
3104 | 3437 | =end original |
3105 | 3438 | |
3106 | 3439 | C<%+> と同様、この変数は現在アクティブな動的スコープで最後に成功した |
3107 | 3440 | マッチングの名前付き捕捉グループへのアクセスを可能にします。 |
3441 | (L</Scoping Rules of Regex Variables> を参照してください)。 | |
3108 | 3442 | 正規表現中に捕捉グループ名が現れるごとに、その名前のグループ全てで |
3109 | 3443 | (複数あるでしょう)捕捉されている値のリストを出現順で含む配列への |
3110 | 3444 | リファレンスと関連付けられます。 |
3111 | 3445 | |
3112 | 3446 | =begin original |
3113 | 3447 | |
3114 | 3448 | Here's an example: |
3115 | 3449 | |
3116 | 3450 | =end original |
3117 | 3451 | |
3118 | 以下 | |
3452 | 以下は例です: | |
3119 | 3453 | |
3120 | 3454 | if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) { |
3121 | 3455 | foreach my $bufname (sort keys %-) { |
3122 | 3456 | my $ary = $-{$bufname}; |
3123 | 3457 | foreach my $idx (0..$#$ary) { |
3124 | 3458 | print "\$-{$bufname}[$idx] : ", |
3125 | (defined($ary->[$idx]) | |
3459 | (defined($ary->[$idx]) | |
3460 | ? "'$ary->[$idx]'" | |
3461 | : "undef"), | |
3126 | 3462 | "\n"; |
3127 | 3463 | } |
3128 | 3464 | } |
3129 | 3465 | } |
3130 | 3466 | |
3131 | 3467 | =begin original |
3132 | 3468 | |
3133 | 3469 | would print out: |
3134 | 3470 | |
3135 | 3471 | =end original |
3136 | 3472 | |
3137 | 3473 | とすると、以下のものが表示されます: |
3138 | 3474 | |
3139 | ||
3475 | $-{A}[0] : '1' | |
3140 | ||
3476 | $-{A}[1] : '3' | |
3141 | ||
3477 | $-{B}[0] : '2' | |
3142 | ||
3478 | $-{B}[1] : '4' | |
3143 | 3479 | |
3144 | 3480 | =begin original |
3145 | 3481 | |
3146 | 3482 | The keys of the C<%-> hash correspond to all buffer names found in |
3147 | 3483 | the regular expression. |
3148 | 3484 | |
3149 | 3485 | =end original |
3150 | 3486 | |
3151 | 3487 | C<%-> ハッシュのキーは正規表現で見つかった全てのバッファ名に対応します。 |
3152 | 3488 | |
3153 | 3489 | =begin original |
3154 | 3490 | |
3155 | 3491 | The behaviour of C<%-> is implemented via the |
3156 | 3492 | L<Tie::Hash::NamedCapture> module. |
3157 | 3493 | |
3158 | 3494 | =end original |
3159 | 3495 | |
3160 | 3496 | C<%-> の振る舞いは L<Tie::Hash::NamedCapture> モジュールを使って |
3161 | 3497 | 実装されています。 |
3162 | 3498 | |
3163 | 3499 | =begin original |
3164 | 3500 | |
3165 | 3501 | B<Note:> C<%-> and C<%+> are tied views into a common internal hash |
3166 | associated with the last successful regular expression. Therefore mixing | |
3502 | associated with the last successful regular expression. Therefore mixing | |
3167 | 3503 | iterative access to them via C<each> may have unpredictable results. |
3168 | 3504 | Likewise, if the last successful match changes, then the results may be |
3169 | surprising. | |
3505 | surprising. See L</Scoping Rules of Regex Variables>. | |
3170 | 3506 | |
3171 | 3507 | =end original |
3172 | 3508 | |
3173 | 3509 | B<注意:> C<%-> and C<%+> は最後に成功した正規表現と関連付けられた共通の |
3174 | 3510 | 内部ハッシュと tie されたビューです。 |
3175 | 従って、C<each> 経由で混ざった反復アクセスを行うと、予測不能の結果と | |
3511 | 従って、C<each> 経由で混ざった反復アクセスを行うと、予測不能の結果となります。 | |
3176 | なります。 | |
3177 | 3512 | 同様に、最後に成功したマッチングを変更すると、結果は驚くべきものとなります。 |
3513 | L</Scoping Rules of Regex Variables> を参照してください。 | |
3178 | 3514 | |
3179 | 3515 | =begin original |
3180 | 3516 | |
3181 | This variable was added in Perl 5.10 | |
3517 | This variable was added in Perl v5.10.0. The C<%{^CAPTURE_ALL}> alias was | |
3518 | added in 5.25.7. | |
3182 | 3519 | |
3183 | 3520 | =end original |
3184 | 3521 | |
3185 | この変数は Perl 5.10 で追加されました。 | |
3522 | この変数は Perl v5.10.0 で追加されました。 | |
3523 | C<%{^CAPTURE_ALL}> の別名は 5.25.7 で追加されました。 | |
3186 | 3524 | |
3187 | 3525 | =begin original |
3188 | 3526 | |
3189 | This variable is read-only and dynamically | |
3527 | This variable is read-only, and its value is dynamically scoped. | |
3190 | 3528 | |
3191 | 3529 | =end original |
3192 | 3530 | |
3193 | この変数は読み込み専用で動的スコープを持ちます。 | |
3531 | この変数は読み込み専用で、その値は動的スコープを持ちます。 | |
3194 | 3532 | |
3533 | =item ${^LAST_SUCCESSFUL_PATTERN} | |
3534 | ||
3535 | =begin original | |
3536 | ||
3537 | The last successful pattern that matched in the current scope. The empty | |
3538 | pattern defaults to matching to this. For instance: | |
3539 | ||
3540 | =end original | |
3541 | ||
3542 | 現在のスコープでマッチングした、最後に成功したパターン。 | |
3543 | からパターンはこれにマッチングします。 | |
3544 | 例えば: | |
3545 | ||
3546 | if (m/foo/ || m/bar/) { | |
3547 | s//BLAH/; | |
3548 | } | |
3549 | ||
3550 | =begin original | |
3551 | ||
3552 | and | |
3553 | ||
3554 | =end original | |
3555 | ||
3556 | および | |
3557 | ||
3558 | if (m/foo/ || m/bar/) { | |
3559 | s/${^LAST_SUCCESSFUL_PATTERN}/BLAH/; | |
3560 | } | |
3561 | ||
3562 | =begin original | |
3563 | ||
3564 | are equivalent. | |
3565 | ||
3566 | =end original | |
3567 | ||
3568 | は等価です。 | |
3569 | ||
3570 | =begin original | |
3571 | ||
3572 | You can use this to debug which pattern matched last, or to match with it again. | |
3573 | ||
3574 | =end original | |
3575 | ||
3576 | どのパターンが最後にマッチングしたかをデバッグしたり、 | |
3577 | 再び同じものでマッチングするためにこれを使えます。 | |
3578 | ||
3579 | =begin original | |
3580 | ||
3581 | Added in Perl 5.37.10. | |
3582 | ||
3583 | =end original | |
3584 | ||
3585 | Perl 5.37.10 で追加されました。 | |
3586 | ||
3195 | 3587 | =item $LAST_REGEXP_CODE_RESULT |
3196 | 3588 | |
3197 | 3589 | =item $^R |
3198 | 3590 | X<$^R> X<$LAST_REGEXP_CODE_RESULT> |
3199 | 3591 | |
3200 | 3592 | =begin original |
3201 | 3593 | |
3202 | 3594 | The result of evaluation of the last successful C<(?{ code })> |
3203 | regular expression assertion (see L<perlre>). | |
3595 | regular expression assertion (see L<perlre>). | |
3204 | 3596 | |
3205 | 3597 | =end original |
3206 | 3598 | |
3207 | 3599 | 最後に成功した C<(?{ code })> 正規表現アサートの評価の結果です |
3208 | (L<perlre> を参照して下さい)。 | |
3600 | (L<perlre> を参照して下さい)。 | |
3209 | 3601 | |
3210 | 3602 | =begin original |
3211 | 3603 | |
3604 | This variable may be written to, and its value is scoped normally, | |
3605 | unlike most other regex variables. | |
3606 | ||
3607 | =end original | |
3608 | ||
3609 | この変数は、その他のほとんどの正規表現変数と異なり、 | |
3610 | 書き込み可能で、その値は通常のスコープを持ちます。 | |
3611 | ||
3612 | =begin original | |
3613 | ||
3212 | 3614 | This variable was added in Perl 5.005. |
3213 | 3615 | |
3214 | 3616 | =end original |
3215 | 3617 | |
3216 | 3618 | この変数は Perl 5.005 で追加されました。 |
3217 | 3619 | |
3620 | =item ${^RE_COMPILE_RECURSION_LIMIT} | |
3621 | X<${^RE_COMPILE_RECURSION_LIMIT}> | |
3622 | ||
3623 | =begin original | |
3624 | ||
3625 | The current value giving the maximum number of open but unclosed | |
3626 | parenthetical groups there may be at any point during a regular | |
3627 | expression compilation. The default is currently 1000 nested groups. | |
3628 | You may adjust it depending on your needs and the amount of memory | |
3629 | available. | |
3630 | ||
3631 | =end original | |
3632 | ||
3633 | 正規表現コンパイル中の任意の時点での開いているけれども閉じていない | |
3634 | かっこグループの最大値として与えられている現在の値。 | |
3635 | デフォルトは現在の所 1000 ネストグループです。 | |
3636 | これは必要性と利用可能なメモリ量に合わせて調整できます。 | |
3637 | ||
3638 | =begin original | |
3639 | ||
3640 | This variable was added in Perl v5.30.0. | |
3641 | ||
3642 | =end original | |
3643 | ||
3644 | この変数は Perl v5.30.0 で追加されました。 | |
3645 | ||
3218 | 3646 | =item ${^RE_DEBUG_FLAGS} |
3219 | 3647 | X<${^RE_DEBUG_FLAGS}> |
3220 | 3648 | |
3221 | 3649 | =begin original |
3222 | 3650 | |
3223 | The current value of the regex debugging flags. Set to 0 for no debug output | |
3651 | The current value of the regex debugging flags. Set to 0 for no debug output | |
3224 | even when the C<re 'debug'> module is loaded. See L<re> for details. | |
3652 | even when the C<re 'debug'> module is loaded. See L<re> for details. | |
3225 | 3653 | |
3226 | 3654 | =end original |
3227 | 3655 | |
3228 | 3656 | 正規表現デバッグフラグの現在の値です。 |
3229 | 0 をセットすると、C<re 'debug'> モジュールが読み込まれていても | |
3657 | 0 をセットすると、C<re 'debug'> モジュールが読み込まれていてもデバッグ出力を | |
3230 | ||
3658 | 行いません。 | |
3231 | 3659 | 詳細については L<re> を参照してください。 |
3232 | 3660 | |
3233 | 3661 | =begin original |
3234 | 3662 | |
3235 | This variable was added in Perl 5.10. | |
3663 | This variable was added in Perl v5.10.0. | |
3236 | 3664 | |
3237 | 3665 | =end original |
3238 | 3666 | |
3239 | この変数は Perl 5.10 で追加されました。 | |
3667 | この変数は Perl v5.10.0 で追加されました。 | |
3240 | 3668 | |
3241 | 3669 | =item ${^RE_TRIE_MAXBUF} |
3242 | 3670 | X<${^RE_TRIE_MAXBUF}> |
3243 | 3671 | |
3244 | 3672 | =begin original |
3245 | 3673 | |
3246 | 3674 | Controls how certain regex optimisations are applied and how much memory they |
3247 | utilize. This value by default is 65536 which corresponds to a 512kB | |
3675 | utilize. This value by default is 65536 which corresponds to a 512kB | |
3248 | cache. Set this to a higher value to trade | |
3676 | temporary cache. Set this to a higher value to trade | |
3249 | ||
3677 | memory for speed when matching large alternations. Set | |
3678 | it to a lower value if you want the optimisations to | |
3250 | 3679 | be as conservative of memory as possible but still occur, and set it to a |
3251 | 3680 | negative value to prevent the optimisation and conserve the most memory. |
3252 | 3681 | Under normal situations this variable should be of no interest to you. |
3253 | 3682 | |
3254 | 3683 | =end original |
3255 | 3684 | |
3256 | どれくらい正規表現の最適化を行い、どれくらいのメモリを利用するかを | |
3685 | どれくらい正規表現の最適化を行い、どれくらいのメモリを利用するかを制御します。 | |
3257 | 制御します。 | |
3258 | 3686 | デフォルトではこの値は 65536 で、512kB の一時キャッシュに相当します。 |
3259 | この値を大きくすると、大きなものとマッチングするときに速度を重視して | |
3687 | この値を大きくすると、大きなものとマッチングするときに速度を重視して多くの | |
3260 | ||
3688 | メモリを使います。 | |
3261 | 3689 | もしできるだけ保守的なメモリ消費をするけれども使うこともある、というように |
3262 | 3690 | 最適化したい場合は小さい値を設定します; 負の値を設定すると最適化は行わず、 |
3263 | 3691 | 最大限メモリを節約します。 |
3264 | 3692 | 通常の状況では、この変数はあなたの興味を引くものではないでしょう。 |
3265 | 3693 | |
3266 | 3694 | =begin original |
3267 | 3695 | |
3268 | This variable was added in Perl 5.10. | |
3696 | This variable was added in Perl v5.10.0. | |
3269 | 3697 | |
3270 | 3698 | =end original |
3271 | 3699 | |
3272 | この変数は Perl 5.10 で追加されました。 | |
3700 | この変数は Perl v5.10.0 で追加されました。 | |
3273 | 3701 | |
3274 | 3702 | =back |
3275 | 3703 | |
3276 | 3704 | =head2 Variables related to filehandles |
3277 | 3705 | |
3278 | 3706 | (ファイルハンドル関連の変数) |
3279 | 3707 | |
3280 | 3708 | =begin original |
3281 | 3709 | |
3282 | 3710 | Variables that depend on the currently selected filehandle may be set |
3283 | 3711 | by calling an appropriate object method on the C<IO::Handle> object, |
3284 | 3712 | although this is less efficient than using the regular built-in |
3285 | variables. (Summary lines below for this contain the word HANDLE.) | |
3713 | variables. (Summary lines below for this contain the word HANDLE.) | |
3286 | 3714 | First you must say |
3287 | 3715 | |
3288 | 3716 | =end original |
3289 | 3717 | |
3290 | 3718 | 現在選択されているファイルハンドルに依存する変数の場合には、代わりに |
3291 | 3719 | C<IO::Handle> オブジェクトに関するオブジェクトメソッドを呼び出して |
3292 | 設定 | |
3720 | 設定できますが、通常の組み込み変数よりは効率が落ちます。 | |
3293 | 3721 | (以下の要約では HANDLE という語を含んでいます。) |
3294 | 3722 | まず最初に必ず、 |
3295 | 3723 | |
3296 | ||
3724 | use IO::Handle; | |
3297 | 3725 | |
3298 | 3726 | =begin original |
3299 | 3727 | |
3300 | 3728 | after which you may use either |
3301 | 3729 | |
3302 | 3730 | =end original |
3303 | 3731 | |
3304 | 3732 | と書き、その後で以下のように書くか、 |
3305 | 3733 | |
3306 | ||
3734 | method HANDLE EXPR | |
3307 | 3735 | |
3308 | 3736 | =begin original |
3309 | 3737 | |
3310 | 3738 | or more safely, |
3311 | 3739 | |
3312 | 3740 | =end original |
3313 | 3741 | |
3314 | 3742 | もしくはより安全に以下のように書きます: |
3315 | 3743 | |
3316 | ||
3744 | HANDLE->method(EXPR) | |
3317 | 3745 | |
3318 | 3746 | =begin original |
3319 | 3747 | |
3320 | Each method returns the old value of the C<IO::Handle> attribute. The | |
3748 | Each method returns the old value of the C<IO::Handle> attribute. The | |
3321 | 3749 | methods each take an optional EXPR, which, if supplied, specifies the |
3322 | new value for the C<IO::Handle> attribute in question. If not | |
3750 | new value for the C<IO::Handle> attribute in question. If not | |
3323 | 3751 | supplied, most methods do nothing to the current value--except for |
3324 | 3752 | C<autoflush()>, which will assume a 1 for you, just to be different. |
3325 | 3753 | |
3326 | 3754 | =end original |
3327 | 3755 | |
3328 | 3756 | それぞれのメソッドは、C<IO::Handle> 属性の昔の値を返します。 |
3329 | メソッドはそれぞれ EXPR をとることができ、指定した場合には、 | |
3757 | メソッドはそれぞれ EXPR をとることができ、指定した場合には、問題の | |
3330 | ||
3758 | C<IO::Handle> 属性の新しい値を指定することになります。 | |
3331 | 3759 | 指定しない場合には、多くのメソッドでは現在の値に対して何もしませんが、 |
3332 | 3760 | C<autoflush()> では 1 を指定されたものとします。 |
3333 | 3761 | |
3334 | 3762 | =begin original |
3335 | 3763 | |
3336 | 3764 | Because loading in the C<IO::Handle> class is an expensive operation, |
3337 | 3765 | you should learn how to use the regular built-in variables. |
3338 | 3766 | |
3339 | 3767 | =end original |
3340 | 3768 | |
3341 | 3769 | C<IO::Handle> クラスを読み込むのはコストの高い操作なので、 |
3342 | 3770 | 通常の組み込み変数の使い方を覚えるべきです。 |
3343 | 3771 | |
3344 | 3772 | =begin original |
3345 | 3773 | |
3346 | A few of these variables are considered "read-only". This means that | |
3774 | A few of these variables are considered "read-only". This means that | |
3347 | 3775 | if you try to assign to this variable, either directly or indirectly |
3348 | 3776 | through a reference, you'll raise a run-time exception. |
3349 | 3777 | |
3350 | 3778 | =end original |
3351 | 3779 | |
3352 | 3780 | これらの変数のいくつかは「読み込み専用」と考えられます。 |
3353 | 3781 | つまり、もしこの変数に対して直接またはリファレンスを通して間接に |
3354 | 3782 | 代入しようとすると、、実行時エラーが発生します。 |
3355 | 3783 | |
3356 | 3784 | =begin original |
3357 | 3785 | |
3358 | 3786 | You should be very careful when modifying the default values of most |
3359 | special variables described in this document. In most cases you want | |
3787 | special variables described in this document. In most cases you want | |
3360 | 3788 | to localize these variables before changing them, since if you don't, |
3361 | 3789 | the change may affect other modules which rely on the default values |
3362 | of the special variables that you have changed. This is one of the | |
3790 | of the special variables that you have changed. This is one of the | |
3363 | 3791 | correct ways to read the whole file at once: |
3364 | 3792 | |
3365 | 3793 | =end original |
3366 | 3794 | |
3367 | 3795 | この文書に記述されているほとんどの特殊変数のデフォルト値を変更するときには |
3368 | 3796 | とても慎重になるべきです。 |
3369 | 3797 | ほとんどの場合、これらの変数を変更する前にこれらをローカル化したいでしょう; |
3370 | 3798 | さもなければ、あなたが変更した特殊変数のデフォルト値に依存している |
3371 | 3799 | その他のモジュールにも影響を与えるかもしれないからです。 |
3372 | 3800 | これはファイル全体を一度に読み込む正しい方法の一つです: |
3373 | 3801 | |
3374 | ||
3802 | =begin original | |
3375 | local $/; # enable localized slurp mode | |
3376 | my $content = <$fh>; | |
3377 | close $fh; | |
3378 | 3803 | |
3804 | open my $fh, "<", "foo" or die $!; | |
3805 | local $/; # enable localized slurp mode | |
3806 | my $content = <$fh>; | |
3807 | close $fh; | |
3808 | ||
3809 | =end original | |
3810 | ||
3811 | open my $fh, "<", "foo" or die $!; | |
3812 | local $/; # ローカル化された吸い込みモードを有効にする | |
3813 | my $content = <$fh>; | |
3814 | close $fh; | |
3815 | ||
3379 | 3816 | =begin original |
3380 | 3817 | |
3381 | 3818 | But the following code is quite bad: |
3382 | 3819 | |
3383 | 3820 | =end original |
3384 | 3821 | |
3385 | 3822 | しかし以下のコードは完全に悪いものです: |
3386 | 3823 | |
3387 | ||
3824 | =begin original | |
3388 | undef $/; # enable slurp mode | |
3389 | my $content = <$fh>; | |
3390 | close $fh; | |
3391 | 3825 | |
3826 | open my $fh, "<", "foo" or die $!; | |
3827 | undef $/; # enable slurp mode | |
3828 | my $content = <$fh>; | |
3829 | close $fh; | |
3830 | ||
3831 | =end original | |
3832 | ||
3833 | open my $fh, "<", "foo" or die $!; | |
3834 | undef $/; # 吸い込みモードを有効にする | |
3835 | my $content = <$fh>; | |
3836 | close $fh; | |
3837 | ||
3392 | 3838 | =begin original |
3393 | 3839 | |
3394 | 3840 | since some other module, may want to read data from some file in the |
3395 | 3841 | default "line mode", so if the code we have just presented has been |
3396 | 3842 | executed, the global value of C<$/> is now changed for any other code |
3397 | 3843 | running inside the same Perl interpreter. |
3398 | 3844 | |
3399 | 3845 | =end original |
3400 | 3846 | |
3401 | 3847 | なぜなら、その他のモジュールでは、デフォルトの「行モード」でファイルを |
3402 | 3848 | 読もうとするかも知れませんが、もし単に前述のコードを実行すると、 |
3403 | 3849 | C<$/> のグローバルな値が、同じ Perl インタプリタ内で実行される |
3404 | 3850 | その他のコードに対しても変更されるからです。 |
3405 | 3851 | |
3406 | 3852 | =begin original |
3407 | 3853 | |
3408 | 3854 | Usually when a variable is localized you want to make sure that this |
3409 | change affects the shortest scope possible. So unless you are already | |
3855 | change affects the shortest scope possible. So unless you are already | |
3410 | inside some short C<{}> block, you should create one yourself. For | |
3856 | inside some short C<{}> block, you should create one yourself. For | |
3411 | 3857 | example: |
3412 | 3858 | |
3413 | 3859 | =end original |
3414 | 3860 | |
3415 | 3861 | 通常、変数をローカル化するとき、この変更ができるだけ最短のスコープに |
3416 | 3862 | 影響を与えることを確実にしたいでしょう。 |
3417 | 3863 | 従って、既に小さい C<{}> ブロックの内側であるのでない限り、それを |
3418 | 3864 | 自身で作るべきです。 |
3419 | 3865 | 例えば: |
3420 | 3866 | |
3421 | ||
3867 | my $content = ''; | |
3422 | ||
3868 | open my $fh, "<", "foo" or die $!; | |
3423 | ||
3869 | { | |
3424 | ||
3870 | local $/; | |
3425 | ||
3871 | $content = <$fh>; | |
3426 | ||
3872 | } | |
3427 | ||
3873 | close $fh; | |
3428 | 3874 | |
3429 | 3875 | =begin original |
3430 | 3876 | |
3431 | 3877 | Here is an example of how your own code can go broken: |
3432 | 3878 | |
3433 | 3879 | =end original |
3434 | 3880 | |
3435 | 3881 | 以下はどのように自分のコードが壊れるかの例です: |
3436 | 3882 | |
3437 | ||
3883 | for ( 1..3 ){ | |
3438 | ||
3884 | $\ = "\r\n"; | |
3439 | ||
3885 | nasty_break(); | |
3440 | ||
3886 | print "$_"; | |
3441 | ||
3887 | } | |
3442 | 3888 | |
3443 | ||
3889 | =begin original | |
3444 | $\ = "\f"; | |
3445 | # do something with $_ | |
3446 | } | |
3447 | 3890 | |
3891 | sub nasty_break { | |
3892 | $\ = "\f"; | |
3893 | # do something with $_ | |
3894 | } | |
3895 | ||
3896 | =end original | |
3897 | ||
3898 | sub nasty_break { | |
3899 | $\ = "\f"; | |
3900 | # $_ で何かする | |
3901 | } | |
3902 | ||
3448 | 3903 | =begin original |
3449 | 3904 | |
3450 | 3905 | You probably expect this code to print the equivalent of |
3451 | 3906 | |
3452 | 3907 | =end original |
3453 | 3908 | |
3454 | 3909 | おそらくこのコードは以下のように表示されることを期待しています: |
3455 | 3910 | |
3456 | 3911 | "1\r\n2\r\n3\r\n" |
3457 | 3912 | |
3458 | 3913 | =begin original |
3459 | 3914 | |
3460 | 3915 | but instead you get: |
3461 | 3916 | |
3462 | 3917 | =end original |
3463 | 3918 | |
3464 | 3919 | しかし、以下のようになります: |
3465 | 3920 | |
3466 | 3921 | "1\f2\f3\f" |
3467 | 3922 | |
3468 | 3923 | =begin original |
3469 | 3924 | |
3470 | 3925 | Why? Because C<nasty_break()> modifies C<$\> without localizing it |
3471 | first. The value you set in C<nasty_break()> is still there when you | |
3926 | first. The value you set in C<nasty_break()> is still there when you | |
3472 | return. The fix is to add C<local()> so the value doesn't leak out of | |
3927 | return. The fix is to add C<local()> so the value doesn't leak out of | |
3473 | 3928 | C<nasty_break()>: |
3474 | 3929 | |
3475 | 3930 | =end original |
3476 | 3931 | |
3477 | 3932 | なぜでしょう? |
3478 | 3933 | C<nasty_break()> は C<$_> をローカル化する前に変更するからです。 |
3479 | 3934 | C<nasty_break()> で設定した値は戻ったときにまだそこにあります。 |
3480 | 3935 | 修正するには、C<local()> を追加して、値が C<nasty_break()> の外に |
3481 | 3936 | 漏れないようにします: |
3482 | 3937 | |
3483 | | |
3938 | local $\ = "\f"; | |
3484 | 3939 | |
3485 | 3940 | =begin original |
3486 | 3941 | |
3487 | 3942 | It's easy to notice the problem in such a short example, but in more |
3488 | 3943 | complicated code you are looking for trouble if you don't localize |
3489 | 3944 | changes to the special variables. |
3490 | 3945 | |
3491 | 3946 | =end original |
3492 | 3947 | |
3493 | 3948 | このような短い例では問題に気付くのは簡単ですが、より複雑なコードでは、 |
3494 | 3949 | もし特殊変数の変更をローカル化していないと問題を探すことになります。 |
3495 | 3950 | |
3496 | 3951 | =over 8 |
3497 | 3952 | |
3498 | 3953 | =item $ARGV |
3499 | 3954 | X<$ARGV> |
3500 | 3955 | |
3501 | 3956 | =begin original |
3502 | 3957 | |
3503 | Contains the name of the current file when reading from C<< <> >> | |
3958 | Contains the name of the current file when reading from C<< <> >>. | |
3504 | 3959 | |
3505 | 3960 | =end original |
3506 | 3961 | |
3507 | 3962 | C<< <> >> から読込みを行なっているとき、その時点のファイル名を示します。 |
3508 | 3963 | |
3509 | 3964 | =item @ARGV |
3510 | 3965 | X<@ARGV> |
3511 | 3966 | |
3512 | 3967 | =begin original |
3513 | 3968 | |
3514 | 3969 | The array C<@ARGV> contains the command-line arguments intended for |
3515 | the script. C<$#ARGV> is generally the number of arguments minus | |
3970 | the script. C<$#ARGV> is generally the number of arguments minus | |
3516 | 3971 | one, because C<$ARGV[0]> is the first argument, I<not> the program's |
3517 | command name itself. See | |
3972 | command name itself. See L</$0> for the command name. | |
3518 | 3973 | |
3519 | 3974 | =end original |
3520 | 3975 | |
3521 | 3976 | 配列 C<@ARGV> は、コマンドラインからスクリプトに渡す引数が入れられます。 |
3522 | 3977 | C<$ARGV[0]> がI<プログラムのコマンド名自身ではなく>、 |
3523 | 3978 | 最初の引数ですから、C<$#ARGV> は一般には、引数の個数 - 1 となります。 |
3524 | コマンド名については、 | |
3979 | コマンド名については、L</$0> を参照してください。 | |
3525 | 3980 | |
3526 | 3981 | =item ARGV |
3527 | 3982 | X<ARGV> |
3528 | 3983 | |
3529 | 3984 | =begin original |
3530 | 3985 | |
3531 | 3986 | The special filehandle that iterates over command-line filenames in |
3532 | C<@ARGV>. Usually written as the null filehandle in the angle operator | |
3987 | C<@ARGV>. Usually written as the null filehandle in the angle operator | |
3533 | C<< <> >>. Note that currently C<ARGV> only has its magical effect | |
3988 | C<< <> >>. Note that currently C<ARGV> only has its magical effect | |
3534 | 3989 | within the C<< <> >> operator; elsewhere it is just a plain filehandle |
3535 | corresponding to the last file opened by C<< <> >>. In particular, | |
3990 | corresponding to the last file opened by C<< <> >>. In particular, | |
3536 | 3991 | passing C<\*ARGV> as a parameter to a function that expects a filehandle |
3537 | 3992 | may not cause your function to automatically read the contents of all the |
3538 | 3993 | files in C<@ARGV>. |
3539 | 3994 | |
3540 | 3995 | =end original |
3541 | 3996 | |
3542 | 3997 | C<@ARGV> にあるコマンドラインで指定されたファイル名に対して反復する |
3543 | 3998 | 特殊ファイルハンドルです。 |
3544 | 3999 | 通常角かっこ C<< <> >> の中で空ファイルハンドルとして書かれます。 |
3545 | 4000 | 現在のところ、C<ARGV> は C<< <> >> 演算子の中でのみ特別な効果があることに |
3546 | 4001 | 注意してください; その他の場所では、C<< <> >> で開かれた最後のファイルに |
3547 | 4002 | 対応する普通のファイルハンドルです。 |
3548 | 4003 | 特に、ファイルハンドルを想定している関数に C<\*ARGV> を引数として渡しても、 |
3549 | 4004 | 関数内で C<@ARGV> にある全てのファイルの内容を自動的に読み込むことには |
3550 | 4005 | なりません。 |
3551 | 4006 | |
3552 | 4007 | =item ARGVOUT |
3553 | 4008 | X<ARGVOUT> |
3554 | 4009 | |
3555 | 4010 | =begin original |
3556 | 4011 | |
3557 | 4012 | The special filehandle that points to the currently open output file |
3558 | when doing edit-in-place processing with B<-i>. Useful when you have | |
4013 | when doing edit-in-place processing with B<-i>. Useful when you have | |
3559 | to do a lot of inserting and don't want to keep modifying C<$_>. See | |
4014 | to do a lot of inserting and don't want to keep modifying C<$_>. See | |
3560 | L<perlrun> for the B<-i> switch. | |
4015 | L<perlrun|perlrun/-i[extension]> for the B<-i> switch. | |
3561 | 4016 | |
3562 | 4017 | =end original |
3563 | 4018 | |
3564 | 4019 | B<-i> を使ってその場修正を行っているときに、現在開いている出力ファイルを |
3565 | 4020 | 示す特殊ファイルハンドルです。 |
3566 | たくさんの挿入をする必要があるときに C<$_> を修正し続けたくない場合に | |
4021 | たくさんの挿入をする必要があるときに C<$_> を修正し続けたくない場合に有用です。 | |
3567 | ||
4022 | B<-i> オプションについては L<perlrun|perlrun/-i[extension]> を | |
3568 | ||
4023 | 参照してください。 | |
3569 | 4024 | |
3570 | =item Handle->output_field_separator( EXPR ) | |
4025 | =item IO::Handle->output_field_separator( EXPR ) | |
3571 | 4026 | |
3572 | 4027 | =item $OUTPUT_FIELD_SEPARATOR |
3573 | 4028 | |
3574 | 4029 | =item $OFS |
3575 | 4030 | |
3576 | 4031 | =item $, |
3577 | 4032 | X<$,> X<$OFS> X<$OUTPUT_FIELD_SEPARATOR> |
3578 | 4033 | |
3579 | 4034 | =begin original |
3580 | 4035 | |
3581 | The output field separator for the print operator. If defined, this | |
4036 | The output field separator for the print operator. If defined, this | |
3582 | value is printed between each of print's arguments. Default is C<undef>. | |
4037 | value is printed between each of print's arguments. Default is C<undef>. | |
3583 | 4038 | |
3584 | 4039 | =end original |
3585 | 4040 | |
3586 | 4041 | print 演算子のための出力フィールドセパレータ。 |
3587 | 4042 | 定義されると、この値がそれぞれの print の引数の間に表示されます。 |
3588 | 4043 | デフォルトは C<undef> です。 |
3589 | 4044 | |
3590 | 4045 | =begin original |
3591 | 4046 | |
4047 | You cannot call C<output_field_separator()> on a handle, only as a | |
4048 | static method. See L<IO::Handle|IO::Handle>. | |
4049 | ||
4050 | =end original | |
4051 | ||
4052 | ハンドルに対して C<output_field_separator()> を呼び出すことはできません; | |
4053 | 静的メソッドしてのみです。 | |
4054 | L<IO::Handle|IO::Handle> を参照してください。 | |
4055 | ||
4056 | =begin original | |
4057 | ||
3592 | 4058 | Mnemonic: what is printed when there is a "," in your print statement. |
3593 | 4059 | |
3594 | 4060 | =end original |
3595 | 4061 | |
3596 | 4062 | 記憶法: print 文で "," を書いた場所に印字されるもの。 |
3597 | 4063 | |
3598 | 4064 | =item HANDLE->input_line_number( EXPR ) |
3599 | 4065 | |
3600 | 4066 | =item $INPUT_LINE_NUMBER |
3601 | 4067 | |
3602 | 4068 | =item $NR |
3603 | 4069 | |
3604 | 4070 | =item $. |
3605 | 4071 | X<$.> X<$NR> X<$INPUT_LINE_NUMBER> X<line number> |
3606 | 4072 | |
3607 | 4073 | =begin original |
3608 | 4074 | |
3609 | 4075 | Current line number for the last filehandle accessed. |
3610 | 4076 | |
3611 | 4077 | =end original |
3612 | 4078 | |
3613 | 4079 | 最後にアクセスされたファイルハンドルの現在の行番号。 |
3614 | 4080 | |
3615 | 4081 | =begin original |
3616 | 4082 | |
3617 | 4083 | Each filehandle in Perl counts the number of lines that have been read |
3618 | from it. (Depending on the value of C<$/>, Perl's idea of what | |
4084 | from it. (Depending on the value of C<$/>, Perl's idea of what | |
3619 | 4085 | constitutes a line may not match yours.) When a line is read from a |
3620 | 4086 | filehandle (via C<readline()> or C<< <> >>), or when C<tell()> or |
3621 | 4087 | C<seek()> is called on it, C<$.> becomes an alias to the line counter |
3622 | 4088 | for that filehandle. |
3623 | 4089 | |
3624 | 4090 | =end original |
3625 | 4091 | |
3626 | 4092 | Perl の各ファイルハンドルは、そこから読み込んだ行数を数えています。 |
3627 | 4093 | (C<$/> の値に依存して、何が行を構成するかに関する Perl の考えはあなたの |
3628 | 4094 | 考えと一致しないかもしれません。) |
3629 | 4095 | 行が(C<readline()> や C<< <> >> を使って)ファイルハンドルから読み込まれたか、 |
3630 | 4096 | C<tell()> や C<seek()> がファイルハンドルに対して呼び出された場合、 |
3631 | 4097 | C<$.> はそのファイルハンドルの行カウンタへのエイリアスとなります。 |
3632 | 4098 | |
3633 | 4099 | =begin original |
3634 | 4100 | |
3635 | 4101 | You can adjust the counter by assigning to C<$.>, but this will not |
3636 | actually move the seek pointer. I<Localizing C<$.> will not localize | |
4102 | actually move the seek pointer. I<Localizing C<$.> will not localize | |
3637 | the filehandle's line count>. Instead, it will localize perl's notion | |
4103 | the filehandle's line count>. Instead, it will localize perl's notion | |
3638 | 4104 | of which filehandle C<$.> is currently aliased to. |
3639 | 4105 | |
3640 | 4106 | =end original |
3641 | 4107 | |
3642 | 4108 | C<$.> へ代入することでカウンタの値を修正できますが、これは実際にシーク |
3643 | 4109 | ポインタを動かすことはありません。 |
3644 | I<C<$.> をローカル化してもファイルハンドルの行カウンタは | |
4110 | I<C<$.> をローカル化してもファイルハンドルの行カウンタはローカル化されません>。 | |
3645 | ローカル化されません>。 | |
3646 | 4111 | 代わりに、現在 C<$.> がどのファイルハンドルへのエイリアスかという情報が |
3647 | 4112 | ローカル化されます。 |
3648 | 4113 | |
3649 | 4114 | =begin original |
3650 | 4115 | |
3651 | 4116 | C<$.> is reset when the filehandle is closed, but B<not> when an open |
3652 | filehandle is reopened without an intervening C<close()>. For more | |
4117 | filehandle is reopened without an intervening C<close()>. For more | |
3653 | details, see L<perlop/"IE<sol>O Operators">. Because C<< <> >> never does | |
4118 | details, see L<perlop/"IE<sol>O Operators">. Because C<< <> >> never does | |
3654 | 4119 | an explicit close, line numbers increase across C<ARGV> files (but see |
3655 | 4120 | examples in L<perlfunc/eof>). |
3656 | 4121 | |
3657 | 4122 | =end original |
3658 | 4123 | |
3659 | 4124 | C<$.> はファイルハンドルがクローズされるとリセットされますが、 |
3660 | 4125 | オープンしているファイルハンドルが C<close()> されることなく再オープンされた |
3661 | 4126 | 場合にはリセット B<されません>。 |
3662 | 4127 | さらなる詳細については、L<perlop/"IE<sol>O Operators"> を参照してください。 |
3663 | 4128 | なぜなら、 C<< <> >> は決して明示的なクローズは行わず、行番号は C<ARGV> の |
3664 | 4129 | ファイル間で通算してカウントされるからです(但し L<perlfunc/eof> の例を |
3665 | 4130 | 参照してください)。 |
3666 | 4131 | |
3667 | 4132 | =begin original |
3668 | 4133 | |
3669 | 4134 | You can also use C<< HANDLE->input_line_number(EXPR) >> to access the |
3670 | 4135 | line counter for a given filehandle without having to worry about |
3671 | 4136 | which handle you last accessed. |
3672 | 4137 | |
3673 | 4138 | =end original |
3674 | 4139 | |
3675 | 4140 | また、C<< HANDLE->input_line_number(EXPR) >> とすることで、どのハンドルに |
3676 | 4141 | 最後にアクセスしたかを気にすることなく行カウンタにアクセスできます。 |
3677 | 4142 | |
3678 | 4143 | =begin original |
3679 | 4144 | |
3680 | 4145 | Mnemonic: many programs use "." to mean the current line number. |
3681 | 4146 | |
3682 | 4147 | =end original |
3683 | 4148 | |
3684 | 4149 | 記憶法: 多くのプログラムで "." が現在行番号を示すように使われています。 |
3685 | 4150 | |
3686 | =item H | |
4151 | =item IO::Handle->input_record_separator( EXPR ) | |
3687 | 4152 | |
3688 | 4153 | =item $INPUT_RECORD_SEPARATOR |
3689 | 4154 | |
3690 | 4155 | =item $RS |
3691 | 4156 | |
3692 | 4157 | =item $/ |
3693 | 4158 | X<$/> X<$RS> X<$INPUT_RECORD_SEPARATOR> |
3694 | 4159 | |
3695 | 4160 | =begin original |
3696 | 4161 | |
3697 | The input record separator, newline by default. This influences Perl's | |
4162 | The input record separator, newline by default. This influences Perl's | |
3698 | idea of what a "line" is. Works like B<awk>'s RS variable, including | |
4163 | idea of what a "line" is. Works like B<awk>'s RS variable, including | |
3699 | 4164 | treating empty lines as a terminator if set to the null string (an |
3700 | empty line cannot contain any spaces or tabs). You may set it to a | |
4165 | empty line cannot contain any spaces or tabs). You may set it to a | |
3701 | 4166 | multi-character string to match a multi-character terminator, or to |
3702 | C<undef> to read through the end of file. Setting it to C<"\n\n"> | |
4167 | C<undef> to read through the end of file. Setting it to C<"\n\n"> | |
3703 | 4168 | means something slightly different than setting to C<"">, if the file |
3704 | contains consecutive empty lines. Setting to C<""> will treat two or | |
4169 | contains consecutive empty lines. Setting to C<""> will treat two or | |
3705 | more consecutive empty lines as a single empty line. Setting to | |
4170 | more consecutive empty lines as a single empty line. Setting to | |
3706 | 4171 | C<"\n\n"> will blindly assume that the next input character belongs to |
3707 | 4172 | the next paragraph, even if it's a newline. |
3708 | 4173 | |
3709 | 4174 | =end original |
3710 | 4175 | |
3711 | 4176 | 入力レコードセパレータで、デフォルトでは改行文字。 |
3712 | 4177 | これは Perl での「行」とは何か、ということに影響を与えます。 |
3713 | 空文字列に設定されると、空行をセパレータとして扱うことを | |
4178 | 空文字列に設定されると、空行をセパレータとして扱うことを含めて、B<awk> の | |
3714 | ||
4179 | 変数 RS のように働きます(空行はスペースやタブを含んでいてはいけません)。 | |
3715 | ||
4180 | 複数文字の区切文字を示すために、文字列を設定することもできます; また、 | |
3716 | ||
4181 | ファイルの最後まで読み込むために undef を指定することもできます。 | |
3717 | また、ファイルの最後まで読み込むために undef を指定することもできます。 | |
3718 | 4182 | この変数に C<"\n\n"> を設定すると、空行が続く場合において、 |
3719 | 4183 | C<""> を設定した場合とわずかに違う動作をするようになります。 |
3720 | 4184 | C<""> を設定した場合には、複数の空行も 1 つの空行であるかのように扱います。 |
3721 | 4185 | C<"\n\n"> を設定した場合には、単純に次の文字が (たとえ改行文字であっても) |
3722 | 4186 | 次の段落に含まれるものとして扱います。 |
3723 | 4187 | |
4188 | =begin original | |
4189 | ||
3724 | 4190 | local $/; # enable "slurp" mode |
3725 | 4191 | local $_ = <FH>; # whole file now here |
3726 | 4192 | s/\n[ \t]+/ /g; |
3727 | 4193 | |
4194 | =end original | |
4195 | ||
4196 | local $/; # 「吸い込み」モードを有効にする | |
4197 | local $_ = <FH>; # ファイル全体が入る | |
4198 | s/\n[ \t]+/ /g; | |
4199 | ||
3728 | 4200 | =begin original |
3729 | 4201 | |
3730 | Remember: the value of C<$/> is a string, not a regex. B<awk> has to | |
4202 | Remember: the value of C<$/> is a string, not a regex. B<awk> has to | |
3731 | 4203 | be better for something. :-) |
3732 | 4204 | |
3733 | 4205 | =end original |
3734 | 4206 | |
3735 | 4207 | 注意: C<$/> は文字列であり、正規表現ではありません。 |
3736 | 4208 | B<awk> は何かもっとうまくやらなくてはいけません。:-) |
3737 | 4209 | |
3738 | 4210 | =begin original |
3739 | 4211 | |
4212 | Setting C<$/> to an empty string -- the so-called I<paragraph mode> -- merits | |
4213 | special attention. When C<$/> is set to C<""> and the entire file is read in | |
4214 | with that setting, any sequence of one or more consecutive newlines at the | |
4215 | beginning of the file is discarded. With the exception of the final record in | |
4216 | the file, each sequence of characters ending in two or more newlines is | |
4217 | treated as one record and is read in to end in exactly two newlines. If the | |
4218 | last record in the file ends in zero or one consecutive newlines, that record | |
4219 | is read in with that number of newlines. If the last record ends in two or | |
4220 | more consecutive newlines, it is read in with two newlines like all preceding | |
4221 | records. | |
4222 | ||
4223 | =end original | |
4224 | ||
4225 | C<$/> に空文字列を設定すること -- I<段落モード> と呼ばれます -- には、 | |
4226 | 特に注意する価値があります。 | |
4227 | C<$/> が C<""> に設定されて、ファイル全体がこの設定で読み込まれた場合、 | |
4228 | ファイル先頭の一つ以上の連続する改行の並びは捨てられます。 | |
4229 | ファイルの最後のレコードを例外として、 | |
4230 | 二つ以上の改行で終わるそれぞれの文字並びは一つのレコードとして扱われ、 | |
4231 | 正確に二つの改行で終わるように読み込まれます。 | |
4232 | ファイルの最後のレコードが 0 または 1 の連続する改行で終わっている場合、 | |
4233 | そのレコードはその数の改行と共に読み込まれます。 | |
4234 | 最後のレコードが二つ以上の連続する改行で終わっている場合、 | |
4235 | 全ての先行するレコードと同様、二つの改行と共に読み込まれます。 | |
4236 | ||
4237 | =begin original | |
4238 | ||
4239 | Suppose we wrote the following string to a file: | |
4240 | ||
4241 | =end original | |
4242 | ||
4243 | 次の文字列をファイルに書いたとします: | |
4244 | ||
4245 | my $string = "\n\n\n"; | |
4246 | $string .= "alpha beta\ngamma delta\n\n\n"; | |
4247 | $string .= "epsilon zeta eta\n\n"; | |
4248 | $string .= "theta\n"; | |
4249 | ||
4250 | my $file = 'simple_file.txt'; | |
4251 | open my $OUT, '>', $file or die; | |
4252 | print $OUT $string; | |
4253 | close $OUT or die; | |
4254 | ||
4255 | =begin original | |
4256 | ||
4257 | Now we read that file in paragraph mode: | |
4258 | ||
4259 | =end original | |
4260 | ||
4261 | このファイルを段落モードで読み込みます: | |
4262 | ||
4263 | local $/ = ""; # paragraph mode | |
4264 | open my $IN, '<', $file or die; | |
4265 | my @records = <$IN>; | |
4266 | close $IN or die; | |
4267 | ||
4268 | =begin original | |
4269 | ||
4270 | C<@records> will consist of these 3 strings: | |
4271 | ||
4272 | =end original | |
4273 | ||
4274 | C<@records> は三つの文字列からなります: | |
4275 | ||
4276 | ( | |
4277 | "alpha beta\ngamma delta\n\n", | |
4278 | "epsilon zeta eta\n\n", | |
4279 | "theta\n", | |
4280 | ) | |
4281 | ||
4282 | =begin original | |
4283 | ||
3740 | 4284 | Setting C<$/> to a reference to an integer, scalar containing an |
3741 | 4285 | integer, or scalar that's convertible to an integer will attempt to |
3742 | 4286 | read records instead of lines, with the maximum record size being the |
3743 | referenced integer. So this: | |
4287 | referenced integer number of characters. So this: | |
3744 | 4288 | |
3745 | 4289 | =end original |
3746 | 4290 | |
3747 | 4291 | C<$/> に整数、整数を含むスカラ、整数に変換できるスカラのいずれかへの |
3748 | リファレンスをセットすると、行を読む代わりにレコードを読もうとします | |
4292 | リファレンスをセットすると、行を読む代わりにレコードを読もうとします; | |
3749 | この場合、最大レコードサイズはリファレンス先の整数値となります。 | |
4293 | この場合、最大レコードサイズはリファレンス先の整数値の文字数となります。 | |
4294 | つまり: | |
3750 | 4295 | |
3751 | 4296 | local $/ = \32768; # or \"32768", or \$var_containing_32768 |
3752 | 4297 | open my $fh, "<", $myfile or die $!; |
3753 | 4298 | local $_ = <$fh>; |
3754 | 4299 | |
3755 | 4300 | =begin original |
3756 | 4301 | |
3757 | will read a record of no more than 32768 | |
4302 | will read a record of no more than 32768 characters from $fh. If you're | |
3758 | 4303 | not reading from a record-oriented file (or your OS doesn't have |
3759 | 4304 | record-oriented files), then you'll likely get a full chunk of data |
3760 | with every read. If a record is larger than the record size you've | |
4305 | with every read. If a record is larger than the record size you've | |
3761 | set, you'll get the record back in pieces. Trying to set the record | |
4306 | set, you'll get the record back in pieces. Trying to set the record | |
3762 | size to zero or less | |
4307 | size to zero or less is deprecated and will cause $/ to have the value | |
4308 | of "undef", which will cause reading in the (rest of the) whole file. | |
3763 | 4309 | |
3764 | 4310 | =end original |
3765 | 4311 | |
3766 | これは | |
4312 | これは $fh から 32768 文字を超えないようにレコードを読み込みます。 | |
3767 | もしレコード指向のファイルを読み込まない場合 | |
4313 | もしレコード指向のファイルを読み込まない場合(あるいは OS がレコード指向 | |
3768 | ||
4314 | ファイルを持たない場合)、読み込み毎にデータのチャンク全部を取り込みます。 | |
3769 | 読み込み毎にデータのチャンク全部を取り込みます。 | |
3770 | 4315 | もしレコードがセットしたレコードサイズより大きい場合、 |
3771 | 4316 | レコードの部分を取り込みます。 |
3772 | レコードサイズを 0 以下にセットしようとする | |
4317 | レコードサイズを 0 以下にセットしようとするのは廃止予定で、 | |
3773 | 読み込むことになります。 | |
4318 | $/ に値 "undef" が設定され、(残りの)ファイル全体を読み込むことになります。 | |
3774 | 4319 | |
3775 | 4320 | =begin original |
3776 | 4321 | |
3777 | ||
4322 | As of 5.19.9 setting C<$/> to any other form of reference will throw a | |
3778 | ||
4323 | fatal exception. This is in preparation for supporting new ways to set | |
3779 | ||
4324 | C<$/> in the future. | |
3780 | want to read in record mode is probably unusable in line mode.) | |
3781 | Non-VMS systems do normal I/O, so it's safe to mix record and | |
3782 | non-record reads of a file. | |
3783 | 4325 | |
3784 | 4326 | =end original |
3785 | 4327 | |
3786 | ||
4328 | 5.19.9 から、C<$/> にその他の形式のリファレンスを設定すると致命的エラーが | |
3787 | ||
4329 | 投げられます。 | |
3788 | ||
4330 | これは将来 C<$/> を設定する新しい方法に対応する準備です。 | |
3789 | レコード読み込みしたいファイルは多分行モードでは使えないものだからです。) | |
3790 | VMS 以外のシステムでは普通の I/O を使いますので、 | |
3791 | 同じファイルのレコード読み込みと非レコード読み込みを混ぜても安全です。 | |
3792 | 4331 | |
3793 | 4332 | =begin original |
3794 | 4333 | |
3795 | Se | |
4334 | On VMS only, record reads bypass PerlIO layers and any associated | |
4335 | buffering, so you must not mix record and non-record reads on the | |
4336 | same filehandle. Record mode mixes with line mode only when the | |
4337 | same buffering layer is in use for both modes. | |
3796 | 4338 | |
3797 | 4339 | =end original |
3798 | 4340 | |
3799 | ||
4341 | VMS だけでは、レコードは PerlIO 層とそれに関連するバッファリングを迂回して | |
4342 | 読み込まれるので、同じファイルハンドルでレコード読み込みと | |
4343 | 非レコード読み込みを混ぜてはいけません。 | |
4344 | レコードモードは、同じバッファリング層を両方のモードで使う場合にのみ | |
4345 | ラインモードと混ざります。 | |
3800 | 4346 | |
3801 | 4347 | =begin original |
3802 | 4348 | |
4349 | You cannot call C<input_record_separator()> on a handle, only as a | |
4350 | static method. See L<IO::Handle|IO::Handle>. | |
4351 | ||
4352 | =end original | |
4353 | ||
4354 | ハンドルに対して C<input_record_separator()> を呼び出すことはできません; | |
4355 | 静的メソッドしてのみです。 | |
4356 | L<IO::Handle|IO::Handle> を参照してください。 | |
4357 | ||
4358 | =begin original | |
4359 | ||
4360 | See also L<perlport/"Newlines">. Also see L</$.>. | |
4361 | ||
4362 | =end original | |
4363 | ||
4364 | L<perlport/"Newlines"> を参照してください。 | |
4365 | L</$.> も参照してください。 | |
4366 | ||
4367 | =begin original | |
4368 | ||
3803 | 4369 | Mnemonic: / delimits line boundaries when quoting poetry. |
3804 | 4370 | |
3805 | 4371 | =end original |
3806 | 4372 | |
3807 | 4373 | 記憶法: /は、詩を引用するときに、行の区切りを示します。 |
3808 | 4374 | |
3809 | =item Handle->output_record_separator( EXPR ) | |
4375 | =item IO::Handle->output_record_separator( EXPR ) | |
3810 | 4376 | |
3811 | 4377 | =item $OUTPUT_RECORD_SEPARATOR |
3812 | 4378 | |
3813 | 4379 | =item $ORS |
3814 | 4380 | |
3815 | 4381 | =item $\ |
3816 | 4382 | X<$\> X<$ORS> X<$OUTPUT_RECORD_SEPARATOR> |
3817 | 4383 | |
3818 | 4384 | =begin original |
3819 | 4385 | |
3820 | The output record separator for the print operator. If defined, this | |
4386 | The output record separator for the print operator. If defined, this | |
3821 | value is printed after the last of print's arguments. Default is C<undef>. | |
4387 | value is printed after the last of print's arguments. Default is C<undef>. | |
3822 | 4388 | |
3823 | 4389 | =end original |
3824 | 4390 | |
3825 | 4391 | print 演算子のための出力レコードセパレータ。 |
3826 | 4392 | もし定義されていると、print の最後の引数の最後にこの値が表示されます。 |
3827 | 4393 | デフォルトは C<undef> です。 |
3828 | 4394 | |
3829 | 4395 | =begin original |
3830 | 4396 | |
4397 | You cannot call C<output_record_separator()> on a handle, only as a | |
4398 | static method. See L<IO::Handle|IO::Handle>. | |
4399 | ||
4400 | =end original | |
4401 | ||
4402 | ハンドルに対して C<output_record_separator()> を呼び出すことはできません; | |
4403 | 静的メソッドしてのみです。 | |
4404 | L<IO::Handle|IO::Handle> を参照してください。 | |
4405 | ||
4406 | =begin original | |
4407 | ||
3831 | 4408 | Mnemonic: you set C<$\> instead of adding "\n" at the end of the print. |
3832 | 4409 | Also, it's just like C<$/>, but it's what you get "back" from Perl. |
3833 | 4410 | |
3834 | 4411 | =end original |
3835 | 4412 | |
3836 | 4413 | 記憶法: print の最後に "\n" を付け加える代わりに C<$\> を設定する。 |
3837 | 4414 | また、C<$/> に似通っているが、Perl から「バック」されるものです。 |
3838 | 4415 | |
3839 | 4416 | =item HANDLE->autoflush( EXPR ) |
3840 | 4417 | |
3841 | 4418 | =item $OUTPUT_AUTOFLUSH |
3842 | 4419 | |
3843 | 4420 | =item $| |
3844 | 4421 | X<$|> X<autoflush> X<flush> X<$OUTPUT_AUTOFLUSH> |
3845 | 4422 | |
3846 | 4423 | =begin original |
3847 | 4424 | |
3848 | 4425 | If set to nonzero, forces a flush right away and after every write or |
3849 | print on the currently selected output channel. Default is 0 | |
4426 | print on the currently selected output channel. Default is 0 | |
3850 | 4427 | (regardless of whether the channel is really buffered by the system or |
3851 | 4428 | not; C<$|> tells you only whether you've asked Perl explicitly to |
3852 | flush after each write). STDOUT will typically be line buffered if | |
4429 | flush after each write). STDOUT will typically be line buffered if | |
3853 | output is to the terminal and block buffered otherwise. Setting this | |
4430 | output is to the terminal and block buffered otherwise. Setting this | |
3854 | 4431 | variable is useful primarily when you are outputting to a pipe or |
3855 | 4432 | socket, such as when you are running a Perl program under B<rsh> and |
3856 | want to see the output as it's happening. This has no effect on input | |
4433 | want to see the output as it's happening. This has no effect on input | |
3857 | buffering. See L<perlfunc/getc> for that. See L<perlfunc/select> on | |
4434 | buffering. See L<perlfunc/getc> for that. See L<perlfunc/select> on | |
3858 | how to select the output channel. See also L<IO::Handle>. | |
4435 | how to select the output channel. See also L<IO::Handle>. | |
3859 | 4436 | |
3860 | 4437 | =end original |
3861 | 4438 | |
3862 | 0 以外に設定されると、 | |
4439 | 0 以外に設定されると、その時点で選択されている出力チャネルを直ちにその場で | |
3863 | ||
4440 | フラッシュし、さらに write や print を行なうごとに、強制的にフラッシュします。 | |
3864 | ||
4441 | デフォルトでは 0 となっています(チャンネルが実際にシステムによって | |
3865 | さ | |
4442 | バッファリングされているかどうかは関知しません。 | |
3866 | ||
4443 | C<$|> は Perl が明示的に毎回書き込みの後にフラッシュするかどうかのみを | |
3867 | ||
4444 | 示します)。 | |
3868 | 関知しません。C<$|> は Perl が明示的に毎回書き込みの後に | |
3869 | フラッシュするかどうかのみを示します)。 | |
3870 | 4445 | STDOUT は通常では、端末への出力時には行バッファリング、 |
3871 | 4446 | それ以外ではブロックバッファリングであることに注意してください。 |
3872 | これは、Perl のスクリプトを rsh 配下で実行して、 | |
4447 | これは、Perl のスクリプトを rsh 配下で実行して、実行状況を確認したい | |
3873 | ||
4448 | 場合のように、パイプやソケットに出力するときに特に便利でしょう。 | |
3874 | 便利でしょう。 | |
3875 | 4449 | これは入力バッファリングには何の影響も与えません。 |
3876 | 4450 | 出力チャネルの選択方法については L<perlfunc/select> を参照してください。 |
3877 | 4451 | L<IO::Handle> も参照してください。 |
3878 | 4452 | |
3879 | 4453 | =begin original |
3880 | 4454 | |
3881 | 4455 | Mnemonic: when you want your pipes to be piping hot. |
3882 | 4456 | |
3883 | 4457 | =end original |
3884 | 4458 | |
3885 | 4459 | 記憶法: パイプをホットな状態にしておくために使う。 |
3886 | 4460 | |
4461 | =item ${^LAST_FH} | |
4462 | X<${^LAST_FH}> | |
4463 | ||
4464 | =begin original | |
4465 | ||
4466 | This read-only variable contains a reference to the last-read filehandle. | |
4467 | This is set by C<< <HANDLE> >>, C<readline>, C<tell>, C<eof> and C<seek>. | |
4468 | This is the same handle that C<$.> and C<tell> and C<eof> without arguments | |
4469 | use. It is also the handle used when Perl appends ", <STDIN> line 1" to | |
4470 | an error or warning message. | |
4471 | ||
4472 | =end original | |
4473 | ||
4474 | この読み込み専用変数は最後に読み込んだファイルハンドルへのリファレンスを | |
4475 | 含んでいます。 | |
4476 | これは C<< <HANDLE> >>, C<readline>, C<tell>, C<eof>, C<seek> で | |
4477 | 設定されます。 | |
4478 | これは C<$.> および、C<tell> と C<eof> が引数なしで使われたときと同じ | |
4479 | ハンドルです。 | |
4480 | これはまた、Perl がエラーまたは警告メッセージに ", <STDIN> line 1" を追加する | |
4481 | ハンドルでもあります。 | |
4482 | ||
4483 | =begin original | |
4484 | ||
4485 | This variable was added in Perl v5.18.0. | |
4486 | ||
4487 | =end original | |
4488 | ||
4489 | この変数は Perl v5.18.0 で追加されました。 | |
4490 | ||
3887 | 4491 | =back |
3888 | 4492 | |
3889 | 4493 | =head3 Variables related to formats |
3890 | 4494 | |
3891 | 4495 | (フォーマット関連の変数) |
3892 | 4496 | |
3893 | 4497 | =begin original |
3894 | 4498 | |
3895 | 4499 | The special variables for formats are a subset of those for |
3896 | filehandles. See L<perlform> for more information about Perl's | |
4500 | filehandles. See L<perlform> for more information about Perl's | |
3897 | 4501 | formats. |
3898 | 4502 | |
3899 | 4503 | =end original |
3900 | 4504 | |
3901 | 4505 | フォーマットのための特殊変数はファイルハンドルのための物のサブセットです。 |
3902 | 4506 | Perl のフォーマットに関するさらなる情報については L<perlform> を |
3903 | 4507 | 参照してください。 |
3904 | 4508 | |
3905 | 4509 | =over 8 |
3906 | 4510 | |
3907 | 4511 | =item $ACCUMULATOR |
3908 | 4512 | |
3909 | 4513 | =item $^A |
3910 | 4514 | X<$^A> X<$ACCUMULATOR> |
3911 | 4515 | |
3912 | 4516 | =begin original |
3913 | 4517 | |
3914 | 4518 | The current value of the C<write()> accumulator for C<format()> lines. |
3915 | 4519 | A format contains C<formline()> calls that put their result into |
3916 | C<$^A>. After calling its format, C<write()> prints out the contents | |
4520 | C<$^A>. After calling its format, C<write()> prints out the contents | |
3917 | of C<$^A> and empties. So you never really see the contents of C<$^A> | |
4521 | of C<$^A> and empties. So you never really see the contents of C<$^A> | |
3918 | unless you call C<formline()> yourself and then look at it. See | |
4522 | unless you call C<formline()> yourself and then look at it. See | |
3919 | 4523 | L<perlform> and L<perlfunc/"formline PICTURE,LIST">. |
3920 | 4524 | |
3921 | 4525 | =end original |
3922 | 4526 | |
3923 | 4527 | C<format()> 行のための、その時点での C<write()> アキュムレータの値。 |
3924 | 4528 | format には、C<$^A> に結果を残す、C<formline()> 呼び出しが含まれます。 |
3925 | 4529 | 自分のフォーマットを呼び出した後で、 |
3926 | 4530 | C<write()> は C<$^A> の内容を出力してから消去します。 |
3927 | 4531 | したがって、自分で C<formline()> を呼び出すのでなければ、 |
3928 | 4532 | C<$^A> の値が見えることはありません。 |
3929 | 4533 | L<perlform> と L<perlfunc/"formline PICTURE,LIST"> を参照してください。 |
3930 | 4534 | |
3931 | =item H | |
4535 | =item IO::Handle->format_formfeed(EXPR) | |
3932 | 4536 | |
3933 | 4537 | =item $FORMAT_FORMFEED |
3934 | 4538 | |
3935 | 4539 | =item $^L |
3936 | 4540 | X<$^L> X<$FORMAT_FORMFEED> |
3937 | 4541 | |
3938 | 4542 | =begin original |
3939 | 4543 | |
3940 | What formats output as a form feed. The default is C<\f>. | |
4544 | What formats output as a form feed. The default is C<\f>. | |
3941 | 4545 | |
3942 | 4546 | =end original |
3943 | 4547 | |
3944 | 4548 | フォーマット出力で、改ページのために出力されるもの。 |
3945 | 4549 | デフォルトは C<\f>。 |
3946 | 4550 | |
4551 | =begin original | |
4552 | ||
4553 | You cannot call C<format_formfeed()> on a handle, only as a static | |
4554 | method. See L<IO::Handle|IO::Handle>. | |
4555 | ||
4556 | =end original | |
4557 | ||
4558 | ハンドルに対して C<format_formfeed()> を呼び出すことはできません; | |
4559 | 静的メソッドしてのみです。 | |
4560 | L<IO::Handle|IO::Handle> を参照してください。 | |
4561 | ||
3947 | 4562 | =item HANDLE->format_page_number(EXPR) |
3948 | 4563 | |
3949 | 4564 | =item $FORMAT_PAGE_NUMBER |
3950 | 4565 | |
3951 | 4566 | =item $% |
3952 | 4567 | X<$%> X<$FORMAT_PAGE_NUMBER> |
3953 | 4568 | |
3954 | 4569 | =begin original |
3955 | 4570 | |
3956 | 4571 | The current page number of the currently selected output channel. |
3957 | 4572 | |
3958 | 4573 | =end original |
3959 | 4574 | |
3960 | 4575 | その時点で選択されている出力チャネルの、その時点でのページ番号。 |
3961 | 4576 | |
3962 | 4577 | =begin original |
3963 | 4578 | |
3964 | 4579 | Mnemonic: C<%> is page number in B<nroff>. |
3965 | 4580 | |
3966 | 4581 | =end original |
3967 | 4582 | |
3968 | 4583 | 記憶法: C<%> は、B<nroff> でのページ番号です。 |
3969 | 4584 | |
3970 | 4585 | =item HANDLE->format_lines_left(EXPR) |
3971 | 4586 | |
3972 | 4587 | =item $FORMAT_LINES_LEFT |
3973 | 4588 | |
3974 | 4589 | =item $- |
3975 | 4590 | X<$-> X<$FORMAT_LINES_LEFT> |
3976 | 4591 | |
3977 | 4592 | =begin original |
3978 | 4593 | |
3979 | 4594 | The number of lines left on the page of the currently selected output |
4595 | channel. | |
3980 | 4596 | |
3981 | 4597 | =end original |
3982 | 4598 | |
3983 | 4599 | その時点で選択されている出力チャネルの、ページに残っている行数。 |
3984 | フォーマットで用いられます。 | |
3985 | 4600 | |
3986 | 4601 | =begin original |
3987 | 4602 | |
3988 | 4603 | Mnemonic: lines_on_page - lines_printed. |
3989 | 4604 | |
3990 | 4605 | =end original |
3991 | 4606 | |
3992 | 4607 | 記憶法: "ページ行数" - "印字済み行数" |
3993 | 4608 | |
3994 | =item Handle->format_line_break_characters EXPR | |
4609 | =item IO::Handle->format_line_break_characters EXPR | |
3995 | 4610 | |
3996 | 4611 | =item $FORMAT_LINE_BREAK_CHARACTERS |
3997 | 4612 | |
3998 | 4613 | =item $: |
3999 | 4614 | X<$:> X<FORMAT_LINE_BREAK_CHARACTERS> |
4000 | 4615 | |
4001 | 4616 | =begin original |
4002 | 4617 | |
4003 | 4618 | The current set of characters after which a string may be broken to |
4004 | fill continuation fields (starting with C<^>) in a format. The default is | |
4619 | fill continuation fields (starting with C<^>) in a format. The default is | |
4005 | 4620 | S<" \n-">, to break on a space, newline, or a hyphen. |
4006 | 4621 | |
4007 | 4622 | =end original |
4008 | 4623 | |
4009 | フォーマットの充填継続フィールド (C<^> で始まるもの) への | |
4624 | フォーマットの充填継続フィールド (C<^> で始まるもの) への文字列で行分割を許す | |
4010 | 文字 | |
4625 | 文字集合。 | |
4011 | デフォルトは S<" \n-"> で空白、改行、ハイフンの後で行分割が可能 | |
4626 | デフォルトは S<" \n-"> で空白、改行、ハイフンの後で行分割が可能です。 | |
4012 | 4627 | |
4013 | 4628 | =begin original |
4014 | 4629 | |
4630 | You cannot call C<format_line_break_characters()> on a handle, only as | |
4631 | a static method. See L<IO::Handle|IO::Handle>. | |
4632 | ||
4633 | =end original | |
4634 | ||
4635 | ハンドルに対して C<format_line_break_characters()> を呼び出すことはできません; | |
4636 | 静的メソッドしてのみです。 | |
4637 | L<IO::Handle|IO::Handle> を参照してください。 | |
4638 | ||
4639 | =begin original | |
4640 | ||
4015 | 4641 | Mnemonic: a "colon" in poetry is a part of a line. |
4016 | 4642 | |
4017 | 4643 | =end original |
4018 | 4644 | |
4019 | 4645 | 記憶法: 詩では「コロン」は、行の一部。 |
4020 | 4646 | |
4021 | 4647 | =item HANDLE->format_lines_per_page(EXPR) |
4022 | 4648 | |
4023 | 4649 | =item $FORMAT_LINES_PER_PAGE |
4024 | 4650 | |
4025 | 4651 | =item $= |
4026 | 4652 | X<$=> X<$FORMAT_LINES_PER_PAGE> |
4027 | 4653 | |
4028 | 4654 | =begin original |
4029 | 4655 | |
4030 | 4656 | The current page length (printable lines) of the currently selected |
4031 | output channel. The default is 60. | |
4657 | output channel. The default is 60. | |
4032 | 4658 | |
4033 | 4659 | =end original |
4034 | 4660 | |
4035 | その時点で選択されている出力チャネルの、その時点での | |
4661 | その時点で選択されている出力チャネルの、その時点でのページ長(印字可能行数)。 | |
4036 | ||
4662 | デフォルトは 60 です。 | |
4037 | フォーマットで用いられます。 | |
4038 | 4663 | |
4039 | 4664 | =begin original |
4040 | 4665 | |
4041 | 4666 | Mnemonic: = has horizontal lines. |
4042 | 4667 | |
4043 | 4668 | =end original |
4044 | 4669 | |
4045 | 4670 | 記憶法: = には複数の水平線 (行) が含まれます。 |
4046 | 4671 | |
4047 | 4672 | =item HANDLE->format_top_name(EXPR) |
4048 | 4673 | |
4049 | 4674 | =item $FORMAT_TOP_NAME |
4050 | 4675 | |
4051 | 4676 | =item $^ |
4052 | 4677 | X<$^> X<$FORMAT_TOP_NAME> |
4053 | 4678 | |
4054 | 4679 | =begin original |
4055 | 4680 | |
4056 | 4681 | The name of the current top-of-page format for the currently selected |
4057 | output channel. The default is the name of the filehandle with C<_TOP> | |
4682 | output channel. The default is the name of the filehandle with C<_TOP> | |
4058 | appended. For example, the default format top name for the C<STDOUT> | |
4683 | appended. For example, the default format top name for the C<STDOUT> | |
4059 | filehan | |
4684 | filehandle is C<STDOUT_TOP>. | |
4060 | 4685 | |
4061 | 4686 | =end original |
4062 | 4687 | |
4063 | その時点で選択されている出力チャネルの、その時点でのページ先頭 | |
4688 | その時点で選択されている出力チャネルの、その時点でのページ先頭フォーマット名。 | |
4064 | フォーマット名。 | |
4065 | 4689 | デフォルトは、ファイルハンドル名に _TOP を続けたものです。 |
4066 | 4690 | 例えば、C<STDOUT> ファイルハンドルのデフォルトのページ先頭フォーマット名は |
4067 | 4691 | C<STDOUT_TOP> です。 |
4068 | 4692 | |
4069 | 4693 | =begin original |
4070 | 4694 | |
4071 | 4695 | Mnemonic: points to top of page. |
4072 | 4696 | |
4073 | 4697 | =end original |
4074 | 4698 | |
4075 | 4699 | 記憶法: ページの先頭へのポインタ。 |
4076 | 4700 | |
4077 | 4701 | =item HANDLE->format_name(EXPR) |
4078 | 4702 | |
4079 | 4703 | =item $FORMAT_NAME |
4080 | 4704 | |
4081 | 4705 | =item $~ |
4082 | 4706 | X<$~> X<$FORMAT_NAME> |
4083 | 4707 | |
4084 | 4708 | =begin original |
4085 | 4709 | |
4086 | 4710 | The name of the current report format for the currently selected |
4087 | output channel. The default format name is the same as the filehandle | |
4711 | output channel. The default format name is the same as the filehandle | |
4088 | name. For example, the default format name for the C<STDOUT> | |
4712 | name. For example, the default format name for the C<STDOUT> | |
4089 | 4713 | filehandle is just C<STDOUT>. |
4090 | 4714 | |
4091 | 4715 | =end original |
4092 | 4716 | |
4093 | 4717 | その時点で選択されている出力チャネルの、その時点でのフォーマット名。 |
4094 | 4718 | デフォルトは、ファイルハンドル名です。 |
4095 | 4719 | 例えば、C<STDOUT> ファイルハンドルのデフォルトフォーマット名は |
4096 | 4720 | 単に C<STDOUT> です。 |
4097 | 4721 | |
4098 | 4722 | =begin original |
4099 | 4723 | |
4100 | 4724 | Mnemonic: brother to C<$^>. |
4101 | 4725 | |
4102 | 4726 | =end original |
4103 | 4727 | |
4104 | 4728 | 記憶法: C<$^> の兄弟。 |
4105 | 4729 | |
4106 | 4730 | =back |
4107 | 4731 | |
4108 | =head2 Error | |
4732 | =head2 Error Variables | |
4109 | 4733 | X<error> X<exception> |
4110 | 4734 | |
4111 | (エラー | |
4735 | (エラー変数) | |
4112 | 4736 | |
4113 | 4737 | =begin original |
4114 | 4738 | |
4115 | 4739 | The variables C<$@>, C<$!>, C<$^E>, and C<$?> contain information |
4116 | 4740 | about different types of error conditions that may appear during |
4117 | execution of a Perl program. The variables are shown ordered by | |
4741 | execution of a Perl program. The variables are shown ordered by | |
4118 | 4742 | the "distance" between the subsystem which reported the error and |
4119 | the Perl process. They correspond to errors detected by the Perl | |
4743 | the Perl process. They correspond to errors detected by the Perl | |
4120 | 4744 | interpreter, C library, operating system, or an external program, |
4121 | 4745 | respectively. |
4122 | 4746 | |
4123 | 4747 | =end original |
4124 | 4748 | |
4125 | 4749 | 変数 C<$@>, C<$!>, C<$^E>, C<$?> は Perl プログラムの実行中に |
4126 | 4750 | 発生した、異なる種類のエラー情報を保持します。 |
4127 | 変数はエラーを報告した副システムと Perl プロセスとの「距離」 | |
4751 | 変数はエラーを報告した副システムと Perl プロセスとの「距離」の順番に | |
4128 | ||
4752 | 並んでいます。 | |
4129 | 4753 | これらはそれぞれ、Perl インタプリタ、C ライブラリ、 |
4130 | 4754 | オペレーティングシステム、外部プログラムによって検出された |
4131 | 4755 | エラーに対応しています。 |
4132 | 4756 | |
4133 | 4757 | =begin original |
4134 | 4758 | |
4135 | 4759 | To illustrate the differences between these variables, consider the |
4136 | following Perl expression, which uses a single-quoted string. After | |
4760 | following Perl expression, which uses a single-quoted string. After | |
4137 | 4761 | execution of this statement, perl may have set all four special error |
4138 | 4762 | variables: |
4139 | 4763 | |
4140 | 4764 | =end original |
4141 | 4765 | |
4142 | 4766 | これらの変数の違いを示すために、 |
4143 | 4767 | 以下のようなシングルクォートを用いた Perl 式を考えます。 |
4144 | 4768 | この文の実行後、perl は四つ全ての特殊エラー変数をセットします: |
4145 | 4769 | |
4770 | eval q{ | |
4771 | open my $pipe, "/cdrom/install |" or die $!; | |
4772 | my @res = <$pipe>; | |
4773 | close $pipe or die "bad pipe: $?, $!"; | |
4774 | }; | |
4146 | 4775 | |
4147 | eval q{ | |
4148 | open my $pipe, "/cdrom/install |" or die $!; | |
4149 | my @res = <$pipe>; | |
4150 | close $pipe or die "bad pipe: $?, $!"; | |
4151 | }; | |
4152 | ||
4153 | 4776 | =begin original |
4154 | 4777 | |
4155 | 4778 | When perl executes the C<eval()> expression, it translates the |
4156 | 4779 | C<open()>, C<< <PIPE> >>, and C<close> calls in the C run-time library |
4157 | and thence to the operating system kernel. perl sets C<$!> to | |
4780 | and thence to the operating system kernel. perl sets C<$!> to | |
4158 | 4781 | the C library's C<errno> if one of these calls fails. |
4159 | 4782 | |
4160 | 4783 | =end original |
4161 | 4784 | |
4162 | 4785 | C<eval()> 式が実行されたとき、C<open()>, C<< <PIPE> >>, C<close> は |
4163 | 4786 | C ランタイムライブラリの呼び出しに変換され、それからオペレーティング |
4164 | 4787 | システムコールに変換されます。 |
4165 | 4788 | C<$!> はこれらの呼び出しのどれかが失敗したとき、 |
4166 | 4789 | C ライブラリの C<errno> の値がセットされます。 |
4167 | 4790 | |
4168 | 4791 | =begin original |
4169 | 4792 | |
4170 | 4793 | C<$@> is set if the string to be C<eval>-ed did not compile (this may |
4171 | 4794 | happen if C<open> or C<close> were imported with bad prototypes), or |
4172 | if Perl code executed during evaluation C<die()>d. In these cases the | |
4795 | if Perl code executed during evaluation C<die()>d. In these cases the | |
4173 | 4796 | value of C<$@> is the compile error, or the argument to C<die> (which |
4174 | will interpolate C<$!> and C<$?>). (See also L<Fatal>, though.) | |
4797 | will interpolate C<$!> and C<$?>). (See also L<Fatal>, though.) | |
4175 | 4798 | |
4176 | 4799 | =end original |
4177 | 4800 | |
4178 | C<$@> は C<eval> された文字列がコンパイルされなかったとき | |
4801 | C<$@> は C<eval> された文字列がコンパイルされなかったとき(これは C<open> か | |
4179 | ||
4802 | C<close> が正しくないプロトタイプでインポートされたときに起こり得ます)、 | |
4180 | プロトタイプでインポートされたときに起こり得ます)、 | |
4181 | 4803 | または評価中に実行している Perl コードが C<die()> したときにセットされます。 |
4182 | 4804 | これらの場合には C<$@> の値はコンパイルエラー、または |
4183 | 4805 | C<die> への引数(これには C<$!> と C<$?> が差し挟まれます)です。 |
4184 | 4806 | (しかし、L<Fatal> も参照して下さい。) |
4185 | 4807 | |
4186 | 4808 | =begin original |
4187 | 4809 | |
4188 | 4810 | Under a few operating systems, C<$^E> may contain a more verbose error |
4189 | indicator, such as in this case, "CDROM tray not closed." Systems that | |
4811 | indicator, such as in this case, "CDROM tray not closed." Systems that | |
4190 | 4812 | do not support extended error messages leave C<$^E> the same as C<$!>. |
4191 | 4813 | |
4192 | 4814 | =end original |
4193 | 4815 | |
4194 | いくつかのオペレーティングシステムでは、 | |
4816 | いくつかのオペレーティングシステムでは、C<$^E> により詳細なエラー指示子が | |
4195 | ||
4817 | 入っているかもしれません; 今回の場合で言えば、 | |
4196 | ||
4818 | "CDROM tray not closed." などです。 | |
4197 | 追加のエラーメッセージに対応していないシステムでは、 | |
4819 | 追加のエラーメッセージに対応していないシステムでは、C<$^E> は C<$!> と同じ | |
4198 | ||
4820 | 値です。 | |
4199 | 4821 | |
4200 | 4822 | =begin original |
4201 | 4823 | |
4202 | Finally, C<$?> may be set to non-0 value if the external program | |
4824 | Finally, C<$?> may be set to a non-0 value if the external program | |
4203 | F</cdrom/install> fails. The upper eight bits reflect specific error | |
4825 | F</cdrom/install> fails. The upper eight bits reflect specific error | |
4204 | 4826 | conditions encountered by the program (the program's C<exit()> value). |
4205 | 4827 | The lower eight bits reflect mode of failure, like signal death and |
4206 | core dump information. See | |
4828 | core dump information. See L<wait(2)> for details. In contrast to | |
4207 | C<$!> and C<$^E>, which are set only if error condition is detected, | |
4829 | C<$!> and C<$^E>, which are set only if an error condition is detected, | |
4208 | 4830 | the variable C<$?> is set on each C<wait> or pipe C<close>, |
4209 | overwriting the old value. This is more like C<$@>, which on every | |
4831 | overwriting the old value. This is more like C<$@>, which on every | |
4210 | 4832 | C<eval()> is always set on failure and cleared on success. |
4211 | 4833 | |
4212 | 4834 | =end original |
4213 | 4835 | |
4214 | 4836 | 最後に、C<$?> は外部プログラム F</cdrom/install> が失敗したときに |
4215 | 4837 | 非 0 にセットされるかもしれません。 |
4216 | 4838 | 上位の 8 ビットはプログラムが遭遇した特定のエラー状況 |
4217 | 4839 | (プログラムの C<exit()> の値)を反映します。 |
4218 | 4840 | 下位の 8 ビットは、シグナルの死亡やコアダンプ情報と言った失敗のモードを |
4219 | 4841 | 反映します。 |
4220 | 詳細については | |
4842 | 詳細については L<wait(2)> を参照して下さい。 | |
4221 | 4843 | C<$!> と C<$^E> はエラー状況が検出されたときにのみ設定されますが、 |
4222 | 4844 | 変数 C<$?> は C<wait> やパイプの C<close> の度に、前の値を上書きします。 |
4223 | 4845 | これは、C<$@> が C<eval()> の実行毎に、エラーならセットされ、 |
4224 | 4846 | 成功ならクリアされるという動作と似ています。 |
4225 | 4847 | |
4226 | 4848 | =begin original |
4227 | 4849 | |
4228 | 4850 | For more details, see the individual descriptions at C<$@>, C<$!>, |
4229 | 4851 | C<$^E>, and C<$?>. |
4230 | 4852 | |
4231 | 4853 | =end original |
4232 | 4854 | |
4233 | 4855 | より詳細については、C<$@>, C<$!>, C<$^E>, C<$?> それぞれの説明を |
4234 | 4856 | 参照して下さい。 |
4235 | 4857 | |
4236 | 4858 | =over 8 |
4237 | 4859 | |
4238 | 4860 | =item ${^CHILD_ERROR_NATIVE} |
4239 | 4861 | X<$^CHILD_ERROR_NATIVE> |
4240 | 4862 | |
4241 | 4863 | =begin original |
4242 | 4864 | |
4243 | 4865 | The native status returned by the last pipe close, backtick (C<``>) |
4244 | 4866 | command, successful call to C<wait()> or C<waitpid()>, or from the |
4245 | C<system()> operator. On POSIX-like systems this value can be decoded | |
4867 | C<system()> operator. On POSIX-like systems this value can be decoded | |
4246 | with the WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, | |
4868 | with the WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, and | |
4247 | WSTOPSIG | |
4869 | WSTOPSIG functions provided by the L<POSIX> module. | |
4248 | 4870 | |
4249 | 4871 | =end original |
4250 | 4872 | |
4251 | 4873 | 最後のパイプクローズ、逆クォート (C<``>) コマンド、C<wait()> と |
4252 | 4874 | C<waitpid()> の成功した呼び出し、C<system()> 演算子から返された、 |
4253 | 4875 | ネイティブなステータスです。 |
4254 | 4876 | POSIX 風システムでは、この値は L<POSIX> モジュールで提供される |
4255 | WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG | |
4877 | WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG 関数で | |
4256 | ||
4878 | デコードできます。 | |
4257 | 4879 | |
4258 | 4880 | =begin original |
4259 | 4881 | |
4260 | 4882 | Under VMS this reflects the actual VMS exit status; i.e. it is the |
4261 | 4883 | same as C<$?> when the pragma C<use vmsish 'status'> is in effect. |
4262 | 4884 | |
4263 | 4885 | =end original |
4264 | 4886 | |
4265 | 4887 | VMS ではこれは実際の VMS の終了ステータスを反映します; |
4266 | 4888 | 言い換えると、これは C<use vmsish 'status'> プラグマが有効なときの $? と |
4267 | 4889 | 同じです。 |
4268 | 4890 | |
4269 | 4891 | =begin original |
4270 | 4892 | |
4271 | This variable was added in Perl 5. | |
4893 | This variable was added in Perl v5.10.0. | |
4272 | 4894 | |
4273 | 4895 | =end original |
4274 | 4896 | |
4275 | この変数は Perl 5. | |
4897 | この変数は Perl v5.10.0 で追加されました。 | |
4276 | 4898 | |
4277 | 4899 | =item $EXTENDED_OS_ERROR |
4278 | 4900 | |
4279 | 4901 | =item $^E |
4280 | 4902 | X<$^E> X<$EXTENDED_OS_ERROR> |
4281 | 4903 | |
4282 | 4904 | =begin original |
4283 | 4905 | |
4284 | Error information specific to the current operating system. At the | |
4906 | Error information specific to the current operating system. At the | |
4285 | moment, this differs from C<$!> under only VMS, OS/2, and Win32 (and | |
4907 | moment, this differs from C<L</$!>> under only VMS, OS/2, and Win32 (and | |
4286 | for MacPerl). On all other platforms, C<$^E> is always just the same | |
4908 | for MacPerl). On all other platforms, C<$^E> is always just the same | |
4287 | 4909 | as C<$!>. |
4288 | 4910 | |
4289 | 4911 | =end original |
4290 | 4912 | |
4291 | 4913 | 現在のオペレーティングシステムに特化したエラー情報です。 |
4292 | 4914 | 現在のところ、VMS, OS/2, Win32 (と MacPerl) のみで |
4293 | C<$!> と異なる値をもちます。 | |
4915 | C<L</$!>> と異なる値をもちます。 | |
4294 | 4916 | その他のプラットフォームでは、C<$^E> はいつも C<$!> と同じです。 |
4295 | 4917 | |
4296 | 4918 | =begin original |
4297 | 4919 | |
4298 | 4920 | Under VMS, C<$^E> provides the VMS status value from the last system |
4299 | error. This is more specific information about the last system error | |
4921 | error. This is more specific information about the last system error | |
4300 | than that provided by C<$!>. This is particularly important when C<$!> | |
4922 | than that provided by C<$!>. This is particularly important when C<$!> | |
4301 | 4923 | is set to B<EVMSERR>. |
4302 | 4924 | |
4303 | 4925 | =end original |
4304 | 4926 | |
4305 | 4927 | VMS では、C<$^E> は最後のシステムエラーの VMS ステータス値です。 |
4306 | 4928 | これは、最後のシステムエラーについて C<$!> で提供されるものより |
4307 | 4929 | 具体的な情報を示します。 |
4308 | 4930 | これは特に C<$!> が B<EVMSERR> にセットされた場合に重要です。 |
4309 | 4931 | |
4310 | 4932 | =begin original |
4311 | 4933 | |
4312 | 4934 | Under OS/2, C<$^E> is set to the error code of the last call to OS/2 |
4313 | 4935 | API either via CRT, or directly from perl. |
4314 | 4936 | |
4315 | 4937 | =end original |
4316 | 4938 | |
4317 | 4939 | OS/2 では、C<$^E> は CRT 経由、または Perl から直接呼び出された |
4318 | 4940 | 最後の OS/2 API のエラーコードがセットされます。 |
4319 | 4941 | |
4320 | 4942 | =begin original |
4321 | 4943 | |
4322 | 4944 | Under Win32, C<$^E> always returns the last error information reported |
4323 | 4945 | by the Win32 call C<GetLastError()> which describes the last error |
4324 | from within the Win32 API. Most Win32-specific code will report errors | |
4946 | from within the Win32 API. Most Win32-specific code will report errors | |
4325 | via C<$^E>. ANSI C and Unix-like calls set C<errno> and so most | |
4947 | via C<$^E>. ANSI C and Unix-like calls set C<errno> and so most | |
4326 | 4948 | portable Perl code will report errors via C<$!>. |
4327 | 4949 | |
4328 | 4950 | =end original |
4329 | 4951 | |
4330 | 4952 | Win32 では、C<$^E> は Win32 API での最後のエラーの内容を返す |
4331 | 4953 | C<GetLastError()> Win32 呼び出しで報告される最新のエラー情報を |
4332 | 4954 | 返します。 |
4333 | 4955 | ほとんどの Win32 固有のコードはエラーを C<$^E> 経由で返します。 |
4334 | 4956 | ANSI C と Unix 風の呼び出しは C<errno> をセットするので、 |
4335 | 4957 | ほとんどの移植性のある Perl コードは C<$!> 経由で |
4336 | 4958 | エラーを報告します。 |
4337 | 4959 | |
4338 | 4960 | =begin original |
4339 | 4961 | |
4340 | Caveats mentioned in the description of C<$!> generally apply to | |
4962 | Caveats mentioned in the description of C<L</$!>> generally apply to | |
4341 | 4963 | C<$^E>, also. |
4342 | 4964 | |
4343 | 4965 | =end original |
4344 | 4966 | |
4345 | C<$!> の説明で触れた問題点は一般的に C<$^E> にも適用されます。 | |
4967 | C<L</$!>> の説明で触れた問題点は一般的に C<$^E> にも適用されます。 | |
4346 | 4968 | |
4347 | 4969 | =begin original |
4348 | 4970 | |
4349 | 4971 | This variable was added in Perl 5.003. |
4350 | 4972 | |
4351 | 4973 | =end original |
4352 | 4974 | |
4353 | 4975 | この変数は Perl 5.003 で追加されました。 |
4354 | 4976 | |
4355 | 4977 | =begin original |
4356 | 4978 | |
4357 | 4979 | Mnemonic: Extra error explanation. |
4358 | 4980 | |
4359 | 4981 | =end original |
4360 | 4982 | |
4361 | 4983 | 記憶法: 追加の(Extra)エラーの説明。 |
4362 | 4984 | |
4363 | 4985 | =item $EXCEPTIONS_BEING_CAUGHT |
4364 | 4986 | |
4365 | 4987 | =item $^S |
4366 | 4988 | X<$^S> X<$EXCEPTIONS_BEING_CAUGHT> |
4367 | 4989 | |
4368 | 4990 | =begin original |
4369 | 4991 | |
4370 | 4992 | Current state of the interpreter. |
4371 | 4993 | |
4372 | 4994 | =end original |
4373 | 4995 | |
4374 | 4996 | 現在のインタプリタの状態を示します。 |
4375 | 4997 | |
4376 | 4998 | =begin original |
4377 | 4999 | |
4378 | ||
5000 | $^S State | |
4379 | ||
5001 | --------- ------------------------------------- | |
4380 | ||
5002 | undef Parsing module, eval, or main program | |
4381 | ||
5003 | true (1) Executing an eval or try block | |
4382 | ||
5004 | false (0) Otherwise | |
4383 | 5005 | |
4384 | 5006 | =end original |
4385 | 5007 | |
4386 | ||
5008 | $^S 状態 | |
4387 | ||
5009 | --------- ------------------- | |
4388 | ||
5010 | undef モジュール、eval、メインプログラムのパース中 | |
4389 | ||
5011 | 真 (1) eval または try ブロックの実行中 | |
4390 | ||
5012 | 偽 (0) その他 | |
4391 | 5013 | |
4392 | 5014 | =begin original |
4393 | 5015 | |
4394 | 5016 | The first state may happen in C<$SIG{__DIE__}> and C<$SIG{__WARN__}> |
4395 | 5017 | handlers. |
4396 | 5018 | |
4397 | 5019 | =end original |
4398 | 5020 | |
4399 | 5021 | 最初の状態は C<$SIG{__DIE__}> と C<$SIG{__WARN__}> のハンドラで起きる |
4400 | 5022 | 可能性があります。 |
4401 | 5023 | |
4402 | 5024 | =begin original |
4403 | 5025 | |
5026 | The English name $EXCEPTIONS_BEING_CAUGHT is slightly misleading, because | |
5027 | the C<undef> value does not indicate whether exceptions are being caught, | |
5028 | since compilation of the main program does not catch exceptions. | |
5029 | ||
5030 | =end original | |
5031 | ||
5032 | 英語名 $EXCEPTIONS_BEING_CAUGHT は少し誤解を招きます; C<undef> は例外が | |
5033 | 捕捉されたかどうかを示しているわけではないからです; メインプログラムの | |
5034 | コンパイルは例外を捕捉しません。 | |
5035 | ||
5036 | =begin original | |
5037 | ||
4404 | 5038 | This variable was added in Perl 5.004. |
4405 | 5039 | |
4406 | 5040 | =end original |
4407 | 5041 | |
4408 | 5042 | この変数は Perl 5.004 で追加されました。 |
4409 | 5043 | |
4410 | 5044 | =item $WARNING |
4411 | 5045 | |
4412 | 5046 | =item $^W |
4413 | 5047 | X<$^W> X<$WARNING> |
4414 | 5048 | |
4415 | 5049 | =begin original |
4416 | 5050 | |
4417 | 5051 | The current value of the warning switch, initially true if B<-w> was |
4418 | 5052 | used, false otherwise, but directly modifiable. |
4419 | 5053 | |
4420 | 5054 | =end original |
4421 | 5055 | |
4422 | 5056 | 警告スイッチの値で、B<-w> スイッチが使われると内部的に真となり、 |
4423 | 5057 | そうでない場合は直接変更可能です。 |
4424 | 5058 | |
4425 | 5059 | =begin original |
4426 | 5060 | |
4427 | 5061 | See also L<warnings>. |
4428 | 5062 | |
4429 | 5063 | =end original |
4430 | 5064 | |
4431 | 5065 | L<warnings> も参照して下さい。 |
4432 | 5066 | |
4433 | 5067 | =begin original |
4434 | 5068 | |
4435 | 5069 | Mnemonic: related to the B<-w> switch. |
4436 | 5070 | |
4437 | 5071 | =end original |
4438 | 5072 | |
4439 | 5073 | 記憶法: B<-w> スイッチに関係します。 |
4440 | 5074 | |
4441 | 5075 | =item ${^WARNING_BITS} |
4442 | 5076 | X<${^WARNING_BITS}> |
4443 | 5077 | |
4444 | 5078 | =begin original |
4445 | 5079 | |
4446 | 5080 | The current set of warning checks enabled by the C<use warnings> pragma. |
4447 | ||
5081 | It has the same scoping as the C<$^H> and C<%^H> variables. The exact | |
5082 | values are considered internal to the L<warnings> pragma and may change | |
5083 | between versions of Perl. | |
4448 | 5084 | |
4449 | 5085 | =end original |
4450 | 5086 | |
4451 | 5087 | C<use warnings> プラグマで有効にされた、現在の警告チェックの集合です。 |
4452 | ||
5088 | C<$^H> および C<%^H> 変数と同じスコープを持ちます。 | |
5089 | 正確な値は L<warnings> プラグマの内部の値と考えられ、Perl の | |
5090 | バージョンによって変更されるかもしれません。 | |
4453 | 5091 | |
4454 | 5092 | =begin original |
4455 | 5093 | |
4456 | ||
5094 | Each time a statement completes being compiled, the current value of | |
5095 | C<${^WARNING_BITS}> is stored with that statement, and can later be | |
5096 | retrieved via C<(caller($level))[9]>. | |
4457 | 5097 | |
4458 | 5098 | =end original |
4459 | 5099 | |
4460 | ||
5100 | 文のコンパイルが完了する毎に、C<${^WARNING_BITS}> の現在の値が文と共に | |
5101 | 保管され、C<(caller($level))[9]> として後で取得できます。 | |
4461 | 5102 | |
5103 | =begin original | |
5104 | ||
5105 | This variable was added in Perl v5.6.0. | |
5106 | ||
5107 | =end original | |
5108 | ||
5109 | この変数は Perl v5.6.0 で追加されました。 | |
5110 | ||
4462 | 5111 | =item $OS_ERROR |
4463 | 5112 | |
4464 | 5113 | =item $ERRNO |
4465 | 5114 | |
4466 | 5115 | =item $! |
4467 | 5116 | X<$!> X<$ERRNO> X<$OS_ERROR> |
4468 | 5117 | |
4469 | 5118 | =begin original |
4470 | 5119 | |
4471 | ||
5120 | When referenced, C<$!> retrieves the current value | |
4472 | ||
5121 | of the C C<errno> integer variable. | |
4473 | ||
5122 | If C<$!> is assigned a numerical value, that value is stored in C<errno>. | |
4474 | ||
5123 | When referenced as a string, C<$!> yields the system error string | |
5124 | corresponding to C<errno>. | |
4475 | 5125 | |
4476 | 5126 | =end original |
4477 | 5127 | |
4478 | ||
5128 | 参照されると、C<$!> は C の C<errno> 整数変数の現在の値を取得します。 | |
4479 | ||
5129 | C<$!> に数値が代入されると、その値は C<errno> に保管されます。 | |
4480 | ||
5130 | 文字列として参照されると、C<$!> は C<errno> に対応するシステムエラー | |
4481 | ||
5131 | 文字列を返します。 | |
4482 | 意味します。 | |
4483 | 5132 | |
4484 | ||
5133 | =begin original | |
4485 | ||
4486 | ||
5135 | Many system or library calls set C<errno> if they fail, | |
5136 | to indicate the cause of failure. They usually do B<not> | |
5137 | set C<errno> to zero if they succeed and may set C<errno> to a | |
5138 | non-zero value on success. This means C<errno>, hence C<$!>, is | |
5139 | meaningful only I<immediately> after a B<failure>: | |
5140 | ||
5141 | =end original | |
5142 | ||
5143 | 多くのシステムやライブラリ呼び出しは、失敗したときに、失敗の理由を示すために | |
5144 | C<errno> を設定します。 | |
5145 | これらは普通は成功したときには C<errno> にゼロを設定 B<しません>; | |
5146 | 成功時には C<errno> に非ゼロを設定するかもしれません。 | |
5147 | これは、C<errno>、C<$!> は、B<失敗> の I<直後> でのみ意味が | |
5148 | あるということです: | |
5149 | ||
5150 | =begin original | |
5151 | ||
5152 | if (open my $fh, "<", $filename) { | |
5153 | # Here $! is meaningless. | |
5154 | ... | |
4487 | 5155 | } |
4488 | 5156 | else { |
4489 | ||
5157 | # ONLY here is $! meaningful. | |
4490 | ||
5158 | ... | |
4491 | ||
5159 | # Already here $! might be meaningless. | |
4492 | 5160 | } |
4493 | 5161 | # Since here we might have either success or failure, |
4494 | # | |
5162 | # $! is meaningless. | |
4495 | 5163 | |
5164 | =end original | |
5165 | ||
5166 | if (open my $fh, "<", $filename) { | |
5167 | # ここで $! は無意味。 | |
5168 | ... | |
5169 | } | |
5170 | else { | |
5171 | # ここでだけ $! に意味がある。 | |
5172 | ... | |
5173 | # ここで既に $! は無意味かもしれません。 | |
5174 | } | |
5175 | # ここでは成功と失敗の両方の可能性があるので、 | |
5176 | # $! は無意味。 | |
5177 | ||
4496 | 5178 | =begin original |
4497 | 5179 | |
4498 | ||
5180 | Here, I<meaningless> means that C<$!> may be unrelated to the outcome | |
4499 | ||
5181 | of the C<open()> operator. Assignment to C<$!> is similarly ephemeral. | |
4500 | ||
5182 | It can be used immediately before invoking the C<die()> operator, | |
5183 | to set the exit value, or to inspect the system error string | |
5184 | corresponding to error I<n>, or to restore C<$!> to a meaningful state. | |
4501 | 5185 | |
4502 | 5186 | =end original |
4503 | 5187 | |
4504 | I< | |
5188 | ここで、I<無意味> というのは C<$!> は C<open()> 演算子の結果に | |
4505 | ||
5189 | 関係ないということです。 | |
4506 | ||
5190 | C<$!> への代入も同様に一時的なものです。 | |
5191 | これは、終了値を設定したり、エラー I<n> に対応するシステムエラー文字列を | |
5192 | 調べたり、C<$!> を意味のある状態に復元するために、C<die()> 演算子を | |
5193 | 起動する直前で使えます。 | |
4507 | 5194 | |
4508 | 5195 | =begin original |
4509 | 5196 | |
4510 | ||
5197 | Perl itself may set C<errno> to a non-zero on failure even if no | |
4511 | ||
5198 | system call is performed. | |
4512 | want C<"$!"> to return the string for error I<n>, or you want to set | |
4513 | the exit value for the C<die()> operator. | |
4514 | 5199 | |
4515 | 5200 | =end original |
4516 | 5201 | |
4517 | ||
5202 | Perl 自身は、システムコールを実行しなくても失敗時には | |
4518 | ||
5203 | C<errno> に非ゼロを設定するかもしれません。 | |
4519 | C<die()> 演算子の exit 値を設定するために、I<errno> を設定するため | |
4520 | C<$!> へ代入を行なうことが可能です。 | |
4521 | 5204 | |
4522 | 5205 | =begin original |
4523 | 5206 | |
4524 | 5207 | Mnemonic: What just went bang? |
4525 | 5208 | |
4526 | 5209 | =end original |
4527 | 5210 | |
4528 | 5211 | 記憶法: 何が bang(!) したか。 |
4529 | 5212 | |
4530 | 5213 | =item %OS_ERROR |
4531 | 5214 | |
4532 | 5215 | =item %ERRNO |
4533 | 5216 | |
4534 | 5217 | =item %! |
4535 | 5218 | X<%!> X<%OS_ERROR> X<%ERRNO> |
4536 | 5219 | |
4537 | 5220 | =begin original |
4538 | 5221 | |
4539 | 5222 | Each element of C<%!> has a true value only if C<$!> is set to that |
4540 | value. For example, C<$!{ENOENT}> is true if and only if the current | |
5223 | value. For example, C<$!{ENOENT}> is true if and only if the current | |
4541 | 5224 | value of C<$!> is C<ENOENT>; that is, if the most recent error was "No |
4542 | 5225 | such file or directory" (or its moral equivalent: not all operating |
4543 | systems give that exact error, and certainly not all languages). T | |
5226 | systems give that exact error, and certainly not all languages). The | |
4544 | ||
5227 | specific true value is not guaranteed, but in the past has generally | |
4545 | ||
5228 | been the numeric value of C<$!>. To check if a particular key is | |
4546 | fo | |
5229 | meaningful on your system, use C<exists $!{the_key}>; for a list of legal | |
5230 | keys, use C<keys %!>. See L<Errno> for more information, and also see | |
5231 | L</$!>. | |
4547 | 5232 | |
4548 | 5233 | =end original |
4549 | 5234 | |
4550 | C<%!> の各要素は、C<$!> がその値にセットされている場合にのみ真の値を | |
5235 | C<%!> の各要素は、C<$!> がその値にセットされている場合にのみ真の値を持ちます。 | |
4551 | 持ちます。 | |
4552 | 5236 | 例えば、C<$!{ENOENT}> は、現在の C<$!> の値が C<ENOENT> の場合にのみ |
4553 | 真となります; これは、最近のエラーが | |
5237 | 真となります; これは、最近のエラーが "No such file or directory" (あるいは | |
4554 | ||
5238 | 倫理的に等価なもの: 全ての OS が正確に同じエラーを出すわけではないですし、 | |
4555 | ||
5239 | 全ての言語で出るわけでもありません) の場合です。 | |
4556 | ||
5240 | 特定の真の値は保証されませんが、以前は一般的には C<$!> の数値でした。 | |
4557 | 5241 | あなたのシステムで特定のキーが意味があるかどうかを調べるには、 |
4558 | 5242 | C<exists $!{the_key}> を使ってください; 有効なキーのリストを得るには、 |
4559 | 5243 | C<keys %!> としてください。 |
4560 | 5244 | さらなる情報に関しては L<Errno> と C</$!> を参照してください。 |
4561 | 5245 | |
4562 | 5246 | =begin original |
4563 | 5247 | |
4564 | 5248 | This variable was added in Perl 5.005. |
4565 | 5249 | |
4566 | 5250 | =end original |
4567 | 5251 | |
4568 | 5252 | この変数は Perl 5.005 で追加されました。 |
4569 | 5253 | |
4570 | 5254 | =item $CHILD_ERROR |
4571 | 5255 | |
4572 | 5256 | =item $? |
4573 | 5257 | X<$?> X<$CHILD_ERROR> |
4574 | 5258 | |
4575 | 5259 | =begin original |
4576 | 5260 | |
4577 | 5261 | The status returned by the last pipe close, backtick (C<``>) command, |
4578 | 5262 | successful call to C<wait()> or C<waitpid()>, or from the C<system()> |
4579 | operator. This is just the 16-bit status word returned by the | |
5263 | operator. This is just the 16-bit status word returned by the | |
4580 | 5264 | traditional Unix C<wait()> system call (or else is made up to look |
4581 | like it). Thus, the exit value of the subprocess is really (C<<< $? >> | |
5265 | like it). Thus, the exit value of the subprocess is really (C<<< $? >> | |
4582 | 5266 | 8 >>>), and C<$? & 127> gives which signal, if any, the process died |
4583 | 5267 | from, and C<$? & 128> reports whether there was a core dump. |
4584 | 5268 | |
4585 | 5269 | =end original |
4586 | 5270 | |
4587 | 5271 | 最後に close したパイプ、バッククォート (C<``>) コマンド、 |
4588 | 5272 | 成功した C<wait()> または waitpid() 呼び出し、C<system()> 演算子が返した |
4589 | 5273 | ステータス。 |
4590 | 5274 | このステータスワードは伝統的な Unix の C<wait()> システムコールが返した |
4591 | 5275 | 16 ビットのステータス(またはそのように見えるもの)です。 |
4592 | 5276 | 従ってサブプロセスの exit 値は、実際には (C<<< $? >> 8 >>>) |
4593 | 5277 | で、C<$? & 127> は、もしあれば、そのプロセスを止めたシグナルで、 |
4594 | 5278 | C<$? & 128> はコアダンプがあるかどうかを示します。 |
4595 | 5279 | |
4596 | 5280 | =begin original |
4597 | 5281 | |
4598 | 5282 | Additionally, if the C<h_errno> variable is supported in C, its value |
4599 | 5283 | is returned via C<$?> if any C<gethost*()> function fails. |
4600 | 5284 | |
4601 | 5285 | =end original |
4602 | 5286 | |
4603 | 5287 | さらに、C で C<h_errno> 変数に対応している場合は、 |
4604 | 5288 | C<gethost*()> が失敗したときに C<$?> を通して返されます。 |
4605 | 5289 | |
4606 | 5290 | =begin original |
4607 | 5291 | |
4608 | 5292 | If you have installed a signal handler for C<SIGCHLD>, the |
4609 | 5293 | value of C<$?> will usually be wrong outside that handler. |
4610 | 5294 | |
4611 | 5295 | =end original |
4612 | 5296 | |
4613 | 5297 | C<SIGCHLD> のシグナルハンドラを設定した場合、 |
4614 | 5298 | C<$?> の値は通常ハンドラの外側では正しくない値となります。 |
4615 | 5299 | |
4616 | 5300 | =begin original |
4617 | 5301 | |
4618 | 5302 | Inside an C<END> subroutine C<$?> contains the value that is going to be |
4619 | given to C<exit()>. You can modify C<$?> in an C<END> subroutine to | |
5303 | given to C<exit()>. You can modify C<$?> in an C<END> subroutine to | |
4620 | change the exit status of your program. For example: | |
5304 | change the exit status of your program. For example: | |
4621 | 5305 | |
4622 | 5306 | =end original |
4623 | 5307 | |
4624 | 5308 | C<END> サブルーチンの内側では C<$?> には C<exit()> に渡されようとしている |
4625 | 5309 | 値を含みます。 |
4626 | 5310 | プログラムの終了ステータスを変更するために、C<END> サブルーチン 内で |
4627 | 5311 | C<$?> を変更できます。 |
4628 | 5312 | 例えば: |
4629 | 5313 | |
5314 | =begin original | |
5315 | ||
4630 | 5316 | END { |
4631 | ||
5317 | $? = 1 if $? == 255; # die would make it 255 | |
4632 | 5318 | } |
4633 | 5319 | |
5320 | =end original | |
5321 | ||
5322 | END { | |
5323 | $? = 1 if $? == 255; # die は 255 | |
5324 | } | |
5325 | ||
4634 | 5326 | =begin original |
4635 | 5327 | |
4636 | 5328 | Under VMS, the pragma C<use vmsish 'status'> makes C<$?> reflect the |
4637 | 5329 | actual VMS exit status, instead of the default emulation of POSIX |
4638 | 5330 | status; see L<perlvms/$?> for details. |
4639 | 5331 | |
4640 | 5332 | =end original |
4641 | 5333 | |
4642 | 5334 | VMS では、C<use vmsish 'status'> を指定すると、 |
4643 | 5335 | C<$?> はPOSIX ステータスをエミュレートしたものではなく、 |
4644 | 5336 | 実際の VMS 終了ステータスを反映します; 詳細は L<perlvms/$?> を |
4645 | 5337 | 参照してください。 |
4646 | 5338 | |
4647 | 5339 | =begin original |
4648 | 5340 | |
4649 | 5341 | Mnemonic: similar to B<sh> and B<ksh>. |
4650 | 5342 | |
4651 | 5343 | =end original |
4652 | 5344 | |
4653 | 5345 | 記憶法: B<sh> や B<ksh> と同様。 |
4654 | 5346 | |
4655 | 5347 | =item $EVAL_ERROR |
4656 | 5348 | |
4657 | 5349 | =item $@ |
4658 | 5350 | X<$@> X<$EVAL_ERROR> |
4659 | 5351 | |
4660 | 5352 | =begin original |
4661 | 5353 | |
4662 | The Perl | |
5354 | The Perl error from the last C<eval> operator, i.e. the last exception that | |
4663 | ||
5355 | was caught. For C<eval BLOCK>, this is either a runtime error message or the | |
4664 | ||
5356 | string or reference C<die> was called with. The C<eval STRING> form also | |
4665 | ||
5357 | catches syntax errors and other compile time exceptions. | |
4666 | 5358 | |
4667 | 5359 | =end original |
4668 | 5360 | |
4669 | 最後の C<eval | |
5361 | 最後の C<eval> 操作子による Perl のエラーです; つまり、最後に補足された | |
4670 | ||
5362 | 例外です。 | |
4671 | ||
5363 | C<eval BLOCK> の場合は、これは実行時エラーか、C<die> が呼び出されたときの | |
4672 | ||
5364 | 文字列かリファレンスです。 | |
5365 | C<eval STRING> 型式は、文法エラーやその他のコンパイル時例外も捕捉します。 | |
4673 | 5366 | |
4674 | 5367 | =begin original |
4675 | 5368 | |
4676 | ||
5369 | If no error occurs, C<eval> sets C<$@> to the empty string. | |
5370 | ||
5371 | =end original | |
5372 | ||
5373 | エラーが起きなければ、C<eval> は C<$@> に空文字列を設定します。 | |
5374 | ||
5375 | =begin original | |
5376 | ||
5377 | Warning messages are not collected in this variable. You can, however, | |
4677 | 5378 | set up a routine to process warnings by setting C<$SIG{__WARN__}> as |
4678 | 5379 | described in L</%SIG>. |
4679 | 5380 | |
4680 | 5381 | =end original |
4681 | 5382 | |
4682 | 5383 | 警告メッセージはこの変数に入りません。 |
4683 | 5384 | しかし、L</%SIG> に記述されている C<$SIG{__WARN__}> にセットすることで |
4684 | 5385 | 警告を処理するルーチンを設定できます。 |
4685 | 5386 | |
4686 | 5387 | =begin original |
4687 | 5388 | |
4688 | Mnemonic: Where was the | |
5389 | Mnemonic: Where was the error "at"? | |
4689 | 5390 | |
4690 | 5391 | =end original |
4691 | 5392 | |
4692 | 記憶法: どこで ("at") | |
5393 | 記憶法: どこで ("at") エラーが起ったか。 | |
4693 | 5394 | |
4694 | 5395 | =back |
4695 | 5396 | |
5397 | =head2 Variables related to the interpreter state | |
5398 | ||
5399 | (インタプリタの状態に関連する変数) | |
5400 | ||
5401 | =begin original | |
5402 | ||
5403 | These variables provide information about the current interpreter state. | |
5404 | ||
5405 | =end original | |
5406 | ||
5407 | これらの変数は現在のインタプリタの状態に関する情報を提供します。 | |
5408 | ||
5409 | =over 8 | |
5410 | ||
5411 | =item $COMPILING | |
5412 | ||
5413 | =item $^C | |
5414 | X<$^C> X<$COMPILING> | |
5415 | ||
5416 | =begin original | |
5417 | ||
5418 | The current value of the flag associated with the B<-c> switch. | |
5419 | Mainly of use with B<-MO=...> to allow code to alter its behavior | |
5420 | when being compiled, such as for example to C<AUTOLOAD> at compile | |
5421 | time rather than normal, deferred loading. Setting | |
5422 | C<$^C = 1> is similar to calling C<B::minus_c>. | |
5423 | ||
5424 | =end original | |
5425 | ||
5426 | B<-c> スイッチに関連付けられた現在の値です。 | |
5427 | 主に B<-MO=...> と共に用いられ、例えば C<AUTOLOAD> を通常の遅延ロードでは | |
5428 | なくコンパイル時に実行するといった、コンパイル時の振る舞いを | |
5429 | 変えるために用います。 | |
5430 | C<$^C = 1> に設定することは C<B::minus_c> を呼び出すのと似ています。 | |
5431 | ||
5432 | =begin original | |
5433 | ||
5434 | This variable was added in Perl v5.6.0. | |
5435 | ||
5436 | =end original | |
5437 | ||
5438 | この変数は Perl v5.6.0 で追加されました。 | |
5439 | ||
5440 | =item $DEBUGGING | |
5441 | ||
5442 | =item $^D | |
5443 | X<$^D> X<$DEBUGGING> | |
5444 | ||
5445 | =begin original | |
5446 | ||
5447 | The current value of the debugging flags. May be read or set. Like its | |
5448 | L<command-line equivalent|perlrun/B<-D>I<letters>>, you can use numeric | |
5449 | or symbolic values, e.g. C<$^D = 10> or C<$^D = "st">. See | |
5450 | L<perlrun/B<-D>I<number>>. The contents of this variable also affects the | |
5451 | debugger operation. See L<perldebguts/Debugger Internals>. | |
5452 | ||
5453 | =end original | |
5454 | ||
5455 | デバッグフラグの現在の値を示します。 | |
5456 | 読み書き可能です。 | |
5457 | L<コマンドラインによる等価な機能|perlrun/B<-D>I<letters>> と同様に、 | |
5458 | 数値とシンボル値が使えます | |
5459 | (例: C<$^D = 10> または C<$^D = "st">)。 | |
5460 | L<perlrun/B<-D>I<number>> を参照してください。 | |
5461 | この変数の内容はデバッガ操作にも影響されます。 | |
5462 | L<perldebguts/Debugger Internals> を参照してください。 | |
5463 | ||
5464 | =begin original | |
5465 | ||
5466 | Mnemonic: value of B<-D> switch. | |
5467 | ||
5468 | =end original | |
5469 | ||
5470 | 記憶法: B<-D> スイッチの値。 | |
5471 | ||
5472 | =item ${^GLOBAL_PHASE} | |
5473 | X<${^GLOBAL_PHASE}> | |
5474 | ||
5475 | =begin original | |
5476 | ||
5477 | The current phase of the perl interpreter. | |
5478 | ||
5479 | =end original | |
5480 | ||
5481 | perl インタプリタの現在のフェーズ。 | |
5482 | ||
5483 | =begin original | |
5484 | ||
5485 | Possible values are: | |
5486 | ||
5487 | =end original | |
5488 | ||
5489 | 取り得る値は: | |
5490 | ||
5491 | =over 8 | |
5492 | ||
5493 | =item CONSTRUCT | |
5494 | ||
5495 | =begin original | |
5496 | ||
5497 | The C<PerlInterpreter*> is being constructed via C<perl_construct>. This | |
5498 | value is mostly there for completeness and for use via the | |
5499 | underlying C variable C<PL_phase>. It's not really possible for Perl | |
5500 | code to be executed unless construction of the interpreter is | |
5501 | finished. | |
5502 | ||
5503 | =end original | |
5504 | ||
5505 | C<PerlInterpreter*> は C<perl_construct> で構築されます。 | |
5506 | この変数はほとんど完全性のためと、基礎となっている C 変数 | |
5507 | C<PL_phase> 経由での使用のために存在しています。 | |
5508 | 実際にはインタプリタの構築が完了しない限り Perl コードを | |
5509 | 実行することはできません。 | |
5510 | ||
5511 | =item START | |
5512 | ||
5513 | =begin original | |
5514 | ||
5515 | This is the global compile-time. That includes, basically, every | |
5516 | C<BEGIN> block executed directly or indirectly from during the | |
5517 | compile-time of the top-level program. | |
5518 | ||
5519 | =end original | |
5520 | ||
5521 | これはコンパイル時にグローバルです。 | |
5522 | これは基本的に、直接実行されたり、トップレベルプログラムの | |
5523 | コンパイル時の間に間接的に実行される全ての C<BEGIN> です。 | |
5524 | ||
5525 | =begin original | |
5526 | ||
5527 | This phase is not called "BEGIN" to avoid confusion with | |
5528 | C<BEGIN>-blocks, as those are executed during compile-time of any | |
5529 | compilation unit, not just the top-level program. A new, localised | |
5530 | compile-time entered at run-time, for example by constructs as | |
5531 | C<eval "use SomeModule"> are not global interpreter phases, and | |
5532 | therefore aren't reflected by C<${^GLOBAL_PHASE}>. | |
5533 | ||
5534 | =end original | |
5535 | ||
5536 | C<BEGIN> ブロックとの混乱を避けるために、このフェーズの名前は "BEGIN" では | |
5537 | ありません; これらは単にトップレベルプログラムではなく、任意のコンパイル | |
5538 | ユニットのコンパイル中に実行されます。 | |
5539 | 例えば C<eval "use SomeModule"> のように、実行時に入った | |
5540 | 新しいローカル化されたコンパイル時はグローバルなインタプリタフェーズではなく、 | |
5541 | 従って C<${^GLOBAL_PHASE}> に反映されません。 | |
5542 | ||
5543 | =item CHECK | |
5544 | ||
5545 | =begin original | |
5546 | ||
5547 | Execution of any C<CHECK> blocks. | |
5548 | ||
5549 | =end original | |
5550 | ||
5551 | C<CHECK> ブロックの実行。 | |
5552 | ||
5553 | =item INIT | |
5554 | ||
5555 | =begin original | |
5556 | ||
5557 | Similar to "CHECK", but for C<INIT>-blocks, not C<CHECK> blocks. | |
5558 | ||
5559 | =end original | |
5560 | ||
5561 | "CHECK" と似ていますが、C<CHECK> ブロックではなく C<INIT> ブロック。 | |
5562 | ||
5563 | =item RUN | |
5564 | ||
5565 | =begin original | |
5566 | ||
5567 | The main run-time, i.e. the execution of C<PL_main_root>. | |
5568 | ||
5569 | =end original | |
5570 | ||
5571 | メインの実行; つまり C<PL_main_root> の実行。 | |
5572 | ||
5573 | =item END | |
5574 | ||
5575 | =begin original | |
5576 | ||
5577 | Execution of any C<END> blocks. | |
5578 | ||
5579 | =end original | |
5580 | ||
5581 | C<END> ブロックの実行。 | |
5582 | ||
5583 | =item DESTRUCT | |
5584 | ||
5585 | =begin original | |
5586 | ||
5587 | Global destruction. | |
5588 | ||
5589 | =end original | |
5590 | ||
5591 | グローバルなデストラクタ。 | |
5592 | ||
5593 | =back | |
5594 | ||
5595 | =begin original | |
5596 | ||
5597 | Also note that there's no value for UNITCHECK-blocks. That's because | |
5598 | those are run for each compilation unit individually, and therefore is | |
5599 | not a global interpreter phase. | |
5600 | ||
5601 | =end original | |
5602 | ||
5603 | また、UNITCHECK ブロックのための値はないことに注意してください。 | |
5604 | なぜなら、これらはコンパイルユニット毎に独立に実行され、従って | |
5605 | グローバルなインタプリタフェーズではないからです。 | |
5606 | ||
5607 | =begin original | |
5608 | ||
5609 | Not every program has to go through each of the possible phases, but | |
5610 | transition from one phase to another can only happen in the order | |
5611 | described in the above list. | |
5612 | ||
5613 | =end original | |
5614 | ||
5615 | 全てのプログラムが可能な全てのフェーズを通らなければならないわけでは | |
5616 | ありませんが、あるフェーズから他のフェーズへの移行は上述の | |
5617 | 順でのみ起こります。 | |
5618 | ||
5619 | =begin original | |
5620 | ||
5621 | An example of all of the phases Perl code can see: | |
5622 | ||
5623 | =end original | |
5624 | ||
5625 | Perl コードの全てのフェーズを見る例です: | |
5626 | ||
5627 | BEGIN { print "compile-time: ${^GLOBAL_PHASE}\n" } | |
5628 | ||
5629 | INIT { print "init-time: ${^GLOBAL_PHASE}\n" } | |
5630 | ||
5631 | CHECK { print "check-time: ${^GLOBAL_PHASE}\n" } | |
5632 | ||
5633 | { | |
5634 | package Print::Phase; | |
5635 | ||
5636 | sub new { | |
5637 | my ($class, $time) = @_; | |
5638 | return bless \$time, $class; | |
5639 | } | |
5640 | ||
5641 | sub DESTROY { | |
5642 | my $self = shift; | |
5643 | print "$$self: ${^GLOBAL_PHASE}\n"; | |
5644 | } | |
5645 | } | |
5646 | ||
5647 | print "run-time: ${^GLOBAL_PHASE}\n"; | |
5648 | ||
5649 | my $runtime = Print::Phase->new( | |
5650 | "lexical variables are garbage collected before END" | |
5651 | ); | |
5652 | ||
5653 | END { print "end-time: ${^GLOBAL_PHASE}\n" } | |
5654 | ||
5655 | our $destruct = Print::Phase->new( | |
5656 | "package variables are garbage collected after END" | |
5657 | ); | |
5658 | ||
5659 | =begin original | |
5660 | ||
5661 | This will print out | |
5662 | ||
5663 | =end original | |
5664 | ||
5665 | これは以下のものを出力します: | |
5666 | ||
5667 | compile-time: START | |
5668 | check-time: CHECK | |
5669 | init-time: INIT | |
5670 | run-time: RUN | |
5671 | lexical variables are garbage collected before END: RUN | |
5672 | end-time: END | |
5673 | package variables are garbage collected after END: DESTRUCT | |
5674 | ||
5675 | =begin original | |
5676 | ||
5677 | This variable was added in Perl 5.14.0. | |
5678 | ||
5679 | =end original | |
5680 | ||
5681 | この変数は Perl 5.14.0 で追加されました。 | |
5682 | ||
5683 | =item $^H | |
5684 | X<$^H> | |
5685 | ||
5686 | =begin original | |
5687 | ||
5688 | WARNING: This variable is strictly for | |
5689 | internal use only. Its availability, | |
5690 | behavior, and contents are subject to change without notice. | |
5691 | ||
5692 | =end original | |
5693 | ||
5694 | 警告: この変数は厳密に内部使用に限定されます。 | |
5695 | その可用性、挙動、内容は告知なく変更される可能性があります。 | |
5696 | ||
5697 | =begin original | |
5698 | ||
5699 | This variable contains compile-time hints for the Perl interpreter. At the | |
5700 | end of compilation of a BLOCK the value of this variable is restored to the | |
5701 | value when the interpreter started to compile the BLOCK. | |
5702 | ||
5703 | =end original | |
5704 | ||
5705 | この変数には Perl インタプリタのコンパイル時のヒントが入ります。 | |
5706 | BLOCK のコンパイル終了時に、この変数の値は | |
5707 | インタプリタが BLOCK のコンパイルを開始した時の値に戻されます。 | |
5708 | ||
5709 | =begin original | |
5710 | ||
5711 | Each time a statement completes being compiled, the current value of | |
5712 | C<$^H> is stored with that statement, and can later be retrieved via | |
5713 | C<(caller($level))[8]>. See L<perlfunc/caller EXPR>. | |
5714 | ||
5715 | =end original | |
5716 | ||
5717 | 文のコンパイルが完了する毎に、C<$^H> の現在の値が文と共に | |
5718 | 保管され、C<(caller($level))[8]> として後で取得できます。 | |
5719 | L<perlfunc/caller EXPR> を参照してください。 | |
5720 | ||
5721 | =begin original | |
5722 | ||
5723 | When perl begins to parse any block construct that provides a lexical scope | |
5724 | (e.g., eval body, required file, subroutine body, loop body, or conditional | |
5725 | block), the existing value of C<$^H> is saved, but its value is left unchanged. | |
5726 | When the compilation of the block is completed, it regains the saved value. | |
5727 | Between the points where its value is saved and restored, code that | |
5728 | executes within BEGIN blocks is free to change the value of C<$^H>. | |
5729 | ||
5730 | =end original | |
5731 | ||
5732 | Perl がレキシカルスコープを持つブロック構造(eval の中身、required された | |
5733 | ファイル、サブルーチンの中身、loop の中身、条件付きブロック)の | |
5734 | パースを開始するとき、現在の C<$^H> の値は保存されますが、値は | |
5735 | 変更されません。 | |
5736 | ブロックのコンパイルが終わると、保存された値が戻されます。 | |
5737 | 値の保存と回復の間の地点で、BEGIN ブロックの中で実行されるコードは自由に | |
5738 | C<$^H> の値を変更できます。 | |
5739 | ||
5740 | =begin original | |
5741 | ||
5742 | This behavior provides the semantic of lexical scoping, and is used in, | |
5743 | for instance, the C<use strict> pragma. | |
5744 | ||
5745 | =end original | |
5746 | ||
5747 | この振る舞いはレキシカルスコープを持ち、その中で使えます; 例としては | |
5748 | C<use strict> があります。 | |
5749 | ||
5750 | =begin original | |
5751 | ||
5752 | The contents should be an integer; different bits of it are used for | |
5753 | different pragmatic flags. Here's an example: | |
5754 | ||
5755 | =end original | |
5756 | ||
5757 | 内容は整数であるべきです; ビット毎に異なるプラグマフラグとして使われます。 | |
5758 | 以下は例です: | |
5759 | ||
5760 | sub add_100 { $^H |= 0x100 } | |
5761 | ||
5762 | sub foo { | |
5763 | BEGIN { add_100() } | |
5764 | bar->baz($boon); | |
5765 | } | |
5766 | ||
5767 | =begin original | |
5768 | ||
5769 | Consider what happens during execution of the BEGIN block. At this point | |
5770 | the BEGIN block has already been compiled, but the body of C<foo()> is still | |
5771 | being compiled. The new value of C<$^H> | |
5772 | will therefore be visible only while | |
5773 | the body of C<foo()> is being compiled. | |
5774 | ||
5775 | =end original | |
5776 | ||
5777 | BEGIN ブロックの実行中に起こることを考えてみます。 | |
5778 | この時点で BEGIN ブロックは既にコンパイルされていますが、 | |
5779 | C<foo()> の中身はまだコンパイル中です。 | |
5780 | 従って C<$^H> の新しい値は C<foo()> の中身がコンパイル中にのみ | |
5781 | 見ることが出来ます。 | |
5782 | ||
5783 | =begin original | |
5784 | ||
5785 | Substitution of C<BEGIN { add_100() }> block with: | |
5786 | ||
5787 | =end original | |
5788 | ||
5789 | C<BEGIN { add_100() }> ブロックを以下のように変更すると: | |
5790 | ||
5791 | BEGIN { require strict; strict->import('vars') } | |
5792 | ||
5793 | =begin original | |
5794 | ||
5795 | demonstrates how C<use strict 'vars'> is implemented. Here's a conditional | |
5796 | version of the same lexical pragma: | |
5797 | ||
5798 | =end original | |
5799 | ||
5800 | どのように C<use strict 'vars'> が実装されているかがわかります。 | |
5801 | 以下は同じレキシカルプラグマの条件付き版です: | |
5802 | ||
5803 | BEGIN { | |
5804 | require strict; strict->import('vars') if $condition | |
5805 | } | |
5806 | ||
5807 | =begin original | |
5808 | ||
5809 | This variable was added in Perl 5.003. | |
5810 | ||
5811 | =end original | |
5812 | ||
5813 | この変数は Perl 5.003 で追加されました。 | |
5814 | ||
5815 | =item %^H | |
5816 | X<%^H> | |
5817 | ||
5818 | =begin original | |
5819 | ||
5820 | The C<%^H> hash provides the same scoping semantics as L<C<$^H>|/$^H>. This | |
5821 | makes it useful for implementing lexically scoped pragmas. See L<perlpragma>. | |
5822 | All the entries are stringified when accessed at runtime, so only simple values | |
5823 | can be accommodated. This means no references to objects, for example. | |
5824 | ||
5825 | =end original | |
5826 | ||
5827 | C<%^H> ハッシュは L<C<$^H>|/$^H> と同じスコープの意味論を持ちます。 | |
5828 | これはレキシカルスコープを持つプラグマを実装するのに便利です。 | |
5829 | L<perlpragma> を参照してください。 | |
5830 | 実行時にアクセスされると全てのエントリは文字列化されるので、 | |
5831 | 単純な値のみに対応します。 | |
5832 | これは、例えばオブジェクトへのリファレンスはないということです。 | |
5833 | ||
5834 | =begin original | |
5835 | ||
5836 | Each time a statement completes being compiled, the current value of | |
5837 | C<%^H> is stored with that statement, and can later be retrieved via | |
5838 | C<(caller($level))[10]>. See L<perlfunc/caller EXPR>. | |
5839 | ||
5840 | =end original | |
5841 | ||
5842 | 文のコンパイルが完了する毎に、C<%^H> の現在の値が文と共に | |
5843 | 保管され、C<(caller($level))[10]> として後で取得できます。 | |
5844 | L<perlfunc/caller EXPR> を参照してください。 | |
5845 | ||
5846 | =begin original | |
5847 | ||
5848 | When putting items into C<%^H>, in order to avoid conflicting with other | |
5849 | users of the hash there is a convention regarding which keys to use. | |
5850 | A module should use only keys that begin with the module's name (the | |
5851 | name of its main package) and a "/" character. For example, a module | |
5852 | C<Foo::Bar> should use keys such as C<Foo::Bar/baz>. | |
5853 | ||
5854 | =end original | |
5855 | ||
5856 | C<%^H> に追加するとき、他のハッシュのユーザーとの衝突を回避するために、 | |
5857 | キーの使い方に関する慣習があります。 | |
5858 | モジュールはモジュールの名前(主なパッケージの名前)と "/" 文字で始まる | |
5859 | キーのみを使うべきです。 | |
5860 | 例えば、モジュール C<Foo::Bar> は C<Foo::Bar/baz> のようなキーを | |
5861 | 使うべきです。 | |
5862 | ||
5863 | =begin original | |
5864 | ||
5865 | This variable was added in Perl v5.6.0. | |
5866 | ||
5867 | =end original | |
5868 | ||
5869 | この変数は Perl v5.6.0 で追加されました。 | |
5870 | ||
5871 | =item ${^OPEN} | |
5872 | X<${^OPEN}> | |
5873 | ||
5874 | =begin original | |
5875 | ||
5876 | An internal variable used by L<PerlIO>. A string in two parts, separated | |
5877 | by a C<\0> byte, the first part describes the input layers, the second | |
5878 | part describes the output layers. | |
5879 | ||
5880 | =end original | |
5881 | ||
5882 | L<PerlIO> で使われる内部変数です。 | |
5883 | 文字列は C<\0> で分割された二つの部分からなり、前半は入力層を、 | |
5884 | 後半は出力層を示します。 | |
5885 | ||
5886 | =begin original | |
5887 | ||
5888 | This is the mechanism that applies the lexical effects of the L<open> | |
5889 | pragma, and the main program scope effects of the C<io> or C<D> options | |
5890 | for the L<-C command-line switch|perlrun/-C [I<numberE<sol>list>]> and | |
5891 | L<PERL_UNICODE environment variable|perlrun/PERL_UNICODE>. | |
5892 | ||
5893 | =end original | |
5894 | ||
5895 | これは L<open> プラグマおよび、C<io> や | |
5896 | L<-C コマンドラインオプション|perlrun/-C [I<numberE<sol>list>]> と | |
5897 | L<PERL_UNICODE 環境変数|perlrun/PERL_UNICODE> の C<D> オプションの | |
5898 | メインプログラムスコープにレキシカルな効果を適用するための機構です。 | |
5899 | ||
5900 | =begin original | |
5901 | ||
5902 | The functions C<accept()>, C<open()>, C<pipe()>, C<readpipe()> (as well | |
5903 | as the related C<qx> and C<`STRING`> operators), C<socket()>, | |
5904 | C<socketpair()>, and C<sysopen()> are affected by the lexical value of | |
5905 | this variable. The implicit L</ARGV> handle opened by C<readline()> (or | |
5906 | the related C<< <> >> and C<<< <<>> >>> operators) on passed filenames is | |
5907 | also affected (but not if it opens C<STDIN>). If this variable is not | |
5908 | set, these functions will set the default layers as described in | |
5909 | L<PerlIO/Defaults and how to override them>. | |
5910 | ||
5911 | =end original | |
5912 | ||
5913 | C<accept()>, C<open()>, C<pipe()>, C<readpipe()> (および関連する | |
5914 | C<qx> と C<`STRING`> 演算子), C<socket()>, | |
5915 | C<socketpair()>, C<sysopen()> 関数は、この変数のレキシカルな値に | |
5916 | 影響を受けます。 | |
5917 | C<readline()> (や関連する C<< <> >> と C<<< <<>> >>> 演算子) に | |
5918 | ファイル名を渡すことによって開かれた暗黙の L</ARGV> も影響を受けます | |
5919 | (しかし C<STDIN> を開いている場合は影響を受けません)。 | |
5920 | この変数が設定されていない場合、これらの関数は | |
5921 | L<PerlIO/Defaults and how to override them> で記述されている | |
5922 | デフォルト層が設定されます。 | |
5923 | ||
5924 | =begin original | |
5925 | ||
5926 | C<open()> ignores this variable (and the default layers) when called with | |
5927 | 3 arguments and explicit layers are specified. Indirect calls to these | |
5928 | functions via modules like L<IO::Handle> are not affected as they occur | |
5929 | in a different lexical scope. Directory handles such as opened by | |
5930 | C<opendir()> are not currently affected. | |
5931 | ||
5932 | =end original | |
5933 | ||
5934 | C<open()> は、3 引数で呼び出され、明示的な層が指定された場合は | |
5935 | この変数(およびデフォルト層)を無視します。 | |
5936 | L<IO::Handle> のようなモジュール経由でのこれらの関数の間接的な呼び出しは | |
5937 | 影響を受けません; これらは異なったレキシカルスコープで起きるからです。 | |
5938 | C<opendir()> で開かれたようなディレクトリハンドルは現在の所 | |
5939 | 影響を受けません。 | |
5940 | ||
5941 | =begin original | |
5942 | ||
5943 | This variable was added in Perl v5.8.0. | |
5944 | ||
5945 | =end original | |
5946 | ||
5947 | この変数は Perl v5.8.0 で追加されました。 | |
5948 | ||
5949 | =item $PERLDB | |
5950 | ||
5951 | =item $^P | |
5952 | X<$^P> X<$PERLDB> | |
5953 | ||
5954 | =begin original | |
5955 | ||
5956 | The internal variable for debugging support. The meanings of the | |
5957 | various bits are subject to change, but currently indicate: | |
5958 | ||
5959 | =end original | |
5960 | ||
5961 | デバッグ機能のための内部変数です。 | |
5962 | それぞれのビットの意味は変わるかもしれませんが、 | |
5963 | 現在のところは以下の通りです: | |
5964 | ||
5965 | =over 6 | |
5966 | ||
5967 | =item 0x01 | |
5968 | ||
5969 | =begin original | |
5970 | ||
5971 | Debug subroutine enter/exit. | |
5972 | ||
5973 | =end original | |
5974 | ||
5975 | サブルーチンの出入りをデバッグします。 | |
5976 | ||
5977 | =item 0x02 | |
5978 | ||
5979 | =begin original | |
5980 | ||
5981 | Line-by-line debugging. Causes C<DB::DB()> subroutine to be called for | |
5982 | each statement executed. Also causes saving source code lines (like | |
5983 | 0x400). | |
5984 | ||
5985 | =end original | |
5986 | ||
5987 | 行毎にデバッグします。 | |
5988 | 各行を実行する毎に C<DB::DB()> サブルーチンを呼び出します。 | |
5989 | さらに、(0x400 のように) ソースコードを保存します。 | |
5990 | ||
5991 | =item 0x04 | |
5992 | ||
5993 | =begin original | |
5994 | ||
5995 | Switch off optimizations. | |
5996 | ||
5997 | =end original | |
5998 | ||
5999 | 最適化を行いません。 | |
6000 | ||
6001 | =item 0x08 | |
6002 | ||
6003 | =begin original | |
6004 | ||
6005 | Preserve more data for future interactive inspections. | |
6006 | ||
6007 | =end original | |
6008 | ||
6009 | 将来の対話的な検査のためにより多くのデータを保存します。 | |
6010 | ||
6011 | =item 0x10 | |
6012 | ||
6013 | =begin original | |
6014 | ||
6015 | Keep info about source lines on which a subroutine is defined. | |
6016 | ||
6017 | =end original | |
6018 | ||
6019 | サブルーチンが定義されたソース行に関する情報を保持します。 | |
6020 | ||
6021 | =item 0x20 | |
6022 | ||
6023 | =begin original | |
6024 | ||
6025 | Start with single-step on. | |
6026 | ||
6027 | =end original | |
6028 | ||
6029 | シングルステップ実行で開始します。 | |
6030 | ||
6031 | =item 0x40 | |
6032 | ||
6033 | =begin original | |
6034 | ||
6035 | Use subroutine address instead of name when reporting. | |
6036 | ||
6037 | =end original | |
6038 | ||
6039 | 報告時にサブルーチン名でなくサブルーチンのアドレスを使います。 | |
6040 | ||
6041 | =item 0x80 | |
6042 | ||
6043 | =begin original | |
6044 | ||
6045 | Report C<goto &subroutine> as well. | |
6046 | ||
6047 | =end original | |
6048 | ||
6049 | C<goto &subroutine> も同様に報告します。 | |
6050 | ||
6051 | =item 0x100 | |
6052 | ||
6053 | =begin original | |
6054 | ||
6055 | Provide informative "file" names for evals based on the place they were compiled. | |
6056 | ||
6057 | =end original | |
6058 | ||
6059 | eval に対して、コンパイルされた位置を元にした「ファイル」名を提供します。 | |
6060 | ||
6061 | =item 0x200 | |
6062 | ||
6063 | =begin original | |
6064 | ||
6065 | Provide informative names to anonymous subroutines based on the place they | |
6066 | were compiled. | |
6067 | ||
6068 | =end original | |
6069 | ||
6070 | 無名サブルーチンに対して、 | |
6071 | コンパイルされた位置を基にした参考名を提供します。 | |
6072 | ||
6073 | =item 0x400 | |
6074 | ||
6075 | =begin original | |
6076 | ||
6077 | Save source code lines into C<@{"_<$filename"}>. | |
6078 | ||
6079 | =end original | |
6080 | ||
6081 | ソースコードの行数を C<@{"_<$filename"}> に保存します。 | |
6082 | ||
6083 | =item 0x800 | |
6084 | ||
6085 | =begin original | |
6086 | ||
6087 | When saving source, include evals that generate no subroutines. | |
6088 | ||
6089 | =end original | |
6090 | ||
6091 | ソースを保存するときに、サブルーチンがない eval を含みます。 | |
6092 | ||
6093 | =item 0x1000 | |
6094 | ||
6095 | =begin original | |
6096 | ||
6097 | When saving source, include source that did not compile. | |
6098 | ||
6099 | =end original | |
6100 | ||
6101 | ソースを保存するときに、コンパイルしていないソースを含みます。 | |
6102 | ||
6103 | =back | |
6104 | ||
6105 | =begin original | |
6106 | ||
6107 | Some bits may be relevant at compile-time only, some at | |
6108 | run-time only. This is a new mechanism and the details may change. | |
6109 | See also L<perldebguts>. | |
6110 | ||
6111 | =end original | |
6112 | ||
6113 | 一部のビットはコンパイル時にのみまたは実行時にのみ意味があります。 | |
6114 | これは新しい機構であり、詳細は変更されるかもしれません。 | |
6115 | L<perldebguts> も参照してください。 | |
6116 | ||
6117 | =item ${^TAINT} | |
6118 | X<${^TAINT}> | |
6119 | ||
6120 | =begin original | |
6121 | ||
6122 | Reflects if taint mode is on or off. 1 for on (the program was run with | |
6123 | B<-T>), 0 for off, -1 when only taint warnings are enabled (i.e. with | |
6124 | B<-t> or B<-TU>). | |
6125 | ||
6126 | =end original | |
6127 | ||
6128 | 汚染検査モードのオン・オフを反映します。 | |
6129 | 1 はオン(プログラムは B<-T> 付きで実行されている)、0 はオフ、-1 は汚染 | |
6130 | 警告のみが有効になっている(つまり B<-t> か B<-TU>)ことを意味します。 | |
6131 | ||
6132 | =begin original | |
6133 | ||
6134 | Note: if your perl was built without taint support (see L<perlsec>), | |
6135 | then C<${^TAINT}> will always be 0, even if the program was run with B<-T>). | |
6136 | ||
6137 | =end original | |
6138 | ||
6139 | 注意: perl が汚染チェック対応 (L<perlsec> 参照) なしでビルドされている場合、 | |
6140 | たとえプログラムが B<-T> 付きで実行されていても、 | |
6141 | C<${^TAINT}> は常に 0 です。 | |
6142 | ||
6143 | =begin original | |
6144 | ||
6145 | This variable is read-only. | |
6146 | ||
6147 | =end original | |
6148 | ||
6149 | この変数は読み込み専用です。 | |
6150 | ||
6151 | =begin original | |
6152 | ||
6153 | This variable was added in Perl v5.8.0. | |
6154 | ||
6155 | =end original | |
6156 | ||
6157 | この変数は Perl v5.8.0 で追加されました。 | |
6158 | ||
6159 | =item ${^SAFE_LOCALES} | |
6160 | X<${^SAFE_LOCALES}> | |
6161 | ||
6162 | =begin original | |
6163 | ||
6164 | Reflects if safe locale operations are available to this perl (when the | |
6165 | value is 1) or not (the value is 0). This variable is always 1 if the | |
6166 | perl has been compiled without threads. It is also 1 if this perl is | |
6167 | using thread-safe locale operations. Note that an individual thread may | |
6168 | choose to use the global locale (generally unsafe) by calling | |
6169 | L<perlapi/switch_to_global_locale>. This variable currently is still | |
6170 | set to 1 in such threads. | |
6171 | ||
6172 | =end original | |
6173 | ||
6174 | この perl で安全なロケール操作が利用可能 (値が 1 の場合) かそうでない | |
6175 | (値が 0 の場合) かを反映します。 | |
6176 | この変数は、perl がスレッドなしでコンパイルされている場合は常に 1 です。 | |
6177 | また、perl がスレッドセーフなロケール操作を使っている場合は 1 です。 | |
6178 | 個々のスレッドは L<perlapi/switch_to_global_locale> を呼び出すことで | |
6179 | (一般的にはスレッドセーフでない) グローバルなロケールを使うことを | |
6180 | 選ぶかも知れないことに注意してください。 | |
6181 | この変数はそのようなスレッドでも 1 のままです。 | |
6182 | ||
6183 | =begin original | |
6184 | ||
6185 | This variable is read-only. | |
6186 | ||
6187 | =end original | |
6188 | ||
6189 | この変数は読み込み専用です。 | |
6190 | ||
6191 | =begin original | |
6192 | ||
6193 | This variable was added in Perl v5.28.0. | |
6194 | ||
6195 | =end original | |
6196 | ||
6197 | この変数は Perl v5.28.0 で追加されました。 | |
6198 | ||
6199 | =item ${^UNICODE} | |
6200 | X<${^UNICODE}> | |
6201 | ||
6202 | =begin original | |
6203 | ||
6204 | Reflects certain Unicode settings of Perl. See | |
6205 | L<perlrun|perlrun/-C [numberE<sol>list]> documentation for the C<-C> | |
6206 | switch for more information about the possible values. | |
6207 | ||
6208 | =end original | |
6209 | ||
6210 | Perl のいくつかの Unicode 設定を反映します。 | |
6211 | 設定できる値に関するさらなる情報については | |
6212 | L<perlrun|perlrun/-C [numberE<sol>list]> の C<-C> オプションを | |
6213 | 参照してください。 | |
6214 | ||
6215 | =begin original | |
6216 | ||
6217 | This variable is set during Perl startup and is thereafter read-only. | |
6218 | ||
6219 | =end original | |
6220 | ||
6221 | この変数は Perl 起動時に設定され、その後は読み込み専用です。 | |
6222 | ||
6223 | =begin original | |
6224 | ||
6225 | This variable was added in Perl v5.8.2. | |
6226 | ||
6227 | =end original | |
6228 | ||
6229 | この変数は Perl v5.8.2 で追加されました。 | |
6230 | ||
6231 | =item ${^UTF8CACHE} | |
6232 | X<${^UTF8CACHE}> | |
6233 | ||
6234 | =begin original | |
6235 | ||
6236 | This variable controls the state of the internal UTF-8 offset caching code. | |
6237 | 1 for on (the default), 0 for off, -1 to debug the caching code by checking | |
6238 | all its results against linear scans, and panicking on any discrepancy. | |
6239 | ||
6240 | =end original | |
6241 | ||
6242 | この変数は内部 UTF-8 オフセットキャッシュコードの状態を制御します。 | |
6243 | 1 はオン(デフォルト)、0 はオフ、-1 は全ての結果を線形走査と比較して、 | |
6244 | 矛盾があれば異常終了する、という形でキャッシュコードをデバッグします。 | |
6245 | ||
6246 | =begin original | |
6247 | ||
6248 | This variable was added in Perl v5.8.9. It is subject to change or | |
6249 | removal without notice, but is currently used to avoid recalculating the | |
6250 | boundaries of multi-byte UTF-8-encoded characters. | |
6251 | ||
6252 | =end original | |
6253 | ||
6254 | この変数は Perl v5.8.9 で追加されました。 | |
6255 | これは予告なく変更されたり削除されたりするかもしれませんが、現在のところ | |
6256 | 複数バイト UTF-8 エンコード文字の境界の再計算を避けるために使われます。 | |
6257 | ||
6258 | =item ${^UTF8LOCALE} | |
6259 | X<${^UTF8LOCALE}> | |
6260 | ||
6261 | =begin original | |
6262 | ||
6263 | This variable indicates whether a UTF-8 locale was detected by perl at | |
6264 | startup. This information is used by perl when it's in | |
6265 | adjust-utf8ness-to-locale mode (as when run with the C<-CL> command-line | |
6266 | switch); see L<perlrun|perlrun/-C [numberE<sol>list]> for more info on | |
6267 | this. | |
6268 | ||
6269 | =end original | |
6270 | ||
6271 | この変数は、起動時に perl によって UTF-8 ロケールが検出されたかどうかを | |
6272 | 示します。 | |
6273 | この情報は(C<-CL> コマンドラインスイッチで起動されることによって) | |
6274 | 「utf8 性をロケールに合わせる」モードのときに perl によって使われます; | |
6275 | これに関するさらなる情報は | |
6276 | L<perlrun|perlrun/-C [numberE<sol>list]> を参照してください。 | |
6277 | ||
6278 | =begin original | |
6279 | ||
6280 | This variable was added in Perl v5.8.8. | |
6281 | ||
6282 | =end original | |
6283 | ||
6284 | この変数は Perl v5.8.8 で追加されました。 | |
6285 | ||
6286 | =back | |
6287 | ||
4696 | 6288 | =head2 Deprecated and removed variables |
4697 | 6289 | |
4698 | 6290 | (非推奨および削除された変数) |
4699 | 6291 | |
4700 | 6292 | =begin original |
4701 | 6293 | |
4702 | 6294 | Deprecating a variable announces the intent of the perl maintainers to |
4703 | eventually remove the variable from the lang | |
6295 | eventually remove the variable from the language. It may still be | |
4704 | available despite its status. Using a deprecated variable triggers | |
6296 | available despite its status. Using a deprecated variable triggers | |
4705 | 6297 | a warning. |
4706 | 6298 | |
4707 | 6299 | =end original |
4708 | 6300 | |
4709 | 6301 | 非推奨となった変数は、perl のメンテナが最終的にこの変数を |
4710 | 6302 | 削除するということを意図して通知されます。 |
4711 | 6303 | その状態にも関わらず、まだ利用可能です。 |
4712 | 6304 | 非推奨となった変数を使うと警告が出ます。 |
4713 | 6305 | |
4714 | 6306 | =begin original |
4715 | 6307 | |
4716 | 6308 | Once a variable is removed, its use triggers an error telling you |
4717 | 6309 | the variable is unsupported. |
4718 | 6310 | |
4719 | 6311 | =end original |
4720 | 6312 | |
4721 | 6313 | 変数が削除された後で変数を使うと、この変数が非対応となったことを |
4722 | 6314 | 知らせるエラーが出ます。 |
4723 | 6315 | |
4724 | 6316 | =begin original |
4725 | 6317 | |
4726 | 6318 | See L<perldiag> for details about error messages. |
4727 | 6319 | |
4728 | 6320 | =end original |
4729 | 6321 | |
4730 | 6322 | エラーメッセージの詳細については L<perldiag> を参照してください。 |
4731 | 6323 | |
4732 | 6324 | =over 8 |
4733 | 6325 | |
4734 | =item $OFMT | |
4735 | ||
4736 | 6326 | =item $# |
4737 | X<$#> | |
6327 | X<$#> | |
4738 | 6328 | |
4739 | 6329 | =begin original |
4740 | 6330 | |
4741 | C<$#> was a variable that | |
6331 | C<$#> was a variable that could be used to format printed numbers. | |
4742 | After a deprecation cycle, its magic was removed in Perl 5.10 and | |
6332 | After a deprecation cycle, its magic was removed in Perl v5.10.0 and | |
4743 | 6333 | using it now triggers a warning: C<$# is no longer supported>. |
4744 | 6334 | |
4745 | 6335 | =end original |
4746 | 6336 | |
4747 | 6337 | C<$#> は、表示番号をフォーマットするために使われていました。 |
4748 | 非推奨化の後、このマジックは Perl 5.10 で取り除かれ、警告を | |
6338 | 非推奨化の後、このマジックは Perl v5.10.0 で取り除かれ、警告を | |
4749 | 6339 | 引き起こします: C<$# is no longer supported>. |
4750 | 6340 | |
4751 | 6341 | =begin original |
4752 | 6342 | |
4753 | 6343 | This is not the sigil you use in front of an array name to get the |
4754 | last index, like C<$#array>. That's still how you get the last index | |
6344 | last index, like C<$#array>. That's still how you get the last index | |
4755 | of an array in Perl. The two have nothing to do with each other. | |
6345 | of an array in Perl. The two have nothing to do with each other. | |
4756 | 6346 | |
4757 | 6347 | =end original |
4758 | 6348 | |
4759 | 6349 | これは C<$#array> のように最後のインデックスを得るために配列名の前に付ける |
4760 | 6350 | 印ではありません。 |
4761 | 6351 | これは今でも Perl で配列の最後のインデックスを得る方法です。 |
4762 | 6352 | これら二つには互いに何の関係もありません。 |
4763 | 6353 | |
4764 | 6354 | =begin original |
4765 | 6355 | |
4766 | 6356 | Deprecated in Perl 5. |
4767 | 6357 | |
4768 | 6358 | =end original |
4769 | 6359 | |
4770 | 6360 | Perl 5 で非推奨となりました。 |
4771 | 6361 | |
4772 | 6362 | =begin original |
4773 | 6363 | |
4774 | Removed in Perl 5.10. | |
6364 | Removed in Perl v5.10.0. | |
4775 | 6365 | |
4776 | 6366 | =end original |
4777 | 6367 | |
4778 | Perl 5.10 で削除されました。 | |
6368 | Perl v5.10.0 で削除されました。 | |
4779 | 6369 | |
4780 | 6370 | =item $* |
4781 | 6371 | X<$*> |
4782 | 6372 | |
4783 | 6373 | =begin original |
4784 | 6374 | |
4785 | 6375 | C<$*> was a variable that you could use to enable multiline matching. |
4786 | After a deprecation cycle, its magic was removed in Perl 5.10. | |
6376 | After a deprecation cycle, its magic was removed in Perl v5.10.0. | |
4787 | 6377 | Using it now triggers a warning: C<$* is no longer supported>. |
4788 | 6378 | You should use the C</s> and C</m> regexp modifiers instead. |
4789 | 6379 | |
4790 | 6380 | =end original |
4791 | 6381 | |
4792 | 6382 | C<$*> は複数行マッチングを有効にするために使われていた変数です。 |
4793 | 非推奨化の後、このマジックは Perl 5.10 で削除されました。 | |
6383 | 非推奨化の後、このマジックは Perl v5.10.0 で削除されました。 | |
4794 | 6384 | これを使うと警告を引き起こします: C<$* is no longer supported>。 |
4795 | 6385 | 代わりに C</s> と C</m> の正規表現修飾子を使うべきです。 |
4796 | 6386 | |
4797 | 6387 | =begin original |
4798 | 6388 | |
4799 | 6389 | Deprecated in Perl 5. |
4800 | 6390 | |
4801 | 6391 | =end original |
4802 | 6392 | |
4803 | 6393 | Perl 5 で非推奨となりました。 |
4804 | 6394 | |
4805 | 6395 | =begin original |
4806 | 6396 | |
4807 | Removed in Perl 5.10. | |
6397 | Removed in Perl v5.10.0. | |
4808 | 6398 | |
4809 | 6399 | =end original |
4810 | 6400 | |
4811 | Perl 5.10 で削除されました。 | |
6401 | Perl v5.10.0 で削除されました。 | |
4812 | 6402 | |
4813 | =item $ARRAY_BASE | |
4814 | ||
4815 | 6403 | =item $[ |
4816 | X<$[> | |
6404 | X<$[> | |
4817 | 6405 | |
4818 | 6406 | =begin original |
4819 | 6407 | |
4820 | 6408 | This variable stores the index of the first element in an array, and |
4821 | of the first character in a substring. The default is 0, but you could | |
6409 | of the first character in a substring. The default is 0, but you could | |
4822 | 6410 | theoretically set it to 1 to make Perl behave more like B<awk> (or Fortran) |
4823 | 6411 | when subscripting and when evaluating the index() and substr() functions. |
4824 | 6412 | |
4825 | 6413 | =end original |
4826 | 6414 | |
4827 | 6415 | この変数は配列の最初の要素や、文字列の最初の文字のインデックスを |
4828 | 6416 | 保管します。 |
4829 | 6417 | デフォルトは 0 ですが、理論的には、index() 関数や |
4830 | 6418 | substr() 関数を評価するときに、Perl の動作をより B<awk> |
4831 | 6419 | (や Fortran) に近づけるため、1 に設定することもできます。 |
4832 | 6420 | |
4833 | 6421 | =begin original |
4834 | 6422 | |
4835 | 6423 | As of release 5 of Perl, assignment to C<$[> is treated as a compiler |
4836 | 6424 | directive, and cannot influence the behavior of any other file. |
4837 | 6425 | (That's why you can only assign compile-time constants to it.) |
4838 | 6426 | Its use is highly discouraged. |
4839 | 6427 | |
4840 | 6428 | =end original |
4841 | 6429 | |
4842 | 6430 | Perl 5 からは C<$[> への代入は、コンパイラ指示子として扱われ、 |
4843 | 6431 | 他のファイルの動作に影響を与えることがなくなりました。 |
4844 | 6432 | (これが、コンパイル時定数しか代入できない理由です。) |
4845 | 6433 | この変数の使用は非推奨です。 |
4846 | 6434 | |
4847 | 6435 | =begin original |
4848 | 6436 | |
4849 | Prior to Perl 5.10, assignment to C<$[> could be seen from outer lexical | |
6437 | Prior to Perl v5.10.0, assignment to C<$[> could be seen from outer lexical | |
4850 | 6438 | scopes in the same file, unlike other compile-time directives (such as |
4851 | L<strict>). Using local() on it would bind its value strictly to a lexical | |
6439 | L<strict>). Using local() on it would bind its value strictly to a lexical | |
4852 | block. Now it is always lexically scoped. | |
6440 | block. Now it is always lexically scoped. | |
4853 | 6441 | |
4854 | 6442 | =end original |
4855 | 6443 | |
4856 | Perl 5.10 より前では、C<$[> は(L<strict> のような)その他のコンパイル時 | |
6444 | Perl v5.10.0 より前では、C<$[> は(L<strict> のような)その他のコンパイル時 | |
4857 | 6445 | 指示子と異なり、同じファイルのレキシカルスコープの外側から見ることが |
4858 | 6446 | 出来ていました。 |
4859 | 6447 | これに local() を使うとこの値を厳密にレキシカルスコープの内側に限定します。 |
4860 | 6448 | 今では常にレキシカルスコープを持ちます。 |
4861 | 6449 | |
4862 | 6450 | =begin original |
4863 | 6451 | |
6452 | As of Perl v5.16.0, it is implemented by the L<arybase> module. | |
6453 | ||
6454 | =end original | |
6455 | ||
6456 | Perl v5.16.0 から、これは L<arybase> モジュールで実装されています。 | |
6457 | ||
6458 | =begin original | |
6459 | ||
6460 | As of Perl v5.30.0, or under C<use v5.16>, or C<no feature "array_base">, | |
6461 | C<$[> no longer has any effect, and always contains 0. | |
6462 | Assigning 0 to it is permitted, but any other value will produce an error. | |
6463 | ||
6464 | =end original | |
6465 | ||
6466 | Perl v5.30.0 以降か、C<use v5.16> または C<no feature "array_base"> の基では、 | |
6467 | C<$[> はもはや何の効果もなく、常に 0 が入っています。 | |
6468 | これに 0 を代入することは許されますが、それ以外の値はエラーを引き起こします。 | |
6469 | ||
6470 | =begin original | |
6471 | ||
4864 | 6472 | Mnemonic: [ begins subscripts. |
4865 | 6473 | |
4866 | 6474 | =end original |
4867 | 6475 | |
4868 | 6476 | 記憶法: [ は添え字付けの始め。 |
4869 | 6477 | |
4870 | 6478 | =begin original |
4871 | 6479 | |
4872 | Deprecated in Perl 5.12. | |
6480 | Deprecated in Perl v5.12.0. | |
4873 | 6481 | |
4874 | 6482 | =end original |
4875 | 6483 | |
4876 | Perl 5.12 で非推奨となりました。 | |
6484 | Perl v5.12.0 で非推奨となりました。 | |
4877 | 6485 | |
4878 | =item $O | |
6486 | =item ${^ENCODING} | |
6487 | X<${^ENCODING}> | |
4879 | 6488 | |
4880 | = | |
6489 | =begin original | |
4881 | X<$]> X<$OLD_PERL_VERSION> | |
4882 | 6490 | |
6491 | This variable is no longer supported. | |
6492 | ||
6493 | =end original | |
6494 | ||
6495 | この変数はもはや対応していません。 | |
6496 | ||
4883 | 6497 | =begin original |
4884 | 6498 | |
4885 | ||
6499 | It used to hold the I<object reference> to the C<Encode> object that was | |
4886 | ||
6500 | used to convert the source code to Unicode. | |
4887 | 6501 | |
4888 | 6502 | =end original |
4889 | 6503 | |
4890 | ||
6504 | これはソースコードを Unicode に変換するために使われる | |
4891 | C< | |
6505 | C<Encode> オブジェクトへの I<オブジェクトリファレンス> を保持していました。 | |
4892 | 6506 | |
4893 | 6507 | =begin original |
4894 | 6508 | |
4895 | ||
6509 | Its purpose was to allow your non-ASCII Perl | |
4896 | c | |
6510 | scripts not to have to be written in UTF-8; this was | |
4897 | s | |
6511 | useful before editors that worked on UTF-8 encoded text were common, but | |
6512 | that was long ago. It caused problems, such as affecting the operation | |
6513 | of other modules that weren't expecting it, causing general mayhem. | |
4898 | 6514 | |
4899 | 6515 | =end original |
4900 | 6516 | |
4901 | Perl | |
6517 | この目的は、非 ASCII Perl スクリプトを UTF-8 で書く必要をなくすためでした; | |
4902 | ス | |
6518 | これは UTF-8 エンコードされたテキストで動作するエディタが一般的になる前は | |
4903 | ||
6519 | 有用でしたが、それはずっと前です。 | |
4904 | ||
6520 | これは、想定してない他のモジュールの操作に影響を与えるような問題を引き起こし、 | |
6521 | 一般的には破壊的です。 | |
4905 | 6522 | |
4906 | ||
6523 | =begin original | |
4907 | 6524 | |
6525 | If you need something like this functionality, it is recommended that use | |
6526 | you a simple source filter, such as L<Filter::Encoding>. | |
6527 | ||
6528 | =end original | |
6529 | ||
6530 | この機能のような何かが必要な場合は、L<Filter::Encoding> のような | |
6531 | 単純なソースフィルタを使うことを勧めます。 | |
6532 | ||
4908 | 6533 | =begin original |
4909 | 6534 | |
4910 | ||
6535 | If you are coming here because code of yours is being adversely affected | |
4911 | nu | |
6536 | by someone's use of this variable, you can usually work around it by | |
6537 | doing this: | |
4912 | 6538 | |
4913 | 6539 | =end original |
4914 | 6540 | |
4915 | ||
6541 | あなたがここに来た理由が、誰かがこの変数を使うことであなたのコードが | |
4916 | ||
6542 | 意図せずに影響を受けたためなら、通常は次のようにして回避できます: | |
4917 | 参照して下さい。 | |
4918 | 6543 | |
6544 | local ${^ENCODING}; | |
6545 | ||
4919 | 6546 | =begin original |
4920 | 6547 | |
4921 | ||
6548 | near the beginning of the functions that are getting broken. This | |
4922 | ||
6549 | undefines the variable during the scope of execution of the including | |
6550 | function. | |
4923 | 6551 | |
4924 | 6552 | =end original |
4925 | 6553 | |
4926 | ||
6554 | これを壊れてしまった関数の先頭付近に書きます。 | |
4927 | ||
6555 | これにより、この関数を含むスコープを実行する間この変数を未定義にします。 | |
4928 | 参照して下さい。 | |
4929 | 6556 | |
4930 | 6557 | =begin original |
4931 | 6558 | |
4932 | ||
6559 | This variable was added in Perl 5.8.2 and removed in 5.26.0. | |
6560 | Setting it to anything other than C<undef> was made fatal in Perl 5.28.0. | |
4933 | 6561 | |
4934 | 6562 | =end original |
4935 | 6563 | |
4936 | ||
6564 | この変数は Perl 5.8.2 で追加され、5.26.0 で削除されました。 | |
6565 | Perl 5.28.0 から、これに C<undef> 以外の値を設定すると致命的エラーになります。 | |
4937 | 6566 | |
6567 | =item ${^WIN32_SLOPPY_STAT} | |
6568 | X<${^WIN32_SLOPPY_STAT}> X<sitecustomize> X<sitecustomize.pl> | |
6569 | ||
4938 | 6570 | =begin original |
4939 | 6571 | |
4940 | ||
6572 | This variable no longer has any function. | |
4941 | 6573 | |
4942 | 6574 | =end original |
4943 | 6575 | |
4944 | ||
6576 | この変数はもはや何の機能もありません。 | |
4945 | 6577 | |
6578 | =begin original | |
6579 | ||
6580 | This variable was added in Perl v5.10.0 and removed in Perl v5.34.0. | |
6581 | ||
6582 | =end original | |
6583 | ||
6584 | この変数は Perl v5.10.0 で追加され、Perl v5.34.0 で削除されました。 | |
6585 | ||
4946 | 6586 | =back |
4947 | 6587 | |
6588 | =cut | |
6589 | ||
4948 | 6590 | =begin meta |
4949 | 6591 | |
4950 | 6592 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> (5.000) |
4951 | 6593 | Update: Kentaro Shirakata <argrath@ub32.org> (5.6.1-) |
6594 | Status: completed | |
4952 | 6595 | |
4953 | 6596 | =end meta |
4954 | ||
4955 | =cut |