perlvar >
5.30.0
との差分
perlvar 5.30.0 と 5.28.0 の差分
1 | 1 | |
2 | 2 | =encoding euc-jp |
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 | 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 | 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 | 28 | A Unicode letter that is not ASCII is not considered to be a letter |
29 | 29 | unless S<C<"use utf8">> is in effect, and somewhat more complicated |
30 | 30 | rules apply; see L<perldata/Identifier parsing> for details. |
31 | 31 | |
32 | 32 | =end original |
33 | 33 | |
34 | 34 | Perl の変数名は様々な形があります。 |
35 | 35 | 通常、変数名は英文字か下線で始まらなければならず、 |
36 | 36 | 任意の長さ(内部制限の 251 文字まで)を取ることができ、 |
37 | 37 | 英文字、数字、下線、特別な文字列である C<::> と C<'> を含むことができます。 |
38 | 38 | この場合、最後の C<::> または C<'> の前は I<パッケージ限定子> として |
39 | 39 | 扱われます; L<perlmod> を参照して下さい。 |
40 | 40 | ASCII ではない Unicode 文字は、S<C<"use utf8">> が有効でない限り |
41 | 41 | 文字として扱われません; そしていくらかより複雑な規則が適用されます; |
42 | 42 | 詳しくは L<perldata/Identifier parsing> を参照してください。 |
43 | 43 | |
44 | 44 | =begin original |
45 | 45 | |
46 | 46 | Perl variable names may also be a sequence of digits, a single |
47 | 47 | punctuation character, or the two-character sequence: C<^> (caret or |
48 | 48 | CIRCUMFLEX ACCENT) followed by any one of the characters C<[][A-Z^_?\]>. |
49 | 49 | These names are all reserved for |
50 | 50 | special uses by Perl; for example, the all-digits names are used |
51 | 51 | to hold data captured by backreferences after a regular expression |
52 | 52 | match. |
53 | 53 | |
54 | 54 | =end original |
55 | 55 | |
56 | 56 | Perl の変数は、数字の列または一文字の句読点文字、2 文字並び( |
57 | 57 | C<^> (キャレット、CIRCUMFLEX ACCENT) に引き続いて C<[][A-Z^_?\]> の文字の一つ) |
58 | 58 | の場合もあります。 |
59 | 59 | これらの名前は全て Perl によって特別な用途のために予約されています; |
60 | 60 | 例えば、全て数字の名前は正規表現マッチの後の後方参照のデータを |
61 | 61 | 保持するために用いられます。 |
62 | 62 | |
63 | 63 | =begin original |
64 | 64 | |
65 | 65 | Since Perl v5.6.0, Perl variable names may also be alphanumeric strings |
66 | 66 | preceded by a caret. These must all be written in the form C<${^Foo}>; |
67 | 67 | the braces are not optional. C<${^Foo}> denotes the scalar variable |
68 | 68 | whose name is considered to be a control-C<F> followed by two C<o>'s. |
69 | 69 | These variables are |
70 | 70 | reserved for future special uses by Perl, except for the ones that |
71 | 71 | begin with C<^_> (caret-underscore). No |
72 | 72 | name that begins with C<^_> will acquire a special |
73 | 73 | meaning in any future version of Perl; such names may therefore be |
74 | 74 | used safely in programs. C<$^_> itself, however, I<is> reserved. |
75 | 75 | |
76 | 76 | =end original |
77 | 77 | |
78 | 78 | Perl v5.6.0 から、キャレットが前置された、英数字からなる文字列の変数名も |
79 | 79 | 使えます。 |
80 | 80 | これらは全て C<${^Foo}> の形で書かれなければなりません; |
81 | 81 | 括弧は必須です。 |
82 | 82 | C<${^Foo}> はコントロール-C<F> の後に二つ C<o> が続く名前を持つ |
83 | 83 | スカラ変数と考えられます。 |
84 | 84 | これらの変数は Perl によって特別な用途のために予約されていますが、 |
85 | 85 | C<^_> (キャレット-下線)で始まるものは例外です。 |
86 | 86 | C<^_> で始まる名前は Perl の将来のバージョンで特別な意味を |
87 | 87 | 持つことはありません; 従ってこれらの名前はプログラム中で安全に使用できます。 |
88 | 88 | 但し、C<$^_> そのものは I<予約されます>。 |
89 | 89 | |
90 | 90 | =begin original |
91 | 91 | |
92 | 92 | Perl identifiers that begin with digits or |
93 | 93 | punctuation characters are exempt from the effects of the C<package> |
94 | 94 | declaration and are always forced to be in package C<main>; they are |
95 | 95 | also exempt from C<strict 'vars'> errors. A few other names are also |
96 | 96 | exempt in these ways: |
97 | 97 | |
98 | 98 | =end original |
99 | 99 | |
100 | 100 | 数字、句読点で始まる Perl の識別子は C<package> 宣言の |
101 | 101 | 効果から逃れて、常に C<main> パッケージにあるものとして扱われます。 |
102 | 102 | さらに以下のものも逃れます: |
103 | 103 | |
104 | 104 | ENV STDIN |
105 | 105 | INC STDOUT |
106 | 106 | ARGV STDERR |
107 | 107 | ARGVOUT |
108 | 108 | SIG |
109 | 109 | |
110 | 110 | =begin original |
111 | 111 | |
112 | 112 | In particular, the special C<${^_XYZ}> variables are always taken |
113 | 113 | to be in package C<main>, regardless of any C<package> declarations |
114 | 114 | presently in scope. |
115 | 115 | |
116 | 116 | =end original |
117 | 117 | |
118 | 118 | 特に、新しい特別な C<${^_XYZ}> 変数はスコープ内の C<package> 宣言に関わらず |
119 | 119 | 常に C<main> パッケージとして扱われます。 |
120 | 120 | |
121 | 121 | =head1 SPECIAL VARIABLES |
122 | 122 | |
123 | 123 | (特殊変数) |
124 | 124 | |
125 | 125 | =begin original |
126 | 126 | |
127 | 127 | The following names have special meaning to Perl. Most punctuation |
128 | 128 | names have reasonable mnemonics, or analogs in the shells. |
129 | 129 | Nevertheless, if you wish to use long variable names, you need only say: |
130 | 130 | |
131 | 131 | =end original |
132 | 132 | |
133 | 133 | 以下の名前は Perl では特別な意味を持ちます。 |
134 | 134 | 記号的な名前の多くは記憶法があるか、シェルでの類推が可能です。 |
135 | 135 | それでも長い名前を使用したい場合には |
136 | 136 | |
137 | 137 | use English; |
138 | 138 | |
139 | 139 | =begin original |
140 | 140 | |
141 | 141 | at the top of your program. This aliases all the short names to the long |
142 | 142 | names in the current package. Some even have medium names, generally |
143 | 143 | borrowed from B<awk>. For more info, please see L<English>. |
144 | 144 | |
145 | 145 | =end original |
146 | 146 | |
147 | 147 | とプログラムの最初に書いてください。 |
148 | 148 | これは、すべての短い名前の別名として、 |
149 | 149 | カレントパッケージで長い名前を付けるものです。 |
150 | 150 | B<awk> から持ってきた中間的な名前を持っているものもあります。 |
151 | 151 | さらなる情報については、どうか L<English> を参照してください。 |
152 | 152 | |
153 | 153 | =begin original |
154 | 154 | |
155 | 155 | Before you continue, note the sort order for variables. In general, we |
156 | 156 | first list the variables in case-insensitive, almost-lexigraphical |
157 | 157 | order (ignoring the C<{> or C<^> preceding words, as in C<${^UNICODE}> |
158 | 158 | or C<$^T>), although C<$_> and C<@_> move up to the top of the pile. |
159 | 159 | For variables with the same identifier, we list it in order of scalar, |
160 | 160 | array, hash, and bareword. |
161 | 161 | |
162 | 162 | =end original |
163 | 163 | |
164 | 164 | 先に進む前に、変数のソート順に注意してください。 |
165 | 165 | 一般的に、変数を大文字小文字を無視して、ほとんど辞書順に並んでいます |
166 | 166 | (C<${^UNICODE}> や C<$^T> のように、先頭についている C<{> や C<^> は |
167 | 167 | 無視します)が、C<$_> と C<@_> は先頭に来ます。 |
168 | 168 | 同じ識別子を持つ変数については、スカラ、配列、ハッシュ、裸の単語の順に |
169 | 169 | 並べています。 |
170 | 170 | |
171 | 171 | =head2 General Variables |
172 | 172 | |
173 | 173 | (一般変数) |
174 | 174 | |
175 | 175 | =over 8 |
176 | 176 | |
177 | 177 | =item $ARG |
178 | 178 | |
179 | 179 | =item $_ |
180 | 180 | X<$_> X<$ARG> |
181 | 181 | |
182 | 182 | =begin original |
183 | 183 | |
184 | 184 | The default input and pattern-searching space. The following pairs are |
185 | 185 | equivalent: |
186 | 186 | |
187 | 187 | =end original |
188 | 188 | |
189 | 189 | デフォルトの入力とパターン検索のスペース。 |
190 | 190 | 以下の 2つは同値です: |
191 | 191 | |
192 | 192 | =begin original |
193 | 193 | |
194 | 194 | while (<>) {...} # equivalent only in while! |
195 | 195 | while (defined($_ = <>)) {...} |
196 | 196 | |
197 | 197 | =end original |
198 | 198 | |
199 | 199 | while (<>) {...} # while の中でのみ等価! |
200 | 200 | while (defined($_ = <>)) {...} |
201 | 201 | |
202 | 202 | /^Subject:/ |
203 | 203 | $_ =~ /^Subject:/ |
204 | 204 | |
205 | 205 | tr/a-z/A-Z/ |
206 | 206 | $_ =~ tr/a-z/A-Z/ |
207 | 207 | |
208 | 208 | chomp |
209 | 209 | chomp($_) |
210 | 210 | |
211 | 211 | =begin original |
212 | 212 | |
213 | 213 | Here are the places where Perl will assume C<$_> even if you don't use it: |
214 | 214 | |
215 | 215 | =end original |
216 | 216 | |
217 | 217 | あなたが使いたくなくても Perl が C<$_> を仮定する場合がいくつかあります: |
218 | 218 | |
219 | 219 | =over 3 |
220 | 220 | |
221 | 221 | =item * |
222 | 222 | |
223 | 223 | =begin original |
224 | 224 | |
225 | 225 | The following functions use C<$_> as a default argument: |
226 | 226 | |
227 | 227 | =end original |
228 | 228 | |
229 | 229 | 以下の関数は C<$_> をデフォルト引数として使います: |
230 | 230 | |
231 | 231 | =begin original |
232 | 232 | |
233 | 233 | abs, alarm, chomp, chop, chr, chroot, |
234 | 234 | cos, defined, eval, evalbytes, exp, fc, glob, hex, int, lc, |
235 | 235 | lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, printf, |
236 | 236 | quotemeta, readlink, readpipe, ref, require, reverse (in scalar context only), |
237 | 237 | rmdir, say, sin, split (for its second |
238 | 238 | argument), sqrt, stat, study, uc, ucfirst, |
239 | 239 | unlink, unpack. |
240 | 240 | |
241 | 241 | =end original |
242 | 242 | |
243 | 243 | abs, alarm, chomp, chop, chr, chroot, |
244 | 244 | cos, defined, eval, evalbytes, exp, fc, glob, hex, int, lc, |
245 | 245 | lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, printf, |
246 | 246 | quotemeta, readlink, readpipe, ref, require, reverse (スカラコンテキストのみ), |
247 | 247 | rmdir, say, sin, split (の 2 番目の引数), |
248 | 248 | sqrt, stat, study, uc, ucfirst, |
249 | 249 | unlink, unpack |
250 | 250 | |
251 | 251 | =item * |
252 | 252 | |
253 | 253 | =begin original |
254 | 254 | |
255 | 255 | All file tests (C<-f>, C<-d>) except for C<-t>, which defaults to STDIN. |
256 | 256 | See L<perlfunc/-X> |
257 | 257 | |
258 | 258 | =end original |
259 | 259 | |
260 | 260 | デフォルトが STDIN である C<-t> を除く全てのファイルテスト(C<-f>, C<-d>)。 |
261 | 261 | L<perlfunc/-X> を参照してください。 |
262 | 262 | |
263 | 263 | =item * |
264 | 264 | |
265 | 265 | =begin original |
266 | 266 | |
267 | 267 | The pattern matching operations C<m//>, C<s///> and C<tr///> (aka C<y///>) |
268 | 268 | when used without an C<=~> operator. |
269 | 269 | |
270 | 270 | =end original |
271 | 271 | |
272 | 272 | C<=~> 演算子なしで用いられたパターンマッチ演算 C<m//>, C<s///>, C<tr///> |
273 | 273 | (またの名を C<y///>)。 |
274 | 274 | |
275 | 275 | =item * |
276 | 276 | |
277 | 277 | =begin original |
278 | 278 | |
279 | 279 | The default iterator variable in a C<foreach> loop if no other |
280 | 280 | variable is supplied. |
281 | 281 | |
282 | 282 | =end original |
283 | 283 | |
284 | 284 | C<foreach> ループでの他の変数が補われなかった場合のデフォルトの繰り返し変数。 |
285 | 285 | |
286 | 286 | =item * |
287 | 287 | |
288 | 288 | =begin original |
289 | 289 | |
290 | 290 | The implicit iterator variable in the C<grep()> and C<map()> functions. |
291 | 291 | |
292 | 292 | =end original |
293 | 293 | |
294 | 294 | C<grep()> 関数と C<map()> 関数の暗黙の繰り返し変数。 |
295 | 295 | |
296 | 296 | =item * |
297 | 297 | |
298 | 298 | =begin original |
299 | 299 | |
300 | 300 | The implicit variable of C<given()>. |
301 | 301 | |
302 | 302 | =end original |
303 | 303 | |
304 | 304 | C<given()> の暗黙の変数。 |
305 | 305 | |
306 | 306 | =item * |
307 | 307 | |
308 | 308 | =begin original |
309 | 309 | |
310 | 310 | The default place to put the next value or input record |
311 | 311 | when a C<< <FH> >>, C<readline>, C<readdir> or C<each> |
312 | 312 | operation's result is tested by itself as the sole criterion of a C<while> |
313 | 313 | test. Outside a C<while> test, this will not happen. |
314 | 314 | |
315 | 315 | =end original |
316 | 316 | |
317 | 317 | C<< <FH> >>, C<readline>, C<readdir>, C<each> が単独で C<while> テストで |
318 | 318 | テストされた場合の、次の値や入力レコードを入れるデフォルトの場所。 |
319 | 319 | C<while> テスト以外ではこれは起こりません。 |
320 | 320 | |
321 | 321 | =back |
322 | 322 | |
323 | 323 | =begin original |
324 | 324 | |
325 | 325 | C<$_> is a global variable. |
326 | 326 | |
327 | 327 | =end original |
328 | 328 | |
329 | 329 | C<$_> はグローバル変数です。 |
330 | 330 | |
331 | 331 | =begin original |
332 | 332 | |
333 | 333 | However, between perl v5.10.0 and v5.24.0, it could be used lexically by |
334 | 334 | writing C<my $_>. Making C<$_> refer to the global C<$_> in the same scope |
335 | 335 | was then possible with C<our $_>. This experimental feature was removed and is |
336 | 336 | now a fatal error, but you may encounter it in older code. |
337 | 337 | |
338 | 338 | =end original |
339 | 339 | |
340 | 340 | しかし、perl v5.10.0 から v5.24.0 の間、 |
341 | 341 | C<my $_> と書くことでこれをレキシカルに使うことが出来ました。 |
342 | 342 | 同じスコープで C<$_> がグローバルな C<$_> を参照するのは |
343 | 343 | C<our $_> で可能になっていました。 |
344 | 344 | この実験的機能は削除されて今では致命的エラーですが、 |
345 | 345 | 古いコードで見かけるかも知れません。 |
346 | 346 | |
347 | 347 | =begin original |
348 | 348 | |
349 | 349 | Mnemonic: underline is understood in certain operations. |
350 | 350 | |
351 | 351 | =end original |
352 | 352 | |
353 | 353 | 記憶法: 下線はある操作を覚えるためのもの。 |
354 | 354 | |
355 | 355 | =item @ARG |
356 | 356 | |
357 | 357 | =item @_ |
358 | 358 | X<@_> X<@ARG> |
359 | 359 | |
360 | 360 | =begin original |
361 | 361 | |
362 | 362 | Within a subroutine the array C<@_> contains the parameters passed to |
363 | 363 | that subroutine. Inside a subroutine, C<@_> is the default array for |
364 | 364 | the array operators C<pop> and C<shift>. |
365 | 365 | |
366 | 366 | =end original |
367 | 367 | |
368 | 368 | サブルーチンに入るときには、配列 C<@_> はサブルーチンに渡された |
369 | 369 | パラメータです。 |
370 | 370 | サブルーチンの内部では、C<@_> は配列演算子 C<push>, C<shift> の |
371 | 371 | デフォルト配列です。 |
372 | 372 | |
373 | 373 | =begin original |
374 | 374 | |
375 | 375 | See L<perlsub>. |
376 | 376 | |
377 | 377 | =end original |
378 | 378 | |
379 | 379 | L<perlsub> を参照して下さい。 |
380 | 380 | |
381 | 381 | =item $LIST_SEPARATOR |
382 | 382 | |
383 | 383 | =item $" |
384 | 384 | X<$"> X<$LIST_SEPARATOR> |
385 | 385 | |
386 | 386 | =begin original |
387 | 387 | |
388 | 388 | When an array or an array slice is interpolated into a double-quoted |
389 | 389 | string or a similar context such as C</.../>, its elements are |
390 | 390 | separated by this value. Default is a space. For example, this: |
391 | 391 | |
392 | 392 | =end original |
393 | 393 | |
394 | 394 | 配列や配列スライスがダブルクォートされた文字列あるいは C</.../> のような |
395 | 395 | 同様のコンテキスト展開されたとき、その要素はこの値で分割されます。 |
396 | 396 | デフォルトは空白です。 |
397 | 397 | 例えば、以下のものは: |
398 | 398 | |
399 | 399 | print "The array is: @array\n"; |
400 | 400 | |
401 | 401 | =begin original |
402 | 402 | |
403 | 403 | is equivalent to this: |
404 | 404 | |
405 | 405 | =end original |
406 | 406 | |
407 | 407 | 以下と等価です: |
408 | 408 | |
409 | 409 | print "The array is: " . join($", @array) . "\n"; |
410 | 410 | |
411 | 411 | =begin original |
412 | 412 | |
413 | 413 | Mnemonic: works in double-quoted context. |
414 | 414 | |
415 | 415 | =end original |
416 | 416 | |
417 | 417 | 記憶法: ダブルクォートされた内容に対して動作します。 |
418 | 418 | |
419 | 419 | =item $PROCESS_ID |
420 | 420 | |
421 | 421 | =item $PID |
422 | 422 | |
423 | 423 | =item $$ |
424 | 424 | X<$$> X<$PID> X<$PROCESS_ID> |
425 | 425 | |
426 | 426 | =begin original |
427 | 427 | |
428 | 428 | The process number of the Perl running this script. Though you I<can> set |
429 | 429 | this variable, doing so is generally discouraged, although it can be |
430 | 430 | invaluable for some testing purposes. It will be reset automatically |
431 | 431 | across C<fork()> calls. |
432 | 432 | |
433 | 433 | =end original |
434 | 434 | |
435 | 435 | このスクリプトを実行している Perl のプロセス番号です。 |
436 | 436 | この変数に値を設定することは I<可能> ですが、そうすることは一般的に |
437 | 437 | 非推奨です; しかしこれは一部のテストの目的には計り知れない価値があります。 |
438 | 438 | C<fork()> 呼び出しがあると自動的にリセットされます。 |
439 | 439 | |
440 | 440 | =begin original |
441 | 441 | |
442 | 442 | Note for Linux and Debian GNU/kFreeBSD users: Before Perl v5.16.0 perl |
443 | 443 | would emulate POSIX semantics on Linux systems using LinuxThreads, a |
444 | 444 | partial implementation of POSIX Threads that has since been superseded |
445 | 445 | by the Native POSIX Thread Library (NPTL). |
446 | 446 | |
447 | 447 | =end original |
448 | 448 | |
449 | 449 | Linux および Debian GNU/kFreeBSD ユーザーに対する注意: Perl v5.16.0 より |
450 | 450 | 前では perl は LinuxThreads を使って Linux システムで POSIX の意味論を |
451 | 451 | エミュレートしていました; これは POSIX Threads の部分的な実装で、 |
452 | 452 | Native POSIX Thread Library (NPTL) で置き換えられました。 |
453 | 453 | |
454 | 454 | =begin original |
455 | 455 | |
456 | 456 | LinuxThreads is now obsolete on Linux, and caching C<getpid()> |
457 | 457 | like this made embedding perl unnecessarily complex (since you'd have |
458 | 458 | to manually update the value of $$), so now C<$$> and C<getppid()> |
459 | 459 | will always return the same values as the underlying C library. |
460 | 460 | |
461 | 461 | =end original |
462 | 462 | |
463 | 463 | LinuxThreads は Linux では古いもので、このように C<getpid()> を |
464 | 464 | キャッシュすると組み込み perl が不必要に複雑になります ($$ の値を手動で |
465 | 465 | 更新する必要があるからです); それで今では C<$$> と C<getppid()> は常に |
466 | 466 | 基礎となる C ライブラリと同じ値を返します。 |
467 | 467 | |
468 | 468 | =begin original |
469 | 469 | |
470 | 470 | Debian GNU/kFreeBSD systems also used LinuxThreads up until and |
471 | 471 | including the 6.0 release, but after that moved to FreeBSD thread |
472 | 472 | semantics, which are POSIX-like. |
473 | 473 | |
474 | 474 | =end original |
475 | 475 | |
476 | 476 | Debian GNU/kFreeBSD システムは 6.0 リリースまで LinuxThreads を |
477 | 477 | 使っていましたが、その後は POSIX 風の FreeBSD スレッドの意味論に |
478 | 478 | 移行しました。 |
479 | 479 | |
480 | 480 | =begin original |
481 | 481 | |
482 | 482 | To see if your system is affected by this discrepancy check if |
483 | 483 | C<getconf GNU_LIBPTHREAD_VERSION | grep -q NPTL> returns a false |
484 | 484 | value. NTPL threads preserve the POSIX semantics. |
485 | 485 | |
486 | 486 | =end original |
487 | 487 | |
488 | 488 | あなたのシステムがこの非一貫性の影響を受けるかどうかを調べるには、 |
489 | 489 | C<getconf GNU_LIBPTHREAD_VERSION | grep -q NPTL> が偽を返すかどうかを |
490 | 490 | チェックしてください。 |
491 | 491 | NTPL スレッドは POSIX の意味論を保存します。 |
492 | 492 | |
493 | 493 | =begin original |
494 | 494 | |
495 | 495 | Mnemonic: same as shells. |
496 | 496 | |
497 | 497 | =end original |
498 | 498 | |
499 | 499 | 記憶法: シェルと同じ。 |
500 | 500 | |
501 | 501 | =item $PROGRAM_NAME |
502 | 502 | |
503 | 503 | =item $0 |
504 | 504 | X<$0> X<$PROGRAM_NAME> |
505 | 505 | |
506 | 506 | =begin original |
507 | 507 | |
508 | 508 | Contains the name of the program being executed. |
509 | 509 | |
510 | 510 | =end original |
511 | 511 | |
512 | 512 | 実行されているプログラムの名前を示します。 |
513 | 513 | |
514 | 514 | =begin original |
515 | 515 | |
516 | 516 | On some (but not all) operating systems assigning to C<$0> modifies |
517 | 517 | the argument area that the C<ps> program sees. On some platforms you |
518 | 518 | may have to use special C<ps> options or a different C<ps> to see the |
519 | 519 | changes. Modifying the C<$0> is more useful as a way of indicating the |
520 | 520 | current program state than it is for hiding the program you're |
521 | 521 | running. |
522 | 522 | |
523 | 523 | =end original |
524 | 524 | |
525 | 525 | 一部の(しかし全てではありません)オペレーティングシステムでは |
526 | 526 | C<$0> に代入を行なうことで B<ps> プログラムが見る引数エリアを修正します。 |
527 | 527 | プラットフォームによっては、この変更を見るために 特殊な C<ps> オプションや、 |
528 | 528 | 他の C<ps> を使う必要があるものもあります。 |
529 | 529 | C<$0> の修正は、実行しているプログラムを隠すよりは、 |
530 | 530 | 実行中のプログラムの状態を表示するときに、使うとよいでしょう。 |
531 | 531 | |
532 | 532 | =begin original |
533 | 533 | |
534 | 534 | Note that there are platform-specific limitations on the maximum |
535 | 535 | length of C<$0>. In the most extreme case it may be limited to the |
536 | 536 | space occupied by the original C<$0>. |
537 | 537 | |
538 | 538 | =end original |
539 | 539 | |
540 | 540 | C<$0> の最大長にはプラットフォーム固有の制限があることに注意してください。 |
541 | 541 | 最も極端な場合では、元の C<$0> で占められているサイズに制限されます。 |
542 | 542 | |
543 | 543 | =begin original |
544 | 544 | |
545 | 545 | In some platforms there may be arbitrary amount of padding, for |
546 | 546 | example space characters, after the modified name as shown by C<ps>. |
547 | 547 | In some platforms this padding may extend all the way to the original |
548 | 548 | length of the argument area, no matter what you do (this is the case |
549 | 549 | for example with Linux 2.2). |
550 | 550 | |
551 | 551 | =end original |
552 | 552 | |
553 | 553 | プラットフォームによっては、任意の量のパッディングがある場合があります; |
554 | 554 | 例えば、C<ps> で見られる修正された名前の後の空白文字です。 |
555 | 555 | プラットフォームによっては、このパッディングは、あなたが何をしたかに |
556 | 556 | 関わらず、元の引数のエリア全体に拡張されるものもあります |
557 | 557 | (例えば、これは Linux 2.2 の場合です)。 |
558 | 558 | |
559 | 559 | =begin original |
560 | 560 | |
561 | 561 | Note for BSD users: setting C<$0> does not completely remove "perl" |
562 | 562 | from the ps(1) output. For example, setting C<$0> to C<"foobar"> may |
563 | 563 | result in C<"perl: foobar (perl)"> (whether both the C<"perl: "> prefix |
564 | 564 | and the " (perl)" suffix are shown depends on your exact BSD variant |
565 | 565 | and version). This is an operating system feature, Perl cannot help it. |
566 | 566 | |
567 | 567 | =end original |
568 | 568 | |
569 | 569 | BSD ユーザーへの注意: C<$0> に値をセットしても、ps(1) の出力から |
570 | 570 | 完全に "perl" の文字列は取り除かれません。 |
571 | 571 | 例えば、C<$0> に C<"foobar"> と設定すると、C<"perl: foobar (perl)"> という |
572 | 572 | 結果になります |
573 | 573 | (C<"perl: "> 接頭辞と" (perl)" 接尾辞が表示されるかどうかは 、正確な |
574 | 574 | BSD の種類とバージョンに依存します)。 |
575 | 575 | これはオペレーティングシステムの機能で、Perl は何もできません。 |
576 | 576 | |
577 | 577 | =begin original |
578 | 578 | |
579 | 579 | In multithreaded scripts Perl coordinates the threads so that any |
580 | 580 | thread may modify its copy of the C<$0> and the change becomes visible |
581 | 581 | to ps(1) (assuming the operating system plays along). Note that |
582 | 582 | the view of C<$0> the other threads have will not change since they |
583 | 583 | have their own copies of it. |
584 | 584 | |
585 | 585 | =end original |
586 | 586 | |
587 | 587 | マルチスレッドスクリプトでは、どのスレッドも自身の C<$0> のコピーを |
588 | 588 | 変更できて、その変更が(OS が対応しているとして) ps(1) で見えるように、 |
589 | 589 | Perl がスレッドを調整します。 |
590 | 590 | 他のスレッドが持っている C<$0> の見え方は(各自が自身のコピーを |
591 | 591 | 持っているので)変わらないことに注意してください。 |
592 | 592 | |
593 | 593 | =begin original |
594 | 594 | |
595 | 595 | If the program has been given to perl via the switches C<-e> or C<-E>, |
596 | 596 | C<$0> will contain the string C<"-e">. |
597 | 597 | |
598 | 598 | =end original |
599 | 599 | |
600 | 600 | プログラムが perl に C<-e> または C<-E> オプション経由で与えられた場合、 |
601 | 601 | C<$0> には文字列 C<"-e"> を含みます。 |
602 | 602 | |
603 | 603 | =begin original |
604 | 604 | |
605 | 605 | On Linux as of perl v5.14.0 the legacy process name will be set with |
606 | 606 | C<prctl(2)>, in addition to altering the POSIX name via C<argv[0]> as |
607 | 607 | perl has done since version 4.000. Now system utilities that read the |
608 | 608 | legacy process name such as ps, top and killall will recognize the |
609 | 609 | name you set when assigning to C<$0>. The string you supply will be |
610 | 610 | cut off at 16 bytes, this is a limitation imposed by Linux. |
611 | 611 | |
612 | 612 | =end original |
613 | 613 | |
614 | 614 | Linux では perl v5.14.0 以降、perl がバージョン 4.000 以降行っていた |
615 | 615 | C<argv[0]> 経由での POSIX 名の置き換えに加えて、 |
616 | 616 | レガシープロセス名は C<prctl(2)> で設定されます。 |
617 | 617 | 今では ps, top, killall のようにレガシープロセス名を読むユーティリティは |
618 | 618 | C<$0> に代入することに設定される名前を認識します。 |
619 | 619 | 指定した文字列は 16 バイトに切り詰められます; これは Linux による |
620 | 620 | 制限です。 |
621 | 621 | |
622 | 622 | =begin original |
623 | 623 | |
624 | 624 | Mnemonic: same as B<sh> and B<ksh>. |
625 | 625 | |
626 | 626 | =end original |
627 | 627 | |
628 | 628 | 記憶法: B<sh> や B<ksh> と同じ。 |
629 | 629 | |
630 | 630 | =item $REAL_GROUP_ID |
631 | 631 | |
632 | 632 | =item $GID |
633 | 633 | |
634 | 634 | =item $( |
635 | 635 | X<$(> X<$GID> X<$REAL_GROUP_ID> |
636 | 636 | |
637 | 637 | =begin original |
638 | 638 | |
639 | 639 | The real gid of this process. If you are on a machine that supports |
640 | 640 | membership in multiple groups simultaneously, gives a space separated |
641 | 641 | list of groups you are in. The first number is the one returned by |
642 | 642 | C<getgid()>, and the subsequent ones by C<getgroups()>, one of which may be |
643 | 643 | the same as the first number. |
644 | 644 | |
645 | 645 | =end original |
646 | 646 | |
647 | 647 | 本プロセスの実 gid を示します。 |
648 | 648 | 同時に複数のグループに所属できるマシンでは、所属するグループをスペースで |
649 | 649 | 区切ったリストが得られます。 |
650 | 650 | 最初の数値は、C<getgid()> で返されるものです; その後に C<getgroups()> が |
651 | 651 | 返す値が続き、その中の 1 つは、最初の値と同じかもしれません。 |
652 | 652 | |
653 | 653 | =begin original |
654 | 654 | |
655 | 655 | However, a value assigned to C<$(> must be a single number used to |
656 | 656 | set the real gid. So the value given by C<$(> should I<not> be assigned |
657 | 657 | back to C<$(> without being forced numeric, such as by adding zero. Note |
658 | 658 | that this is different to the effective gid (C<$)>) which does take a |
659 | 659 | list. |
660 | 660 | |
661 | 661 | =end original |
662 | 662 | |
663 | 663 | しかし、C<$(> に代入された値は実際の gid に設定された値の |
664 | 664 | 一つでなければなりません。 |
665 | 665 | 従って、 C<$(> で与えられた値はゼロを足すことによって |
666 | 666 | 数値化することなく C<$(> に書き戻すべきではありません。 |
667 | 667 | これはリストが得られる実行 GID (C<$)>) とは違うことに注意してください。 |
668 | 668 | |
669 | 669 | =begin original |
670 | 670 | |
671 | 671 | You can change both the real gid and the effective gid at the same |
672 | 672 | time by using C<POSIX::setgid()>. Changes |
673 | 673 | to C<$(> require a check to C<$!> |
674 | 674 | to detect any possible errors after an attempted change. |
675 | 675 | |
676 | 676 | =end original |
677 | 677 | |
678 | 678 | C<POSIX::setgid()> を使って、実 GID と実効 GID の両方を同時に変更できます。 |
679 | 679 | C<$(> を変更した場合は、変更しようとしたときに起こりうるエラーを検出するために |
680 | 680 | C<$!> をチェックする必要があります。 |
681 | 681 | |
682 | 682 | =begin original |
683 | 683 | |
684 | 684 | Mnemonic: parentheses are used to I<group> things. The real gid is the |
685 | 685 | group you I<left>, if you're running setgid. |
686 | 686 | |
687 | 687 | =end original |
688 | 688 | |
689 | 689 | 記憶法: 括弧は、I<グループ化>に使われます。 |
690 | 690 | setgid で実行中であれば、実 gid は I<left> した、つまり離れたグループです。 |
691 | 691 | |
692 | 692 | =item $EFFECTIVE_GROUP_ID |
693 | 693 | |
694 | 694 | =item $EGID |
695 | 695 | |
696 | 696 | =item $) |
697 | 697 | X<$)> X<$EGID> X<$EFFECTIVE_GROUP_ID> |
698 | 698 | |
699 | 699 | =begin original |
700 | 700 | |
701 | 701 | The effective gid of this process. If you are on a machine that |
702 | 702 | supports membership in multiple groups simultaneously, gives a space |
703 | 703 | separated list of groups you are in. The first number is the one |
704 | 704 | returned by C<getegid()>, and the subsequent ones by C<getgroups()>, |
705 | 705 | one of which may be the same as the first number. |
706 | 706 | |
707 | 707 | =end original |
708 | 708 | |
709 | 709 | 本プロセスの実効 gid を示します。 |
710 | 710 | 同時に複数のグループに所属できるマシンでは、所属するグループをスペースで |
711 | 711 | 区切ったリストが得られます。 |
712 | 712 | 最初の数値は、C<getegid()> で返されるものです; その後に C<getgroups()> が |
713 | 713 | 返す値が続き、その中の 1 つは、最初の値と同じかもしれません。 |
714 | 714 | |
715 | 715 | =begin original |
716 | 716 | |
717 | 717 | Similarly, a value assigned to C<$)> must also be a space-separated |
718 | 718 | list of numbers. The first number sets the effective gid, and |
719 | 719 | the rest (if any) are passed to C<setgroups()>. To get the effect of an |
720 | 720 | empty list for C<setgroups()>, just repeat the new effective gid; that is, |
721 | 721 | to force an effective gid of 5 and an effectively empty C<setgroups()> |
722 | 722 | list, say C< $) = "5 5" >. |
723 | 723 | |
724 | 724 | =end original |
725 | 725 | |
726 | 726 | 同様に、C<$)> へ代入する値はスペースで区切られた数値の |
727 | 727 | リストでなければなりません。 |
728 | 728 | 最初の数値は実効 gid を設定し、残りの数値は(もしあれば) C<setgroups()> に |
729 | 729 | 渡されます。 |
730 | 730 | C<setgroups()> に空リストを渡したい場合は、単に新しい実効 gid を |
731 | 731 | 繰り返してください; つまり、実効 gid を 5 にして、C<setgroups()> に空リストを |
732 | 732 | 渡したい場合は、C< $) = "5 5" > としてください。 |
733 | 733 | |
734 | 734 | =begin original |
735 | 735 | |
736 | 736 | You can change both the effective gid and the real gid at the same |
737 | 737 | time by using C<POSIX::setgid()> (use only a single numeric argument). |
738 | 738 | Changes to C<$)> require a check to C<$!> to detect any possible errors |
739 | 739 | after an attempted change. |
740 | 740 | |
741 | 741 | =end original |
742 | 742 | |
743 | 743 | C<POSIX::setgid()> を使って、実効 GID と実 GID を同時に変更できます |
744 | 744 | (1 つの数値引数だけが使えます)。 |
745 | 745 | C<$)> を変更した場合は、変更時に起こりうるエラーを検出するために C<$!> の |
746 | 746 | チェックが必要です。 |
747 | 747 | |
748 | 748 | =begin original |
749 | 749 | |
750 | 750 | C<< $< >>, C<< $> >>, C<$(> and C<$)> can be set only on |
751 | 751 | machines that support the corresponding I<set[re][ug]id()> routine. C<$(> |
752 | 752 | and C<$)> can be swapped only on machines supporting C<setregid()>. |
753 | 753 | |
754 | 754 | =end original |
755 | 755 | |
756 | 756 | C<< $< >>, C<< $> >>, C<$(>, C<$)> は、実行するマシンで、 |
757 | 757 | 対応する I<set[re][ug]id()> ルーティンがサポートされているときにのみ |
758 | 758 | 設定可能です。 |
759 | 759 | C<$(> と C<$)> の交換は、 |
760 | 760 | C<setregid()> がサポートされているマシンでのみ可能です。 |
761 | 761 | |
762 | 762 | =begin original |
763 | 763 | |
764 | 764 | Mnemonic: parentheses are used to I<group> things. The effective gid |
765 | 765 | is the group that's I<right> for you, if you're running setgid. |
766 | 766 | |
767 | 767 | =end original |
768 | 768 | |
769 | 769 | 記憶法: 括弧は、I<グループ化>に使われます。 |
770 | 770 | setgid で実行中であれば、実効 gid は right な、つまり正しいグループです。 |
771 | 771 | |
772 | 772 | =item $REAL_USER_ID |
773 | 773 | |
774 | 774 | =item $UID |
775 | 775 | |
776 | 776 | =item $< |
777 | 777 | X<< $< >> X<$UID> X<$REAL_USER_ID> |
778 | 778 | |
779 | 779 | =begin original |
780 | 780 | |
781 | 781 | The real uid of this process. You can change both the real uid and the |
782 | 782 | effective uid at the same time by using C<POSIX::setuid()>. Since |
783 | 783 | changes to C<< $< >> require a system call, check C<$!> after a change |
784 | 784 | attempt to detect any possible errors. |
785 | 785 | |
786 | 786 | =end original |
787 | 787 | |
788 | 788 | 本プロセスの実 uid を示します。 |
789 | 789 | C<POSIX::setuid()> を使って、実効 UID と実 UID を同時に変更できます。 |
790 | 790 | C<< $< >> の変更にはシステムコールが必要なので、起こりうるエラーを |
791 | 791 | 検出するために C<$!> のチェックが必要です。 |
792 | 792 | |
793 | 793 | =begin original |
794 | 794 | |
795 | 795 | Mnemonic: it's the uid you came I<from>, if you're running setuid. |
796 | 796 | |
797 | 797 | =end original |
798 | 798 | |
799 | 799 | 記憶法: setuid で実行中であれば、そこ「から」来た uid です。 |
800 | 800 | |
801 | 801 | =item $EFFECTIVE_USER_ID |
802 | 802 | |
803 | 803 | =item $EUID |
804 | 804 | |
805 | 805 | =item $> |
806 | 806 | X<< $> >> X<$EUID> X<$EFFECTIVE_USER_ID> |
807 | 807 | |
808 | 808 | =begin original |
809 | 809 | |
810 | 810 | The effective uid of this process. For example: |
811 | 811 | |
812 | 812 | =end original |
813 | 813 | |
814 | 814 | 本プロセスの実効 uid を示します。 |
815 | 815 | 例えば: |
816 | 816 | |
817 | 817 | =begin original |
818 | 818 | |
819 | 819 | $< = $>; # set real to effective uid |
820 | 820 | ($<,$>) = ($>,$<); # swap real and effective uids |
821 | 821 | |
822 | 822 | =end original |
823 | 823 | |
824 | 824 | $< = $>; # 実 uid に実効 uid を設定 |
825 | 825 | ($<,$>) = ($>,$<); # 実 uid と実効 uid を交換 |
826 | 826 | |
827 | 827 | =begin original |
828 | 828 | |
829 | 829 | You can change both the effective uid and the real uid at the same |
830 | 830 | time by using C<POSIX::setuid()>. Changes to C<< $> >> require a check |
831 | 831 | to C<$!> to detect any possible errors after an attempted change. |
832 | 832 | |
833 | 833 | =end original |
834 | 834 | |
835 | 835 | C<POSIX::setuid()> を使って、実効 UID と実 UID を同時に変更できます。 |
836 | 836 | C<< $> >> を変更した場合は、変更時に起こりうるエラーを検出するために |
837 | 837 | C<$!> のチェックが必要です。 |
838 | 838 | |
839 | 839 | =begin original |
840 | 840 | |
841 | 841 | C<< $< >> and C<< $> >> can be swapped only on machines |
842 | 842 | supporting C<setreuid()>. |
843 | 843 | |
844 | 844 | =end original |
845 | 845 | |
846 | 846 | C<< $< >> と C<< $> >> の交換は、C<setreuid()> をサポートしている |
847 | 847 | マシンでのみ可能です。 |
848 | 848 | |
849 | 849 | =begin original |
850 | 850 | |
851 | 851 | Mnemonic: it's the uid you went I<to>, if you're running setuid. |
852 | 852 | |
853 | 853 | =end original |
854 | 854 | |
855 | 855 | 記憶法: setuid で実行中であれば、そこ I<へ> 行く uid です。 |
856 | 856 | |
857 | 857 | =item $SUBSCRIPT_SEPARATOR |
858 | 858 | |
859 | 859 | =item $SUBSEP |
860 | 860 | |
861 | 861 | =item $; |
862 | 862 | X<$;> X<$SUBSEP> X<SUBSCRIPT_SEPARATOR> |
863 | 863 | |
864 | 864 | =begin original |
865 | 865 | |
866 | 866 | The subscript separator for multidimensional array emulation. If you |
867 | 867 | refer to a hash element as |
868 | 868 | |
869 | 869 | =end original |
870 | 870 | |
871 | 871 | 多次元配列のエミュレートのための添え字の区切文字。 |
872 | 872 | ハッシュの要素を |
873 | 873 | |
874 | 874 | $foo{$x,$y,$z} |
875 | 875 | |
876 | 876 | =begin original |
877 | 877 | |
878 | 878 | it really means |
879 | 879 | |
880 | 880 | =end original |
881 | 881 | |
882 | 882 | のようにして参照すると、実際には以下のようになります |
883 | 883 | |
884 | 884 | $foo{join($;, $x, $y, $z)} |
885 | 885 | |
886 | 886 | =begin original |
887 | 887 | |
888 | 888 | But don't put |
889 | 889 | |
890 | 890 | =end original |
891 | 891 | |
892 | 892 | しかし、以下のようにしてはいけません |
893 | 893 | |
894 | 894 | =begin original |
895 | 895 | |
896 | 896 | @foo{$x,$y,$z} # a slice--note the @ |
897 | 897 | |
898 | 898 | =end original |
899 | 899 | |
900 | 900 | @foo{$x,$y,$z} # スライス--@ に注意 |
901 | 901 | |
902 | 902 | =begin original |
903 | 903 | |
904 | 904 | which means |
905 | 905 | |
906 | 906 | =end original |
907 | 907 | |
908 | 908 | これは以下の意味になります |
909 | 909 | |
910 | 910 | ($foo{$x},$foo{$y},$foo{$z}) |
911 | 911 | |
912 | 912 | =begin original |
913 | 913 | |
914 | 914 | Default is "\034", the same as SUBSEP in B<awk>. If your keys contain |
915 | 915 | binary data there might not be any safe value for C<$;>. |
916 | 916 | |
917 | 917 | =end original |
918 | 918 | |
919 | 919 | デフォルトは "\034" で、C<awk> の SUBSEP と同じです。 |
920 | 920 | 使おうとしている key の値がバイナリのデータを含むならば、 |
921 | 921 | C<$;> に設定する安全な値などはないことになります。 |
922 | 922 | |
923 | 923 | =begin original |
924 | 924 | |
925 | 925 | Consider using "real" multidimensional arrays as described |
926 | 926 | in L<perllol>. |
927 | 927 | |
928 | 928 | =end original |
929 | 929 | |
930 | 930 | L<perllol> で記述している「本物の」多次元配列を使うようにしてください。 |
931 | 931 | |
932 | 932 | =begin original |
933 | 933 | |
934 | 934 | Mnemonic: comma (the syntactic subscript separator) is a semi-semicolon. |
935 | 935 | |
936 | 936 | =end original |
937 | 937 | |
938 | 938 | 記憶法: コンマ (構文上の添え字区切り文字) はセミ−セミコロンなのです。 |
939 | 939 | |
940 | 940 | =item $a |
941 | 941 | |
942 | 942 | =item $b |
943 | 943 | X<$a> X<$b> |
944 | 944 | |
945 | 945 | =begin original |
946 | 946 | |
947 | 947 | Special package variables when using C<sort()>, see L<perlfunc/sort>. |
948 | 948 | Because of this specialness C<$a> and C<$b> don't need to be declared |
949 | 949 | (using C<use vars>, or C<our()>) even when using the C<strict 'vars'> |
950 | 950 | pragma. Don't lexicalize them with C<my $a> or C<my $b> if you want to |
951 | 951 | be able to use them in the C<sort()> comparison block or function. |
952 | 952 | |
953 | 953 | =end original |
954 | 954 | |
955 | 955 | C<sort()> を使うときの特殊パッケージ変数です; L<perlfunc/sort> を |
956 | 956 | 参照してください。 |
957 | 957 | この特殊性により、C<$a> と C<$b> は、たとえ C<strict 'vars'> プラグマを |
958 | 958 | 使っているときでも (C<use vars> や C<our()> を使って) 宣言する必要が |
959 | 959 | ありません。 |
960 | 960 | これを C<sort()> 比較ブロックや関数で使えるようにしたい場合は、 |
961 | 961 | C<my $a> や C<my $b> としてレキシカル化しないでください。 |
962 | 962 | |
963 | 963 | =item %ENV |
964 | 964 | X<%ENV> |
965 | 965 | |
966 | 966 | =begin original |
967 | 967 | |
968 | 968 | The hash C<%ENV> contains your current environment. Setting a |
969 | 969 | value in C<ENV> changes the environment for any child processes |
970 | 970 | you subsequently C<fork()> off. |
971 | 971 | |
972 | 972 | =end original |
973 | 973 | |
974 | 974 | ハッシュ C<%ENV> には、その時点の環境変数が設定されています。 |
975 | 975 | C<ENV> に値を設定することで、 |
976 | 976 | 以後に C<fork()> した子プロセスの環境変数を変更します。 |
977 | 977 | |
978 | 978 | =begin original |
979 | 979 | |
980 | 980 | As of v5.18.0, both keys and values stored in C<%ENV> are stringified. |
981 | 981 | |
982 | 982 | =end original |
983 | 983 | |
984 | 984 | v5.18.0 から、C<%ENV> に補完されたキーと値の両方は文字列化されます。 |
985 | 985 | |
986 | 986 | my $foo = 1; |
987 | 987 | $ENV{'bar'} = \$foo; |
988 | 988 | if( ref $ENV{'bar'} ) { |
989 | 989 | say "Pre 5.18.0 Behaviour"; |
990 | 990 | } else { |
991 | 991 | say "Post 5.18.0 Behaviour"; |
992 | 992 | } |
993 | 993 | |
994 | 994 | =begin original |
995 | 995 | |
996 | 996 | Previously, only child processes received stringified values: |
997 | 997 | |
998 | 998 | =end original |
999 | 999 | |
1000 | 1000 | 以前は、子プロセスのみが文字列化された値を受け取っていました: |
1001 | 1001 | |
1002 | 1002 | my $foo = 1; |
1003 | 1003 | $ENV{'bar'} = \$foo; |
1004 | 1004 | |
1005 | 1005 | # Always printed 'non ref' |
1006 | 1006 | system($^X, '-e', |
1007 | 1007 | q/print ( ref $ENV{'bar'} ? 'ref' : 'non ref' ) /); |
1008 | 1008 | |
1009 | 1009 | =begin original |
1010 | 1010 | |
1011 | 1011 | This happens because you can't really share arbitrary data structures with |
1012 | 1012 | foreign processes. |
1013 | 1013 | |
1014 | 1014 | =end original |
1015 | 1015 | |
1016 | 1016 | これは、外部プロセスと本当に任意のデータ構造を共有することができないために |
1017 | 1017 | 起きます。 |
1018 | 1018 | |
1019 | 1019 | =item $OLD_PERL_VERSION |
1020 | 1020 | |
1021 | 1021 | =item $] |
1022 | 1022 | X<$]> X<$OLD_PERL_VERSION> |
1023 | 1023 | |
1024 | 1024 | =begin original |
1025 | 1025 | |
1026 | 1026 | The revision, version, and subversion of the Perl interpreter, represented |
1027 | 1027 | as a decimal of the form 5.XXXYYY, where XXX is the version / 1e3 and YYY |
1028 | 1028 | is the subversion / 1e6. For example, Perl v5.10.1 would be "5.010001". |
1029 | 1029 | |
1030 | 1030 | =end original |
1031 | 1031 | |
1032 | 1032 | 5.XXXYYY 型式の小数で表現される Perl インタプリタの |
1033 | 1033 | revision, version, subversion |
1034 | 1034 | (XXX は version / 1e3、 YYY は subversion / 1e6)。 |
1035 | 1035 | 例えば、、Perl v5.10.1 は "5.010001" です。 |
1036 | 1036 | |
1037 | 1037 | =begin original |
1038 | 1038 | |
1039 | 1039 | This variable can be used to determine whether the Perl interpreter |
1040 | 1040 | executing a script is in the right range of versions: |
1041 | 1041 | |
1042 | 1042 | =end original |
1043 | 1043 | |
1044 | 1044 | スクリプトの最初で、そのスクリプトを実行しているインタプリタのバージョンが |
1045 | 1045 | 適切な範囲内にあるかを調べる、といったことができます: |
1046 | 1046 | |
1047 | 1047 | warn "No PerlIO!\n" if $] lt '5.008'; |
1048 | 1048 | |
1049 | 1049 | =begin original |
1050 | 1050 | |
1051 | 1051 | When comparing C<$]>, string comparison operators are B<highly |
1052 | 1052 | recommended>. The inherent limitations of binary floating point |
1053 | 1053 | representation can sometimes lead to incorrect comparisons for some |
1054 | 1054 | numbers on some architectures. |
1055 | 1055 | |
1056 | 1056 | =end original |
1057 | 1057 | |
1058 | 1058 | C<$]> と比較する場合は、文字列比較演算子を B<強く勧めます> 。 |
1059 | 1059 | バイナリ浮動小数点表現が生来持つ制限により、アーキテクチャと数値によっては |
1060 | 1060 | 比較が正しくないことがあります。 |
1061 | 1061 | |
1062 | 1062 | =begin original |
1063 | 1063 | |
1064 | 1064 | See also the documentation of C<use VERSION> and C<require VERSION> |
1065 | 1065 | for a convenient way to fail if the running Perl interpreter is too old. |
1066 | 1066 | |
1067 | 1067 | =end original |
1068 | 1068 | |
1069 | 1069 | 実行する Perl インタプリタが古すぎる場合に終了する便利な方法に |
1070 | 1070 | ついては C<use VERSION> と C<require VERSION> のドキュメントも |
1071 | 1071 | 参照して下さい。 |
1072 | 1072 | |
1073 | 1073 | =begin original |
1074 | 1074 | |
1075 | 1075 | See L</$^V> for a representation of the Perl version as a L<version> |
1076 | 1076 | object, which allows more flexible string comparisons. |
1077 | 1077 | |
1078 | 1078 | =end original |
1079 | 1079 | |
1080 | 1080 | より柔軟な文字列比較が可能な L<version> オブジェクトとしての |
1081 | 1081 | Perl バージョン表現については L</$^V> を参照してください。 |
1082 | 1082 | |
1083 | 1083 | =begin original |
1084 | 1084 | |
1085 | 1085 | The main advantage of C<$]> over C<$^V> is that it works the same on any |
1086 | 1086 | version of Perl. The disadvantages are that it can't easily be compared |
1087 | 1087 | to versions in other formats (e.g. literal v-strings, "v1.2.3" or |
1088 | 1088 | version objects) and numeric comparisons can occasionally fail; it's good |
1089 | 1089 | for string literal version checks and bad for comparing to a variable |
1090 | 1090 | that hasn't been sanity-checked. |
1091 | 1091 | |
1092 | 1092 | =end original |
1093 | 1093 | |
1094 | 1094 | C<$^V> に対する C<$]> の主な利点は、どのバージョンの Perl でも同様に |
1095 | 1095 | 動作することです。 |
1096 | 1096 | 欠点は、他の型式のバージョン (例えばリテラルな v-文字列、"v1.2.3"、 |
1097 | 1097 | バージョンオブジェクト) と簡単に比較できず、数値比較はときどき |
1098 | 1098 | 失敗することです; 文字列リテラルバージョンチェックとしては良いですが、 |
1099 | 1099 | 正気チェックをされていない変数と比較するには良くないです。 |
1100 | 1100 | |
1101 | 1101 | =begin original |
1102 | 1102 | |
1103 | 1103 | The C<$OLD_PERL_VERSION> form was added in Perl v5.20.0 for historical |
1104 | 1104 | reasons but its use is discouraged. (If your reason to use C<$]> is to |
1105 | 1105 | run code on old perls then referring to it as C<$OLD_PERL_VERSION> would |
1106 | 1106 | be self-defeating.) |
1107 | 1107 | |
1108 | 1108 | =end original |
1109 | 1109 | |
1110 | 1110 | C<$OLD_PERL_VERSION> 型式は歴史的理由により Perl v5.20.0 に追加されましたが、 |
1111 | 1111 | この使用は非推奨です。 |
1112 | 1112 | (C<$]> を使う理由が古い perl でコードを実行することなら、これを |
1113 | 1113 | C<$OLD_PERL_VERSION> して参照すると自滅することになります。) |
1114 | 1114 | |
1115 | 1115 | =begin original |
1116 | 1116 | |
1117 | 1117 | Mnemonic: Is this version of perl in the right bracket? |
1118 | 1118 | |
1119 | 1119 | =end original |
1120 | 1120 | |
1121 | 1121 | 記憶法: Perl のバージョンは、正しい範囲 (right bracket) にあるか。 |
1122 | 1122 | |
1123 | 1123 | =item $SYSTEM_FD_MAX |
1124 | 1124 | |
1125 | 1125 | =item $^F |
1126 | 1126 | X<$^F> X<$SYSTEM_FD_MAX> |
1127 | 1127 | |
1128 | 1128 | =begin original |
1129 | 1129 | |
1130 | 1130 | The maximum system file descriptor, ordinarily 2. System file |
1131 | 1131 | descriptors are passed to C<exec()>ed processes, while higher file |
1132 | 1132 | descriptors are not. Also, during an |
1133 | 1133 | C<open()>, system file descriptors are |
1134 | 1134 | preserved even if the C<open()> fails (ordinary file descriptors are |
1135 | 1135 | closed before the C<open()> is attempted). The close-on-exec |
1136 | 1136 | status of a file descriptor will be decided according to the value of |
1137 | 1137 | C<$^F> when the corresponding file, pipe, or socket was opened, not the |
1138 | 1138 | time of the C<exec()>. |
1139 | 1139 | |
1140 | 1140 | =end original |
1141 | 1141 | |
1142 | 1142 | システムが使用するファイル記述子の最大値を示し、通常は 2 です。 |
1143 | 1143 | システムファイル記述子は、C<exec()> されたプロセスに渡されますが、 |
1144 | 1144 | それ以降のファイル記述子は渡されません。 |
1145 | 1145 | また、C<open()> の実行中は、システムファイル記述子は、 |
1146 | 1146 | たとえ C<open()> が失敗しても、保存されます |
1147 | 1147 | (通常のファイル記述子は、C<open()> が実行される前にクローズされます)。 |
1148 | 1148 | ファイル記述子の close-on-exec のステータスは、C<exec()> 時ではなく、 |
1149 | 1149 | 対応するファイル、パイプソケットの open 時の C<$^F> の値によって |
1150 | 1150 | 決められます。 |
1151 | 1151 | |
1152 | 1152 | =item @F |
1153 | 1153 | X<@F> |
1154 | 1154 | |
1155 | 1155 | =begin original |
1156 | 1156 | |
1157 | 1157 | The array C<@F> contains the fields of each line read in when autosplit |
1158 | 1158 | mode is turned on. See L<perlrun> for the B<-a> switch. This array |
1159 | 1159 | is package-specific, and must be declared or given a full package name |
1160 | 1160 | if not in package main when running under C<strict 'vars'>. |
1161 | 1161 | |
1162 | 1162 | =end original |
1163 | 1163 | |
1164 | 1164 | 自動 split モードが有効の場合、配列 C<@F> には読み込んだ行のフィールドを |
1165 | 1165 | 含みます。 |
1166 | 1166 | B<-a> オプションについては L<perlrun> を参照してください。 |
1167 | 1167 | この配列はパッケージ固有であり、もし C<strict 'vars'> で実行していて |
1168 | 1168 | パッケージ main 以外の場合は完全なパッケージ名で定義したり与えたり |
1169 | 1169 | しなければなりません。 |
1170 | 1170 | |
1171 | 1171 | =item @INC |
1172 | 1172 | X<@INC> |
1173 | 1173 | |
1174 | 1174 | =begin original |
1175 | 1175 | |
1176 | 1176 | The array C<@INC> contains the list of places that the C<do EXPR>, |
1177 | 1177 | C<require>, or C<use> constructs look for their library files. It |
1178 | 1178 | initially consists of the arguments to any B<-I> command-line |
1179 | 1179 | switches, followed by the default Perl library, probably |
1180 | F</usr/local/lib/perl>. | |
1180 | F</usr/local/lib/perl>, followed by ".", to represent the current | |
1181 | ||
1181 | directory. ("." will not be appended if taint checks are enabled, | |
1182 | i | |
1182 | either by C<-T> or by C<-t>, or if configured not to do so by the | |
1183 | ||
1183 | C<-Ddefault_inc_excludes_dot> compile time option.) If you need to | |
1184 | ||
1184 | modify this at runtime, you should use the C<use lib> pragma to get | |
1185 | ||
1185 | the machine-dependent library properly loaded also: | |
1186 | to get the machine-dependent library properly loaded as well: | |
1187 | 1186 | |
1188 | 1187 | =end original |
1189 | 1188 | |
1190 | 1189 | 配列 C<@INC> には、C<do EXPR>, C<require>, C<use> によってライブラリファイルを |
1191 | 1190 | 探すときに評価する場所のリストが納められています。 |
1192 | 1191 | 初期状態では、コマンドラインスイッチ B<-I> の引数とデフォルトの |
1193 | Perl ライブラリディレクトリ (おそらく F</usr/local/lib/perl5>) | |
1192 | Perl ライブラリディレクトリ (おそらく F</usr/local/lib/perl5>) と | |
1194 | 順につなげたものです。 | |
1193 | カレントディレクトリを表わす "." を順につなげたものです。 | |
1195 | ||
1194 | (C<-T> か C<-t> によって汚染チェックが有効の場合か、 | |
1196 | ||
1195 | これをしないように C<-Ddefault_inc_excludes_dot> コンパイル時オプションを | |
1197 | ||
1196 | 設定していない場合は、"." は追加されません。) | |
1198 | ||
1197 | 実行時にこれを変更する必要がある場合は、マシン依存のライブラリも正しく | |
1199 | C<@INC> に C<.> を再追加するのは推奨されません。 | |
1200 | 実行時に C<@INC> 変更する必要がある場合は、マシン依存のライブラリも正しく | |
1201 | 1198 | 読み込むために C<use lib> を使うべきです: |
1202 | 1199 | |
1203 | 1200 | use lib '/mypath/libdir/'; |
1204 | 1201 | use SomeMod; |
1205 | 1202 | |
1206 | 1203 | =begin original |
1207 | 1204 | |
1208 | 1205 | You can also insert hooks into the file inclusion system by putting Perl |
1209 | 1206 | code directly into C<@INC>. Those hooks may be subroutine references, |
1210 | 1207 | array references or blessed objects. See L<perlfunc/require> for details. |
1211 | 1208 | |
1212 | 1209 | =end original |
1213 | 1210 | |
1214 | 1211 | Perl のコードを直接 C<@INC> に入れることで、ファイルインクルード機構に |
1215 | 1212 | フックを挿入できます。 |
1216 | 1213 | このフックはサブルーチンリファレンス、配列リファレンス、bless された |
1217 | 1214 | オブジェクトが可能です。 |
1218 | 1215 | 詳細については L<perlfunc/require> を参照してください。 |
1219 | 1216 | |
1220 | 1217 | =item %INC |
1221 | 1218 | X<%INC> |
1222 | 1219 | |
1223 | 1220 | =begin original |
1224 | 1221 | |
1225 | 1222 | The hash C<%INC> contains entries for each filename included via the |
1226 | 1223 | C<do>, C<require>, or C<use> operators. The key is the filename |
1227 | 1224 | you specified (with module names converted to pathnames), and the |
1228 | 1225 | value is the location of the file found. The C<require> |
1229 | 1226 | operator uses this hash to determine whether a particular file has |
1230 | 1227 | already been included. |
1231 | 1228 | |
1232 | 1229 | =end original |
1233 | 1230 | |
1234 | 1231 | ハッシュ C<%INC> は、C<do>, C<require>, C<use> 演算子によって |
1235 | 1232 | インクルードされた、個々のファイル名をエントリとして持っています。 |
1236 | 1233 | key は指定したファイル名(モジュール名はパス名に変換されます)で、 |
1237 | 1234 | value は見つかった場所となっています。 |
1238 | 1235 | C<require> 演算子は、指定されたファイル名が既に |
1239 | 1236 | インクルードされているかを、このハッシュを使って調べます。 |
1240 | 1237 | |
1241 | 1238 | =begin original |
1242 | 1239 | |
1243 | 1240 | If the file was loaded via a hook (e.g. a subroutine reference, see |
1244 | 1241 | L<perlfunc/require> for a description of these hooks), this hook is |
1245 | 1242 | by default inserted into C<%INC> in place of a filename. Note, however, |
1246 | 1243 | that the hook may have set the C<%INC> entry by itself to provide some more |
1247 | 1244 | specific info. |
1248 | 1245 | |
1249 | 1246 | =end original |
1250 | 1247 | |
1251 | 1248 | ファイルがフック(つまりサブルーチンリファレンス; フックに関する |
1252 | 1249 | 説明については L<perlfunc/require> を参照してください)経由で読み込まれた |
1253 | 1250 | 場合、このフックはデフォルトではファイル名の代わりに C<%INC> に挿入されます。 |
1254 | 1251 | しかし、フックはさらなる特定の情報を提供するために、自身で C<%INC> エントリを |
1255 | 1252 | セットするかもしれないことに注意してください。 |
1256 | 1253 | |
1257 | 1254 | =item $INPLACE_EDIT |
1258 | 1255 | |
1259 | 1256 | =item $^I |
1260 | 1257 | X<$^I> X<$INPLACE_EDIT> |
1261 | 1258 | |
1262 | 1259 | =begin original |
1263 | 1260 | |
1264 | 1261 | The current value of the inplace-edit extension. Use C<undef> to disable |
1265 | 1262 | inplace editing. |
1266 | 1263 | |
1267 | 1264 | =end original |
1268 | 1265 | |
1269 | 1266 | 置き換え編集の拡張子の値を示します。 |
1270 | 1267 | 置き換え編集を禁止するためには、C<undef> を設定します。 |
1271 | 1268 | |
1272 | 1269 | =begin original |
1273 | 1270 | |
1274 | 1271 | Mnemonic: value of B<-i> switch. |
1275 | 1272 | |
1276 | 1273 | =end original |
1277 | 1274 | |
1278 | 1275 | 記憶法: B<-i> スイッチの値。 |
1279 | 1276 | |
1280 | 1277 | =item @ISA |
1281 | 1278 | X<@ISA> |
1282 | 1279 | |
1283 | 1280 | =begin original |
1284 | 1281 | |
1285 | 1282 | Each package contains a special array called C<@ISA> which contains a list |
1286 | 1283 | of that class's parent classes, if any. This array is simply a list of |
1287 | 1284 | scalars, each of which is a string that corresponds to a package name. The |
1288 | 1285 | array is examined when Perl does method resolution, which is covered in |
1289 | 1286 | L<perlobj>. |
1290 | 1287 | |
1291 | 1288 | =end original |
1292 | 1289 | |
1293 | 1290 | それぞれのパッケージには C<@ISA> という名前の特殊配列があります; |
1294 | 1291 | これは (もしあれば) そのクラスの親クラスのリストです。 |
1295 | 1292 | この変数は単なるスカラのリストで、それぞれはパッケージ名に対応する |
1296 | 1293 | 文字列です。 |
1297 | 1294 | この配列は Perl がメソッド解決を行うときにチェックされます; これは |
1298 | 1295 | L<perlobj> に記述しています。 |
1299 | 1296 | |
1300 | 1297 | =begin original |
1301 | 1298 | |
1302 | 1299 | To load packages while adding them to C<@ISA>, see the L<parent> pragma. The |
1303 | 1300 | discouraged L<base> pragma does this as well, but should not be used except |
1304 | 1301 | when compatibility with the discouraged L<fields> pragma is required. |
1305 | 1302 | |
1306 | 1303 | =end original |
1307 | 1304 | |
1308 | 1305 | To load packages while adding them to |
1309 | 1306 | パッケージを読み込むために C<@ISA> に追加するには、L<parent> プラグマを |
1310 | 1307 | 参照してください。 |
1311 | 1308 | 非推奨の L<base> プラグマは同じことをしますが、 |
1312 | 1309 | 非推奨の L<fields> プラグマとの互換性が必要な場合を除いて、 |
1313 | 1310 | 使うべきではありません。 |
1314 | 1311 | |
1315 | 1312 | =item $^M |
1316 | 1313 | X<$^M> |
1317 | 1314 | |
1318 | 1315 | =begin original |
1319 | 1316 | |
1320 | 1317 | By default, running out of memory is an untrappable, fatal error. |
1321 | 1318 | However, if suitably built, Perl can use the contents of C<$^M> |
1322 | 1319 | as an emergency memory pool after C<die()>ing. Suppose that your Perl |
1323 | 1320 | were compiled with C<-DPERL_EMERGENCY_SBRK> and used Perl's malloc. |
1324 | 1321 | Then |
1325 | 1322 | |
1326 | 1323 | =end original |
1327 | 1324 | |
1328 | 1325 | デフォルトでは、メモリ不足はトラップできない致命的エラーとなります。 |
1329 | 1326 | しかし、もし適切に構築されていれば、Perl は C<$^M> の中身を |
1330 | 1327 | C<die()> した後の緊急用メモリとして使えます。 |
1331 | 1328 | Perl が C<-DPERL_EMERGENCY_SBRK> 付きでコンパイルされ、 |
1332 | 1329 | Perl の malloc を使うと仮定します。そして、 |
1333 | 1330 | |
1334 | 1331 | $^M = 'a' x (1 << 16); |
1335 | 1332 | |
1336 | 1333 | =begin original |
1337 | 1334 | |
1338 | 1335 | would allocate a 64K buffer for use in an emergency. See the |
1339 | 1336 | F<INSTALL> file in the Perl distribution for information on how to |
1340 | 1337 | add custom C compilation flags when compiling perl. To discourage casual |
1341 | 1338 | use of this advanced feature, there is no L<English|English> long name for |
1342 | 1339 | this variable. |
1343 | 1340 | |
1344 | 1341 | =end original |
1345 | 1342 | |
1346 | 1343 | とすると緊急用の 64K のバッファを割り当てます。 |
1347 | 1344 | perl をコンパイルするときに独自の C コンパイルフラグを追加する |
1348 | 1345 | 方法についての情報は、Perl 配布パッケージに含まれている |
1349 | 1346 | F<INSTALL> ファイルを参照して下さい。 |
1350 | 1347 | この拡張機能を気軽に使えないようにするために、 |
1351 | 1348 | この変数には L<English|English> の長い名前はありません。 |
1352 | 1349 | |
1353 | 1350 | =begin original |
1354 | 1351 | |
1355 | 1352 | This variable was added in Perl 5.004. |
1356 | 1353 | |
1357 | 1354 | =end original |
1358 | 1355 | |
1359 | 1356 | この変数は Perl 5.004 で追加されました。 |
1360 | 1357 | |
1361 | 1358 | =item $OSNAME |
1362 | 1359 | |
1363 | 1360 | =item $^O |
1364 | 1361 | X<$^O> X<$OSNAME> |
1365 | 1362 | |
1366 | 1363 | =begin original |
1367 | 1364 | |
1368 | 1365 | The name of the operating system under which this copy of Perl was |
1369 | 1366 | built, as determined during the configuration process. For examples |
1370 | 1367 | see L<perlport/PLATFORMS>. |
1371 | 1368 | |
1372 | 1369 | =end original |
1373 | 1370 | |
1374 | 1371 | この Perl が構築されたオペレーティングシステムの名前です; |
1375 | 1372 | これは設定プロセス中に決定されます。 |
1376 | 1373 | 例えば L<perlport/PLATFORMS> を参照してください。 |
1377 | 1374 | |
1378 | 1375 | =begin original |
1379 | 1376 | |
1380 | 1377 | The value is identical to C<$Config{'osname'}>. See also L<Config> |
1381 | 1378 | and the B<-V> command-line switch documented in L<perlrun>. |
1382 | 1379 | |
1383 | 1380 | =end original |
1384 | 1381 | |
1385 | 1382 | この値は C<$Config{'osname'}> と同じです。 |
1386 | 1383 | L<Config> と、L<perlrun> で文書化されている |
1387 | 1384 | B<-V> コマンドラインスイッチも参照して下さい。 |
1388 | 1385 | |
1389 | 1386 | =begin original |
1390 | 1387 | |
1391 | 1388 | In Windows platforms, C<$^O> is not very helpful: since it is always |
1392 | 1389 | C<MSWin32>, it doesn't tell the difference between |
1393 | 1390 | 95/98/ME/NT/2000/XP/CE/.NET. Use C<Win32::GetOSName()> or |
1394 | 1391 | Win32::GetOSVersion() (see L<Win32> and L<perlport>) to distinguish |
1395 | 1392 | between the variants. |
1396 | 1393 | |
1397 | 1394 | =end original |
1398 | 1395 | |
1399 | 1396 | Windows プラットフォームでは、C<$^O> はあまり役に立ちません: これは常に |
1400 | 1397 | C<MSWin32> となり、95/98/ME/NT/2000/XP/CE/.NET の違いを示していないからです。 |
1401 | 1398 | これらを区別するためには、C<Win32::GetOSName()> や Win32::GetOSVersion() を |
1402 | 1399 | 使ってください (L<Win32> と L<perlport> を参照してください)。 |
1403 | 1400 | |
1404 | 1401 | =begin original |
1405 | 1402 | |
1406 | 1403 | This variable was added in Perl 5.003. |
1407 | 1404 | |
1408 | 1405 | =end original |
1409 | 1406 | |
1410 | 1407 | この変数は Perl 5.003 で追加されました。 |
1411 | 1408 | |
1412 | 1409 | =item %SIG |
1413 | 1410 | X<%SIG> |
1414 | 1411 | |
1415 | 1412 | =begin original |
1416 | 1413 | |
1417 | 1414 | The hash C<%SIG> contains signal handlers for signals. For example: |
1418 | 1415 | |
1419 | 1416 | =end original |
1420 | 1417 | |
1421 | 1418 | ハッシュ C<%SIG> にはシグナルのためのシグナルハンドラが含まれています。 |
1422 | 1419 | 例えば: |
1423 | 1420 | |
1424 | 1421 | =begin original |
1425 | 1422 | |
1426 | 1423 | sub handler { # 1st argument is signal name |
1427 | 1424 | my($sig) = @_; |
1428 | 1425 | print "Caught a SIG$sig--shutting down\n"; |
1429 | 1426 | close(LOG); |
1430 | 1427 | exit(0); |
1431 | 1428 | } |
1432 | 1429 | |
1433 | 1430 | =end original |
1434 | 1431 | |
1435 | 1432 | sub handler { # 最初の引数はシグナル名 |
1436 | 1433 | my($sig) = @_; |
1437 | 1434 | print "Caught a SIG$sig--shutting down\n"; |
1438 | 1435 | close(LOG); |
1439 | 1436 | exit(0); |
1440 | 1437 | } |
1441 | 1438 | |
1442 | 1439 | =begin original |
1443 | 1440 | |
1444 | 1441 | $SIG{'INT'} = \&handler; |
1445 | 1442 | $SIG{'QUIT'} = \&handler; |
1446 | 1443 | ... |
1447 | 1444 | $SIG{'INT'} = 'DEFAULT'; # restore default action |
1448 | 1445 | $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT |
1449 | 1446 | |
1450 | 1447 | =end original |
1451 | 1448 | |
1452 | 1449 | $SIG{'INT'} = \&handler; |
1453 | 1450 | $SIG{'QUIT'} = \&handler; |
1454 | 1451 | ... |
1455 | 1452 | $SIG{'INT'} = 'DEFAULT'; # デフォルトの動作を復元 |
1456 | 1453 | $SIG{'QUIT'} = 'IGNORE'; # SIGQUIT を無視 |
1457 | 1454 | |
1458 | 1455 | =begin original |
1459 | 1456 | |
1460 | 1457 | Using a value of C<'IGNORE'> usually has the effect of ignoring the |
1461 | 1458 | signal, except for the C<CHLD> signal. See L<perlipc> for more about |
1462 | 1459 | this special case. |
1463 | 1460 | |
1464 | 1461 | =end original |
1465 | 1462 | |
1466 | 1463 | C<'IGNORE'> という値は通常はシグナルの効果を無視するために使いますが、 |
1467 | 1464 | C<CHLD> シグナルは例外です。 |
1468 | 1465 | この特別な場合に関する詳細は L<perlipc> を参照して下さい。 |
1469 | 1466 | |
1470 | 1467 | =begin original |
1471 | 1468 | |
1472 | 1469 | Here are some other examples: |
1473 | 1470 | |
1474 | 1471 | =end original |
1475 | 1472 | |
1476 | 1473 | 以下にその他の例を示します: |
1477 | 1474 | |
1478 | 1475 | =begin original |
1479 | 1476 | |
1480 | 1477 | $SIG{"PIPE"} = "Plumber"; # assumes main::Plumber (not |
1481 | 1478 | # recommended) |
1482 | 1479 | $SIG{"PIPE"} = \&Plumber; # just fine; assume current |
1483 | 1480 | # Plumber |
1484 | 1481 | $SIG{"PIPE"} = *Plumber; # somewhat esoteric |
1485 | 1482 | $SIG{"PIPE"} = Plumber(); # oops, what did Plumber() |
1486 | 1483 | # return?? |
1487 | 1484 | |
1488 | 1485 | =end original |
1489 | 1486 | |
1490 | 1487 | $SIG{"PIPE"} = "Plumber"; # main::Plumber を仮定します(非推奨) |
1491 | 1488 | $SIG{"PIPE"} = \&Plumber; # 問題なし; カレントの Plumber を仮定します |
1492 | 1489 | $SIG{"PIPE"} = *Plumber; # 少々難解 |
1493 | 1490 | $SIG{"PIPE"} = Plumber(); # げげ、Plumber() は何を返すの?? |
1494 | 1491 | |
1495 | 1492 | =begin original |
1496 | 1493 | |
1497 | 1494 | Be sure not to use a bareword as the name of a signal handler, |
1498 | 1495 | lest you inadvertently call it. |
1499 | 1496 | |
1500 | 1497 | =end original |
1501 | 1498 | |
1502 | 1499 | 裸の単語をシグナルハンドラの名前として使わないようにしてください; |
1503 | 1500 | 不注意で呼び出すのを避けるためです。 |
1504 | 1501 | |
1505 | 1502 | =begin original |
1506 | 1503 | |
1507 | 1504 | If your system has the C<sigaction()> function then signal handlers |
1508 | 1505 | are installed using it. This means you get reliable signal handling. |
1509 | 1506 | |
1510 | 1507 | =end original |
1511 | 1508 | |
1512 | 1509 | システムに sigaction() 関数がある場合は、シグナルハンドラはそれを使って |
1513 | 1510 | インストールされます。 |
1514 | 1511 | これにより、信頼性のあるシグナルハンドリングが可能になります。 |
1515 | 1512 | |
1516 | 1513 | =begin original |
1517 | 1514 | |
1518 | 1515 | The default delivery policy of signals changed in Perl v5.8.0 from |
1519 | 1516 | immediate (also known as "unsafe") to deferred, also known as "safe |
1520 | 1517 | signals". See L<perlipc> for more information. |
1521 | 1518 | |
1522 | 1519 | =end original |
1523 | 1520 | |
1524 | 1521 | デフォルトのシグナル配送ポリシーは Perl v5.8.0 に即時("unsafe"としても |
1525 | 1522 | 知られます)から保留(「安全なシグナル」としても知られます)に変更されました。 |
1526 | 1523 | さらなる情報については L<perlipc> を参照してください。 |
1527 | 1524 | |
1528 | 1525 | =begin original |
1529 | 1526 | |
1530 | 1527 | Certain internal hooks can be also set using the C<%SIG> hash. The |
1531 | 1528 | routine indicated by C<$SIG{__WARN__}> is called when a warning |
1532 | 1529 | message is about to be printed. The warning message is passed as the |
1533 | 1530 | first argument. The presence of a C<__WARN__> hook causes the |
1534 | 1531 | ordinary printing of warnings to C<STDERR> to be suppressed. You can |
1535 | 1532 | use this to save warnings in a variable, or turn warnings into fatal |
1536 | 1533 | errors, like this: |
1537 | 1534 | |
1538 | 1535 | =end original |
1539 | 1536 | |
1540 | 1537 | ある種の内部フックも %SIG ハッシュを使ってセットされます。 |
1541 | 1538 | 警告メッセージを表示しようとするときに C<$SIG{__WARN__}> で |
1542 | 1539 | 示されたルーチンが呼び出されます。 |
1543 | 1540 | 警告メッセージは最初の引数として渡されます。 |
1544 | 1541 | C<__WARN__> フックがあると、通常の C<STDERR> への警告の出力は行われません。 |
1545 | 1542 | これを使って、警告メッセージを変数にいれたり、 |
1546 | 1543 | あるいは以下のようにして警告を致命的エラーに変えたり出来ます: |
1547 | 1544 | |
1548 | 1545 | local $SIG{__WARN__} = sub { die $_[0] }; |
1549 | 1546 | eval $proggie; |
1550 | 1547 | |
1551 | 1548 | =begin original |
1552 | 1549 | |
1553 | 1550 | As the C<'IGNORE'> hook is not supported by C<__WARN__>, you can |
1554 | 1551 | disable warnings using the empty subroutine: |
1555 | 1552 | |
1556 | 1553 | =end original |
1557 | 1554 | |
1558 | 1555 | C<__WARN__> では C<'IGNORE'> フックには対応していないので、空サブルーチンを |
1559 | 1556 | 使って警告を無効に出来ます: |
1560 | 1557 | |
1561 | 1558 | local $SIG{__WARN__} = sub {}; |
1562 | 1559 | |
1563 | 1560 | =begin original |
1564 | 1561 | |
1565 | 1562 | The routine indicated by C<$SIG{__DIE__}> is called when a fatal |
1566 | 1563 | exception is about to be thrown. The error message is passed as the |
1567 | 1564 | first argument. When a C<__DIE__> hook routine returns, the exception |
1568 | 1565 | processing continues as it would have in the absence of the hook, |
1569 | 1566 | unless the hook routine itself exits via a C<goto &sub>, a loop exit, |
1570 | 1567 | or a C<die()>. The C<__DIE__> handler is explicitly disabled during |
1571 | 1568 | the call, so that you can die from a C<__DIE__> handler. Similarly |
1572 | 1569 | for C<__WARN__>. |
1573 | 1570 | |
1574 | 1571 | =end original |
1575 | 1572 | |
1576 | 1573 | C<$SIG{__DIE__}> で示されるルーチンは |
1577 | 1574 | 致命的な例外がまさに投げられようとするときに呼び出されます。 |
1578 | 1575 | エラーメッセージは最初の引数として渡されます。 |
1579 | 1576 | C<__DIE__> フックから戻ると、例外処理はフックがなかったかのように |
1580 | 1577 | 再開されますが、フックルーチン自体が C<goto &sub>、ループ終了、 |
1581 | 1578 | C<die()> によって終了した場合を除きます。 |
1582 | 1579 | C<__DIE__> ハンドラは呼び出し中は明示的に無効になりますので、 |
1583 | 1580 | C<__DIE__> ハンドラから die できます。 |
1584 | 1581 | C<__WARN__> も同様です。 |
1585 | 1582 | |
1586 | 1583 | =begin original |
1587 | 1584 | |
1588 | 1585 | The C<$SIG{__DIE__}> hook is called even inside an C<eval()>. It was |
1589 | 1586 | never intended to happen this way, but an implementation glitch made |
1590 | 1587 | this possible. This used to be deprecated, as it allowed strange action |
1591 | 1588 | at a distance like rewriting a pending exception in C<$@>. Plans to |
1592 | 1589 | rectify this have been scrapped, as users found that rewriting a |
1593 | 1590 | pending exception is actually a useful feature, and not a bug. |
1594 | 1591 | |
1595 | 1592 | =end original |
1596 | 1593 | |
1597 | 1594 | C<$SIG{__DIE__}> は eval() の中でも呼び出されます。 |
1598 | 1595 | これは決してこのようになることを意図したものではありませんでしたが、 |
1599 | 1596 | 実装上のミスでこれが可能になっていました。 |
1600 | 1597 | これは以前廃止予定でした; C<$@> で保留されている例外を書き換えるといった |
1601 | 1598 | 変わった行動を離れた場所でできるようにしていたからです。 |
1602 | 1599 | これを修正する計画は破棄されました; |
1603 | 1600 | 保留されている例外を書き換えるというのは実際有用な機能であることがわかり、 |
1604 | 1601 | またバグではないからです。 |
1605 | 1602 | |
1606 | 1603 | =begin original |
1607 | 1604 | |
1608 | 1605 | C<__DIE__>/C<__WARN__> handlers are very special in one respect: they |
1609 | 1606 | may be called to report (probable) errors found by the parser. In such |
1610 | 1607 | a case the parser may be in inconsistent state, so any attempt to |
1611 | 1608 | evaluate Perl code from such a handler will probably result in a |
1612 | 1609 | segfault. This means that warnings or errors that result from parsing |
1613 | 1610 | Perl should be used with extreme caution, like this: |
1614 | 1611 | |
1615 | 1612 | =end original |
1616 | 1613 | |
1617 | 1614 | C<__DIE__> と C<__WARN__> のハンドラは一つの点で非常に特別です: |
1618 | 1615 | パーサによってエラー(であろうもの)を報告するために呼び出されることがある |
1619 | 1616 | ことです。 |
1620 | 1617 | このような場合、パーサは不安定な状態になっているかもしれないので、 |
1621 | 1618 | ハンドラから Perl コードを評価しようとするとセグメンテーションフォールトが |
1622 | 1619 | 発生するかもしれません。 |
1623 | 1620 | Perl のパース中の警告やエラーは、以下のように非常に注意して扱うべきです; |
1624 | 1621 | |
1625 | 1622 | require Carp if defined $^S; |
1626 | 1623 | Carp::confess("Something wrong") if defined &Carp::confess; |
1627 | 1624 | die "Something wrong, but could not load Carp to give " |
1628 | 1625 | . "backtrace...\n\t" |
1629 | 1626 | . "To see backtrace try starting Perl with -MCarp switch"; |
1630 | 1627 | |
1631 | 1628 | =begin original |
1632 | 1629 | |
1633 | 1630 | Here the first line will load C<Carp> I<unless> it is the parser who |
1634 | 1631 | called the handler. The second line will print backtrace and die if |
1635 | 1632 | C<Carp> was available. The third line will be executed only if C<Carp> was |
1636 | 1633 | not available. |
1637 | 1634 | |
1638 | 1635 | =end original |
1639 | 1636 | |
1640 | 1637 | 一行目は、パーサが C<ハンドラ> を I<呼び出したのでなければ> C<Carp> を |
1641 | 1638 | 読み込みます。 |
1642 | 1639 | C<二行目> は、C<Carp> が使えるならバックとレースを表示して die します。 |
1643 | 1640 | 三行目は C<Carp> が使えないときにのみ実行されます。 |
1644 | 1641 | |
1645 | 1642 | =begin original |
1646 | 1643 | |
1647 | 1644 | Having to even think about the C<$^S> variable in your exception |
1648 | 1645 | handlers is simply wrong. C<$SIG{__DIE__}> as currently implemented |
1649 | 1646 | invites grievous and difficult to track down errors. Avoid it |
1650 | 1647 | and use an C<END{}> or CORE::GLOBAL::die override instead. |
1651 | 1648 | |
1652 | 1649 | =end original |
1653 | 1650 | |
1654 | 1651 | 例外ハンドラの中で C<$^S> を使おうなどとは考えてもいけません。 |
1655 | 1652 | 現在の実装の C<$SIG{__DIE__}> は面倒を引き寄せ、エラーの追跡を困難にします。 |
1656 | 1653 | これの代わりに C<END{}> を使うか、CORE::GLOBAL::die を |
1657 | 1654 | オーバーライドしてください。 |
1658 | 1655 | |
1659 | 1656 | =begin original |
1660 | 1657 | |
1661 | 1658 | See L<perlfunc/die>, L<perlfunc/warn>, L<perlfunc/eval>, and |
1662 | 1659 | L<warnings> for additional information. |
1663 | 1660 | |
1664 | 1661 | =end original |
1665 | 1662 | |
1666 | 1663 | 追加の情報については L<perlfunc/die>, L<perlfunc/warn>, L<perlfunc/eval>, |
1667 | 1664 | L<warnings> を参照して下さい。 |
1668 | 1665 | |
1669 | 1666 | =item $BASETIME |
1670 | 1667 | |
1671 | 1668 | =item $^T |
1672 | 1669 | X<$^T> X<$BASETIME> |
1673 | 1670 | |
1674 | 1671 | =begin original |
1675 | 1672 | |
1676 | 1673 | The time at which the program began running, in seconds since the |
1677 | 1674 | epoch (beginning of 1970). The values returned by the B<-M>, B<-A>, |
1678 | 1675 | and B<-C> filetests are based on this value. |
1679 | 1676 | |
1680 | 1677 | =end original |
1681 | 1678 | |
1682 | 1679 | プログラムを実行開始した時刻を、紀元 (1970年の始め) からの秒数で |
1683 | 1680 | 示したものです。 |
1684 | 1681 | ファイルテスト B<-M>、B<-A>、B<-C> で返される値は、この値に基づいています。 |
1685 | 1682 | |
1686 | 1683 | =item $PERL_VERSION |
1687 | 1684 | |
1688 | 1685 | =item $^V |
1689 | 1686 | X<$^V> X<$PERL_VERSION> |
1690 | 1687 | |
1691 | 1688 | =begin original |
1692 | 1689 | |
1693 | 1690 | The revision, version, and subversion of the Perl interpreter, |
1694 | 1691 | represented as a L<version> object. |
1695 | 1692 | |
1696 | 1693 | =end original |
1697 | 1694 | |
1698 | 1695 | L<version> オブジェクトとして表現される Perl インタプリタの |
1699 | 1696 | revision, version, subversion。 |
1700 | 1697 | |
1701 | 1698 | =begin original |
1702 | 1699 | |
1703 | 1700 | This variable first appeared in perl v5.6.0; earlier versions of perl |
1704 | 1701 | will see an undefined value. Before perl v5.10.0 C<$^V> was represented |
1705 | 1702 | as a v-string rather than a L<version> object. |
1706 | 1703 | |
1707 | 1704 | =end original |
1708 | 1705 | |
1709 | 1706 | この変数は perl v5.6.0 で最初に現れました; それより前のバージョンでは |
1710 | 1707 | 未定義値となります。 |
1711 | 1708 | perl v5.10.0 以前では C<$^V> は L<version> オブジェクトではなく |
1712 | 1709 | v-string 形式で表現されます。 |
1713 | 1710 | |
1714 | 1711 | =begin original |
1715 | 1712 | |
1716 | 1713 | C<$^V> can be used to determine whether the Perl interpreter executing |
1717 | 1714 | a script is in the right range of versions. For example: |
1718 | 1715 | |
1719 | 1716 | =end original |
1720 | 1717 | |
1721 | 1718 | C<$^V> はスクリプトを実行している Perl インタプリタのバージョンが |
1722 | 1719 | 正しい範囲に入っているかを調べるのに使えます。 |
1723 | 1720 | 例えば: |
1724 | 1721 | |
1725 | 1722 | warn "Hashes not randomized!\n" if !$^V or $^V lt v5.8.1 |
1726 | 1723 | |
1727 | 1724 | =begin original |
1728 | 1725 | |
1729 | 1726 | While version objects overload stringification, to portably convert |
1730 | 1727 | C<$^V> into its string representation, use C<sprintf()>'s C<"%vd"> |
1731 | 1728 | conversion, which works for both v-strings or version objects: |
1732 | 1729 | |
1733 | 1730 | =end original |
1734 | 1731 | |
1735 | 1732 | 移植性がある形で C<$^V> を文字列表現に変換するために、 |
1736 | 1733 | バージョンオブジェクトは文字列化をオーバーロードしますが、 |
1737 | 1734 | v-文字列とバージョンオブジェクトの療養で動作する |
1738 | 1735 | C<sprintf()> の C<"%vd"> 変換を使ってください。 |
1739 | 1736 | |
1740 | 1737 | =begin original |
1741 | 1738 | |
1742 | 1739 | printf "version is v%vd\n", $^V; # Perl's version |
1743 | 1740 | |
1744 | 1741 | =end original |
1745 | 1742 | |
1746 | 1743 | printf "version is v%vd\n", $^V; # Perl のバージョン |
1747 | 1744 | |
1748 | 1745 | =begin original |
1749 | 1746 | |
1750 | 1747 | See the documentation of C<use VERSION> and C<require VERSION> |
1751 | 1748 | for a convenient way to fail if the running Perl interpreter is too old. |
1752 | 1749 | |
1753 | 1750 | =end original |
1754 | 1751 | |
1755 | 1752 | 実行する Perl インタプリタが古すぎる場合に終了する便利な方法については |
1756 | 1753 | C<use VERSION> と C<require VERSION> のドキュメントを参照して下さい。 |
1757 | 1754 | |
1758 | 1755 | =begin original |
1759 | 1756 | |
1760 | 1757 | See also C<L</$]>> for a decimal representation of the Perl version. |
1761 | 1758 | |
1762 | 1759 | =end original |
1763 | 1760 | |
1764 | 1761 | Perl バージョンの 10 進表現については C<L</$]>> も参照して下さい。 |
1765 | 1762 | |
1766 | 1763 | =begin original |
1767 | 1764 | |
1768 | 1765 | The main advantage of C<$^V> over C<$]> is that, for Perl v5.10.0 or |
1769 | 1766 | later, it overloads operators, allowing easy comparison against other |
1770 | 1767 | version representations (e.g. decimal, literal v-string, "v1.2.3", or |
1771 | 1768 | objects). The disadvantage is that prior to v5.10.0, it was only a |
1772 | 1769 | literal v-string, which can't be easily printed or compared, whereas |
1773 | 1770 | the behavior of C<$]> is unchanged on all versions of Perl. |
1774 | 1771 | |
1775 | 1772 | =end original |
1776 | 1773 | |
1777 | 1774 | Perl 5.10.0 以降での、C<$]> に対する C<$^V> の主な利点は、これは演算子を |
1778 | 1775 | オーバーロードするので、他のバージョン表現 (例えば 10 進数、 |
1779 | 1776 | リテラルな v-文字列、"v1.2.3"、オブジェクト)との比較が簡単であることです。 |
1780 | 1777 | v5.10.0 より前での欠点は、これは単なるリテラルな v-文字列であるため、 |
1781 | 1778 | 簡単に表示したり比較したり出来ないことです; 一方、 |
1782 | 1779 | C<$]> の振る舞いは全てのバージョンの Perl で変化しません。 |
1783 | 1780 | |
1784 | 1781 | =begin original |
1785 | 1782 | |
1786 | 1783 | Mnemonic: use ^V for a version object. |
1787 | 1784 | |
1788 | 1785 | =end original |
1789 | 1786 | |
1790 | 1787 | 記憶法: ^V をバージョンオブジェクトに使います。 |
1791 | 1788 | |
1792 | 1789 | =item ${^WIN32_SLOPPY_STAT} |
1793 | 1790 | X<${^WIN32_SLOPPY_STAT}> X<sitecustomize> X<sitecustomize.pl> |
1794 | 1791 | |
1795 | 1792 | =begin original |
1796 | 1793 | |
1797 | 1794 | If this variable is set to a true value, then C<stat()> on Windows will |
1798 | 1795 | not try to open the file. This means that the link count cannot be |
1799 | 1796 | determined and file attributes may be out of date if additional |
1800 | 1797 | hardlinks to the file exist. On the other hand, not opening the file |
1801 | 1798 | is considerably faster, especially for files on network drives. |
1802 | 1799 | |
1803 | 1800 | =end original |
1804 | 1801 | |
1805 | 1802 | この変数が真の値にセットされると、Windows での C<stat()> はファイルを |
1806 | 1803 | オープンしようとはしません。 |
1807 | 1804 | これは、このファイルへの追加のハードリンクが存在する場合、リンクカウントを |
1808 | 1805 | 決定できませんし、ファイル属性が古いものになるかもしれないことを意味します。 |
1809 | 1806 | 一方、ファイルを開かないので、(特にファイルがネットワークドライブにある |
1810 | 1807 | 場合は)大幅に高速です。 |
1811 | 1808 | |
1812 | 1809 | =begin original |
1813 | 1810 | |
1814 | 1811 | This variable could be set in the F<sitecustomize.pl> file to |
1815 | 1812 | configure the local Perl installation to use "sloppy" C<stat()> by |
1816 | 1813 | default. See the documentation for B<-f> in |
1817 | 1814 | L<perlrun|perlrun/"Command Switches"> for more information about site |
1818 | 1815 | customization. |
1819 | 1816 | |
1820 | 1817 | =end original |
1821 | 1818 | |
1822 | 1819 | デフォルトで「ずさんな」C<stat()> を使うために、この変数は、ローカルな |
1823 | 1820 | Perl を設定するための F<sitecustomize.pl> で設定できます。 |
1824 | 1821 | サイトカスタマイズに関するさらなる情報については |
1825 | 1822 | L<perlrun|perlrun/"Command Switches"> の B<-f> を参照してください。 |
1826 | 1823 | |
1827 | 1824 | =begin original |
1828 | 1825 | |
1829 | 1826 | This variable was added in Perl v5.10.0. |
1830 | 1827 | |
1831 | 1828 | =end original |
1832 | 1829 | |
1833 | 1830 | この変数は Perl v5.10.0 で追加されました。 |
1834 | 1831 | |
1835 | 1832 | =item $EXECUTABLE_NAME |
1836 | 1833 | |
1837 | 1834 | =item $^X |
1838 | 1835 | X<$^X> X<$EXECUTABLE_NAME> |
1839 | 1836 | |
1840 | 1837 | =begin original |
1841 | 1838 | |
1842 | 1839 | The name used to execute the current copy of Perl, from C's |
1843 | 1840 | C<argv[0]> or (where supported) F</proc/self/exe>. |
1844 | 1841 | |
1845 | 1842 | =end original |
1846 | 1843 | |
1847 | 1844 | Perl バイナリ自身が実行された時の名前を C の argv[0] または (対応していれば) |
1848 | 1845 | F</proc/self/exe> から持ってきたものです。 |
1849 | 1846 | |
1850 | 1847 | =begin original |
1851 | 1848 | |
1852 | 1849 | Depending on the host operating system, the value of C<$^X> may be |
1853 | 1850 | a relative or absolute pathname of the perl program file, or may |
1854 | 1851 | be the string used to invoke perl but not the pathname of the |
1855 | 1852 | perl program file. Also, most operating systems permit invoking |
1856 | 1853 | programs that are not in the PATH environment variable, so there |
1857 | 1854 | is no guarantee that the value of C<$^X> is in PATH. For VMS, the |
1858 | 1855 | value may or may not include a version number. |
1859 | 1856 | |
1860 | 1857 | =end original |
1861 | 1858 | |
1862 | 1859 | ホスト OS に依存して、C<$^X> の値は perl プログラムファイルの絶対パスかも |
1863 | 1860 | しれませんし、相対パスかもしれませんし、perl を起動するために使われる |
1864 | 1861 | 文字列ではありますが perl プログラムファイルのパス名ではないかもしれません。 |
1865 | 1862 | また、ほとんどの OS は PATH 環境変数にない位置のプログラムを起動することを |
1866 | 1863 | 許しているので、C<$^X> の値が PATH にある保証はありません。 |
1867 | 1864 | VMS では、この値はバージョン番号を含む場合も含まない場合もあります。 |
1868 | 1865 | |
1869 | 1866 | =begin original |
1870 | 1867 | |
1871 | 1868 | You usually can use the value of C<$^X> to re-invoke an independent |
1872 | 1869 | copy of the same perl that is currently running, e.g., |
1873 | 1870 | |
1874 | 1871 | =end original |
1875 | 1872 | |
1876 | 1873 | 通常は、現在実行中のものと同じ perl の独立したコピーを再起動するために |
1877 | 1874 | C<$^X> の値を使えます; つまり: |
1878 | 1875 | |
1879 | 1876 | @first_run = `$^X -le "print int rand 100 for 1..100"`; |
1880 | 1877 | |
1881 | 1878 | =begin original |
1882 | 1879 | |
1883 | 1880 | But recall that not all operating systems support forking or |
1884 | 1881 | capturing of the output of commands, so this complex statement |
1885 | 1882 | may not be portable. |
1886 | 1883 | |
1887 | 1884 | =end original |
1888 | 1885 | |
1889 | 1886 | しかし、全ての OS が fork やコマンドの出力の捕捉に対応しているわけでは |
1890 | 1887 | ないので、この複雑な文は移植性がないかもしれないことを忘れないでください。 |
1891 | 1888 | |
1892 | 1889 | =begin original |
1893 | 1890 | |
1894 | 1891 | It is not safe to use the value of C<$^X> as a path name of a file, |
1895 | 1892 | as some operating systems that have a mandatory suffix on |
1896 | 1893 | executable files do not require use of the suffix when invoking |
1897 | 1894 | a command. To convert the value of C<$^X> to a path name, use the |
1898 | 1895 | following statements: |
1899 | 1896 | |
1900 | 1897 | =end original |
1901 | 1898 | |
1902 | 1899 | C<$^X> の値をファイルのパス名として使うのは安全ではありません; 実行ファイルに |
1903 | 1900 | 固定の接尾辞があり、コマンドの起動時には接尾辞が不要な OS もあるからです。 |
1904 | 1901 | C<$^X> の値をパス名に変換するには、以下のコードを使ってください: |
1905 | 1902 | |
1906 | 1903 | =begin original |
1907 | 1904 | |
1908 | 1905 | # Build up a set of file names (not command names). |
1909 | 1906 | use Config; |
1910 | 1907 | my $this_perl = $^X; |
1911 | 1908 | if ($^O ne 'VMS') { |
1912 | 1909 | $this_perl .= $Config{_exe} |
1913 | 1910 | unless $this_perl =~ m/$Config{_exe}$/i; |
1914 | 1911 | } |
1915 | 1912 | |
1916 | 1913 | =end original |
1917 | 1914 | |
1918 | 1915 | # (コマンド名ではなく)ファイル名を構築する。 |
1919 | 1916 | use Config; |
1920 | 1917 | my $this_perl = $^X; |
1921 | 1918 | if ($^O ne 'VMS') { |
1922 | 1919 | $this_perl .= $Config{_exe} |
1923 | 1920 | unless $this_perl =~ m/$Config{_exe}$/i; |
1924 | 1921 | } |
1925 | 1922 | |
1926 | 1923 | =begin original |
1927 | 1924 | |
1928 | 1925 | Because many operating systems permit anyone with read access to |
1929 | 1926 | the Perl program file to make a copy of it, patch the copy, and |
1930 | 1927 | then execute the copy, the security-conscious Perl programmer |
1931 | 1928 | should take care to invoke the installed copy of perl, not the |
1932 | 1929 | copy referenced by C<$^X>. The following statements accomplish |
1933 | 1930 | this goal, and produce a pathname that can be invoked as a |
1934 | 1931 | command or referenced as a file. |
1935 | 1932 | |
1936 | 1933 | =end original |
1937 | 1934 | |
1938 | 1935 | 多くの OS が Perl のプログラムファイルのコピーを作って、コピーにパッチを当て、 |
1939 | 1936 | それを実行するための読み込み権限を全員に与えているので、セキュリティ |
1940 | 1937 | 意識のある Perl プログラマは C<$^X> で参照されているコピーではなく、 |
1941 | 1938 | インストールされている perl を起動するように気をつけるべきです。 |
1942 | 1939 | 以下のコードはこの目的を達成し、コマンドとして起動したりファイルとして |
1943 | 1940 | 参照するためのパス名を作成します。 |
1944 | 1941 | |
1945 | 1942 | use Config; |
1946 | 1943 | my $secure_perl_path = $Config{perlpath}; |
1947 | 1944 | if ($^O ne 'VMS') { |
1948 | 1945 | $secure_perl_path .= $Config{_exe} |
1949 | 1946 | unless $secure_perl_path =~ m/$Config{_exe}$/i; |
1950 | 1947 | } |
1951 | 1948 | |
1952 | 1949 | =back |
1953 | 1950 | |
1954 | 1951 | =head2 Variables related to regular expressions |
1955 | 1952 | |
1956 | 1953 | (正規表現に関する変数) |
1957 | 1954 | |
1958 | 1955 | =begin original |
1959 | 1956 | |
1960 | 1957 | Most of the special variables related to regular expressions are side |
1961 | 1958 | effects. Perl sets these variables when it has a successful match, so |
1962 | 1959 | you should check the match result before using them. For instance: |
1963 | 1960 | |
1964 | 1961 | =end original |
1965 | 1962 | |
1966 | 1963 | 正規表現に関連する特殊変数のほとんどは副作用です。 |
1967 | 1964 | Perl はマッチングに成功したときにこれらの変数を設定するので、変数を |
1968 | 1965 | 使う前にマッチングの結果をチェックするべきです。 |
1969 | 1966 | 例えば: |
1970 | 1967 | |
1971 | 1968 | if( /P(A)TT(ER)N/ ) { |
1972 | 1969 | print "I found $1 and $2\n"; |
1973 | 1970 | } |
1974 | 1971 | |
1975 | 1972 | =begin original |
1976 | 1973 | |
1977 | 1974 | These variables are read-only and dynamically-scoped, unless we note |
1978 | 1975 | otherwise. |
1979 | 1976 | |
1980 | 1977 | =end original |
1981 | 1978 | |
1982 | 1979 | これらの変数は特に記さない限り読み込み専用で動的スコープを持ちます。 |
1983 | 1980 | |
1984 | 1981 | =begin original |
1985 | 1982 | |
1986 | 1983 | The dynamic nature of the regular expression variables means that |
1987 | 1984 | their value is limited to the block that they are in, as demonstrated |
1988 | 1985 | by this bit of code: |
1989 | 1986 | |
1990 | 1987 | =end original |
1991 | 1988 | |
1992 | 1989 | 正規表現変数の動的な特性により、以下のコード片で示されているように、 |
1993 | 1990 | 変数の値はブロック内に制限されます: |
1994 | 1991 | |
1995 | 1992 | my $outer = 'Wallace and Grommit'; |
1996 | 1993 | my $inner = 'Mutt and Jeff'; |
1997 | 1994 | |
1998 | 1995 | my $pattern = qr/(\S+) and (\S+)/; |
1999 | 1996 | |
2000 | 1997 | sub show_n { print "\$1 is $1; \$2 is $2\n" } |
2001 | 1998 | |
2002 | 1999 | { |
2003 | 2000 | OUTER: |
2004 | 2001 | show_n() if $outer =~ m/$pattern/; |
2005 | 2002 | |
2006 | 2003 | INNER: { |
2007 | 2004 | show_n() if $inner =~ m/$pattern/; |
2008 | 2005 | } |
2009 | 2006 | |
2010 | 2007 | show_n(); |
2011 | 2008 | } |
2012 | 2009 | |
2013 | 2010 | =begin original |
2014 | 2011 | |
2015 | 2012 | The output shows that while in the C<OUTER> block, the values of C<$1> |
2016 | 2013 | and C<$2> are from the match against C<$outer>. Inside the C<INNER> |
2017 | 2014 | block, the values of C<$1> and C<$2> are from the match against |
2018 | 2015 | C<$inner>, but only until the end of the block (i.e. the dynamic |
2019 | 2016 | scope). After the C<INNER> block completes, the values of C<$1> and |
2020 | 2017 | C<$2> return to the values for the match against C<$outer> even though |
2021 | 2018 | we have not made another match: |
2022 | 2019 | |
2023 | 2020 | =end original |
2024 | 2021 | |
2025 | 2022 | 出力から分かることは、C<OUTER> ブロックの間では C<$1> と C<$2> の値は |
2026 | 2023 | C<$outer> に対するマッチングからのものになります。 |
2027 | 2024 | C<INNER> ブロックの内側では、C<$1> と C<$2> の値は C<$inner> での |
2028 | 2025 | マッチングからのものになりますが、ブロックの最後までです (つまり、 |
2029 | 2026 | 動的スコープを持ちます)。 |
2030 | 2027 | C<INNER> ブロックの終了後、C<$1> と C<$2> の値は、他のマッチングがなくても |
2031 | 2028 | C<$outer> に対するマッチングからのものになります: |
2032 | 2029 | |
2033 | 2030 | $1 is Wallace; $2 is Grommit |
2034 | 2031 | $1 is Mutt; $2 is Jeff |
2035 | 2032 | $1 is Wallace; $2 is Grommit |
2036 | 2033 | |
2037 | 2034 | =head3 Performance issues |
2038 | 2035 | |
2039 | 2036 | (性能問題) |
2040 | 2037 | |
2041 | 2038 | =begin original |
2042 | 2039 | |
2043 | 2040 | Traditionally in Perl, any use of any of the three variables C<$`>, C<$&> |
2044 | 2041 | or C<$'> (or their C<use English> equivalents) anywhere in the code, caused |
2045 | 2042 | all subsequent successful pattern matches to make a copy of the matched |
2046 | 2043 | string, in case the code might subsequently access one of those variables. |
2047 | 2044 | This imposed a considerable performance penalty across the whole program, |
2048 | 2045 | so generally the use of these variables has been discouraged. |
2049 | 2046 | |
2050 | 2047 | =end original |
2051 | 2048 | |
2052 | 2049 | Perl では伝統的に、C<$`>, C<$&>, C<$'> (または C<use English> での |
2053 | 2050 | 等価物) をコードのどこかで使うと、コードが引き続いてこれらの変数に |
2054 | 2051 | アクセスするかもしれないので、引き続くすべての成功したパターンマッチングで |
2055 | 2052 | マッチングした文字列のコピーを作ります。 |
2056 | 2053 | これはプログラム全体に対してかなりの性能上の負荷を掛けるので、、一般的に |
2057 | 2054 | これらの変数の使用は非推奨です。 |
2058 | 2055 | |
2059 | 2056 | =begin original |
2060 | 2057 | |
2061 | 2058 | In Perl 5.6.0 the C<@-> and C<@+> dynamic arrays were introduced that |
2062 | 2059 | supply the indices of successful matches. So you could for example do |
2063 | 2060 | this: |
2064 | 2061 | |
2065 | 2062 | =end original |
2066 | 2063 | |
2067 | 2064 | Perl 5.6.0 では、マッチングに成功したインデックスを提供する C<@-> と |
2068 | 2065 | C<@+> 動的配列が導入されました。 |
2069 | 2066 | それで、たとえばこのようにできます: |
2070 | 2067 | |
2071 | 2068 | $str =~ /pattern/; |
2072 | 2069 | |
2073 | 2070 | print $`, $&, $'; # bad: performance hit |
2074 | 2071 | |
2075 | 2072 | print # good: no performance hit |
2076 | 2073 | substr($str, 0, $-[0]), |
2077 | 2074 | substr($str, $-[0], $+[0]-$-[0]), |
2078 | 2075 | substr($str, $+[0]); |
2079 | 2076 | |
2080 | 2077 | =begin original |
2081 | 2078 | |
2082 | 2079 | In Perl 5.10.0 the C</p> match operator flag and the C<${^PREMATCH}>, |
2083 | 2080 | C<${^MATCH}>, and C<${^POSTMATCH}> variables were introduced, that allowed |
2084 | 2081 | you to suffer the penalties only on patterns marked with C</p>. |
2085 | 2082 | |
2086 | 2083 | =end original |
2087 | 2084 | |
2088 | 2085 | Perl 5.10.0 で C</p> マッチング演算子フラグと C<${^PREMATCH}>, |
2089 | 2086 | C<${^MATCH}>, C<${^POSTMATCH}> 変数が導入され、C</p> でマークされた |
2090 | 2087 | パターンのみが負荷を被るようにできるようになりました。 |
2091 | 2088 | |
2092 | 2089 | =begin original |
2093 | 2090 | |
2094 | 2091 | In Perl 5.18.0 onwards, perl started noting the presence of each of the |
2095 | 2092 | three variables separately, and only copied that part of the string |
2096 | 2093 | required; so in |
2097 | 2094 | |
2098 | 2095 | =end original |
2099 | 2096 | |
2100 | 2097 | Perl 5.18.0 以降では、perl は三つの変数の存在を別々に注意するようになり、 |
2101 | 2098 | 必要な部分文字列のみをコピーするようになりました; 従って、次の場合は |
2102 | 2099 | |
2103 | 2100 | $`; $&; "abcdefgh" =~ /d/ |
2104 | 2101 | |
2105 | 2102 | =begin original |
2106 | 2103 | |
2107 | 2104 | perl would only copy the "abcd" part of the string. That could make a big |
2108 | 2105 | difference in something like |
2109 | 2106 | |
2110 | 2107 | =end original |
2111 | 2108 | |
2112 | 2109 | perl は文字列のうち "abcd" の部分のみをコピーします。 |
2113 | 2110 | これは次のようなものとは大きな違いになります |
2114 | 2111 | |
2115 | 2112 | $str = 'x' x 1_000_000; |
2116 | 2113 | $&; # whoops |
2117 | 2114 | $str =~ /x/g # one char copied a million times, not a million chars |
2118 | 2115 | |
2119 | 2116 | =begin original |
2120 | 2117 | |
2121 | 2118 | In Perl 5.20.0 a new copy-on-write system was enabled by default, which |
2122 | 2119 | finally fixes all performance issues with these three variables, and makes |
2123 | 2120 | them safe to use anywhere. |
2124 | 2121 | |
2125 | 2122 | =end original |
2126 | 2123 | |
2127 | 2124 | Perl 5.20.0 では新しいコピーオンライトシステムがデフォルトで有効になり、 |
2128 | 2125 | これらの変数に関する性能問題はすべて最終的に修正され、これらをどこで使っても |
2129 | 2126 | 安全になりました。 |
2130 | 2127 | |
2131 | 2128 | =begin original |
2132 | 2129 | |
2133 | 2130 | The C<Devel::NYTProf> and C<Devel::FindAmpersand> modules can help you |
2134 | 2131 | find uses of these problematic match variables in your code. |
2135 | 2132 | |
2136 | 2133 | =end original |
2137 | 2134 | |
2138 | 2135 | C<Devel::NYTProf> と C<Devel::FindAmpersand> のモジュールは、コード中に |
2139 | 2136 | これらの問題のあるマッチング変数の使用を探す助けになります。 |
2140 | 2137 | |
2141 | 2138 | =over 8 |
2142 | 2139 | |
2143 | 2140 | =item $<I<digits>> ($1, $2, ...) |
2144 | 2141 | X<$1> X<$2> X<$3> X<$I<digits>> |
2145 | 2142 | |
2146 | 2143 | =begin original |
2147 | 2144 | |
2148 | 2145 | Contains the subpattern from the corresponding set of capturing |
2149 | 2146 | parentheses from the last successful pattern match, not counting patterns |
2150 | 2147 | matched in nested blocks that have been exited already. |
2151 | 2148 | |
2152 | 2149 | =end original |
2153 | 2150 | |
2154 | 2151 | 最後に成功したパターンマッチングで対応する括弧のサブパターンにマッチングした |
2155 | 2152 | 文字列が入っているが、既に抜けてしまったブロックでの |
2156 | 2153 | パターンマッチングは勘定に入れません。 |
2157 | 2154 | |
2158 | 2155 | =begin original |
2159 | 2156 | |
2160 | 2157 | Note there is a distinction between a capture buffer which matches |
2161 | 2158 | the empty string a capture buffer which is optional. Eg, C<(x?)> and |
2162 | 2159 | C<(x)?> The latter may be undef, the former not. |
2163 | 2160 | |
2164 | 2161 | =end original |
2165 | 2162 | |
2166 | 2163 | 空文字列にマッチングする捕捉バッファと、オプションの捕捉バッファの |
2167 | 2164 | 違いに注意してください。 |
2168 | 2165 | 例えば、C<(x?)> と C<(x)?> では、後者は undef かもしれませんが、 |
2169 | 2166 | 前者は違います。 |
2170 | 2167 | |
2171 | 2168 | =begin original |
2172 | 2169 | |
2173 | 2170 | These variables are read-only and dynamically-scoped. |
2174 | 2171 | |
2175 | 2172 | =end original |
2176 | 2173 | |
2177 | 2174 | これらの変数はすべて読み込み専用で、動的なスコープを持ちます。 |
2178 | 2175 | |
2179 | 2176 | =begin original |
2180 | 2177 | |
2181 | 2178 | Mnemonic: like \digits. |
2182 | 2179 | |
2183 | 2180 | =end original |
2184 | 2181 | |
2185 | 2182 | 記憶法: \(数字) のようなもの。 |
2186 | 2183 | |
2187 | 2184 | =item @{^CAPTURE} |
2188 | 2185 | X<@{^CAPTURE}> X<@^CAPTURE> |
2189 | 2186 | |
2190 | 2187 | =begin original |
2191 | 2188 | |
2192 | 2189 | An array which exposes the contents of the capture buffers, if any, of |
2193 | 2190 | the last successful pattern match, not counting patterns matched |
2194 | 2191 | in nested blocks that have been exited already. |
2195 | 2192 | |
2196 | 2193 | =end original |
2197 | 2194 | |
2198 | 2195 | 最後に成功したパターンマッチングの (もしあれば) 捕捉バッファの内容を |
2199 | 2196 | 露出させた配列; 既に終了したネストしたブロックの中でマッチングしたパターンは |
2200 | 2197 | 考慮しません。 |
2201 | 2198 | |
2202 | 2199 | =begin original |
2203 | 2200 | |
2204 | 2201 | Note that the 0 index of @{^CAPTURE} is equivalent to $1, the 1 index |
2205 | 2202 | is equivalent to $2, etc. |
2206 | 2203 | |
2207 | 2204 | =end original |
2208 | 2205 | |
2209 | 2206 | @{^CAPTURE} の添え字 0 は $1 と等価、 |
2210 | 2207 | 添え字 1 は $2 と等価、などであることに注意してください。 |
2211 | 2208 | |
2212 | 2209 | if ("foal"=~/(.)(.)(.)(.)/) { |
2213 | 2210 | print join "-", @{^CAPTURE}; |
2214 | 2211 | } |
2215 | 2212 | |
2216 | 2213 | =begin original |
2217 | 2214 | |
2218 | 2215 | should output "f-o-a-l". |
2219 | 2216 | |
2220 | 2217 | =end original |
2221 | 2218 | |
2222 | 2219 | これは "f-o-a-l" を出力します。 |
2223 | 2220 | |
2224 | 2221 | =begin original |
2225 | 2222 | |
2226 | See also L< | |
2223 | See also L</$I<digits>>, L</%{^CAPTURE}> and L</%{^CAPTURE_ALL}>. | |
2227 | L</%{^CAPTURE_ALL}>. | |
2228 | 2224 | |
2229 | 2225 | =end original |
2230 | 2226 | |
2231 | L< | |
2227 | L</$I<digits>>, L</%{^CAPTURE}>, L</%{^CAPTURE_ALL}> も参照してください。 | |
2232 | L</%{^CAPTURE_ALL}> も参照してください。 | |
2233 | 2228 | |
2234 | 2229 | =begin original |
2235 | 2230 | |
2236 | 2231 | Note that unlike most other regex magic variables there is no single |
2237 | 2232 | letter equivalent to C<@{^CAPTURE}>. |
2238 | 2233 | |
2239 | 2234 | =end original |
2240 | 2235 | |
2241 | 2236 | その他のほとんどの正規表現マジカル変数と異なり、 |
2242 | 2237 | C<@{^CAPTURE}> と等価な単一文字変数はないことに注意してください。 |
2243 | 2238 | |
2244 | 2239 | =begin original |
2245 | 2240 | |
2246 | 2241 | This variable was added in 5.25.7 |
2247 | 2242 | |
2248 | 2243 | =end original |
2249 | 2244 | |
2250 | 2245 | これは 5.25.7 で追加されました。 |
2251 | 2246 | |
2252 | 2247 | =item $MATCH |
2253 | 2248 | |
2254 | 2249 | =item $& |
2255 | 2250 | X<$&> X<$MATCH> |
2256 | 2251 | |
2257 | 2252 | =begin original |
2258 | 2253 | |
2259 | 2254 | The string matched by the last successful pattern match (not counting |
2260 | 2255 | any matches hidden within a BLOCK or C<eval()> enclosed by the current |
2261 | 2256 | BLOCK). |
2262 | 2257 | |
2263 | 2258 | =end original |
2264 | 2259 | |
2265 | 2260 | 最後に成功したパターンマッチでマッチした文字列 (現在の BLOCK で囲まれた |
2266 | 2261 | BLOCK や C<eval()> で隠れている部分でのマッチは勘定に入れません)。 |
2267 | 2262 | |
2268 | 2263 | =begin original |
2269 | 2264 | |
2270 | 2265 | See L</Performance issues> above for the serious performance implications |
2271 | 2266 | of using this variable (even once) in your code. |
2272 | 2267 | |
2273 | 2268 | =end original |
2274 | 2269 | |
2275 | 2270 | この変数を(一度でも)使うことによる重大な性能の問題については前述した |
2276 | 2271 | L</Performance issues> を参照してください。 |
2277 | 2272 | |
2278 | 2273 | =begin original |
2279 | 2274 | |
2280 | 2275 | This variable is read-only and dynamically-scoped. |
2281 | 2276 | |
2282 | 2277 | =end original |
2283 | 2278 | |
2284 | 2279 | この変数は読み込み専用で動的スコープを持ちます。 |
2285 | 2280 | |
2286 | 2281 | =begin original |
2287 | 2282 | |
2288 | 2283 | Mnemonic: like C<&> in some editors. |
2289 | 2284 | |
2290 | 2285 | =end original |
2291 | 2286 | |
2292 | 2287 | 記憶法: あるエディタの C<&> ようなもの。 |
2293 | 2288 | |
2294 | 2289 | =item ${^MATCH} |
2295 | 2290 | X<${^MATCH}> |
2296 | 2291 | |
2297 | 2292 | =begin original |
2298 | 2293 | |
2299 | 2294 | This is similar to C<$&> (C<$MATCH>) except that it does not incur the |
2300 | 2295 | performance penalty associated with that variable. |
2301 | 2296 | |
2302 | 2297 | =end original |
2303 | 2298 | |
2304 | 2299 | これは C<$&> (C<$MATCH>) と同様ですが、この変数と関連付けられた性能上の |
2305 | 2300 | ペナルティを被りません。 |
2306 | 2301 | |
2307 | 2302 | =begin original |
2308 | 2303 | |
2309 | 2304 | See L</Performance issues> above. |
2310 | 2305 | |
2311 | 2306 | =end original |
2312 | 2307 | |
2313 | 2308 | 前述した L</Performance issues> を参照してください。 |
2314 | 2309 | |
2315 | 2310 | =begin original |
2316 | 2311 | |
2317 | 2312 | In Perl v5.18 and earlier, it is only guaranteed |
2318 | 2313 | to return a defined value when the pattern was compiled or executed with |
2319 | 2314 | the C</p> modifier. In Perl v5.20, the C</p> modifier does nothing, so |
2320 | 2315 | C<${^MATCH}> does the same thing as C<$MATCH>. |
2321 | 2316 | |
2322 | 2317 | =end original |
2323 | 2318 | |
2324 | 2319 | Perl v5.18 以前では、パターンが C</p> 修飾子付きでコンパイルまたは実行された |
2325 | 2320 | 場合にのみ定義された値を返すことが保証されます。 |
2326 | 2321 | Perl v5.20 では、C</p> 修飾子は何もしないので、C<${^MATCH}> は C<$MATCH> と |
2327 | 2322 | 同じです。 |
2328 | 2323 | |
2329 | 2324 | =begin original |
2330 | 2325 | |
2331 | 2326 | This variable was added in Perl v5.10.0. |
2332 | 2327 | |
2333 | 2328 | =end original |
2334 | 2329 | |
2335 | 2330 | この変数は Perl v5.10.0 で追加されました。 |
2336 | 2331 | |
2337 | 2332 | =begin original |
2338 | 2333 | |
2339 | 2334 | This variable is read-only and dynamically-scoped. |
2340 | 2335 | |
2341 | 2336 | =end original |
2342 | 2337 | |
2343 | 2338 | この変数は読み込み専用で動的スコープを持ちます。 |
2344 | 2339 | |
2345 | 2340 | =item $PREMATCH |
2346 | 2341 | |
2347 | 2342 | =item $` |
2348 | 2343 | X<$`> X<$PREMATCH> X<${^PREMATCH}> |
2349 | 2344 | |
2350 | 2345 | =begin original |
2351 | 2346 | |
2352 | 2347 | The string preceding whatever was matched by the last successful |
2353 | 2348 | pattern match, not counting any matches hidden within a BLOCK or C<eval> |
2354 | 2349 | enclosed by the current BLOCK. |
2355 | 2350 | |
2356 | 2351 | =end original |
2357 | 2352 | |
2358 | 2353 | 最後の成功したパターンマッチ (現在のBLOCK で囲まれた BLOCK や eval() に |
2359 | 2354 | 隠れている部分でのマッチは勘定に入れません) でマッチした部分の前の文字列。 |
2360 | 2355 | |
2361 | 2356 | =begin original |
2362 | 2357 | |
2363 | 2358 | See L</Performance issues> above for the serious performance implications |
2364 | 2359 | of using this variable (even once) in your code. |
2365 | 2360 | |
2366 | 2361 | =end original |
2367 | 2362 | |
2368 | 2363 | この変数を(一度でも)使うことによる重大な性能の問題については前述した |
2369 | 2364 | L</Performance issues> を参照してください。 |
2370 | 2365 | |
2371 | 2366 | =begin original |
2372 | 2367 | |
2373 | 2368 | This variable is read-only and dynamically-scoped. |
2374 | 2369 | |
2375 | 2370 | =end original |
2376 | 2371 | |
2377 | 2372 | この変数は読み込み専用で動的スコープを持ちます。 |
2378 | 2373 | |
2379 | 2374 | =begin original |
2380 | 2375 | |
2381 | 2376 | Mnemonic: C<`> often precedes a quoted string. |
2382 | 2377 | |
2383 | 2378 | =end original |
2384 | 2379 | |
2385 | 2380 | 記憶法: C<`> は多くの場合クォートされた文字列の前にある。 |
2386 | 2381 | |
2387 | 2382 | =item ${^PREMATCH} |
2388 | 2383 | X<$`> X<${^PREMATCH}> |
2389 | 2384 | |
2390 | 2385 | =begin original |
2391 | 2386 | |
2392 | 2387 | This is similar to C<$`> ($PREMATCH) except that it does not incur the |
2393 | 2388 | performance penalty associated with that variable. |
2394 | 2389 | |
2395 | 2390 | =end original |
2396 | 2391 | |
2397 | 2392 | これは C<$`> ($PREMATCH) と同様ですが、この変数と関連付けられた性能上の |
2398 | 2393 | ペナルティを被りません。 |
2399 | 2394 | |
2400 | 2395 | =begin original |
2401 | 2396 | |
2402 | 2397 | See L</Performance issues> above. |
2403 | 2398 | |
2404 | 2399 | =end original |
2405 | 2400 | |
2406 | 2401 | 前述した L</Performance issues> を参照してください。 |
2407 | 2402 | |
2408 | 2403 | =begin original |
2409 | 2404 | |
2410 | 2405 | In Perl v5.18 and earlier, it is only guaranteed |
2411 | 2406 | to return a defined value when the pattern was compiled or executed with |
2412 | 2407 | the C</p> modifier. In Perl v5.20, the C</p> modifier does nothing, so |
2413 | 2408 | C<${^PREMATCH}> does the same thing as C<$PREMATCH>. |
2414 | 2409 | |
2415 | 2410 | =end original |
2416 | 2411 | |
2417 | 2412 | Perl v5.18 以前では、パターンが C</p> 修飾子付きでコンパイルまたは実行された |
2418 | 2413 | 場合にのみ定義された値を返すことが保証されます。 |
2419 | 2414 | Perl v5.20 では、C</p> 修飾子は何もしないので、C<${^PREMATCH}> は |
2420 | 2415 | C<$PREMATCH> と同じです。 |
2421 | 2416 | |
2422 | 2417 | =begin original |
2423 | 2418 | |
2424 | 2419 | This variable was added in Perl v5.10.0. |
2425 | 2420 | |
2426 | 2421 | =end original |
2427 | 2422 | |
2428 | 2423 | この変数は Perl v5.10.0 で追加されました。 |
2429 | 2424 | |
2430 | 2425 | =begin original |
2431 | 2426 | |
2432 | 2427 | This variable is read-only and dynamically-scoped. |
2433 | 2428 | |
2434 | 2429 | =end original |
2435 | 2430 | |
2436 | 2431 | この変数は読み込み専用で動的スコープを持ちます。 |
2437 | 2432 | |
2438 | 2433 | =item $POSTMATCH |
2439 | 2434 | |
2440 | 2435 | =item $' |
2441 | 2436 | X<$'> X<$POSTMATCH> X<${^POSTMATCH}> X<@-> |
2442 | 2437 | |
2443 | 2438 | =begin original |
2444 | 2439 | |
2445 | 2440 | The string following whatever was matched by the last successful |
2446 | 2441 | pattern match (not counting any matches hidden within a BLOCK or C<eval()> |
2447 | 2442 | enclosed by the current BLOCK). Example: |
2448 | 2443 | |
2449 | 2444 | =end original |
2450 | 2445 | |
2451 | 2446 | 最後の成功したパターンマッチ (現在のBLOCK で囲まれた BLOCK や eval() に |
2452 | 2447 | 隠れている部分でのマッチは勘定に入れない) でマッチした部分に続く文字列。 |
2453 | 2448 | 例: |
2454 | 2449 | |
2455 | 2450 | =begin original |
2456 | 2451 | |
2457 | 2452 | local $_ = 'abcdefghi'; |
2458 | 2453 | /def/; |
2459 | 2454 | print "$`:$&:$'\n"; # prints abc:def:ghi |
2460 | 2455 | |
2461 | 2456 | =end original |
2462 | 2457 | |
2463 | 2458 | local $_ = 'abcdefghi'; |
2464 | 2459 | /def/; |
2465 | 2460 | print "$`:$&:$'\n"; # abc:def:ghi を表示 |
2466 | 2461 | |
2467 | 2462 | =begin original |
2468 | 2463 | |
2469 | 2464 | See L</Performance issues> above for the serious performance implications |
2470 | 2465 | of using this variable (even once) in your code. |
2471 | 2466 | |
2472 | 2467 | =end original |
2473 | 2468 | |
2474 | 2469 | この変数を(一度でも)使うことによる重大な性能の問題については前述した |
2475 | 2470 | L</Performance issues> を参照してください。 |
2476 | 2471 | |
2477 | 2472 | =begin original |
2478 | 2473 | |
2479 | 2474 | This variable is read-only and dynamically-scoped. |
2480 | 2475 | |
2481 | 2476 | =end original |
2482 | 2477 | |
2483 | 2478 | この変数は読み込み専用で動的スコープを持ちます。 |
2484 | 2479 | |
2485 | 2480 | =begin original |
2486 | 2481 | |
2487 | 2482 | Mnemonic: C<'> often follows a quoted string. |
2488 | 2483 | |
2489 | 2484 | =end original |
2490 | 2485 | |
2491 | 2486 | 記憶法: C<'> は多くの場合クォートされた文字列の後にある。 |
2492 | 2487 | |
2493 | 2488 | =item ${^POSTMATCH} |
2494 | 2489 | X<${^POSTMATCH}> X<$'> X<$POSTMATCH> |
2495 | 2490 | |
2496 | 2491 | =begin original |
2497 | 2492 | |
2498 | 2493 | This is similar to C<$'> (C<$POSTMATCH>) except that it does not incur the |
2499 | 2494 | performance penalty associated with that variable. |
2500 | 2495 | |
2501 | 2496 | =end original |
2502 | 2497 | |
2503 | 2498 | これは C<$'> (C<$POSTMATCH>) と同様ですが、この変数と関連付けられた性能上の |
2504 | 2499 | ペナルティを被りません。 |
2505 | 2500 | |
2506 | 2501 | =begin original |
2507 | 2502 | |
2508 | 2503 | See L</Performance issues> above. |
2509 | 2504 | |
2510 | 2505 | =end original |
2511 | 2506 | |
2512 | 2507 | 前述した L</Performance issues> を参照してください。 |
2513 | 2508 | |
2514 | 2509 | =begin original |
2515 | 2510 | |
2516 | 2511 | In Perl v5.18 and earlier, it is only guaranteed |
2517 | 2512 | to return a defined value when the pattern was compiled or executed with |
2518 | 2513 | the C</p> modifier. In Perl v5.20, the C</p> modifier does nothing, so |
2519 | 2514 | C<${^POSTMATCH}> does the same thing as C<$POSTMATCH>. |
2520 | 2515 | |
2521 | 2516 | =end original |
2522 | 2517 | |
2523 | 2518 | Perl v5.18 以前では、パターンが C</p> 修飾子付きでコンパイルまたは実行された |
2524 | 2519 | 場合にのみ定義された値を返すことが保証されます。 |
2525 | 2520 | Perl v5.20 では、C</p> 修飾子は何もしないので、C<${^POSTMATCH}> は |
2526 | 2521 | C<$POSTMATCH> と同じです。 |
2527 | 2522 | |
2528 | 2523 | =begin original |
2529 | 2524 | |
2530 | 2525 | This variable was added in Perl v5.10.0. |
2531 | 2526 | |
2532 | 2527 | =end original |
2533 | 2528 | |
2534 | 2529 | この変数は Perl v5.10.0 で追加されました。 |
2535 | 2530 | |
2536 | 2531 | =begin original |
2537 | 2532 | |
2538 | 2533 | This variable is read-only and dynamically-scoped. |
2539 | 2534 | |
2540 | 2535 | =end original |
2541 | 2536 | |
2542 | 2537 | この変数は読み込み専用で動的スコープを持ちます。 |
2543 | 2538 | |
2544 | 2539 | =item $LAST_PAREN_MATCH |
2545 | 2540 | |
2546 | 2541 | =item $+ |
2547 | 2542 | X<$+> X<$LAST_PAREN_MATCH> |
2548 | 2543 | |
2549 | 2544 | =begin original |
2550 | 2545 | |
2551 | The text matched by the | |
2546 | The text matched by the last bracket of the last successful search pattern. | |
2552 | successful search pattern. It is logically equivalent to the highest | |
2553 | numbered capture variable (C<$1>, C<$2>, ...) which has a defined value. | |
2554 | ||
2555 | ||
2556 | =end original | |
2557 | ||
2558 | 最後に検索されたパターンの最大の使われたの捕捉グループにマッチした文字列。 | |
2559 | これはいくつかの選択肢の中でどれがマッチするのか | |
2560 | これは、定義されている最大の番号の捕捉変数 | |
2561 | (C<$1>, C<$2>, ...) と論理的に等価です。 | |
2562 | ||
2563 | =begin original | |
2564 | ||
2565 | 2547 | This is useful if you don't know which one of a set of alternative patterns |
2566 | 2548 | matched. For example: |
2567 | 2549 | |
2568 | 2550 | =end original |
2569 | 2551 | |
2552 | 最後に検索されたパターンの最後の括弧にマッチした文字列。 | |
2553 | これはいくつかの選択肢の中でどれがマッチするのか | |
2570 | 2554 | わからないような場合に使うと便利です。 |
2571 | 2555 | 例えば: |
2572 | 2556 | |
2573 | 2557 | /Version: (.*)|Revision: (.*)/ && ($rev = $+); |
2574 | 2558 | |
2575 | 2559 | =begin original |
2576 | 2560 | |
2577 | 2561 | This variable is read-only and dynamically-scoped. |
2578 | 2562 | |
2579 | 2563 | =end original |
2580 | 2564 | |
2581 | 2565 | この変数は読み込み専用で動的スコープを持ちます。 |
2582 | 2566 | |
2583 | 2567 | =begin original |
2584 | 2568 | |
2585 | 2569 | Mnemonic: be positive and forward looking. |
2586 | 2570 | |
2587 | 2571 | =end original |
2588 | 2572 | |
2589 | 2573 | 記憶法: ポジティブで前向き。 |
2590 | 2574 | |
2591 | 2575 | =item $LAST_SUBMATCH_RESULT |
2592 | 2576 | |
2593 | 2577 | =item $^N |
2594 | 2578 | X<$^N> X<$LAST_SUBMATCH_RESULT> |
2595 | 2579 | |
2596 | 2580 | =begin original |
2597 | 2581 | |
2598 | 2582 | The text matched by the used group most-recently closed (i.e. the group |
2599 | 2583 | with the rightmost closing parenthesis) of the last successful search |
2600 | pattern. | |
2584 | pattern. | |
2601 | 2585 | |
2602 | 2586 | =end original |
2603 | 2587 | |
2604 | 2588 | 最近のマッチングに成功した検索パターンのうち、一番最近に閉じられた使われた |
2605 | 2589 | グループ(つまり、一番右の閉じかっこのグループ)にマッチングしたテキスト。 |
2606 | これは C<$+> とわずかに異なります。 | |
2607 | 例えば次のものは | |
2608 | 2590 | |
2609 | "ab" =~ /^((.)(.))$/ | |
2610 | ||
2611 | 2591 | =begin original |
2612 | 2592 | |
2613 | we have | |
2614 | ||
2615 | =end original | |
2616 | ||
2617 | 次の結果になります | |
2618 | ||
2619 | $1,$^N have the value "ab" | |
2620 | $2 has the value "a" | |
2621 | $3,$+ have the value "b" | |
2622 | ||
2623 | =begin original | |
2624 | ||
2625 | 2593 | This is primarily used inside C<(?{...})> blocks for examining text |
2626 | 2594 | recently matched. For example, to effectively capture text to a variable |
2627 | 2595 | (in addition to C<$1>, C<$2>, etc.), replace C<(...)> with |
2628 | 2596 | |
2629 | 2597 | =end original |
2630 | 2598 | |
2631 | 2599 | これは主として最近マッチしたテキストを調べるために C<(?{...})> ブロックの |
2632 | 2600 | 中で使われます。 |
2633 | 2601 | 例えば、(C<$1>, C<$2> などに加えて) テキストを変数に効率的に捕捉するには、 |
2634 | 2602 | C<(...)> を以下で置き換えます: |
2635 | 2603 | |
2636 | 2604 | (?:(...)(?{ $var = $^N })) |
2637 | 2605 | |
2638 | 2606 | =begin original |
2639 | 2607 | |
2640 | 2608 | By setting and then using C<$var> in this way relieves you from having to |
2641 | 2609 | worry about exactly which numbered set of parentheses they are. |
2642 | 2610 | |
2643 | 2611 | =end original |
2644 | 2612 | |
2645 | 2613 | C<$var> をこの方法で設定してから使うことで、かっこの組の番号について |
2646 | 2614 | 気にしなくてすむようになります。 |
2647 | 2615 | |
2648 | 2616 | =begin original |
2649 | 2617 | |
2650 | 2618 | This variable was added in Perl v5.8.0. |
2651 | 2619 | |
2652 | 2620 | =end original |
2653 | 2621 | |
2654 | 2622 | この変数は Perl v5.8.0 で追加されました。 |
2655 | 2623 | |
2656 | 2624 | =begin original |
2657 | 2625 | |
2658 | 2626 | Mnemonic: the (possibly) Nested parenthesis that most recently closed. |
2659 | 2627 | |
2660 | 2628 | =end original |
2661 | 2629 | |
2662 | 2630 | 記憶法: もっとも最近閉じられた、(おそらく) ネストした (Nested) かっこ。 |
2663 | 2631 | |
2664 | 2632 | =item @LAST_MATCH_END |
2665 | 2633 | |
2666 | 2634 | =item @+ |
2667 | 2635 | X<@+> X<@LAST_MATCH_END> |
2668 | 2636 | |
2669 | 2637 | =begin original |
2670 | 2638 | |
2671 | 2639 | This array holds the offsets of the ends of the last successful |
2672 | 2640 | submatches in the currently active dynamic scope. C<$+[0]> is |
2673 | 2641 | the offset into the string of the end of the entire match. This |
2674 | 2642 | is the same value as what the C<pos> function returns when called |
2675 | 2643 | on the variable that was matched against. The I<n>th element |
2676 | 2644 | of this array holds the offset of the I<n>th submatch, so |
2677 | 2645 | C<$+[1]> is the offset past where C<$1> ends, C<$+[2]> the offset |
2678 | 2646 | past where C<$2> ends, and so on. You can use C<$#+> to determine |
2679 | 2647 | how many subgroups were in the last successful match. See the |
2680 | 2648 | examples given for the C<@-> variable. |
2681 | 2649 | |
2682 | 2650 | =end original |
2683 | 2651 | |
2684 | 2652 | この配列は、現在アクティブな動的スコープで最後に成功した部分マッチングの |
2685 | 2653 | 最後へのオフセットを保持します。 |
2686 | 2654 | C<$+[0]> はマッチ全体の文字列の最後へのオフセットです。 |
2687 | 2655 | これはマッチした変数に対して C<pos> 関数を呼び出したときの返り値と同じです。 |
2688 | 2656 | この配列の I<n> 番目の要素は I<n> 番目のサブマッチのオフセットを |
2689 | 2657 | 保持しているので、C<$+[1]> は過去の C<$1> の終わりのオフセット、C<$+[2]> は |
2690 | 2658 | C<$2> のオフセット、という形になります。 |
2691 | 2659 | C<$#+> は最後に成功したマッチでいくつサブグループがあるかを決定するのに |
2692 | 2660 | 使えます。 |
2693 | 2661 | C<@-> 変数の例を参照して下さい。 |
2694 | 2662 | |
2695 | 2663 | =begin original |
2696 | 2664 | |
2697 | 2665 | This variable was added in Perl v5.6.0. |
2698 | 2666 | |
2699 | 2667 | =end original |
2700 | 2668 | |
2701 | 2669 | この変数は Perl v5.6.0 で追加されました。 |
2702 | 2670 | |
2703 | 2671 | =item %{^CAPTURE} |
2704 | 2672 | |
2705 | 2673 | =item %LAST_PAREN_MATCH |
2706 | 2674 | |
2707 | 2675 | =item %+ |
2708 | 2676 | X<%+> X<%LAST_PAREN_MATCH> X<%{^CAPTURE}> |
2709 | 2677 | |
2710 | 2678 | =begin original |
2711 | 2679 | |
2712 | 2680 | Similar to C<@+>, the C<%+> hash allows access to the named capture |
2713 | 2681 | buffers, should they exist, in the last successful match in the |
2714 | 2682 | currently active dynamic scope. |
2715 | 2683 | |
2716 | 2684 | =end original |
2717 | 2685 | |
2718 | 2686 | C<@+> と同様、C<%+> ハッシュは、現在アクティブな動的スコープで最後に成功した |
2719 | 2687 | マッチングの名前付き捕捉バッファ(存在すれば)へのアクセスを可能にします。 |
2720 | 2688 | |
2721 | 2689 | =begin original |
2722 | 2690 | |
2723 | 2691 | For example, C<$+{foo}> is equivalent to C<$1> after the following match: |
2724 | 2692 | |
2725 | 2693 | =end original |
2726 | 2694 | |
2727 | 2695 | 例えば、C<$+{foo}> は以下のマッチングの後の C<$1> と等価です: |
2728 | 2696 | |
2729 | 2697 | 'foo' =~ /(?<foo>foo)/; |
2730 | 2698 | |
2731 | 2699 | =begin original |
2732 | 2700 | |
2733 | 2701 | The keys of the C<%+> hash list only the names of buffers that have |
2734 | 2702 | captured (and that are thus associated to defined values). |
2735 | 2703 | |
2736 | 2704 | =end original |
2737 | 2705 | |
2738 | 2706 | C<%+> ハッシュのキーは捕捉された(従って定義された値と結びついている) |
2739 | 2707 | バッファの名前のみの一覧です。 |
2740 | 2708 | |
2741 | 2709 | =begin original |
2742 | 2710 | |
2743 | 2711 | If multiple distinct capture groups have the same name, then |
2744 | 2712 | C<$+{NAME}> will refer to the leftmost defined group in the match. |
2745 | 2713 | |
2746 | 2714 | =end original |
2747 | 2715 | |
2748 | 2716 | 同じ名前の複数の異なる補足グループがある場合、 |
2749 | 2717 | C<$+{NAME}> はマッチングの中で一番左側に定義されているグループを |
2750 | 2718 | 参照します。 |
2751 | 2719 | |
2752 | 2720 | =begin original |
2753 | 2721 | |
2754 | 2722 | The underlying behaviour of C<%+> is provided by the |
2755 | 2723 | L<Tie::Hash::NamedCapture> module. |
2756 | 2724 | |
2757 | 2725 | =end original |
2758 | 2726 | |
2759 | 2727 | C<%+> の基礎となる振る舞いは L<Tie::Hash::NamedCapture> モジュールで |
2760 | 2728 | 提供されています。 |
2761 | 2729 | |
2762 | 2730 | =begin original |
2763 | 2731 | |
2764 | 2732 | B<Note:> C<%-> and C<%+> are tied views into a common internal hash |
2765 | 2733 | associated with the last successful regular expression. Therefore mixing |
2766 | 2734 | iterative access to them via C<each> may have unpredictable results. |
2767 | 2735 | Likewise, if the last successful match changes, then the results may be |
2768 | 2736 | surprising. |
2769 | 2737 | |
2770 | 2738 | =end original |
2771 | 2739 | |
2772 | 2740 | B<注意:> C<%-> and C<%+> は最後に成功した正規表現と関連付けられた共通の |
2773 | 2741 | 内部ハッシュと tie されたビューです。 |
2774 | 2742 | 従って、C<each> 経由で混ざった反復アクセスを行うと、予測不能の結果となります。 |
2775 | 2743 | 同様に、最後に成功したマッチングを変更すると、結果は驚くべきものとなります。 |
2776 | 2744 | |
2777 | 2745 | =begin original |
2778 | 2746 | |
2779 | 2747 | This variable was added in Perl v5.10.0. The C<%{^CAPTURE}> alias was |
2780 | 2748 | added in 5.25.7. |
2781 | 2749 | |
2782 | 2750 | =end original |
2783 | 2751 | |
2784 | 2752 | この変数は Perl v5.10.0 で追加されました。 |
2785 | 2753 | C<%{^CAPTURE}> の別名は 5.25.7 で追加されました。 |
2786 | 2754 | |
2787 | 2755 | =begin original |
2788 | 2756 | |
2789 | 2757 | This variable is read-only and dynamically-scoped. |
2790 | 2758 | |
2791 | 2759 | =end original |
2792 | 2760 | |
2793 | 2761 | この変数は読み込み専用で動的スコープを持ちます。 |
2794 | 2762 | |
2795 | 2763 | =item @LAST_MATCH_START |
2796 | 2764 | |
2797 | 2765 | =item @- |
2798 | 2766 | X<@-> X<@LAST_MATCH_START> |
2799 | 2767 | |
2800 | 2768 | =begin original |
2801 | 2769 | |
2802 | 2770 | C<$-[0]> is the offset of the start of the last successful match. |
2803 | C<$-[I<n>]> is the offset of the start of the substring matched by | |
2771 | C<$-[>I<n>C<]> is the offset of the start of the substring matched by | |
2804 | 2772 | I<n>-th subpattern, or undef if the subpattern did not match. |
2805 | 2773 | |
2806 | 2774 | =end original |
2807 | 2775 | |
2808 | 2776 | C<$-[0]> は最後に成功したマッチの先頭のオフセットです。 |
2809 | C<$-[I<n>]> は I<n> 番目のサブパターンにマッチした部分文字列の先頭の | |
2777 | C<$-[>I<n>C<]> は I<n> 番目のサブパターンにマッチした部分文字列の先頭の | |
2810 | 2778 | オフセットです; サブパターンがマッチしなかった場合は undef です。 |
2811 | 2779 | |
2812 | 2780 | =begin original |
2813 | 2781 | |
2814 | 2782 | Thus, after a match against C<$_>, C<$&> coincides with C<substr $_, $-[0], |
2815 | 2783 | $+[0] - $-[0]>. Similarly, $I<n> coincides with C<substr $_, $-[n], |
2816 | 2784 | $+[n] - $-[n]> if C<$-[n]> is defined, and $+ coincides with |
2817 | 2785 | C<substr $_, $-[$#-], $+[$#-] - $-[$#-]>. One can use C<$#-> to find the |
2818 | 2786 | last matched subgroup in the last successful match. Contrast with |
2819 | 2787 | C<$#+>, the number of subgroups in the regular expression. Compare |
2820 | 2788 | with C<@+>. |
2821 | 2789 | |
2822 | 2790 | =end original |
2823 | 2791 | |
2824 | 2792 | 従って C<$_> のマッチの後、C<$&> は C<substr $_, $-[0], $+[0] - $-[0]> と |
2825 | 2793 | 一致します。 |
2826 | 2794 | 同様に、$I<n> は、C<$-[n]> が定義されていれば |
2827 | 2795 | C<substr $_, $-[n], $+[n] - $-[n]> と一致し、 |
2828 | 2796 | $+ は C<substr $_, $-[$#-], $+[$#-] - $-[$#-]> と一致します。 |
2829 | 2797 | C<$#-> は直前に成功したマッチで最後のマッチしたサブグループを |
2830 | 2798 | 探すのに使えます。 |
2831 | 2799 | 正規表現でのサブグループの数である C<$#+> と対照的です。 |
2832 | 2800 | C<@+> と比較してください。 |
2833 | 2801 | |
2834 | 2802 | =begin original |
2835 | 2803 | |
2836 | 2804 | This array holds the offsets of the beginnings of the last |
2837 | 2805 | successful submatches in the currently active dynamic scope. |
2838 | 2806 | C<$-[0]> is the offset into the string of the beginning of the |
2839 | 2807 | entire match. The I<n>th element of this array holds the offset |
2840 | 2808 | of the I<n>th submatch, so C<$-[1]> is the offset where C<$1> |
2841 | 2809 | begins, C<$-[2]> the offset where C<$2> begins, and so on. |
2842 | 2810 | |
2843 | 2811 | =end original |
2844 | 2812 | |
2845 | 2813 | この配列は現在アクティブな動的スコープ内で最後に成功した |
2846 | 2814 | サブマッチの先頭位置のオフセットを保持します。 |
2847 | 2815 | C<$-[0]> はマッチ全体の先頭の文字列へのオフセットです。 |
2848 | 2816 | この配列の I<n> 番目の要素は I<n> 番目のサブマッチへの |
2849 | 2817 | オフセットを保持しますので、C<$-[1]> は C<$1> の先頭への |
2850 | 2818 | オフセット、C<$-[2]> は C<$2> の先頭へのオフセット、などとなります。 |
2851 | 2819 | |
2852 | 2820 | =begin original |
2853 | 2821 | |
2854 | 2822 | After a match against some variable C<$var>: |
2855 | 2823 | |
2856 | 2824 | =end original |
2857 | 2825 | |
2858 | 2826 | ある変数 C<$var> でマッチした後、以下のようになります。 |
2859 | 2827 | |
2860 | 2828 | =over 5 |
2861 | 2829 | |
2862 | 2830 | =item C<$`> is the same as C<substr($var, 0, $-[0])> |
2863 | 2831 | |
2864 | 2832 | (C<$`> は C<substr($var, 0, $-[0])> と同じです) |
2865 | 2833 | |
2866 | 2834 | =item C<$&> is the same as C<substr($var, $-[0], $+[0] - $-[0])> |
2867 | 2835 | |
2868 | 2836 | (C<$&> は C<substr($var, $-[0], $+[0] - $-[0])> と同じです) |
2869 | 2837 | |
2870 | 2838 | =item C<$'> is the same as C<substr($var, $+[0])> |
2871 | 2839 | |
2872 | 2840 | (C<$'> は C<substr($var, $+[0])> と同じです) |
2873 | 2841 | |
2874 | 2842 | =item C<$1> is the same as C<substr($var, $-[1], $+[1] - $-[1])> |
2875 | 2843 | |
2876 | 2844 | (C<$1> は C<substr($var, $-[1], $+[1] - $-[1])> と同じです) |
2877 | 2845 | |
2878 | 2846 | =item C<$2> is the same as C<substr($var, $-[2], $+[2] - $-[2])> |
2879 | 2847 | |
2880 | 2848 | (C<$2> は C<substr($var, $-[2], $+[2] - $-[2])> と同じです) |
2881 | 2849 | |
2882 | 2850 | =item C<$3> is the same as C<substr($var, $-[3], $+[3] - $-[3])> |
2883 | 2851 | |
2884 | 2852 | (C<$3> は C<substr $var, $-[3], $+[3] - $-[3])> と同じです) |
2885 | 2853 | |
2886 | 2854 | =back |
2887 | 2855 | |
2888 | 2856 | =begin original |
2889 | 2857 | |
2890 | 2858 | This variable was added in Perl v5.6.0. |
2891 | 2859 | |
2892 | 2860 | =end original |
2893 | 2861 | |
2894 | 2862 | この変数は Perl v5.6.0 で追加されました。 |
2895 | 2863 | |
2896 | 2864 | =item %{^CAPTURE_ALL} |
2897 | 2865 | X<%{^CAPTURE_ALL}> |
2898 | 2866 | |
2899 | 2867 | =item %- |
2900 | 2868 | X<%-> |
2901 | 2869 | |
2902 | 2870 | =begin original |
2903 | 2871 | |
2904 | 2872 | Similar to C<%+>, this variable allows access to the named capture groups |
2905 | 2873 | in the last successful match in the currently active dynamic scope. To |
2906 | 2874 | each capture group name found in the regular expression, it associates a |
2907 | 2875 | reference to an array containing the list of values captured by all |
2908 | 2876 | buffers with that name (should there be several of them), in the order |
2909 | 2877 | where they appear. |
2910 | 2878 | |
2911 | 2879 | =end original |
2912 | 2880 | |
2913 | 2881 | C<%+> と同様、この変数は現在アクティブな動的スコープで最後に成功した |
2914 | 2882 | マッチングの名前付き捕捉グループへのアクセスを可能にします。 |
2915 | 2883 | 正規表現中に捕捉グループ名が現れるごとに、その名前のグループ全てで |
2916 | 2884 | (複数あるでしょう)捕捉されている値のリストを出現順で含む配列への |
2917 | 2885 | リファレンスと関連付けられます。 |
2918 | 2886 | |
2919 | 2887 | =begin original |
2920 | 2888 | |
2921 | 2889 | Here's an example: |
2922 | 2890 | |
2923 | 2891 | =end original |
2924 | 2892 | |
2925 | 2893 | 以下は例です: |
2926 | 2894 | |
2927 | 2895 | if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) { |
2928 | 2896 | foreach my $bufname (sort keys %-) { |
2929 | 2897 | my $ary = $-{$bufname}; |
2930 | 2898 | foreach my $idx (0..$#$ary) { |
2931 | 2899 | print "\$-{$bufname}[$idx] : ", |
2932 | 2900 | (defined($ary->[$idx]) |
2933 | 2901 | ? "'$ary->[$idx]'" |
2934 | 2902 | : "undef"), |
2935 | 2903 | "\n"; |
2936 | 2904 | } |
2937 | 2905 | } |
2938 | 2906 | } |
2939 | 2907 | |
2940 | 2908 | =begin original |
2941 | 2909 | |
2942 | 2910 | would print out: |
2943 | 2911 | |
2944 | 2912 | =end original |
2945 | 2913 | |
2946 | 2914 | とすると、以下のものが表示されます: |
2947 | 2915 | |
2948 | 2916 | $-{A}[0] : '1' |
2949 | 2917 | $-{A}[1] : '3' |
2950 | 2918 | $-{B}[0] : '2' |
2951 | 2919 | $-{B}[1] : '4' |
2952 | 2920 | |
2953 | 2921 | =begin original |
2954 | 2922 | |
2955 | 2923 | The keys of the C<%-> hash correspond to all buffer names found in |
2956 | 2924 | the regular expression. |
2957 | 2925 | |
2958 | 2926 | =end original |
2959 | 2927 | |
2960 | 2928 | C<%-> ハッシュのキーは正規表現で見つかった全てのバッファ名に対応します。 |
2961 | 2929 | |
2962 | 2930 | =begin original |
2963 | 2931 | |
2964 | 2932 | The behaviour of C<%-> is implemented via the |
2965 | 2933 | L<Tie::Hash::NamedCapture> module. |
2966 | 2934 | |
2967 | 2935 | =end original |
2968 | 2936 | |
2969 | 2937 | C<%-> の振る舞いは L<Tie::Hash::NamedCapture> モジュールを使って |
2970 | 2938 | 実装されています。 |
2971 | 2939 | |
2972 | 2940 | =begin original |
2973 | 2941 | |
2974 | 2942 | B<Note:> C<%-> and C<%+> are tied views into a common internal hash |
2975 | 2943 | associated with the last successful regular expression. Therefore mixing |
2976 | 2944 | iterative access to them via C<each> may have unpredictable results. |
2977 | 2945 | Likewise, if the last successful match changes, then the results may be |
2978 | 2946 | surprising. |
2979 | 2947 | |
2980 | 2948 | =end original |
2981 | 2949 | |
2982 | 2950 | B<注意:> C<%-> and C<%+> は最後に成功した正規表現と関連付けられた共通の |
2983 | 2951 | 内部ハッシュと tie されたビューです。 |
2984 | 2952 | 従って、C<each> 経由で混ざった反復アクセスを行うと、予測不能の結果となります。 |
2985 | 2953 | 同様に、最後に成功したマッチングを変更すると、結果は驚くべきものとなります。 |
2986 | 2954 | |
2987 | 2955 | =begin original |
2988 | 2956 | |
2989 | 2957 | This variable was added in Perl v5.10.0. The C<%{^CAPTURE_ALL}> alias was |
2990 | 2958 | added in 5.25.7. |
2991 | 2959 | |
2992 | 2960 | =end original |
2993 | 2961 | |
2994 | 2962 | この変数は Perl v5.10.0 で追加されました。 |
2995 | 2963 | C<%{^CAPTURE_ALL}> の別名は 5.25.7 で追加されました。 |
2996 | 2964 | |
2997 | 2965 | =begin original |
2998 | 2966 | |
2999 | 2967 | This variable is read-only and dynamically-scoped. |
3000 | 2968 | |
3001 | 2969 | =end original |
3002 | 2970 | |
3003 | 2971 | この変数は読み込み専用で動的スコープを持ちます。 |
3004 | 2972 | |
3005 | 2973 | =item $LAST_REGEXP_CODE_RESULT |
3006 | 2974 | |
3007 | 2975 | =item $^R |
3008 | 2976 | X<$^R> X<$LAST_REGEXP_CODE_RESULT> |
3009 | 2977 | |
3010 | 2978 | =begin original |
3011 | 2979 | |
3012 | 2980 | The result of evaluation of the last successful C<(?{ code })> |
3013 | 2981 | regular expression assertion (see L<perlre>). May be written to. |
3014 | 2982 | |
3015 | 2983 | =end original |
3016 | 2984 | |
3017 | 2985 | 最後に成功した C<(?{ code })> 正規表現アサートの評価の結果です |
3018 | 2986 | (L<perlre> を参照して下さい)。おそらくもっと書き足します。 |
3019 | 2987 | |
3020 | 2988 | =begin original |
3021 | 2989 | |
3022 | 2990 | This variable was added in Perl 5.005. |
3023 | 2991 | |
3024 | 2992 | =end original |
3025 | 2993 | |
3026 | 2994 | この変数は Perl 5.005 で追加されました。 |
3027 | 2995 | |
3028 | =item ${^RE_COMPILE_RECURSION_LIMIT} | |
3029 | X<${^RE_COMPILE_RECURSION_LIMIT}> | |
3030 | ||
3031 | =begin original | |
3032 | ||
3033 | The current value giving the maximum number of open but unclosed | |
3034 | parenthetical groups there may be at any point during a regular | |
3035 | expression compilation. The default is currently 1000 nested groups. | |
3036 | You may adjust it depending on your needs and the amount of memory | |
3037 | available. | |
3038 | ||
3039 | =end original | |
3040 | ||
3041 | 正規表現コンパイル中の任意の時点での開いているけれども閉じていない | |
3042 | かっこグループの最大値として与えられている現在の値。 | |
3043 | デフォルトは現在の所 1000 ネストグループです。 | |
3044 | これは必要性と利用可能なメモリ量に合わせて調整できます。 | |
3045 | ||
3046 | =begin original | |
3047 | ||
3048 | This variable was added in Perl v5.30.0. | |
3049 | ||
3050 | =end original | |
3051 | ||
3052 | この変数は Perl v5.30.0 で追加されました。 | |
3053 | ||
3054 | 2996 | =item ${^RE_DEBUG_FLAGS} |
3055 | 2997 | X<${^RE_DEBUG_FLAGS}> |
3056 | 2998 | |
3057 | 2999 | =begin original |
3058 | 3000 | |
3059 | 3001 | The current value of the regex debugging flags. Set to 0 for no debug output |
3060 | 3002 | even when the C<re 'debug'> module is loaded. See L<re> for details. |
3061 | 3003 | |
3062 | 3004 | =end original |
3063 | 3005 | |
3064 | 3006 | 正規表現デバッグフラグの現在の値です。 |
3065 | 3007 | 0 をセットすると、C<re 'debug'> モジュールが読み込まれていてもデバッグ出力を |
3066 | 3008 | 行いません。 |
3067 | 3009 | 詳細については L<re> を参照してください。 |
3068 | 3010 | |
3069 | 3011 | =begin original |
3070 | 3012 | |
3071 | 3013 | This variable was added in Perl v5.10.0. |
3072 | 3014 | |
3073 | 3015 | =end original |
3074 | 3016 | |
3075 | 3017 | この変数は Perl v5.10.0 で追加されました。 |
3076 | 3018 | |
3077 | 3019 | =item ${^RE_TRIE_MAXBUF} |
3078 | 3020 | X<${^RE_TRIE_MAXBUF}> |
3079 | 3021 | |
3080 | 3022 | =begin original |
3081 | 3023 | |
3082 | 3024 | Controls how certain regex optimisations are applied and how much memory they |
3083 | 3025 | utilize. This value by default is 65536 which corresponds to a 512kB |
3084 | 3026 | temporary cache. Set this to a higher value to trade |
3085 | 3027 | memory for speed when matching large alternations. Set |
3086 | 3028 | it to a lower value if you want the optimisations to |
3087 | 3029 | be as conservative of memory as possible but still occur, and set it to a |
3088 | 3030 | negative value to prevent the optimisation and conserve the most memory. |
3089 | 3031 | Under normal situations this variable should be of no interest to you. |
3090 | 3032 | |
3091 | 3033 | =end original |
3092 | 3034 | |
3093 | 3035 | どれくらい正規表現の最適化を行い、どれくらいのメモリを利用するかを制御します。 |
3094 | 3036 | デフォルトではこの値は 65536 で、512kB の一時キャッシュに相当します。 |
3095 | 3037 | この値を大きくすると、大きなものとマッチングするときに速度を重視して多くの |
3096 | 3038 | メモリを使います。 |
3097 | 3039 | もしできるだけ保守的なメモリ消費をするけれども使うこともある、というように |
3098 | 3040 | 最適化したい場合は小さい値を設定します; 負の値を設定すると最適化は行わず、 |
3099 | 3041 | 最大限メモリを節約します。 |
3100 | 3042 | 通常の状況では、この変数はあなたの興味を引くものではないでしょう。 |
3101 | 3043 | |
3102 | 3044 | =begin original |
3103 | 3045 | |
3104 | 3046 | This variable was added in Perl v5.10.0. |
3105 | 3047 | |
3106 | 3048 | =end original |
3107 | 3049 | |
3108 | 3050 | この変数は Perl v5.10.0 で追加されました。 |
3109 | 3051 | |
3110 | 3052 | =back |
3111 | 3053 | |
3112 | 3054 | =head2 Variables related to filehandles |
3113 | 3055 | |
3114 | 3056 | (ファイルハンドル関連の変数) |
3115 | 3057 | |
3116 | 3058 | =begin original |
3117 | 3059 | |
3118 | 3060 | Variables that depend on the currently selected filehandle may be set |
3119 | 3061 | by calling an appropriate object method on the C<IO::Handle> object, |
3120 | 3062 | although this is less efficient than using the regular built-in |
3121 | 3063 | variables. (Summary lines below for this contain the word HANDLE.) |
3122 | 3064 | First you must say |
3123 | 3065 | |
3124 | 3066 | =end original |
3125 | 3067 | |
3126 | 3068 | 現在選択されているファイルハンドルに依存する変数の場合には、代わりに |
3127 | 3069 | C<IO::Handle> オブジェクトに関するオブジェクトメソッドを呼び出して |
3128 | 3070 | 設定できますが、通常の組み込み変数よりは効率が落ちます。 |
3129 | 3071 | (以下の要約では HANDLE という語を含んでいます。) |
3130 | 3072 | まず最初に必ず、 |
3131 | 3073 | |
3132 | 3074 | use IO::Handle; |
3133 | 3075 | |
3134 | 3076 | =begin original |
3135 | 3077 | |
3136 | 3078 | after which you may use either |
3137 | 3079 | |
3138 | 3080 | =end original |
3139 | 3081 | |
3140 | 3082 | と書き、その後で以下のように書くか、 |
3141 | 3083 | |
3142 | 3084 | method HANDLE EXPR |
3143 | 3085 | |
3144 | 3086 | =begin original |
3145 | 3087 | |
3146 | 3088 | or more safely, |
3147 | 3089 | |
3148 | 3090 | =end original |
3149 | 3091 | |
3150 | 3092 | もしくはより安全に以下のように書きます: |
3151 | 3093 | |
3152 | 3094 | HANDLE->method(EXPR) |
3153 | 3095 | |
3154 | 3096 | =begin original |
3155 | 3097 | |
3156 | 3098 | Each method returns the old value of the C<IO::Handle> attribute. The |
3157 | 3099 | methods each take an optional EXPR, which, if supplied, specifies the |
3158 | 3100 | new value for the C<IO::Handle> attribute in question. If not |
3159 | 3101 | supplied, most methods do nothing to the current value--except for |
3160 | 3102 | C<autoflush()>, which will assume a 1 for you, just to be different. |
3161 | 3103 | |
3162 | 3104 | =end original |
3163 | 3105 | |
3164 | 3106 | それぞれのメソッドは、C<IO::Handle> 属性の昔の値を返します。 |
3165 | 3107 | メソッドはそれぞれ EXPR をとることができ、指定した場合には、問題の |
3166 | 3108 | C<IO::Handle> 属性の新しい値を指定することになります。 |
3167 | 3109 | 指定しない場合には、多くのメソッドでは現在の値に対して何もしませんが、 |
3168 | 3110 | C<autoflush()> では 1 を指定されたものとします。 |
3169 | 3111 | |
3170 | 3112 | =begin original |
3171 | 3113 | |
3172 | 3114 | Because loading in the C<IO::Handle> class is an expensive operation, |
3173 | 3115 | you should learn how to use the regular built-in variables. |
3174 | 3116 | |
3175 | 3117 | =end original |
3176 | 3118 | |
3177 | 3119 | C<IO::Handle> クラスを読み込むのはコストの高い操作なので、 |
3178 | 3120 | 通常の組み込み変数の使い方を覚えるべきです。 |
3179 | 3121 | |
3180 | 3122 | =begin original |
3181 | 3123 | |
3182 | 3124 | A few of these variables are considered "read-only". This means that |
3183 | 3125 | if you try to assign to this variable, either directly or indirectly |
3184 | 3126 | through a reference, you'll raise a run-time exception. |
3185 | 3127 | |
3186 | 3128 | =end original |
3187 | 3129 | |
3188 | 3130 | これらの変数のいくつかは「読み込み専用」と考えられます。 |
3189 | 3131 | つまり、もしこの変数に対して直接またはリファレンスを通して間接に |
3190 | 3132 | 代入しようとすると、、実行時エラーが発生します。 |
3191 | 3133 | |
3192 | 3134 | =begin original |
3193 | 3135 | |
3194 | 3136 | You should be very careful when modifying the default values of most |
3195 | 3137 | special variables described in this document. In most cases you want |
3196 | 3138 | to localize these variables before changing them, since if you don't, |
3197 | 3139 | the change may affect other modules which rely on the default values |
3198 | 3140 | of the special variables that you have changed. This is one of the |
3199 | 3141 | correct ways to read the whole file at once: |
3200 | 3142 | |
3201 | 3143 | =end original |
3202 | 3144 | |
3203 | 3145 | この文書に記述されているほとんどの特殊変数のデフォルト値を変更するときには |
3204 | 3146 | とても慎重になるべきです。 |
3205 | 3147 | ほとんどの場合、これらの変数を変更する前にこれらをローカル化したいでしょう; |
3206 | 3148 | さもなければ、あなたが変更した特殊変数のデフォルト値に依存している |
3207 | 3149 | その他のモジュールにも影響を与えるかもしれないからです。 |
3208 | 3150 | これはファイル全体を一度に読み込む正しい方法の一つです: |
3209 | 3151 | |
3210 | 3152 | =begin original |
3211 | 3153 | |
3212 | 3154 | open my $fh, "<", "foo" or die $!; |
3213 | 3155 | local $/; # enable localized slurp mode |
3214 | 3156 | my $content = <$fh>; |
3215 | 3157 | close $fh; |
3216 | 3158 | |
3217 | 3159 | =end original |
3218 | 3160 | |
3219 | 3161 | open my $fh, "<", "foo" or die $!; |
3220 | 3162 | local $/; # ローカル化された吸い込みモードを有効にする |
3221 | 3163 | my $content = <$fh>; |
3222 | 3164 | close $fh; |
3223 | 3165 | |
3224 | 3166 | =begin original |
3225 | 3167 | |
3226 | 3168 | But the following code is quite bad: |
3227 | 3169 | |
3228 | 3170 | =end original |
3229 | 3171 | |
3230 | 3172 | しかし以下のコードは完全に悪いものです: |
3231 | 3173 | |
3232 | 3174 | =begin original |
3233 | 3175 | |
3234 | 3176 | open my $fh, "<", "foo" or die $!; |
3235 | 3177 | undef $/; # enable slurp mode |
3236 | 3178 | my $content = <$fh>; |
3237 | 3179 | close $fh; |
3238 | 3180 | |
3239 | 3181 | =end original |
3240 | 3182 | |
3241 | 3183 | open my $fh, "<", "foo" or die $!; |
3242 | 3184 | undef $/; # 吸い込みモードを有効にする |
3243 | 3185 | my $content = <$fh>; |
3244 | 3186 | close $fh; |
3245 | 3187 | |
3246 | 3188 | =begin original |
3247 | 3189 | |
3248 | 3190 | since some other module, may want to read data from some file in the |
3249 | 3191 | default "line mode", so if the code we have just presented has been |
3250 | 3192 | executed, the global value of C<$/> is now changed for any other code |
3251 | 3193 | running inside the same Perl interpreter. |
3252 | 3194 | |
3253 | 3195 | =end original |
3254 | 3196 | |
3255 | 3197 | なぜなら、その他のモジュールでは、デフォルトの「行モード」でファイルを |
3256 | 3198 | 読もうとするかも知れませんが、もし単に前述のコードを実行すると、 |
3257 | 3199 | C<$/> のグローバルな値が、同じ Perl インタプリタ内で実行される |
3258 | 3200 | その他のコードに対しても変更されるからです。 |
3259 | 3201 | |
3260 | 3202 | =begin original |
3261 | 3203 | |
3262 | 3204 | Usually when a variable is localized you want to make sure that this |
3263 | 3205 | change affects the shortest scope possible. So unless you are already |
3264 | 3206 | inside some short C<{}> block, you should create one yourself. For |
3265 | 3207 | example: |
3266 | 3208 | |
3267 | 3209 | =end original |
3268 | 3210 | |
3269 | 3211 | 通常、変数をローカル化するとき、この変更ができるだけ最短のスコープに |
3270 | 3212 | 影響を与えることを確実にしたいでしょう。 |
3271 | 3213 | 従って、既に小さい C<{}> ブロックの内側であるのでない限り、それを |
3272 | 3214 | 自身で作るべきです。 |
3273 | 3215 | 例えば: |
3274 | 3216 | |
3275 | 3217 | my $content = ''; |
3276 | 3218 | open my $fh, "<", "foo" or die $!; |
3277 | 3219 | { |
3278 | 3220 | local $/; |
3279 | 3221 | $content = <$fh>; |
3280 | 3222 | } |
3281 | 3223 | close $fh; |
3282 | 3224 | |
3283 | 3225 | =begin original |
3284 | 3226 | |
3285 | 3227 | Here is an example of how your own code can go broken: |
3286 | 3228 | |
3287 | 3229 | =end original |
3288 | 3230 | |
3289 | 3231 | 以下はどのように自分のコードが壊れるかの例です: |
3290 | 3232 | |
3291 | 3233 | for ( 1..3 ){ |
3292 | 3234 | $\ = "\r\n"; |
3293 | 3235 | nasty_break(); |
3294 | 3236 | print "$_"; |
3295 | 3237 | } |
3296 | 3238 | |
3297 | 3239 | =begin original |
3298 | 3240 | |
3299 | 3241 | sub nasty_break { |
3300 | 3242 | $\ = "\f"; |
3301 | 3243 | # do something with $_ |
3302 | 3244 | } |
3303 | 3245 | |
3304 | 3246 | =end original |
3305 | 3247 | |
3306 | 3248 | sub nasty_break { |
3307 | 3249 | $\ = "\f"; |
3308 | 3250 | # $_ で何かする |
3309 | 3251 | } |
3310 | 3252 | |
3311 | 3253 | =begin original |
3312 | 3254 | |
3313 | 3255 | You probably expect this code to print the equivalent of |
3314 | 3256 | |
3315 | 3257 | =end original |
3316 | 3258 | |
3317 | 3259 | おそらくこのコードは以下のように表示されることを期待しています: |
3318 | 3260 | |
3319 | 3261 | "1\r\n2\r\n3\r\n" |
3320 | 3262 | |
3321 | 3263 | =begin original |
3322 | 3264 | |
3323 | 3265 | but instead you get: |
3324 | 3266 | |
3325 | 3267 | =end original |
3326 | 3268 | |
3327 | 3269 | しかし、以下のようになります: |
3328 | 3270 | |
3329 | 3271 | "1\f2\f3\f" |
3330 | 3272 | |
3331 | 3273 | =begin original |
3332 | 3274 | |
3333 | 3275 | Why? Because C<nasty_break()> modifies C<$\> without localizing it |
3334 | 3276 | first. The value you set in C<nasty_break()> is still there when you |
3335 | 3277 | return. The fix is to add C<local()> so the value doesn't leak out of |
3336 | 3278 | C<nasty_break()>: |
3337 | 3279 | |
3338 | 3280 | =end original |
3339 | 3281 | |
3340 | 3282 | なぜでしょう? |
3341 | 3283 | C<nasty_break()> は C<$_> をローカル化する前に変更するからです。 |
3342 | 3284 | C<nasty_break()> で設定した値は戻ったときにまだそこにあります。 |
3343 | 3285 | 修正するには、C<local()> を追加して、値が C<nasty_break()> の外に |
3344 | 3286 | 漏れないようにします: |
3345 | 3287 | |
3346 | 3288 | local $\ = "\f"; |
3347 | 3289 | |
3348 | 3290 | =begin original |
3349 | 3291 | |
3350 | 3292 | It's easy to notice the problem in such a short example, but in more |
3351 | 3293 | complicated code you are looking for trouble if you don't localize |
3352 | 3294 | changes to the special variables. |
3353 | 3295 | |
3354 | 3296 | =end original |
3355 | 3297 | |
3356 | 3298 | このような短い例では問題に気付くのは簡単ですが、より複雑なコードでは、 |
3357 | 3299 | もし特殊変数の変更をローカル化していないと問題を探すことになります。 |
3358 | 3300 | |
3359 | 3301 | =over 8 |
3360 | 3302 | |
3361 | 3303 | =item $ARGV |
3362 | 3304 | X<$ARGV> |
3363 | 3305 | |
3364 | 3306 | =begin original |
3365 | 3307 | |
3366 | 3308 | Contains the name of the current file when reading from C<< <> >>. |
3367 | 3309 | |
3368 | 3310 | =end original |
3369 | 3311 | |
3370 | 3312 | C<< <> >> から読込みを行なっているとき、その時点のファイル名を示します。 |
3371 | 3313 | |
3372 | 3314 | =item @ARGV |
3373 | 3315 | X<@ARGV> |
3374 | 3316 | |
3375 | 3317 | =begin original |
3376 | 3318 | |
3377 | 3319 | The array C<@ARGV> contains the command-line arguments intended for |
3378 | 3320 | the script. C<$#ARGV> is generally the number of arguments minus |
3379 | 3321 | one, because C<$ARGV[0]> is the first argument, I<not> the program's |
3380 | 3322 | command name itself. See L</$0> for the command name. |
3381 | 3323 | |
3382 | 3324 | =end original |
3383 | 3325 | |
3384 | 3326 | 配列 C<@ARGV> は、コマンドラインからスクリプトに渡す引数が入れられます。 |
3385 | 3327 | C<$ARGV[0]> がI<プログラムのコマンド名自身ではなく>、 |
3386 | 3328 | 最初の引数ですから、C<$#ARGV> は一般には、引数の個数 - 1 となります。 |
3387 | 3329 | コマンド名については、L</$0> を参照してください。 |
3388 | 3330 | |
3389 | 3331 | =item ARGV |
3390 | 3332 | X<ARGV> |
3391 | 3333 | |
3392 | 3334 | =begin original |
3393 | 3335 | |
3394 | 3336 | The special filehandle that iterates over command-line filenames in |
3395 | 3337 | C<@ARGV>. Usually written as the null filehandle in the angle operator |
3396 | 3338 | C<< <> >>. Note that currently C<ARGV> only has its magical effect |
3397 | 3339 | within the C<< <> >> operator; elsewhere it is just a plain filehandle |
3398 | 3340 | corresponding to the last file opened by C<< <> >>. In particular, |
3399 | 3341 | passing C<\*ARGV> as a parameter to a function that expects a filehandle |
3400 | 3342 | may not cause your function to automatically read the contents of all the |
3401 | 3343 | files in C<@ARGV>. |
3402 | 3344 | |
3403 | 3345 | =end original |
3404 | 3346 | |
3405 | 3347 | C<@ARGV> にあるコマンドラインで指定されたファイル名に対して反復する |
3406 | 3348 | 特殊ファイルハンドルです。 |
3407 | 3349 | 通常角かっこ C<< <> >> の中で空ファイルハンドルとして書かれます。 |
3408 | 3350 | 現在のところ、C<ARGV> は C<< <> >> 演算子の中でのみ特別な効果があることに |
3409 | 3351 | 注意してください; その他の場所では、C<< <> >> で開かれた最後のファイルに |
3410 | 3352 | 対応する普通のファイルハンドルです。 |
3411 | 3353 | 特に、ファイルハンドルを想定している関数に C<\*ARGV> を引数として渡しても、 |
3412 | 3354 | 関数内で C<@ARGV> にある全てのファイルの内容を自動的に読み込むことには |
3413 | 3355 | なりません。 |
3414 | 3356 | |
3415 | 3357 | =item ARGVOUT |
3416 | 3358 | X<ARGVOUT> |
3417 | 3359 | |
3418 | 3360 | =begin original |
3419 | 3361 | |
3420 | 3362 | The special filehandle that points to the currently open output file |
3421 | 3363 | when doing edit-in-place processing with B<-i>. Useful when you have |
3422 | 3364 | to do a lot of inserting and don't want to keep modifying C<$_>. See |
3423 | 3365 | L<perlrun> for the B<-i> switch. |
3424 | 3366 | |
3425 | 3367 | =end original |
3426 | 3368 | |
3427 | 3369 | B<-i> を使ってその場修正を行っているときに、現在開いている出力ファイルを |
3428 | 3370 | 示す特殊ファイルハンドルです。 |
3429 | 3371 | たくさんの挿入をする必要があるときに C<$_> を修正し続けたくない場合に有用です。 |
3430 | 3372 | B<-i> オプションについては L<perlrun> を参照してください。 |
3431 | 3373 | |
3432 | 3374 | =item IO::Handle->output_field_separator( EXPR ) |
3433 | 3375 | |
3434 | 3376 | =item $OUTPUT_FIELD_SEPARATOR |
3435 | 3377 | |
3436 | 3378 | =item $OFS |
3437 | 3379 | |
3438 | 3380 | =item $, |
3439 | 3381 | X<$,> X<$OFS> X<$OUTPUT_FIELD_SEPARATOR> |
3440 | 3382 | |
3441 | 3383 | =begin original |
3442 | 3384 | |
3443 | 3385 | The output field separator for the print operator. If defined, this |
3444 | 3386 | value is printed between each of print's arguments. Default is C<undef>. |
3445 | 3387 | |
3446 | 3388 | =end original |
3447 | 3389 | |
3448 | 3390 | print 演算子のための出力フィールドセパレータ。 |
3449 | 3391 | 定義されると、この値がそれぞれの print の引数の間に表示されます。 |
3450 | 3392 | デフォルトは C<undef> です。 |
3451 | 3393 | |
3452 | 3394 | =begin original |
3453 | 3395 | |
3454 | 3396 | You cannot call C<output_field_separator()> on a handle, only as a |
3455 | 3397 | static method. See L<IO::Handle|IO::Handle>. |
3456 | 3398 | |
3457 | 3399 | =end original |
3458 | 3400 | |
3459 | 3401 | ハンドルに対して C<output_field_separator()> を呼び出すことはできません; |
3460 | 3402 | 静的メソッドしてのみです。 |
3461 | 3403 | L<IO::Handle|IO::Handle> を参照してください。 |
3462 | 3404 | |
3463 | 3405 | =begin original |
3464 | 3406 | |
3465 | 3407 | Mnemonic: what is printed when there is a "," in your print statement. |
3466 | 3408 | |
3467 | 3409 | =end original |
3468 | 3410 | |
3469 | 3411 | 記憶法: print 文で "," を書いた場所に印字されるもの。 |
3470 | 3412 | |
3471 | 3413 | =item HANDLE->input_line_number( EXPR ) |
3472 | 3414 | |
3473 | 3415 | =item $INPUT_LINE_NUMBER |
3474 | 3416 | |
3475 | 3417 | =item $NR |
3476 | 3418 | |
3477 | 3419 | =item $. |
3478 | 3420 | X<$.> X<$NR> X<$INPUT_LINE_NUMBER> X<line number> |
3479 | 3421 | |
3480 | 3422 | =begin original |
3481 | 3423 | |
3482 | 3424 | Current line number for the last filehandle accessed. |
3483 | 3425 | |
3484 | 3426 | =end original |
3485 | 3427 | |
3486 | 3428 | 最後にアクセスされたファイルハンドルの現在の行番号。 |
3487 | 3429 | |
3488 | 3430 | =begin original |
3489 | 3431 | |
3490 | 3432 | Each filehandle in Perl counts the number of lines that have been read |
3491 | 3433 | from it. (Depending on the value of C<$/>, Perl's idea of what |
3492 | 3434 | constitutes a line may not match yours.) When a line is read from a |
3493 | 3435 | filehandle (via C<readline()> or C<< <> >>), or when C<tell()> or |
3494 | 3436 | C<seek()> is called on it, C<$.> becomes an alias to the line counter |
3495 | 3437 | for that filehandle. |
3496 | 3438 | |
3497 | 3439 | =end original |
3498 | 3440 | |
3499 | 3441 | Perl の各ファイルハンドルは、そこから読み込んだ行数を数えています。 |
3500 | 3442 | (C<$/> の値に依存して、何が行を構成するかに関する Perl の考えはあなたの |
3501 | 3443 | 考えと一致しないかもしれません。) |
3502 | 3444 | 行が(C<readline()> や C<< <> >> を使って)ファイルハンドルから読み込まれたか、 |
3503 | 3445 | C<tell()> や C<seek()> がファイルハンドルに対して呼び出された場合、 |
3504 | 3446 | C<$.> はそのファイルハンドルの行カウンタへのエイリアスとなります。 |
3505 | 3447 | |
3506 | 3448 | =begin original |
3507 | 3449 | |
3508 | 3450 | You can adjust the counter by assigning to C<$.>, but this will not |
3509 | 3451 | actually move the seek pointer. I<Localizing C<$.> will not localize |
3510 | 3452 | the filehandle's line count>. Instead, it will localize perl's notion |
3511 | 3453 | of which filehandle C<$.> is currently aliased to. |
3512 | 3454 | |
3513 | 3455 | =end original |
3514 | 3456 | |
3515 | 3457 | C<$.> へ代入することでカウンタの値を修正できますが、これは実際にシーク |
3516 | 3458 | ポインタを動かすことはありません。 |
3517 | 3459 | I<C<$.> をローカル化してもファイルハンドルの行カウンタはローカル化されません>。 |
3518 | 3460 | 代わりに、現在 C<$.> がどのファイルハンドルへのエイリアスかという情報が |
3519 | 3461 | ローカル化されます。 |
3520 | 3462 | |
3521 | 3463 | =begin original |
3522 | 3464 | |
3523 | 3465 | C<$.> is reset when the filehandle is closed, but B<not> when an open |
3524 | 3466 | filehandle is reopened without an intervening C<close()>. For more |
3525 | 3467 | details, see L<perlop/"IE<sol>O Operators">. Because C<< <> >> never does |
3526 | 3468 | an explicit close, line numbers increase across C<ARGV> files (but see |
3527 | 3469 | examples in L<perlfunc/eof>). |
3528 | 3470 | |
3529 | 3471 | =end original |
3530 | 3472 | |
3531 | 3473 | C<$.> はファイルハンドルがクローズされるとリセットされますが、 |
3532 | 3474 | オープンしているファイルハンドルが C<close()> されることなく再オープンされた |
3533 | 3475 | 場合にはリセット B<されません>。 |
3534 | 3476 | さらなる詳細については、L<perlop/"IE<sol>O Operators"> を参照してください。 |
3535 | 3477 | なぜなら、 C<< <> >> は決して明示的なクローズは行わず、行番号は C<ARGV> の |
3536 | 3478 | ファイル間で通算してカウントされるからです(但し L<perlfunc/eof> の例を |
3537 | 3479 | 参照してください)。 |
3538 | 3480 | |
3539 | 3481 | =begin original |
3540 | 3482 | |
3541 | 3483 | You can also use C<< HANDLE->input_line_number(EXPR) >> to access the |
3542 | 3484 | line counter for a given filehandle without having to worry about |
3543 | 3485 | which handle you last accessed. |
3544 | 3486 | |
3545 | 3487 | =end original |
3546 | 3488 | |
3547 | 3489 | また、C<< HANDLE->input_line_number(EXPR) >> とすることで、どのハンドルに |
3548 | 3490 | 最後にアクセスしたかを気にすることなく行カウンタにアクセスできます。 |
3549 | 3491 | |
3550 | 3492 | =begin original |
3551 | 3493 | |
3552 | 3494 | Mnemonic: many programs use "." to mean the current line number. |
3553 | 3495 | |
3554 | 3496 | =end original |
3555 | 3497 | |
3556 | 3498 | 記憶法: 多くのプログラムで "." が現在行番号を示すように使われています。 |
3557 | 3499 | |
3558 | 3500 | =item IO::Handle->input_record_separator( EXPR ) |
3559 | 3501 | |
3560 | 3502 | =item $INPUT_RECORD_SEPARATOR |
3561 | 3503 | |
3562 | 3504 | =item $RS |
3563 | 3505 | |
3564 | 3506 | =item $/ |
3565 | 3507 | X<$/> X<$RS> X<$INPUT_RECORD_SEPARATOR> |
3566 | 3508 | |
3567 | 3509 | =begin original |
3568 | 3510 | |
3569 | 3511 | The input record separator, newline by default. This influences Perl's |
3570 | 3512 | idea of what a "line" is. Works like B<awk>'s RS variable, including |
3571 | 3513 | treating empty lines as a terminator if set to the null string (an |
3572 | 3514 | empty line cannot contain any spaces or tabs). You may set it to a |
3573 | 3515 | multi-character string to match a multi-character terminator, or to |
3574 | 3516 | C<undef> to read through the end of file. Setting it to C<"\n\n"> |
3575 | 3517 | means something slightly different than setting to C<"">, if the file |
3576 | 3518 | contains consecutive empty lines. Setting to C<""> will treat two or |
3577 | 3519 | more consecutive empty lines as a single empty line. Setting to |
3578 | 3520 | C<"\n\n"> will blindly assume that the next input character belongs to |
3579 | 3521 | the next paragraph, even if it's a newline. |
3580 | 3522 | |
3581 | 3523 | =end original |
3582 | 3524 | |
3583 | 3525 | 入力レコードセパレータで、デフォルトでは改行文字。 |
3584 | 3526 | これは Perl での「行」とは何か、ということに影響を与えます。 |
3585 | 3527 | 空文字列に設定されると、空行をセパレータとして扱うことを含めて、B<awk> の |
3586 | 3528 | 変数 RS のように働きます(空行はスペースやタブを含んでいてはいけません)。 |
3587 | 3529 | 複数文字の区切文字を示すために、文字列を設定することもできます; また、 |
3588 | 3530 | ファイルの最後まで読み込むために undef を指定することもできます。 |
3589 | 3531 | この変数に C<"\n\n"> を設定すると、空行が続く場合において、 |
3590 | 3532 | C<""> を設定した場合とわずかに違う動作をするようになります。 |
3591 | 3533 | C<""> を設定した場合には、複数の空行も 1 つの空行であるかのように扱います。 |
3592 | 3534 | C<"\n\n"> を設定した場合には、単純に次の文字が (たとえ改行文字であっても) |
3593 | 3535 | 次の段落に含まれるものとして扱います。 |
3594 | 3536 | |
3595 | 3537 | =begin original |
3596 | 3538 | |
3597 | 3539 | local $/; # enable "slurp" mode |
3598 | 3540 | local $_ = <FH>; # whole file now here |
3599 | 3541 | s/\n[ \t]+/ /g; |
3600 | 3542 | |
3601 | 3543 | =end original |
3602 | 3544 | |
3603 | 3545 | local $/; # 「吸い込み」モードを有効にする |
3604 | 3546 | local $_ = <FH>; # ファイル全体が入る |
3605 | 3547 | s/\n[ \t]+/ /g; |
3606 | 3548 | |
3607 | 3549 | =begin original |
3608 | 3550 | |
3609 | 3551 | Remember: the value of C<$/> is a string, not a regex. B<awk> has to |
3610 | 3552 | be better for something. :-) |
3611 | 3553 | |
3612 | 3554 | =end original |
3613 | 3555 | |
3614 | 3556 | 注意: C<$/> は文字列であり、正規表現ではありません。 |
3615 | 3557 | B<awk> は何かもっとうまくやらなくてはいけません。:-) |
3616 | 3558 | |
3617 | 3559 | =begin original |
3618 | 3560 | |
3619 | Setting C<$/> to an empty string -- the so-called I<paragraph mode> -- merits | |
3620 | special attention. When C<$/> is set to C<""> and the entire file is read in | |
3621 | with that setting, any sequence of consecutive newlines C<"\n\n"> at the | |
3622 | beginning of the file is discarded. With the exception of the final record in | |
3623 | the file, each sequence of characters ending in two or more newlines is | |
3624 | treated as one record and is read in to end in exactly two newlines. If the | |
3625 | last record in the file ends in zero or one consecutive newlines, that record | |
3626 | is read in with that number of newlines. If the last record ends in two or | |
3627 | more consecutive newlines, it is read in with two newlines like all preceding | |
3628 | records. | |
3629 | ||
3630 | =end original | |
3631 | ||
3632 | C<$/> に空文字列を設定すること -- I<段落モード> と呼ばれます -- には、 | |
3633 | 特に注意する価値があります。 | |
3634 | C<$/> が C<""> に設定されて、ファイル全体がこの設定で読み込まれた場合、 | |
3635 | ファイル先頭の連続する改行の並び C<"\n\n"> は捨てられます。 | |
3636 | ファイルの最後のレコードを例外として、 | |
3637 | 二つ以上の改行で終わるそれぞれの文字並びは一つのレコードとして扱われ、 | |
3638 | 正確に二つの改行で終わるように読み込まれます。 | |
3639 | ファイルの最後のレコードが 0 または 1 の連続する改行で終わっている場合、 | |
3640 | そのレコードはその数の改行と共に読み込まれます。 | |
3641 | 最後のレコードが二つ以上の連続する改行で終わっている場合、 | |
3642 | 全ての先行するレコードと同様、二つの改行と共に読み込まれます。 | |
3643 | ||
3644 | =begin original | |
3645 | ||
3646 | Suppose we wrote the following string to a file: | |
3647 | ||
3648 | =end original | |
3649 | ||
3650 | 次の文字列をファイルに書いたとします: | |
3651 | ||
3652 | my $string = "\n\n\n"; | |
3653 | $string .= "alpha beta\ngamma delta\n\n\n"; | |
3654 | $string .= "epsilon zeta eta\n\n"; | |
3655 | $string .= "theta\n"; | |
3656 | ||
3657 | my $file = 'simple_file.txt'; | |
3658 | open my $OUT, '>', $file or die; | |
3659 | print $OUT $string; | |
3660 | close $OUT or die; | |
3661 | ||
3662 | =begin original | |
3663 | ||
3664 | Now we read that file in paragraph mode: | |
3665 | ||
3666 | =end original | |
3667 | ||
3668 | このファイルを段落モードで読み込みます: | |
3669 | ||
3670 | local $/ = ""; # paragraph mode | |
3671 | open my $IN, '<', $file or die; | |
3672 | my @records = <$IN>; | |
3673 | close $IN or die; | |
3674 | ||
3675 | =begin original | |
3676 | ||
3677 | C<@records> will consist of these 3 strings: | |
3678 | ||
3679 | =end original | |
3680 | ||
3681 | C<@records> は三つの文字列からなります: | |
3682 | ||
3683 | ( | |
3684 | "alpha beta\ngamma delta\n\n", | |
3685 | "epsilon zeta eta\n\n", | |
3686 | "theta\n", | |
3687 | ) | |
3688 | ||
3689 | =begin original | |
3690 | ||
3691 | 3561 | Setting C<$/> to a reference to an integer, scalar containing an |
3692 | 3562 | integer, or scalar that's convertible to an integer will attempt to |
3693 | 3563 | read records instead of lines, with the maximum record size being the |
3694 | 3564 | referenced integer number of characters. So this: |
3695 | 3565 | |
3696 | 3566 | =end original |
3697 | 3567 | |
3698 | 3568 | C<$/> に整数、整数を含むスカラ、整数に変換できるスカラのいずれかへの |
3699 | 3569 | リファレンスをセットすると、行を読む代わりにレコードを読もうとします; |
3700 | 3570 | この場合、最大レコードサイズはリファレンス先の整数値の文字数となります。 |
3701 | 3571 | つまり: |
3702 | 3572 | |
3703 | 3573 | local $/ = \32768; # or \"32768", or \$var_containing_32768 |
3704 | 3574 | open my $fh, "<", $myfile or die $!; |
3705 | 3575 | local $_ = <$fh>; |
3706 | 3576 | |
3707 | 3577 | =begin original |
3708 | 3578 | |
3709 | 3579 | will read a record of no more than 32768 characters from $fh. If you're |
3710 | 3580 | not reading from a record-oriented file (or your OS doesn't have |
3711 | 3581 | record-oriented files), then you'll likely get a full chunk of data |
3712 | 3582 | with every read. If a record is larger than the record size you've |
3713 | 3583 | set, you'll get the record back in pieces. Trying to set the record |
3714 | 3584 | size to zero or less is deprecated and will cause $/ to have the value |
3715 | 3585 | of "undef", which will cause reading in the (rest of the) whole file. |
3716 | 3586 | |
3717 | 3587 | =end original |
3718 | 3588 | |
3719 | 3589 | これは $fh から 32768 文字を超えないようにレコードを読み込みます。 |
3720 | 3590 | もしレコード指向のファイルを読み込まない場合(あるいは OS がレコード指向 |
3721 | 3591 | ファイルを持たない場合)、読み込み毎にデータのチャンク全部を取り込みます。 |
3722 | 3592 | もしレコードがセットしたレコードサイズより大きい場合、 |
3723 | 3593 | レコードの部分を取り込みます。 |
3724 | 3594 | レコードサイズを 0 以下にセットしようとするのは廃止予定で、 |
3725 | 3595 | $/ に値 "undef" が設定され、(残りの)ファイル全体を読み込むことになります。 |
3726 | 3596 | |
3727 | 3597 | =begin original |
3728 | 3598 | |
3729 | 3599 | As of 5.19.9 setting C<$/> to any other form of reference will throw a |
3730 | 3600 | fatal exception. This is in preparation for supporting new ways to set |
3731 | 3601 | C<$/> in the future. |
3732 | 3602 | |
3733 | 3603 | =end original |
3734 | 3604 | |
3735 | 3605 | 5.19.9 から、C<$/> にその他の形式のリファレンスを設定すると致命的エラーが |
3736 | 3606 | 投げられます。 |
3737 | 3607 | これは将来 C<$/> を設定する新しい方法に対応する準備です。 |
3738 | 3608 | |
3739 | 3609 | =begin original |
3740 | 3610 | |
3741 | 3611 | On VMS only, record reads bypass PerlIO layers and any associated |
3742 | 3612 | buffering, so you must not mix record and non-record reads on the |
3743 | 3613 | same filehandle. Record mode mixes with line mode only when the |
3744 | 3614 | same buffering layer is in use for both modes. |
3745 | 3615 | |
3746 | 3616 | =end original |
3747 | 3617 | |
3748 | 3618 | VMS だけでは、レコードは PerlIO 層とそれに関連するバッファリングを迂回して |
3749 | 3619 | 読み込まれるので、同じファイルハンドルでレコード読み込みと |
3750 | 3620 | 非レコード読み込みを混ぜてはいけません。 |
3751 | 3621 | レコードモードは、同じバッファリング層を両方のモードで使う場合にのみ |
3752 | 3622 | ラインモードと混ざります。 |
3753 | 3623 | |
3754 | 3624 | =begin original |
3755 | 3625 | |
3756 | 3626 | You cannot call C<input_record_separator()> on a handle, only as a |
3757 | 3627 | static method. See L<IO::Handle|IO::Handle>. |
3758 | 3628 | |
3759 | 3629 | =end original |
3760 | 3630 | |
3761 | 3631 | ハンドルに対して C<input_record_separator()> を呼び出すことはできません; |
3762 | 3632 | 静的メソッドしてのみです。 |
3763 | 3633 | L<IO::Handle|IO::Handle> を参照してください。 |
3764 | 3634 | |
3765 | 3635 | =begin original |
3766 | 3636 | |
3767 | 3637 | See also L<perlport/"Newlines">. Also see L</$.>. |
3768 | 3638 | |
3769 | 3639 | =end original |
3770 | 3640 | |
3771 | 3641 | L<perlport/"Newlines"> を参照してください。 |
3772 | 3642 | L</$.> も参照してください。 |
3773 | 3643 | |
3774 | 3644 | =begin original |
3775 | 3645 | |
3776 | 3646 | Mnemonic: / delimits line boundaries when quoting poetry. |
3777 | 3647 | |
3778 | 3648 | =end original |
3779 | 3649 | |
3780 | 3650 | 記憶法: /は、詩を引用するときに、行の区切りを示します。 |
3781 | 3651 | |
3782 | 3652 | =item IO::Handle->output_record_separator( EXPR ) |
3783 | 3653 | |
3784 | 3654 | =item $OUTPUT_RECORD_SEPARATOR |
3785 | 3655 | |
3786 | 3656 | =item $ORS |
3787 | 3657 | |
3788 | 3658 | =item $\ |
3789 | 3659 | X<$\> X<$ORS> X<$OUTPUT_RECORD_SEPARATOR> |
3790 | 3660 | |
3791 | 3661 | =begin original |
3792 | 3662 | |
3793 | 3663 | The output record separator for the print operator. If defined, this |
3794 | 3664 | value is printed after the last of print's arguments. Default is C<undef>. |
3795 | 3665 | |
3796 | 3666 | =end original |
3797 | 3667 | |
3798 | 3668 | print 演算子のための出力レコードセパレータ。 |
3799 | 3669 | もし定義されていると、print の最後の引数の最後にこの値が表示されます。 |
3800 | 3670 | デフォルトは C<undef> です。 |
3801 | 3671 | |
3802 | 3672 | =begin original |
3803 | 3673 | |
3804 | 3674 | You cannot call C<output_record_separator()> on a handle, only as a |
3805 | 3675 | static method. See L<IO::Handle|IO::Handle>. |
3806 | 3676 | |
3807 | 3677 | =end original |
3808 | 3678 | |
3809 | 3679 | ハンドルに対して C<output_record_separator()> を呼び出すことはできません; |
3810 | 3680 | 静的メソッドしてのみです。 |
3811 | 3681 | L<IO::Handle|IO::Handle> を参照してください。 |
3812 | 3682 | |
3813 | 3683 | =begin original |
3814 | 3684 | |
3815 | 3685 | Mnemonic: you set C<$\> instead of adding "\n" at the end of the print. |
3816 | 3686 | Also, it's just like C<$/>, but it's what you get "back" from Perl. |
3817 | 3687 | |
3818 | 3688 | =end original |
3819 | 3689 | |
3820 | 3690 | 記憶法: print の最後に "\n" を付け加える代わりに C<$\> を設定する。 |
3821 | 3691 | また、C<$/> に似通っているが、Perl から「バック」されるものです。 |
3822 | 3692 | |
3823 | 3693 | =item HANDLE->autoflush( EXPR ) |
3824 | 3694 | |
3825 | 3695 | =item $OUTPUT_AUTOFLUSH |
3826 | 3696 | |
3827 | 3697 | =item $| |
3828 | 3698 | X<$|> X<autoflush> X<flush> X<$OUTPUT_AUTOFLUSH> |
3829 | 3699 | |
3830 | 3700 | =begin original |
3831 | 3701 | |
3832 | 3702 | If set to nonzero, forces a flush right away and after every write or |
3833 | 3703 | print on the currently selected output channel. Default is 0 |
3834 | 3704 | (regardless of whether the channel is really buffered by the system or |
3835 | 3705 | not; C<$|> tells you only whether you've asked Perl explicitly to |
3836 | 3706 | flush after each write). STDOUT will typically be line buffered if |
3837 | 3707 | output is to the terminal and block buffered otherwise. Setting this |
3838 | 3708 | variable is useful primarily when you are outputting to a pipe or |
3839 | 3709 | socket, such as when you are running a Perl program under B<rsh> and |
3840 | 3710 | want to see the output as it's happening. This has no effect on input |
3841 | 3711 | buffering. See L<perlfunc/getc> for that. See L<perlfunc/select> on |
3842 | 3712 | how to select the output channel. See also L<IO::Handle>. |
3843 | 3713 | |
3844 | 3714 | =end original |
3845 | 3715 | |
3846 | 3716 | 0 以外に設定されると、その時点で選択されている出力チャネルを直ちにその場で |
3847 | 3717 | フラッシュし、さらに write や print を行なうごとに、強制的にフラッシュします。 |
3848 | 3718 | デフォルトでは 0 となっています(チャンネルが実際にシステムによって |
3849 | 3719 | バッファリングされているかどうかは関知しません。 |
3850 | 3720 | C<$|> は Perl が明示的に毎回書き込みの後にフラッシュするかどうかのみを |
3851 | 3721 | 示します)。 |
3852 | 3722 | STDOUT は通常では、端末への出力時には行バッファリング、 |
3853 | 3723 | それ以外ではブロックバッファリングであることに注意してください。 |
3854 | 3724 | これは、Perl のスクリプトを rsh 配下で実行して、実行状況を確認したい |
3855 | 3725 | 場合のように、パイプやソケットに出力するときに特に便利でしょう。 |
3856 | 3726 | これは入力バッファリングには何の影響も与えません。 |
3857 | 3727 | 出力チャネルの選択方法については L<perlfunc/select> を参照してください。 |
3858 | 3728 | L<IO::Handle> も参照してください。 |
3859 | 3729 | |
3860 | 3730 | =begin original |
3861 | 3731 | |
3862 | 3732 | Mnemonic: when you want your pipes to be piping hot. |
3863 | 3733 | |
3864 | 3734 | =end original |
3865 | 3735 | |
3866 | 3736 | 記憶法: パイプをホットな状態にしておくために使う。 |
3867 | 3737 | |
3868 | 3738 | =item ${^LAST_FH} |
3869 | 3739 | X<${^LAST_FH}> |
3870 | 3740 | |
3871 | 3741 | =begin original |
3872 | 3742 | |
3873 | 3743 | This read-only variable contains a reference to the last-read filehandle. |
3874 | 3744 | This is set by C<< <HANDLE> >>, C<readline>, C<tell>, C<eof> and C<seek>. |
3875 | 3745 | This is the same handle that C<$.> and C<tell> and C<eof> without arguments |
3876 | 3746 | use. It is also the handle used when Perl appends ", <STDIN> line 1" to |
3877 | 3747 | an error or warning message. |
3878 | 3748 | |
3879 | 3749 | =end original |
3880 | 3750 | |
3881 | 3751 | この読み込み専用変数は最後に読み込んだファイルハンドルへのリファレンスを |
3882 | 3752 | 含んでいます。 |
3883 | 3753 | これは C<< <HANDLE> >>, C<readline>, C<tell>, C<eof>, C<seek> で |
3884 | 3754 | 設定されます。 |
3885 | 3755 | これは C<$.> および、C<tell> と C<eof> が引数なしで使われたときと同じ |
3886 | 3756 | ハンドルです。 |
3887 | 3757 | これはまた、Perl がエラーまたは警告メッセージに ", <STDIN> line 1" を追加する |
3888 | 3758 | ハンドルでもあります。 |
3889 | 3759 | |
3890 | 3760 | =begin original |
3891 | 3761 | |
3892 | 3762 | This variable was added in Perl v5.18.0. |
3893 | 3763 | |
3894 | 3764 | =end original |
3895 | 3765 | |
3896 | 3766 | この変数は Perl v5.18.0 で追加されました。 |
3897 | 3767 | |
3898 | 3768 | =back |
3899 | 3769 | |
3900 | 3770 | =head3 Variables related to formats |
3901 | 3771 | |
3902 | 3772 | (フォーマット関連の変数) |
3903 | 3773 | |
3904 | 3774 | =begin original |
3905 | 3775 | |
3906 | 3776 | The special variables for formats are a subset of those for |
3907 | 3777 | filehandles. See L<perlform> for more information about Perl's |
3908 | 3778 | formats. |
3909 | 3779 | |
3910 | 3780 | =end original |
3911 | 3781 | |
3912 | 3782 | フォーマットのための特殊変数はファイルハンドルのための物のサブセットです。 |
3913 | 3783 | Perl のフォーマットに関するさらなる情報については L<perlform> を |
3914 | 3784 | 参照してください。 |
3915 | 3785 | |
3916 | 3786 | =over 8 |
3917 | 3787 | |
3918 | 3788 | =item $ACCUMULATOR |
3919 | 3789 | |
3920 | 3790 | =item $^A |
3921 | 3791 | X<$^A> X<$ACCUMULATOR> |
3922 | 3792 | |
3923 | 3793 | =begin original |
3924 | 3794 | |
3925 | 3795 | The current value of the C<write()> accumulator for C<format()> lines. |
3926 | 3796 | A format contains C<formline()> calls that put their result into |
3927 | 3797 | C<$^A>. After calling its format, C<write()> prints out the contents |
3928 | 3798 | of C<$^A> and empties. So you never really see the contents of C<$^A> |
3929 | 3799 | unless you call C<formline()> yourself and then look at it. See |
3930 | 3800 | L<perlform> and L<perlfunc/"formline PICTURE,LIST">. |
3931 | 3801 | |
3932 | 3802 | =end original |
3933 | 3803 | |
3934 | 3804 | C<format()> 行のための、その時点での C<write()> アキュムレータの値。 |
3935 | 3805 | format には、C<$^A> に結果を残す、C<formline()> 呼び出しが含まれます。 |
3936 | 3806 | 自分のフォーマットを呼び出した後で、 |
3937 | 3807 | C<write()> は C<$^A> の内容を出力してから消去します。 |
3938 | 3808 | したがって、自分で C<formline()> を呼び出すのでなければ、 |
3939 | 3809 | C<$^A> の値が見えることはありません。 |
3940 | 3810 | L<perlform> と L<perlfunc/"formline PICTURE,LIST"> を参照してください。 |
3941 | 3811 | |
3942 | 3812 | =item IO::Handle->format_formfeed(EXPR) |
3943 | 3813 | |
3944 | 3814 | =item $FORMAT_FORMFEED |
3945 | 3815 | |
3946 | 3816 | =item $^L |
3947 | 3817 | X<$^L> X<$FORMAT_FORMFEED> |
3948 | 3818 | |
3949 | 3819 | =begin original |
3950 | 3820 | |
3951 | 3821 | What formats output as a form feed. The default is C<\f>. |
3952 | 3822 | |
3953 | 3823 | =end original |
3954 | 3824 | |
3955 | 3825 | フォーマット出力で、改ページのために出力されるもの。 |
3956 | 3826 | デフォルトは C<\f>。 |
3957 | 3827 | |
3958 | 3828 | =begin original |
3959 | 3829 | |
3960 | 3830 | You cannot call C<format_formfeed()> on a handle, only as a static |
3961 | 3831 | method. See L<IO::Handle|IO::Handle>. |
3962 | 3832 | |
3963 | 3833 | =end original |
3964 | 3834 | |
3965 | 3835 | ハンドルに対して C<format_formfeed()> を呼び出すことはできません; |
3966 | 3836 | 静的メソッドしてのみです。 |
3967 | 3837 | L<IO::Handle|IO::Handle> を参照してください。 |
3968 | 3838 | |
3969 | 3839 | =item HANDLE->format_page_number(EXPR) |
3970 | 3840 | |
3971 | 3841 | =item $FORMAT_PAGE_NUMBER |
3972 | 3842 | |
3973 | 3843 | =item $% |
3974 | 3844 | X<$%> X<$FORMAT_PAGE_NUMBER> |
3975 | 3845 | |
3976 | 3846 | =begin original |
3977 | 3847 | |
3978 | 3848 | The current page number of the currently selected output channel. |
3979 | 3849 | |
3980 | 3850 | =end original |
3981 | 3851 | |
3982 | 3852 | その時点で選択されている出力チャネルの、その時点でのページ番号。 |
3983 | 3853 | |
3984 | 3854 | =begin original |
3985 | 3855 | |
3986 | 3856 | Mnemonic: C<%> is page number in B<nroff>. |
3987 | 3857 | |
3988 | 3858 | =end original |
3989 | 3859 | |
3990 | 3860 | 記憶法: C<%> は、B<nroff> でのページ番号です。 |
3991 | 3861 | |
3992 | 3862 | =item HANDLE->format_lines_left(EXPR) |
3993 | 3863 | |
3994 | 3864 | =item $FORMAT_LINES_LEFT |
3995 | 3865 | |
3996 | 3866 | =item $- |
3997 | 3867 | X<$-> X<$FORMAT_LINES_LEFT> |
3998 | 3868 | |
3999 | 3869 | =begin original |
4000 | 3870 | |
4001 | 3871 | The number of lines left on the page of the currently selected output |
4002 | 3872 | channel. |
4003 | 3873 | |
4004 | 3874 | =end original |
4005 | 3875 | |
4006 | 3876 | その時点で選択されている出力チャネルの、ページに残っている行数。 |
4007 | 3877 | |
4008 | 3878 | =begin original |
4009 | 3879 | |
4010 | 3880 | Mnemonic: lines_on_page - lines_printed. |
4011 | 3881 | |
4012 | 3882 | =end original |
4013 | 3883 | |
4014 | 3884 | 記憶法: "ページ行数" - "印字済み行数" |
4015 | 3885 | |
4016 | 3886 | =item IO::Handle->format_line_break_characters EXPR |
4017 | 3887 | |
4018 | 3888 | =item $FORMAT_LINE_BREAK_CHARACTERS |
4019 | 3889 | |
4020 | 3890 | =item $: |
4021 | 3891 | X<$:> X<FORMAT_LINE_BREAK_CHARACTERS> |
4022 | 3892 | |
4023 | 3893 | =begin original |
4024 | 3894 | |
4025 | 3895 | The current set of characters after which a string may be broken to |
4026 | 3896 | fill continuation fields (starting with C<^>) in a format. The default is |
4027 | 3897 | S<" \n-">, to break on a space, newline, or a hyphen. |
4028 | 3898 | |
4029 | 3899 | =end original |
4030 | 3900 | |
4031 | 3901 | フォーマットの充填継続フィールド (C<^> で始まるもの) への文字列で行分割を許す |
4032 | 3902 | 文字集合。 |
4033 | 3903 | デフォルトは S<" \n-"> で空白、改行、ハイフンの後で行分割が可能です。 |
4034 | 3904 | |
4035 | 3905 | =begin original |
4036 | 3906 | |
4037 | 3907 | You cannot call C<format_line_break_characters()> on a handle, only as |
4038 | 3908 | a static method. See L<IO::Handle|IO::Handle>. |
4039 | 3909 | |
4040 | 3910 | =end original |
4041 | 3911 | |
4042 | 3912 | ハンドルに対して C<format_line_break_characters()> を呼び出すことはできません; |
4043 | 3913 | 静的メソッドしてのみです。 |
4044 | 3914 | L<IO::Handle|IO::Handle> を参照してください。 |
4045 | 3915 | |
4046 | 3916 | =begin original |
4047 | 3917 | |
4048 | 3918 | Mnemonic: a "colon" in poetry is a part of a line. |
4049 | 3919 | |
4050 | 3920 | =end original |
4051 | 3921 | |
4052 | 3922 | 記憶法: 詩では「コロン」は、行の一部。 |
4053 | 3923 | |
4054 | 3924 | =item HANDLE->format_lines_per_page(EXPR) |
4055 | 3925 | |
4056 | 3926 | =item $FORMAT_LINES_PER_PAGE |
4057 | 3927 | |
4058 | 3928 | =item $= |
4059 | 3929 | X<$=> X<$FORMAT_LINES_PER_PAGE> |
4060 | 3930 | |
4061 | 3931 | =begin original |
4062 | 3932 | |
4063 | 3933 | The current page length (printable lines) of the currently selected |
4064 | 3934 | output channel. The default is 60. |
4065 | 3935 | |
4066 | 3936 | =end original |
4067 | 3937 | |
4068 | 3938 | その時点で選択されている出力チャネルの、その時点でのページ長(印字可能行数)。 |
4069 | 3939 | デフォルトは 60 です。 |
4070 | 3940 | |
4071 | 3941 | =begin original |
4072 | 3942 | |
4073 | 3943 | Mnemonic: = has horizontal lines. |
4074 | 3944 | |
4075 | 3945 | =end original |
4076 | 3946 | |
4077 | 3947 | 記憶法: = には複数の水平線 (行) が含まれます。 |
4078 | 3948 | |
4079 | 3949 | =item HANDLE->format_top_name(EXPR) |
4080 | 3950 | |
4081 | 3951 | =item $FORMAT_TOP_NAME |
4082 | 3952 | |
4083 | 3953 | =item $^ |
4084 | 3954 | X<$^> X<$FORMAT_TOP_NAME> |
4085 | 3955 | |
4086 | 3956 | =begin original |
4087 | 3957 | |
4088 | 3958 | The name of the current top-of-page format for the currently selected |
4089 | 3959 | output channel. The default is the name of the filehandle with C<_TOP> |
4090 | 3960 | appended. For example, the default format top name for the C<STDOUT> |
4091 | 3961 | filehandle is C<STDOUT_TOP>. |
4092 | 3962 | |
4093 | 3963 | =end original |
4094 | 3964 | |
4095 | 3965 | その時点で選択されている出力チャネルの、その時点でのページ先頭フォーマット名。 |
4096 | 3966 | デフォルトは、ファイルハンドル名に _TOP を続けたものです。 |
4097 | 3967 | 例えば、C<STDOUT> ファイルハンドルのデフォルトのページ先頭フォーマット名は |
4098 | 3968 | C<STDOUT_TOP> です。 |
4099 | 3969 | |
4100 | 3970 | =begin original |
4101 | 3971 | |
4102 | 3972 | Mnemonic: points to top of page. |
4103 | 3973 | |
4104 | 3974 | =end original |
4105 | 3975 | |
4106 | 3976 | 記憶法: ページの先頭へのポインタ。 |
4107 | 3977 | |
4108 | 3978 | =item HANDLE->format_name(EXPR) |
4109 | 3979 | |
4110 | 3980 | =item $FORMAT_NAME |
4111 | 3981 | |
4112 | 3982 | =item $~ |
4113 | 3983 | X<$~> X<$FORMAT_NAME> |
4114 | 3984 | |
4115 | 3985 | =begin original |
4116 | 3986 | |
4117 | 3987 | The name of the current report format for the currently selected |
4118 | 3988 | output channel. The default format name is the same as the filehandle |
4119 | 3989 | name. For example, the default format name for the C<STDOUT> |
4120 | 3990 | filehandle is just C<STDOUT>. |
4121 | 3991 | |
4122 | 3992 | =end original |
4123 | 3993 | |
4124 | 3994 | その時点で選択されている出力チャネルの、その時点でのフォーマット名。 |
4125 | 3995 | デフォルトは、ファイルハンドル名です。 |
4126 | 3996 | 例えば、C<STDOUT> ファイルハンドルのデフォルトフォーマット名は |
4127 | 3997 | 単に C<STDOUT> です。 |
4128 | 3998 | |
4129 | 3999 | =begin original |
4130 | 4000 | |
4131 | 4001 | Mnemonic: brother to C<$^>. |
4132 | 4002 | |
4133 | 4003 | =end original |
4134 | 4004 | |
4135 | 4005 | 記憶法: C<$^> の兄弟。 |
4136 | 4006 | |
4137 | 4007 | =back |
4138 | 4008 | |
4139 | 4009 | =head2 Error Variables |
4140 | 4010 | X<error> X<exception> |
4141 | 4011 | |
4142 | 4012 | (エラー変数) |
4143 | 4013 | |
4144 | 4014 | =begin original |
4145 | 4015 | |
4146 | 4016 | The variables C<$@>, C<$!>, C<$^E>, and C<$?> contain information |
4147 | 4017 | about different types of error conditions that may appear during |
4148 | 4018 | execution of a Perl program. The variables are shown ordered by |
4149 | 4019 | the "distance" between the subsystem which reported the error and |
4150 | 4020 | the Perl process. They correspond to errors detected by the Perl |
4151 | 4021 | interpreter, C library, operating system, or an external program, |
4152 | 4022 | respectively. |
4153 | 4023 | |
4154 | 4024 | =end original |
4155 | 4025 | |
4156 | 4026 | 変数 C<$@>, C<$!>, C<$^E>, C<$?> は Perl プログラムの実行中に |
4157 | 4027 | 発生した、異なる種類のエラー情報を保持します。 |
4158 | 4028 | 変数はエラーを報告した副システムと Perl プロセスとの「距離」の順番に |
4159 | 4029 | 並んでいます。 |
4160 | 4030 | これらはそれぞれ、Perl インタプリタ、C ライブラリ、 |
4161 | 4031 | オペレーティングシステム、外部プログラムによって検出された |
4162 | 4032 | エラーに対応しています。 |
4163 | 4033 | |
4164 | 4034 | =begin original |
4165 | 4035 | |
4166 | 4036 | To illustrate the differences between these variables, consider the |
4167 | 4037 | following Perl expression, which uses a single-quoted string. After |
4168 | 4038 | execution of this statement, perl may have set all four special error |
4169 | 4039 | variables: |
4170 | 4040 | |
4171 | 4041 | =end original |
4172 | 4042 | |
4173 | 4043 | これらの変数の違いを示すために、 |
4174 | 4044 | 以下のようなシングルクォートを用いた Perl 式を考えます。 |
4175 | 4045 | この文の実行後、perl は四つ全ての特殊エラー変数をセットします: |
4176 | 4046 | |
4177 | 4047 | eval q{ |
4178 | 4048 | open my $pipe, "/cdrom/install |" or die $!; |
4179 | 4049 | my @res = <$pipe>; |
4180 | 4050 | close $pipe or die "bad pipe: $?, $!"; |
4181 | 4051 | }; |
4182 | 4052 | |
4183 | 4053 | =begin original |
4184 | 4054 | |
4185 | 4055 | When perl executes the C<eval()> expression, it translates the |
4186 | 4056 | C<open()>, C<< <PIPE> >>, and C<close> calls in the C run-time library |
4187 | 4057 | and thence to the operating system kernel. perl sets C<$!> to |
4188 | 4058 | the C library's C<errno> if one of these calls fails. |
4189 | 4059 | |
4190 | 4060 | =end original |
4191 | 4061 | |
4192 | 4062 | C<eval()> 式が実行されたとき、C<open()>, C<< <PIPE> >>, C<close> は |
4193 | 4063 | C ランタイムライブラリの呼び出しに変換され、それからオペレーティング |
4194 | 4064 | システムコールに変換されます。 |
4195 | 4065 | C<$!> はこれらの呼び出しのどれかが失敗したとき、 |
4196 | 4066 | C ライブラリの C<errno> の値がセットされます。 |
4197 | 4067 | |
4198 | 4068 | =begin original |
4199 | 4069 | |
4200 | 4070 | C<$@> is set if the string to be C<eval>-ed did not compile (this may |
4201 | 4071 | happen if C<open> or C<close> were imported with bad prototypes), or |
4202 | 4072 | if Perl code executed during evaluation C<die()>d. In these cases the |
4203 | 4073 | value of C<$@> is the compile error, or the argument to C<die> (which |
4204 | 4074 | will interpolate C<$!> and C<$?>). (See also L<Fatal>, though.) |
4205 | 4075 | |
4206 | 4076 | =end original |
4207 | 4077 | |
4208 | 4078 | C<$@> は C<eval> された文字列がコンパイルされなかったとき(これは C<open> か |
4209 | 4079 | C<close> が正しくないプロトタイプでインポートされたときに起こり得ます)、 |
4210 | 4080 | または評価中に実行している Perl コードが C<die()> したときにセットされます。 |
4211 | 4081 | これらの場合には C<$@> の値はコンパイルエラー、または |
4212 | 4082 | C<die> への引数(これには C<$!> と C<$?> が差し挟まれます)です。 |
4213 | 4083 | (しかし、L<Fatal> も参照して下さい。) |
4214 | 4084 | |
4215 | 4085 | =begin original |
4216 | 4086 | |
4217 | 4087 | Under a few operating systems, C<$^E> may contain a more verbose error |
4218 | 4088 | indicator, such as in this case, "CDROM tray not closed." Systems that |
4219 | 4089 | do not support extended error messages leave C<$^E> the same as C<$!>. |
4220 | 4090 | |
4221 | 4091 | =end original |
4222 | 4092 | |
4223 | 4093 | いくつかのオペレーティングシステムでは、C<$^E> により詳細なエラー指示子が |
4224 | 4094 | 入っているかもしれません; 今回の場合で言えば、 |
4225 | 4095 | "CDROM tray not closed." などです。 |
4226 | 4096 | 追加のエラーメッセージに対応していないシステムでは、C<$^E> は C<$!> と同じ |
4227 | 4097 | 値です。 |
4228 | 4098 | |
4229 | 4099 | =begin original |
4230 | 4100 | |
4231 | 4101 | Finally, C<$?> may be set to a non-0 value if the external program |
4232 | 4102 | F</cdrom/install> fails. The upper eight bits reflect specific error |
4233 | 4103 | conditions encountered by the program (the program's C<exit()> value). |
4234 | 4104 | The lower eight bits reflect mode of failure, like signal death and |
4235 | 4105 | core dump information. See L<wait(2)> for details. In contrast to |
4236 | 4106 | C<$!> and C<$^E>, which are set only if an error condition is detected, |
4237 | 4107 | the variable C<$?> is set on each C<wait> or pipe C<close>, |
4238 | 4108 | overwriting the old value. This is more like C<$@>, which on every |
4239 | 4109 | C<eval()> is always set on failure and cleared on success. |
4240 | 4110 | |
4241 | 4111 | =end original |
4242 | 4112 | |
4243 | 4113 | 最後に、C<$?> は外部プログラム F</cdrom/install> が失敗したときに |
4244 | 4114 | 非 0 にセットされるかもしれません。 |
4245 | 4115 | 上位の 8 ビットはプログラムが遭遇した特定のエラー状況 |
4246 | 4116 | (プログラムの C<exit()> の値)を反映します。 |
4247 | 4117 | 下位の 8 ビットは、シグナルの死亡やコアダンプ情報と言った失敗のモードを |
4248 | 4118 | 反映します。 |
4249 | 4119 | 詳細については L<wait(2)> を参照して下さい。 |
4250 | 4120 | C<$!> と C<$^E> はエラー状況が検出されたときにのみ設定されますが、 |
4251 | 4121 | 変数 C<$?> は C<wait> やパイプの C<close> の度に、前の値を上書きします。 |
4252 | 4122 | これは、C<$@> が C<eval()> の実行毎に、エラーならセットされ、 |
4253 | 4123 | 成功ならクリアされるという動作と似ています。 |
4254 | 4124 | |
4255 | 4125 | =begin original |
4256 | 4126 | |
4257 | 4127 | For more details, see the individual descriptions at C<$@>, C<$!>, |
4258 | 4128 | C<$^E>, and C<$?>. |
4259 | 4129 | |
4260 | 4130 | =end original |
4261 | 4131 | |
4262 | 4132 | より詳細については、C<$@>, C<$!>, C<$^E>, C<$?> それぞれの説明を |
4263 | 4133 | 参照して下さい。 |
4264 | 4134 | |
4265 | 4135 | =over 8 |
4266 | 4136 | |
4267 | 4137 | =item ${^CHILD_ERROR_NATIVE} |
4268 | 4138 | X<$^CHILD_ERROR_NATIVE> |
4269 | 4139 | |
4270 | 4140 | =begin original |
4271 | 4141 | |
4272 | 4142 | The native status returned by the last pipe close, backtick (C<``>) |
4273 | 4143 | command, successful call to C<wait()> or C<waitpid()>, or from the |
4274 | 4144 | C<system()> operator. On POSIX-like systems this value can be decoded |
4275 | 4145 | with the WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, |
4276 | 4146 | WSTOPSIG and WIFCONTINUED functions provided by the L<POSIX> module. |
4277 | 4147 | |
4278 | 4148 | =end original |
4279 | 4149 | |
4280 | 4150 | 最後のパイプクローズ、逆クォート (C<``>) コマンド、C<wait()> と |
4281 | 4151 | C<waitpid()> の成功した呼び出し、C<system()> 演算子から返された、 |
4282 | 4152 | ネイティブなステータスです。 |
4283 | 4153 | POSIX 風システムでは、この値は L<POSIX> モジュールで提供される |
4284 | 4154 | WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, |
4285 | 4155 | WIFCONTINUED 関数でデコードできます。 |
4286 | 4156 | |
4287 | 4157 | =begin original |
4288 | 4158 | |
4289 | 4159 | Under VMS this reflects the actual VMS exit status; i.e. it is the |
4290 | 4160 | same as C<$?> when the pragma C<use vmsish 'status'> is in effect. |
4291 | 4161 | |
4292 | 4162 | =end original |
4293 | 4163 | |
4294 | 4164 | VMS ではこれは実際の VMS の終了ステータスを反映します; |
4295 | 4165 | 言い換えると、これは C<use vmsish 'status'> プラグマが有効なときの $? と |
4296 | 4166 | 同じです。 |
4297 | 4167 | |
4298 | 4168 | =begin original |
4299 | 4169 | |
4300 | 4170 | This variable was added in Perl v5.10.0. |
4301 | 4171 | |
4302 | 4172 | =end original |
4303 | 4173 | |
4304 | 4174 | この変数は Perl v5.10.0 で追加されました。 |
4305 | 4175 | |
4306 | 4176 | =item $EXTENDED_OS_ERROR |
4307 | 4177 | |
4308 | 4178 | =item $^E |
4309 | 4179 | X<$^E> X<$EXTENDED_OS_ERROR> |
4310 | 4180 | |
4311 | 4181 | =begin original |
4312 | 4182 | |
4313 | 4183 | Error information specific to the current operating system. At the |
4314 | 4184 | moment, this differs from C<L</$!>> under only VMS, OS/2, and Win32 (and |
4315 | 4185 | for MacPerl). On all other platforms, C<$^E> is always just the same |
4316 | 4186 | as C<$!>. |
4317 | 4187 | |
4318 | 4188 | =end original |
4319 | 4189 | |
4320 | 4190 | 現在のオペレーティングシステムに特化したエラー情報です。 |
4321 | 4191 | 現在のところ、VMS, OS/2, Win32 (と MacPerl) のみで |
4322 | 4192 | C<L</$!>> と異なる値をもちます。 |
4323 | 4193 | その他のプラットフォームでは、C<$^E> はいつも C<$!> と同じです。 |
4324 | 4194 | |
4325 | 4195 | =begin original |
4326 | 4196 | |
4327 | 4197 | Under VMS, C<$^E> provides the VMS status value from the last system |
4328 | 4198 | error. This is more specific information about the last system error |
4329 | 4199 | than that provided by C<$!>. This is particularly important when C<$!> |
4330 | 4200 | is set to B<EVMSERR>. |
4331 | 4201 | |
4332 | 4202 | =end original |
4333 | 4203 | |
4334 | 4204 | VMS では、C<$^E> は最後のシステムエラーの VMS ステータス値です。 |
4335 | 4205 | これは、最後のシステムエラーについて C<$!> で提供されるものより |
4336 | 4206 | 具体的な情報を示します。 |
4337 | 4207 | これは特に C<$!> が B<EVMSERR> にセットされた場合に重要です。 |
4338 | 4208 | |
4339 | 4209 | =begin original |
4340 | 4210 | |
4341 | 4211 | Under OS/2, C<$^E> is set to the error code of the last call to OS/2 |
4342 | 4212 | API either via CRT, or directly from perl. |
4343 | 4213 | |
4344 | 4214 | =end original |
4345 | 4215 | |
4346 | 4216 | OS/2 では、C<$^E> は CRT 経由、または Perl から直接呼び出された |
4347 | 4217 | 最後の OS/2 API のエラーコードがセットされます。 |
4348 | 4218 | |
4349 | 4219 | =begin original |
4350 | 4220 | |
4351 | 4221 | Under Win32, C<$^E> always returns the last error information reported |
4352 | 4222 | by the Win32 call C<GetLastError()> which describes the last error |
4353 | 4223 | from within the Win32 API. Most Win32-specific code will report errors |
4354 | 4224 | via C<$^E>. ANSI C and Unix-like calls set C<errno> and so most |
4355 | 4225 | portable Perl code will report errors via C<$!>. |
4356 | 4226 | |
4357 | 4227 | =end original |
4358 | 4228 | |
4359 | 4229 | Win32 では、C<$^E> は Win32 API での最後のエラーの内容を返す |
4360 | 4230 | C<GetLastError()> Win32 呼び出しで報告される最新のエラー情報を |
4361 | 4231 | 返します。 |
4362 | 4232 | ほとんどの Win32 固有のコードはエラーを C<$^E> 経由で返します。 |
4363 | 4233 | ANSI C と Unix 風の呼び出しは C<errno> をセットするので、 |
4364 | 4234 | ほとんどの移植性のある Perl コードは C<$!> 経由で |
4365 | 4235 | エラーを報告します。 |
4366 | 4236 | |
4367 | 4237 | =begin original |
4368 | 4238 | |
4369 | 4239 | Caveats mentioned in the description of C<L</$!>> generally apply to |
4370 | 4240 | C<$^E>, also. |
4371 | 4241 | |
4372 | 4242 | =end original |
4373 | 4243 | |
4374 | 4244 | C<L</$!>> の説明で触れた問題点は一般的に C<$^E> にも適用されます。 |
4375 | 4245 | |
4376 | 4246 | =begin original |
4377 | 4247 | |
4378 | 4248 | This variable was added in Perl 5.003. |
4379 | 4249 | |
4380 | 4250 | =end original |
4381 | 4251 | |
4382 | 4252 | この変数は Perl 5.003 で追加されました。 |
4383 | 4253 | |
4384 | 4254 | =begin original |
4385 | 4255 | |
4386 | 4256 | Mnemonic: Extra error explanation. |
4387 | 4257 | |
4388 | 4258 | =end original |
4389 | 4259 | |
4390 | 4260 | 記憶法: 追加の(Extra)エラーの説明。 |
4391 | 4261 | |
4392 | 4262 | =item $EXCEPTIONS_BEING_CAUGHT |
4393 | 4263 | |
4394 | 4264 | =item $^S |
4395 | 4265 | X<$^S> X<$EXCEPTIONS_BEING_CAUGHT> |
4396 | 4266 | |
4397 | 4267 | =begin original |
4398 | 4268 | |
4399 | 4269 | Current state of the interpreter. |
4400 | 4270 | |
4401 | 4271 | =end original |
4402 | 4272 | |
4403 | 4273 | 現在のインタプリタの状態を示します。 |
4404 | 4274 | |
4405 | 4275 | =begin original |
4406 | 4276 | |
4407 | 4277 | $^S State |
4408 | 4278 | --------- ------------------------------------- |
4409 | 4279 | undef Parsing module, eval, or main program |
4410 | 4280 | true (1) Executing an eval |
4411 | 4281 | false (0) Otherwise |
4412 | 4282 | |
4413 | 4283 | =end original |
4414 | 4284 | |
4415 | 4285 | $^S 状態 |
4416 | 4286 | --------- ------------------- |
4417 | 4287 | undef モジュール、eval、メインプログラムのパース中 |
4418 | 4288 | 真 (1) eval の実行中 |
4419 | 4289 | 偽 (0) その他 |
4420 | 4290 | |
4421 | 4291 | =begin original |
4422 | 4292 | |
4423 | 4293 | The first state may happen in C<$SIG{__DIE__}> and C<$SIG{__WARN__}> |
4424 | 4294 | handlers. |
4425 | 4295 | |
4426 | 4296 | =end original |
4427 | 4297 | |
4428 | 4298 | 最初の状態は C<$SIG{__DIE__}> と C<$SIG{__WARN__}> のハンドラで起きる |
4429 | 4299 | 可能性があります。 |
4430 | 4300 | |
4431 | 4301 | =begin original |
4432 | 4302 | |
4433 | 4303 | The English name $EXCEPTIONS_BEING_CAUGHT is slightly misleading, because |
4434 | 4304 | the C<undef> value does not indicate whether exceptions are being caught, |
4435 | 4305 | since compilation of the main program does not catch exceptions. |
4436 | 4306 | |
4437 | 4307 | =end original |
4438 | 4308 | |
4439 | 4309 | 英語名 $EXCEPTIONS_BEING_CAUGHT は少し誤解を招きます; C<undef> は例外が |
4440 | 4310 | 捕捉されたかどうかを示しているわけではないからです; メインプログラムの |
4441 | 4311 | コンパイルは例外を捕捉しません。 |
4442 | 4312 | |
4443 | 4313 | =begin original |
4444 | 4314 | |
4445 | 4315 | This variable was added in Perl 5.004. |
4446 | 4316 | |
4447 | 4317 | =end original |
4448 | 4318 | |
4449 | 4319 | この変数は Perl 5.004 で追加されました。 |
4450 | 4320 | |
4451 | 4321 | =item $WARNING |
4452 | 4322 | |
4453 | 4323 | =item $^W |
4454 | 4324 | X<$^W> X<$WARNING> |
4455 | 4325 | |
4456 | 4326 | =begin original |
4457 | 4327 | |
4458 | 4328 | The current value of the warning switch, initially true if B<-w> was |
4459 | 4329 | used, false otherwise, but directly modifiable. |
4460 | 4330 | |
4461 | 4331 | =end original |
4462 | 4332 | |
4463 | 4333 | 警告スイッチの値で、B<-w> スイッチが使われると内部的に真となり、 |
4464 | 4334 | そうでない場合は直接変更可能です。 |
4465 | 4335 | |
4466 | 4336 | =begin original |
4467 | 4337 | |
4468 | 4338 | See also L<warnings>. |
4469 | 4339 | |
4470 | 4340 | =end original |
4471 | 4341 | |
4472 | 4342 | L<warnings> も参照して下さい。 |
4473 | 4343 | |
4474 | 4344 | =begin original |
4475 | 4345 | |
4476 | 4346 | Mnemonic: related to the B<-w> switch. |
4477 | 4347 | |
4478 | 4348 | =end original |
4479 | 4349 | |
4480 | 4350 | 記憶法: B<-w> スイッチに関係します。 |
4481 | 4351 | |
4482 | 4352 | =item ${^WARNING_BITS} |
4483 | 4353 | X<${^WARNING_BITS}> |
4484 | 4354 | |
4485 | 4355 | =begin original |
4486 | 4356 | |
4487 | 4357 | The current set of warning checks enabled by the C<use warnings> pragma. |
4488 | 4358 | It has the same scoping as the C<$^H> and C<%^H> variables. The exact |
4489 | 4359 | values are considered internal to the L<warnings> pragma and may change |
4490 | 4360 | between versions of Perl. |
4491 | 4361 | |
4492 | 4362 | =end original |
4493 | 4363 | |
4494 | 4364 | C<use warnings> プラグマで有効にされた、現在の警告チェックの集合です。 |
4495 | 4365 | C<$^H> および C<%^H> 変数と同じスコープを持ちます。 |
4496 | 4366 | 正確な値は L<warnings> プラグマの内部の値と考えられ、Perl の |
4497 | 4367 | バージョンによって変更されるかもしれません。 |
4498 | 4368 | |
4499 | 4369 | =begin original |
4500 | 4370 | |
4501 | 4371 | This variable was added in Perl v5.6.0. |
4502 | 4372 | |
4503 | 4373 | =end original |
4504 | 4374 | |
4505 | 4375 | この変数は Perl v5.6.0 で追加されました。 |
4506 | 4376 | |
4507 | 4377 | =item $OS_ERROR |
4508 | 4378 | |
4509 | 4379 | =item $ERRNO |
4510 | 4380 | |
4511 | 4381 | =item $! |
4512 | 4382 | X<$!> X<$ERRNO> X<$OS_ERROR> |
4513 | 4383 | |
4514 | 4384 | =begin original |
4515 | 4385 | |
4516 | 4386 | When referenced, C<$!> retrieves the current value |
4517 | 4387 | of the C C<errno> integer variable. |
4518 | 4388 | If C<$!> is assigned a numerical value, that value is stored in C<errno>. |
4519 | 4389 | When referenced as a string, C<$!> yields the system error string |
4520 | 4390 | corresponding to C<errno>. |
4521 | 4391 | |
4522 | 4392 | =end original |
4523 | 4393 | |
4524 | 4394 | 参照されると、C<$!> は C の C<errno> 整数変数の現在の値を取得します。 |
4525 | 4395 | C<$!> に数値が代入されると、その値は C<errno> に保管されます。 |
4526 | 4396 | 文字列として参照されると、C<$!> は C<errno> に対応するシステムエラー |
4527 | 4397 | 文字列を返します。 |
4528 | 4398 | |
4529 | 4399 | =begin original |
4530 | 4400 | |
4531 | 4401 | Many system or library calls set C<errno> if they fail, |
4532 | 4402 | to indicate the cause of failure. They usually do B<not> |
4533 | 4403 | set C<errno> to zero if they succeed. This means C<errno>, |
4534 | 4404 | hence C<$!>, is meaningful only I<immediately> after a B<failure>: |
4535 | 4405 | |
4536 | 4406 | =end original |
4537 | 4407 | |
4538 | 4408 | 多くのシステムやライブラリ呼び出しは、失敗したときに、失敗の理由を示すために |
4539 | 4409 | C<errno> を設定します。 |
4540 | 4410 | これらは普通は成功したときには C<errno> にゼロを設定 B<しません>。 |
4541 | 4411 | これは、C<errno>、C<$!> は、B<失敗> の I<直後> でのみ意味が |
4542 | 4412 | あるということです: |
4543 | 4413 | |
4544 | 4414 | =begin original |
4545 | 4415 | |
4546 | 4416 | if (open my $fh, "<", $filename) { |
4547 | 4417 | # Here $! is meaningless. |
4548 | 4418 | ... |
4549 | 4419 | } |
4550 | 4420 | else { |
4551 | 4421 | # ONLY here is $! meaningful. |
4552 | 4422 | ... |
4553 | 4423 | # Already here $! might be meaningless. |
4554 | 4424 | } |
4555 | 4425 | # Since here we might have either success or failure, |
4556 | 4426 | # $! is meaningless. |
4557 | 4427 | |
4558 | 4428 | =end original |
4559 | 4429 | |
4560 | 4430 | if (open my $fh, "<", $filename) { |
4561 | 4431 | # ここで $! は無意味。 |
4562 | 4432 | ... |
4563 | 4433 | } |
4564 | 4434 | else { |
4565 | 4435 | # ここでだけ $! に意味がある。 |
4566 | 4436 | ... |
4567 | 4437 | # ここで既に $! は無意味かもしれません。 |
4568 | 4438 | } |
4569 | 4439 | # ここでは成功と失敗の両方の可能性があるので、 |
4570 | 4440 | # $! は無意味。 |
4571 | 4441 | |
4572 | 4442 | =begin original |
4573 | 4443 | |
4574 | 4444 | Here, I<meaningless> means that C<$!> may be unrelated to the outcome |
4575 | 4445 | of the C<open()> operator. Assignment to C<$!> is similarly ephemeral. |
4576 | 4446 | It can be used immediately before invoking the C<die()> operator, |
4577 | 4447 | to set the exit value, or to inspect the system error string |
4578 | 4448 | corresponding to error I<n>, or to restore C<$!> to a meaningful state. |
4579 | 4449 | |
4580 | 4450 | =end original |
4581 | 4451 | |
4582 | 4452 | ここで、I<無意味> というのは C<$!> は C<open()> 演算子の結果に |
4583 | 4453 | 関係ないということです。 |
4584 | 4454 | C<$!> への代入も同様に一時的なものです。 |
4585 | 4455 | これは、終了値を設定したり、エラー I<n> に対応するシステムエラー文字列を |
4586 | 4456 | 調べたり、C<$!> を意味のある状態に復元するために、C<die()> 演算子を |
4587 | 4457 | 起動する直前で使えます。 |
4588 | 4458 | |
4589 | 4459 | =begin original |
4590 | 4460 | |
4591 | 4461 | Mnemonic: What just went bang? |
4592 | 4462 | |
4593 | 4463 | =end original |
4594 | 4464 | |
4595 | 4465 | 記憶法: 何が bang(!) したか。 |
4596 | 4466 | |
4597 | 4467 | =item %OS_ERROR |
4598 | 4468 | |
4599 | 4469 | =item %ERRNO |
4600 | 4470 | |
4601 | 4471 | =item %! |
4602 | 4472 | X<%!> X<%OS_ERROR> X<%ERRNO> |
4603 | 4473 | |
4604 | 4474 | =begin original |
4605 | 4475 | |
4606 | 4476 | Each element of C<%!> has a true value only if C<$!> is set to that |
4607 | 4477 | value. For example, C<$!{ENOENT}> is true if and only if the current |
4608 | 4478 | value of C<$!> is C<ENOENT>; that is, if the most recent error was "No |
4609 | 4479 | such file or directory" (or its moral equivalent: not all operating |
4610 | 4480 | systems give that exact error, and certainly not all languages). The |
4611 | 4481 | specific true value is not guaranteed, but in the past has generally |
4612 | 4482 | been the numeric value of C<$!>. To check if a particular key is |
4613 | 4483 | meaningful on your system, use C<exists $!{the_key}>; for a list of legal |
4614 | 4484 | keys, use C<keys %!>. See L<Errno> for more information, and also see |
4615 | 4485 | L</$!>. |
4616 | 4486 | |
4617 | 4487 | =end original |
4618 | 4488 | |
4619 | 4489 | C<%!> の各要素は、C<$!> がその値にセットされている場合にのみ真の値を持ちます。 |
4620 | 4490 | 例えば、C<$!{ENOENT}> は、現在の C<$!> の値が C<ENOENT> の場合にのみ |
4621 | 4491 | 真となります; これは、最近のエラーが "No such file or directory" (あるいは |
4622 | 4492 | 倫理的に等価なもの: 全ての OS が正確に同じエラーを出すわけではないですし、 |
4623 | 4493 | 全ての言語で出るわけでもありません) の場合です。 |
4624 | 4494 | 特定の真の値は保証されませんが、以前は一般的には C<$!> の数値でした。 |
4625 | 4495 | あなたのシステムで特定のキーが意味があるかどうかを調べるには、 |
4626 | 4496 | C<exists $!{the_key}> を使ってください; 有効なキーのリストを得るには、 |
4627 | 4497 | C<keys %!> としてください。 |
4628 | 4498 | さらなる情報に関しては L<Errno> と C</$!> を参照してください。 |
4629 | 4499 | |
4630 | 4500 | =begin original |
4631 | 4501 | |
4632 | 4502 | This variable was added in Perl 5.005. |
4633 | 4503 | |
4634 | 4504 | =end original |
4635 | 4505 | |
4636 | 4506 | この変数は Perl 5.005 で追加されました。 |
4637 | 4507 | |
4638 | 4508 | =item $CHILD_ERROR |
4639 | 4509 | |
4640 | 4510 | =item $? |
4641 | 4511 | X<$?> X<$CHILD_ERROR> |
4642 | 4512 | |
4643 | 4513 | =begin original |
4644 | 4514 | |
4645 | 4515 | The status returned by the last pipe close, backtick (C<``>) command, |
4646 | 4516 | successful call to C<wait()> or C<waitpid()>, or from the C<system()> |
4647 | 4517 | operator. This is just the 16-bit status word returned by the |
4648 | 4518 | traditional Unix C<wait()> system call (or else is made up to look |
4649 | 4519 | like it). Thus, the exit value of the subprocess is really (C<<< $? >> |
4650 | 4520 | 8 >>>), and C<$? & 127> gives which signal, if any, the process died |
4651 | 4521 | from, and C<$? & 128> reports whether there was a core dump. |
4652 | 4522 | |
4653 | 4523 | =end original |
4654 | 4524 | |
4655 | 4525 | 最後に close したパイプ、バッククォート (C<``>) コマンド、 |
4656 | 4526 | 成功した C<wait()> または waitpid() 呼び出し、C<system()> 演算子が返した |
4657 | 4527 | ステータス。 |
4658 | 4528 | このステータスワードは伝統的な Unix の C<wait()> システムコールが返した |
4659 | 4529 | 16 ビットのステータス(またはそのように見えるもの)です。 |
4660 | 4530 | 従ってサブプロセスの exit 値は、実際には (C<<< $? >> 8 >>>) |
4661 | 4531 | で、C<$? & 127> は、もしあれば、そのプロセスを止めたシグナルで、 |
4662 | 4532 | C<$? & 128> はコアダンプがあるかどうかを示します。 |
4663 | 4533 | |
4664 | 4534 | =begin original |
4665 | 4535 | |
4666 | 4536 | Additionally, if the C<h_errno> variable is supported in C, its value |
4667 | 4537 | is returned via C<$?> if any C<gethost*()> function fails. |
4668 | 4538 | |
4669 | 4539 | =end original |
4670 | 4540 | |
4671 | 4541 | さらに、C で C<h_errno> 変数に対応している場合は、 |
4672 | 4542 | C<gethost*()> が失敗したときに C<$?> を通して返されます。 |
4673 | 4543 | |
4674 | 4544 | =begin original |
4675 | 4545 | |
4676 | 4546 | If you have installed a signal handler for C<SIGCHLD>, the |
4677 | 4547 | value of C<$?> will usually be wrong outside that handler. |
4678 | 4548 | |
4679 | 4549 | =end original |
4680 | 4550 | |
4681 | 4551 | C<SIGCHLD> のシグナルハンドラを設定した場合、 |
4682 | 4552 | C<$?> の値は通常ハンドラの外側では正しくない値となります。 |
4683 | 4553 | |
4684 | 4554 | =begin original |
4685 | 4555 | |
4686 | 4556 | Inside an C<END> subroutine C<$?> contains the value that is going to be |
4687 | 4557 | given to C<exit()>. You can modify C<$?> in an C<END> subroutine to |
4688 | 4558 | change the exit status of your program. For example: |
4689 | 4559 | |
4690 | 4560 | =end original |
4691 | 4561 | |
4692 | 4562 | C<END> サブルーチンの内側では C<$?> には C<exit()> に渡されようとしている |
4693 | 4563 | 値を含みます。 |
4694 | 4564 | プログラムの終了ステータスを変更するために、C<END> サブルーチン 内で |
4695 | 4565 | C<$?> を変更できます。 |
4696 | 4566 | 例えば: |
4697 | 4567 | |
4698 | 4568 | =begin original |
4699 | 4569 | |
4700 | 4570 | END { |
4701 | 4571 | $? = 1 if $? == 255; # die would make it 255 |
4702 | 4572 | } |
4703 | 4573 | |
4704 | 4574 | =end original |
4705 | 4575 | |
4706 | 4576 | END { |
4707 | 4577 | $? = 1 if $? == 255; # die は 255 |
4708 | 4578 | } |
4709 | 4579 | |
4710 | 4580 | =begin original |
4711 | 4581 | |
4712 | 4582 | Under VMS, the pragma C<use vmsish 'status'> makes C<$?> reflect the |
4713 | 4583 | actual VMS exit status, instead of the default emulation of POSIX |
4714 | 4584 | status; see L<perlvms/$?> for details. |
4715 | 4585 | |
4716 | 4586 | =end original |
4717 | 4587 | |
4718 | 4588 | VMS では、C<use vmsish 'status'> を指定すると、 |
4719 | 4589 | C<$?> はPOSIX ステータスをエミュレートしたものではなく、 |
4720 | 4590 | 実際の VMS 終了ステータスを反映します; 詳細は L<perlvms/$?> を |
4721 | 4591 | 参照してください。 |
4722 | 4592 | |
4723 | 4593 | =begin original |
4724 | 4594 | |
4725 | 4595 | Mnemonic: similar to B<sh> and B<ksh>. |
4726 | 4596 | |
4727 | 4597 | =end original |
4728 | 4598 | |
4729 | 4599 | 記憶法: B<sh> や B<ksh> と同様。 |
4730 | 4600 | |
4731 | 4601 | =item $EVAL_ERROR |
4732 | 4602 | |
4733 | 4603 | =item $@ |
4734 | 4604 | X<$@> X<$EVAL_ERROR> |
4735 | 4605 | |
4736 | 4606 | =begin original |
4737 | 4607 | |
4738 | 4608 | The Perl error from the last C<eval> operator, i.e. the last exception that |
4739 | 4609 | was caught. For C<eval BLOCK>, this is either a runtime error message or the |
4740 | 4610 | string or reference C<die> was called with. The C<eval STRING> form also |
4741 | 4611 | catches syntax errors and other compile time exceptions. |
4742 | 4612 | |
4743 | 4613 | =end original |
4744 | 4614 | |
4745 | 4615 | 最後の C<eval> 操作子による Perl のエラーです; つまり、最後に補足された |
4746 | 4616 | 例外です。 |
4747 | 4617 | C<eval BLOCK> の場合は、これは実行時エラーか、C<die> が呼び出されたときの |
4748 | 4618 | 文字列かリファレンスです。 |
4749 | 4619 | C<eval STRING> 型式は、文法エラーやその他のコンパイル時例外も捕捉します。 |
4750 | 4620 | |
4751 | 4621 | =begin original |
4752 | 4622 | |
4753 | 4623 | If no error occurs, C<eval> sets C<$@> to the empty string. |
4754 | 4624 | |
4755 | 4625 | =end original |
4756 | 4626 | |
4757 | 4627 | エラーが起きなければ、C<eval> は C<$@> に空文字列を設定します。 |
4758 | 4628 | |
4759 | 4629 | =begin original |
4760 | 4630 | |
4761 | 4631 | Warning messages are not collected in this variable. You can, however, |
4762 | 4632 | set up a routine to process warnings by setting C<$SIG{__WARN__}> as |
4763 | 4633 | described in L</%SIG>. |
4764 | 4634 | |
4765 | 4635 | =end original |
4766 | 4636 | |
4767 | 4637 | 警告メッセージはこの変数に入りません。 |
4768 | 4638 | しかし、L</%SIG> に記述されている C<$SIG{__WARN__}> にセットすることで |
4769 | 4639 | 警告を処理するルーチンを設定できます。 |
4770 | 4640 | |
4771 | 4641 | =begin original |
4772 | 4642 | |
4773 | 4643 | Mnemonic: Where was the error "at"? |
4774 | 4644 | |
4775 | 4645 | =end original |
4776 | 4646 | |
4777 | 4647 | 記憶法: どこで ("at") エラーが起ったか。 |
4778 | 4648 | |
4779 | 4649 | =back |
4780 | 4650 | |
4781 | 4651 | =head2 Variables related to the interpreter state |
4782 | 4652 | |
4783 | 4653 | (インタプリタの状態に関連する変数) |
4784 | 4654 | |
4785 | 4655 | =begin original |
4786 | 4656 | |
4787 | 4657 | These variables provide information about the current interpreter state. |
4788 | 4658 | |
4789 | 4659 | =end original |
4790 | 4660 | |
4791 | 4661 | これらの変数は現在のインタプリタの状態に関する情報を提供します。 |
4792 | 4662 | |
4793 | 4663 | =over 8 |
4794 | 4664 | |
4795 | 4665 | =item $COMPILING |
4796 | 4666 | |
4797 | 4667 | =item $^C |
4798 | 4668 | X<$^C> X<$COMPILING> |
4799 | 4669 | |
4800 | 4670 | =begin original |
4801 | 4671 | |
4802 | 4672 | The current value of the flag associated with the B<-c> switch. |
4803 | 4673 | Mainly of use with B<-MO=...> to allow code to alter its behavior |
4804 | 4674 | when being compiled, such as for example to C<AUTOLOAD> at compile |
4805 | 4675 | time rather than normal, deferred loading. Setting |
4806 | 4676 | C<$^C = 1> is similar to calling C<B::minus_c>. |
4807 | 4677 | |
4808 | 4678 | =end original |
4809 | 4679 | |
4810 | 4680 | B<-c> スイッチに関連付けられた現在の値です。 |
4811 | 4681 | 主に B<-MO=...> と共に用いられ、例えば C<AUTOLOAD> を通常の遅延ロードでは |
4812 | 4682 | なくコンパイル時に実行するといった、コンパイル時の振る舞いを |
4813 | 4683 | 変えるために用います。 |
4814 | 4684 | C<$^C = 1> に設定することは C<B::minus_c> を呼び出すのと似ています。 |
4815 | 4685 | |
4816 | 4686 | =begin original |
4817 | 4687 | |
4818 | 4688 | This variable was added in Perl v5.6.0. |
4819 | 4689 | |
4820 | 4690 | =end original |
4821 | 4691 | |
4822 | 4692 | この変数は Perl v5.6.0 で追加されました。 |
4823 | 4693 | |
4824 | 4694 | =item $DEBUGGING |
4825 | 4695 | |
4826 | 4696 | =item $^D |
4827 | 4697 | X<$^D> X<$DEBUGGING> |
4828 | 4698 | |
4829 | 4699 | =begin original |
4830 | 4700 | |
4831 | 4701 | The current value of the debugging flags. May be read or set. Like its |
4832 | 4702 | L<command-line equivalent|perlrun/B<-D>I<letters>>, you can use numeric |
4833 | 4703 | or symbolic values, e.g. C<$^D = 10> or C<$^D = "st">. See |
4834 | 4704 | L<perlrun/B<-D>I<number>>. The contents of this variable also affects the |
4835 | 4705 | debugger operation. See L<perldebguts/Debugger Internals>. |
4836 | 4706 | |
4837 | 4707 | =end original |
4838 | 4708 | |
4839 | 4709 | デバッグフラグの現在の値を示します。 |
4840 | 4710 | 読み書き可能です。 |
4841 | 4711 | L<コマンドラインによる等価な機能|perlrun/B<-D>I<letters>> と同様に、 |
4842 | 4712 | 数値とシンボル値が使えます |
4843 | 4713 | (例: C<$^D = 10> または C<$^D = "st">)。 |
4844 | 4714 | L<perlrun/B<-D>I<number>> を参照してください。 |
4845 | 4715 | この変数の内容はデバッガ操作にも影響されます。 |
4846 | 4716 | L<perldebguts/Debugger Internals> を参照してください。 |
4847 | 4717 | |
4848 | 4718 | =begin original |
4849 | 4719 | |
4850 | 4720 | Mnemonic: value of B<-D> switch. |
4851 | 4721 | |
4852 | 4722 | =end original |
4853 | 4723 | |
4854 | 4724 | 記憶法: B<-D> スイッチの値。 |
4855 | 4725 | |
4856 | 4726 | =item ${^ENCODING} |
4857 | 4727 | X<${^ENCODING}> |
4858 | 4728 | |
4859 | 4729 | =begin original |
4860 | 4730 | |
4861 | 4731 | This variable is no longer supported. |
4862 | 4732 | |
4863 | 4733 | =end original |
4864 | 4734 | |
4865 | 4735 | この変数はもはや対応していません。 |
4866 | 4736 | |
4867 | 4737 | =begin original |
4868 | 4738 | |
4869 | 4739 | It used to hold the I<object reference> to the C<Encode> object that was |
4870 | 4740 | used to convert the source code to Unicode. |
4871 | 4741 | |
4872 | 4742 | =end original |
4873 | 4743 | |
4874 | 4744 | これはソースコードを Unicode に変換するために使われる |
4875 | 4745 | C<Encode> オブジェクトへの I<オブジェクトリファレンス> を保持していました。 |
4876 | 4746 | |
4877 | 4747 | =begin original |
4878 | 4748 | |
4879 | 4749 | Its purpose was to allow your non-ASCII Perl |
4880 | 4750 | scripts not to have to be written in UTF-8; this was |
4881 | 4751 | useful before editors that worked on UTF-8 encoded text were common, but |
4882 | 4752 | that was long ago. It caused problems, such as affecting the operation |
4883 | 4753 | of other modules that weren't expecting it, causing general mayhem. |
4884 | 4754 | |
4885 | 4755 | =end original |
4886 | 4756 | |
4887 | 4757 | この目的は、非 ASCII Perl スクリプトを UTF-8 で書く必要をなくすためでした; |
4888 | 4758 | これは UTF-8 エンコードされたテキストで動作するエディタが一般的になる前は |
4889 | 4759 | 有用でしたが、それはずっと前です。 |
4890 | 4760 | これは、想定してない他のモジュールの操作に影響を与えるような問題を引き起こし、 |
4891 | 4761 | 一般的には破壊的です。 |
4892 | 4762 | |
4893 | 4763 | =begin original |
4894 | 4764 | |
4895 | 4765 | If you need something like this functionality, it is recommended that use |
4896 | 4766 | you a simple source filter, such as L<Filter::Encoding>. |
4897 | 4767 | |
4898 | 4768 | =end original |
4899 | 4769 | |
4900 | 4770 | この機能のような何かが必要な場合は、L<Filter::Encoding> のような |
4901 | 4771 | 単純なソースフィルタを使うことを勧めます。 |
4902 | 4772 | |
4903 | 4773 | =begin original |
4904 | 4774 | |
4905 | 4775 | If you are coming here because code of yours is being adversely affected |
4906 | 4776 | by someone's use of this variable, you can usually work around it by |
4907 | 4777 | doing this: |
4908 | 4778 | |
4909 | 4779 | =end original |
4910 | 4780 | |
4911 | 4781 | あなたがここに来た理由が、誰かがこの変数を使うことであなたのコードが |
4912 | 4782 | 意図せずに影響を受けたためなら、通常は次のようにして回避できます: |
4913 | 4783 | |
4914 | 4784 | local ${^ENCODING}; |
4915 | 4785 | |
4916 | 4786 | =begin original |
4917 | 4787 | |
4918 | 4788 | near the beginning of the functions that are getting broken. This |
4919 | 4789 | undefines the variable during the scope of execution of the including |
4920 | 4790 | function. |
4921 | 4791 | |
4922 | 4792 | =end original |
4923 | 4793 | |
4924 | 4794 | これを壊れてしまった関数の先頭付近に書きます。 |
4925 | 4795 | これにより、この関数を含むスコープを実行する間この変数を未定義にします。 |
4926 | 4796 | |
4927 | 4797 | =begin original |
4928 | 4798 | |
4929 | 4799 | This variable was added in Perl 5.8.2 and removed in 5.26.0. |
4930 | 4800 | Setting it to anything other than C<undef> was made fatal in Perl 5.28.0. |
4931 | 4801 | |
4932 | 4802 | =end original |
4933 | 4803 | |
4934 | 4804 | この変数は Perl 5.8.2 で追加され、5.26.0 で削除されました。 |
4935 | 4805 | Perl 5.28.0 から、これに C<undef> 以外の値を設定すると致命的エラーになります。 |
4936 | 4806 | |
4937 | 4807 | =item ${^GLOBAL_PHASE} |
4938 | 4808 | X<${^GLOBAL_PHASE}> |
4939 | 4809 | |
4940 | 4810 | =begin original |
4941 | 4811 | |
4942 | 4812 | The current phase of the perl interpreter. |
4943 | 4813 | |
4944 | 4814 | =end original |
4945 | 4815 | |
4946 | 4816 | perl インタプリタの現在のフェーズ。 |
4947 | 4817 | |
4948 | 4818 | =begin original |
4949 | 4819 | |
4950 | 4820 | Possible values are: |
4951 | 4821 | |
4952 | 4822 | =end original |
4953 | 4823 | |
4954 | 4824 | 取り得る値は: |
4955 | 4825 | |
4956 | 4826 | =over 8 |
4957 | 4827 | |
4958 | 4828 | =item CONSTRUCT |
4959 | 4829 | |
4960 | 4830 | =begin original |
4961 | 4831 | |
4962 | 4832 | The C<PerlInterpreter*> is being constructed via C<perl_construct>. This |
4963 | 4833 | value is mostly there for completeness and for use via the |
4964 | 4834 | underlying C variable C<PL_phase>. It's not really possible for Perl |
4965 | 4835 | code to be executed unless construction of the interpreter is |
4966 | 4836 | finished. |
4967 | 4837 | |
4968 | 4838 | =end original |
4969 | 4839 | |
4970 | 4840 | C<PerlInterpreter*> は C<perl_construct> で構築されます。 |
4971 | 4841 | この変数はほとんど完全性のためと、基礎となっている C 変数 |
4972 | 4842 | C<PL_phase> 経由での使用のために存在しています。 |
4973 | 4843 | 実際にはインタプリタの構築が完了しない限り Perl コードを |
4974 | 4844 | 実行することはできません。 |
4975 | 4845 | |
4976 | 4846 | =item START |
4977 | 4847 | |
4978 | 4848 | =begin original |
4979 | 4849 | |
4980 | 4850 | This is the global compile-time. That includes, basically, every |
4981 | 4851 | C<BEGIN> block executed directly or indirectly from during the |
4982 | 4852 | compile-time of the top-level program. |
4983 | 4853 | |
4984 | 4854 | =end original |
4985 | 4855 | |
4986 | 4856 | これはコンパイル時にグローバルです。 |
4987 | 4857 | これは基本的に、直接実行されたり、トップレベルプログラムの |
4988 | 4858 | コンパイル時の間に間接的に実行される全ての C<BEGIN> です。 |
4989 | 4859 | |
4990 | 4860 | =begin original |
4991 | 4861 | |
4992 | 4862 | This phase is not called "BEGIN" to avoid confusion with |
4993 | 4863 | C<BEGIN>-blocks, as those are executed during compile-time of any |
4994 | 4864 | compilation unit, not just the top-level program. A new, localised |
4995 | 4865 | compile-time entered at run-time, for example by constructs as |
4996 | 4866 | C<eval "use SomeModule"> are not global interpreter phases, and |
4997 | 4867 | therefore aren't reflected by C<${^GLOBAL_PHASE}>. |
4998 | 4868 | |
4999 | 4869 | =end original |
5000 | 4870 | |
5001 | 4871 | C<BEGIN> ブロックとの混乱を避けるために、このフェーズの名前は "BEGIN" では |
5002 | 4872 | ありません; これらは単にトップレベルプログラムではなく、任意のコンパイル |
5003 | 4873 | ユニットのコンパイル中に実行されます。 |
5004 | 4874 | 例えば C<eval "use SomeModule"> のように、実行時に入った |
5005 | 4875 | 新しいローカル化されたコンパイル時はグローバルなインタプリタフェーズではなく、 |
5006 | 4876 | 従って C<${^GLOBAL_PHASE}> に反映されません。 |
5007 | 4877 | |
5008 | 4878 | =item CHECK |
5009 | 4879 | |
5010 | 4880 | =begin original |
5011 | 4881 | |
5012 | 4882 | Execution of any C<CHECK> blocks. |
5013 | 4883 | |
5014 | 4884 | =end original |
5015 | 4885 | |
5016 | 4886 | C<CHECK> ブロックの実行。 |
5017 | 4887 | |
5018 | 4888 | =item INIT |
5019 | 4889 | |
5020 | 4890 | =begin original |
5021 | 4891 | |
5022 | 4892 | Similar to "CHECK", but for C<INIT>-blocks, not C<CHECK> blocks. |
5023 | 4893 | |
5024 | 4894 | =end original |
5025 | 4895 | |
5026 | 4896 | "CHECK" と似ていますが、C<CHECK> ブロックではなく C<INIT> ブロック。 |
5027 | 4897 | |
5028 | 4898 | =item RUN |
5029 | 4899 | |
5030 | 4900 | =begin original |
5031 | 4901 | |
5032 | 4902 | The main run-time, i.e. the execution of C<PL_main_root>. |
5033 | 4903 | |
5034 | 4904 | =end original |
5035 | 4905 | |
5036 | 4906 | メインの実行; つまり C<PL_main_root> の実行。 |
5037 | 4907 | |
5038 | 4908 | =item END |
5039 | 4909 | |
5040 | 4910 | =begin original |
5041 | 4911 | |
5042 | 4912 | Execution of any C<END> blocks. |
5043 | 4913 | |
5044 | 4914 | =end original |
5045 | 4915 | |
5046 | 4916 | C<END> ブロックの実行。 |
5047 | 4917 | |
5048 | 4918 | =item DESTRUCT |
5049 | 4919 | |
5050 | 4920 | =begin original |
5051 | 4921 | |
5052 | 4922 | Global destruction. |
5053 | 4923 | |
5054 | 4924 | =end original |
5055 | 4925 | |
5056 | 4926 | グローバルなデストラクタ。 |
5057 | 4927 | |
5058 | 4928 | =back |
5059 | 4929 | |
5060 | 4930 | =begin original |
5061 | 4931 | |
5062 | 4932 | Also note that there's no value for UNITCHECK-blocks. That's because |
5063 | 4933 | those are run for each compilation unit individually, and therefore is |
5064 | 4934 | not a global interpreter phase. |
5065 | 4935 | |
5066 | 4936 | =end original |
5067 | 4937 | |
5068 | 4938 | また、UNITCHECK ブロックのための値はないことに注意してください。 |
5069 | 4939 | なぜなら、これらはコンパイルユニット毎に独立に実行され、従って |
5070 | 4940 | グローバルなインタプリタフェーズではないからです。 |
5071 | 4941 | |
5072 | 4942 | =begin original |
5073 | 4943 | |
5074 | 4944 | Not every program has to go through each of the possible phases, but |
5075 | 4945 | transition from one phase to another can only happen in the order |
5076 | 4946 | described in the above list. |
5077 | 4947 | |
5078 | 4948 | =end original |
5079 | 4949 | |
5080 | 4950 | 全てのプログラムが可能な全てのフェーズを通らなければならないわけでは |
5081 | 4951 | ありませんが、あるフェーズから他のフェーズへの移行は上述の |
5082 | 4952 | 順でのみ起こります。 |
5083 | 4953 | |
5084 | 4954 | =begin original |
5085 | 4955 | |
5086 | 4956 | An example of all of the phases Perl code can see: |
5087 | 4957 | |
5088 | 4958 | =end original |
5089 | 4959 | |
5090 | 4960 | Perl コードの全てのフェーズを見る例です: |
5091 | 4961 | |
5092 | 4962 | BEGIN { print "compile-time: ${^GLOBAL_PHASE}\n" } |
5093 | 4963 | |
5094 | 4964 | INIT { print "init-time: ${^GLOBAL_PHASE}\n" } |
5095 | 4965 | |
5096 | 4966 | CHECK { print "check-time: ${^GLOBAL_PHASE}\n" } |
5097 | 4967 | |
5098 | 4968 | { |
5099 | 4969 | package Print::Phase; |
5100 | 4970 | |
5101 | 4971 | sub new { |
5102 | 4972 | my ($class, $time) = @_; |
5103 | 4973 | return bless \$time, $class; |
5104 | 4974 | } |
5105 | 4975 | |
5106 | 4976 | sub DESTROY { |
5107 | 4977 | my $self = shift; |
5108 | 4978 | print "$$self: ${^GLOBAL_PHASE}\n"; |
5109 | 4979 | } |
5110 | 4980 | } |
5111 | 4981 | |
5112 | 4982 | print "run-time: ${^GLOBAL_PHASE}\n"; |
5113 | 4983 | |
5114 | 4984 | my $runtime = Print::Phase->new( |
5115 | 4985 | "lexical variables are garbage collected before END" |
5116 | 4986 | ); |
5117 | 4987 | |
5118 | 4988 | END { print "end-time: ${^GLOBAL_PHASE}\n" } |
5119 | 4989 | |
5120 | 4990 | our $destruct = Print::Phase->new( |
5121 | 4991 | "package variables are garbage collected after END" |
5122 | 4992 | ); |
5123 | 4993 | |
5124 | 4994 | =begin original |
5125 | 4995 | |
5126 | 4996 | This will print out |
5127 | 4997 | |
5128 | 4998 | =end original |
5129 | 4999 | |
5130 | 5000 | これは以下のものを出力します: |
5131 | 5001 | |
5132 | 5002 | compile-time: START |
5133 | 5003 | check-time: CHECK |
5134 | 5004 | init-time: INIT |
5135 | 5005 | run-time: RUN |
5136 | 5006 | lexical variables are garbage collected before END: RUN |
5137 | 5007 | end-time: END |
5138 | 5008 | package variables are garbage collected after END: DESTRUCT |
5139 | 5009 | |
5140 | 5010 | =begin original |
5141 | 5011 | |
5142 | 5012 | This variable was added in Perl 5.14.0. |
5143 | 5013 | |
5144 | 5014 | =end original |
5145 | 5015 | |
5146 | 5016 | この変数は Perl 5.14.0 で追加されました。 |
5147 | 5017 | |
5148 | 5018 | =item $^H |
5149 | 5019 | X<$^H> |
5150 | 5020 | |
5151 | 5021 | =begin original |
5152 | 5022 | |
5153 | 5023 | WARNING: This variable is strictly for |
5154 | 5024 | internal use only. Its availability, |
5155 | 5025 | behavior, and contents are subject to change without notice. |
5156 | 5026 | |
5157 | 5027 | =end original |
5158 | 5028 | |
5159 | 5029 | 警告: この変数は厳密に内部使用に限定されます。 |
5160 | 5030 | その可用性、挙動、内容は告知なく変更される可能性があります。 |
5161 | 5031 | |
5162 | 5032 | =begin original |
5163 | 5033 | |
5164 | 5034 | This variable contains compile-time hints for the Perl interpreter. At the |
5165 | 5035 | end of compilation of a BLOCK the value of this variable is restored to the |
5166 | 5036 | value when the interpreter started to compile the BLOCK. |
5167 | 5037 | |
5168 | 5038 | =end original |
5169 | 5039 | |
5170 | 5040 | この変数には Perl インタプリタのコンパイル時のヒントが入ります。 |
5171 | 5041 | BLOCK のコンパイル終了時に、この変数の値は |
5172 | 5042 | インタプリタが BLOCK のコンパイルを開始した時の値に戻されます。 |
5173 | 5043 | |
5174 | 5044 | =begin original |
5175 | 5045 | |
5176 | 5046 | When perl begins to parse any block construct that provides a lexical scope |
5177 | 5047 | (e.g., eval body, required file, subroutine body, loop body, or conditional |
5178 | 5048 | block), the existing value of C<$^H> is saved, but its value is left unchanged. |
5179 | 5049 | When the compilation of the block is completed, it regains the saved value. |
5180 | 5050 | Between the points where its value is saved and restored, code that |
5181 | 5051 | executes within BEGIN blocks is free to change the value of C<$^H>. |
5182 | 5052 | |
5183 | 5053 | =end original |
5184 | 5054 | |
5185 | 5055 | Perl がレキシカルスコープを持つブロック構造(eval の中身、required された |
5186 | 5056 | ファイル、サブルーチンの中身、loop の中身、条件付きブロック)の |
5187 | 5057 | パースを開始するとき、現在の C<$^H> の値は保存されますが、値は |
5188 | 5058 | 変更されません。 |
5189 | 5059 | ブロックのコンパイルが終わると、保存された値が戻されます。 |
5190 | 5060 | 値の保存と回復の間の地点で、BEGIN ブロックの中で実行されるコードは自由に |
5191 | 5061 | C<$^H> の値を変更できます。 |
5192 | 5062 | |
5193 | 5063 | =begin original |
5194 | 5064 | |
5195 | 5065 | This behavior provides the semantic of lexical scoping, and is used in, |
5196 | 5066 | for instance, the C<use strict> pragma. |
5197 | 5067 | |
5198 | 5068 | =end original |
5199 | 5069 | |
5200 | 5070 | この振る舞いはレキシカルスコープを持ち、その中で使えます; 例としては |
5201 | 5071 | C<use strict> があります。 |
5202 | 5072 | |
5203 | 5073 | =begin original |
5204 | 5074 | |
5205 | 5075 | The contents should be an integer; different bits of it are used for |
5206 | 5076 | different pragmatic flags. Here's an example: |
5207 | 5077 | |
5208 | 5078 | =end original |
5209 | 5079 | |
5210 | 5080 | 内容は整数であるべきです; ビット毎に異なるプラグマフラグとして使われます。 |
5211 | 5081 | 以下は例です: |
5212 | 5082 | |
5213 | 5083 | sub add_100 { $^H |= 0x100 } |
5214 | 5084 | |
5215 | 5085 | sub foo { |
5216 | 5086 | BEGIN { add_100() } |
5217 | 5087 | bar->baz($boon); |
5218 | 5088 | } |
5219 | 5089 | |
5220 | 5090 | =begin original |
5221 | 5091 | |
5222 | 5092 | Consider what happens during execution of the BEGIN block. At this point |
5223 | 5093 | the BEGIN block has already been compiled, but the body of C<foo()> is still |
5224 | 5094 | being compiled. The new value of C<$^H> |
5225 | 5095 | will therefore be visible only while |
5226 | 5096 | the body of C<foo()> is being compiled. |
5227 | 5097 | |
5228 | 5098 | =end original |
5229 | 5099 | |
5230 | 5100 | BEGIN ブロックの実行中に起こることを考えてみます。 |
5231 | 5101 | この時点で BEGIN ブロックは既にコンパイルされていますが、 |
5232 | 5102 | C<foo()> の中身はまだコンパイル中です。 |
5233 | 5103 | 従って C<$^H> の新しい値は C<foo()> の中身がコンパイル中にのみ |
5234 | 5104 | 見ることが出来ます。 |
5235 | 5105 | |
5236 | 5106 | =begin original |
5237 | 5107 | |
5238 | 5108 | Substitution of C<BEGIN { add_100() }> block with: |
5239 | 5109 | |
5240 | 5110 | =end original |
5241 | 5111 | |
5242 | 5112 | C<BEGIN { add_100() }> ブロックを以下のように変更すると: |
5243 | 5113 | |
5244 | 5114 | BEGIN { require strict; strict->import('vars') } |
5245 | 5115 | |
5246 | 5116 | =begin original |
5247 | 5117 | |
5248 | 5118 | demonstrates how C<use strict 'vars'> is implemented. Here's a conditional |
5249 | 5119 | version of the same lexical pragma: |
5250 | 5120 | |
5251 | 5121 | =end original |
5252 | 5122 | |
5253 | 5123 | どのように C<use strict 'vars'> が実装されているかがわかります。 |
5254 | 5124 | 以下は同じレキシカルプラグマの条件付き版です: |
5255 | 5125 | |
5256 | 5126 | BEGIN { |
5257 | 5127 | require strict; strict->import('vars') if $condition |
5258 | 5128 | } |
5259 | 5129 | |
5260 | 5130 | =begin original |
5261 | 5131 | |
5262 | 5132 | This variable was added in Perl 5.003. |
5263 | 5133 | |
5264 | 5134 | =end original |
5265 | 5135 | |
5266 | 5136 | この変数は Perl 5.003 で追加されました。 |
5267 | 5137 | |
5268 | 5138 | =item %^H |
5269 | 5139 | X<%^H> |
5270 | 5140 | |
5271 | 5141 | =begin original |
5272 | 5142 | |
5273 | 5143 | The C<%^H> hash provides the same scoping semantic as C<$^H>. This makes |
5274 | 5144 | it useful for implementation of lexically scoped pragmas. See |
5275 | 5145 | L<perlpragma>. All the entries are stringified when accessed at |
5276 | 5146 | runtime, so only simple values can be accommodated. This means no |
5277 | 5147 | pointers to objects, for example. |
5278 | 5148 | |
5279 | 5149 | =end original |
5280 | 5150 | |
5281 | 5151 | C<%^H> ハッシュは C<$^H> と同じスコープを持ちます。 |
5282 | 5152 | これはレキシカルスコープを持つプラグマを実装するのに便利です。 |
5283 | 5153 | L<perlpragma> を参照してください。 |
5284 | 5154 | 実行時にアクセスされると全てのエントリは文字列化されるので、 |
5285 | 5155 | 単純な値のみに対応します。 |
5286 | 5156 | これは、例えばオブジェクトへのポインタはないということです。 |
5287 | 5157 | |
5288 | 5158 | =begin original |
5289 | 5159 | |
5290 | 5160 | When putting items into C<%^H>, in order to avoid conflicting with other |
5291 | 5161 | users of the hash there is a convention regarding which keys to use. |
5292 | 5162 | A module should use only keys that begin with the module's name (the |
5293 | 5163 | name of its main package) and a "/" character. For example, a module |
5294 | 5164 | C<Foo::Bar> should use keys such as C<Foo::Bar/baz>. |
5295 | 5165 | |
5296 | 5166 | =end original |
5297 | 5167 | |
5298 | 5168 | C<%^H> に追加するとき、他のハッシュのユーザーとの衝突を回避するために、 |
5299 | 5169 | キーの使い方に関する慣習があります。 |
5300 | 5170 | モジュールはモジュールの名前(主なパッケージの名前)と "/" 文字で始まる |
5301 | 5171 | キーのみを使うべきです。 |
5302 | 5172 | 例えば、モジュール C<Foo::Bar> は C<Foo::Bar/baz> のようなキーを |
5303 | 5173 | 使うべきです。 |
5304 | 5174 | |
5305 | 5175 | =begin original |
5306 | 5176 | |
5307 | 5177 | This variable was added in Perl v5.6.0. |
5308 | 5178 | |
5309 | 5179 | =end original |
5310 | 5180 | |
5311 | 5181 | この変数は Perl v5.6.0 で追加されました。 |
5312 | 5182 | |
5313 | 5183 | =item ${^OPEN} |
5314 | 5184 | X<${^OPEN}> |
5315 | 5185 | |
5316 | 5186 | =begin original |
5317 | 5187 | |
5318 | 5188 | An internal variable used by PerlIO. A string in two parts, separated |
5319 | 5189 | by a C<\0> byte, the first part describes the input layers, the second |
5320 | 5190 | part describes the output layers. |
5321 | 5191 | |
5322 | 5192 | =end original |
5323 | 5193 | |
5324 | 5194 | PerlIO で使われる内部変数です。 |
5325 | 5195 | 文字列は C<\0> で分割された二つの部分からなり、前半は入力層を、 |
5326 | 5196 | 後半は出力層を示します。 |
5327 | 5197 | |
5328 | 5198 | =begin original |
5329 | 5199 | |
5330 | 5200 | This variable was added in Perl v5.8.0. |
5331 | 5201 | |
5332 | 5202 | =end original |
5333 | 5203 | |
5334 | 5204 | この変数は Perl v5.8.0 で追加されました。 |
5335 | 5205 | |
5336 | 5206 | =item $PERLDB |
5337 | 5207 | |
5338 | 5208 | =item $^P |
5339 | 5209 | X<$^P> X<$PERLDB> |
5340 | 5210 | |
5341 | 5211 | =begin original |
5342 | 5212 | |
5343 | 5213 | The internal variable for debugging support. The meanings of the |
5344 | 5214 | various bits are subject to change, but currently indicate: |
5345 | 5215 | |
5346 | 5216 | =end original |
5347 | 5217 | |
5348 | 5218 | デバッグ機能のための内部変数です。 |
5349 | 5219 | それぞれのビットの意味は変わるかもしれませんが、 |
5350 | 5220 | 現在のところは以下の通りです: |
5351 | 5221 | |
5352 | 5222 | =over 6 |
5353 | 5223 | |
5354 | 5224 | =item 0x01 |
5355 | 5225 | |
5356 | 5226 | =begin original |
5357 | 5227 | |
5358 | 5228 | Debug subroutine enter/exit. |
5359 | 5229 | |
5360 | 5230 | =end original |
5361 | 5231 | |
5362 | 5232 | サブルーチンの出入りをデバッグします。 |
5363 | 5233 | |
5364 | 5234 | =item 0x02 |
5365 | 5235 | |
5366 | 5236 | =begin original |
5367 | 5237 | |
5368 | 5238 | Line-by-line debugging. Causes C<DB::DB()> subroutine to be called for |
5369 | 5239 | each statement executed. Also causes saving source code lines (like |
5370 | 5240 | 0x400). |
5371 | 5241 | |
5372 | 5242 | =end original |
5373 | 5243 | |
5374 | 5244 | 行毎にデバッグします。 |
5375 | 5245 | 各行を実行する毎に C<DB::DB()> サブルーチンを呼び出します。 |
5376 | 5246 | さらに、(0x400 のように) ソースコードを保存します。 |
5377 | 5247 | |
5378 | 5248 | =item 0x04 |
5379 | 5249 | |
5380 | 5250 | =begin original |
5381 | 5251 | |
5382 | 5252 | Switch off optimizations. |
5383 | 5253 | |
5384 | 5254 | =end original |
5385 | 5255 | |
5386 | 5256 | 最適化を行いません。 |
5387 | 5257 | |
5388 | 5258 | =item 0x08 |
5389 | 5259 | |
5390 | 5260 | =begin original |
5391 | 5261 | |
5392 | 5262 | Preserve more data for future interactive inspections. |
5393 | 5263 | |
5394 | 5264 | =end original |
5395 | 5265 | |
5396 | 5266 | 将来の対話的な検査のためにより多くのデータを保存します。 |
5397 | 5267 | |
5398 | 5268 | =item 0x10 |
5399 | 5269 | |
5400 | 5270 | =begin original |
5401 | 5271 | |
5402 | 5272 | Keep info about source lines on which a subroutine is defined. |
5403 | 5273 | |
5404 | 5274 | =end original |
5405 | 5275 | |
5406 | 5276 | サブルーチンが定義されたソース行に関する情報を保持します。 |
5407 | 5277 | |
5408 | 5278 | =item 0x20 |
5409 | 5279 | |
5410 | 5280 | =begin original |
5411 | 5281 | |
5412 | 5282 | Start with single-step on. |
5413 | 5283 | |
5414 | 5284 | =end original |
5415 | 5285 | |
5416 | 5286 | シングルステップ実行で開始します。 |
5417 | 5287 | |
5418 | 5288 | =item 0x40 |
5419 | 5289 | |
5420 | 5290 | =begin original |
5421 | 5291 | |
5422 | 5292 | Use subroutine address instead of name when reporting. |
5423 | 5293 | |
5424 | 5294 | =end original |
5425 | 5295 | |
5426 | 5296 | 報告時にサブルーチン名でなくサブルーチンのアドレスを使います。 |
5427 | 5297 | |
5428 | 5298 | =item 0x80 |
5429 | 5299 | |
5430 | 5300 | =begin original |
5431 | 5301 | |
5432 | 5302 | Report C<goto &subroutine> as well. |
5433 | 5303 | |
5434 | 5304 | =end original |
5435 | 5305 | |
5436 | 5306 | C<goto &subroutine> も同様に報告します。 |
5437 | 5307 | |
5438 | 5308 | =item 0x100 |
5439 | 5309 | |
5440 | 5310 | =begin original |
5441 | 5311 | |
5442 | 5312 | Provide informative "file" names for evals based on the place they were compiled. |
5443 | 5313 | |
5444 | 5314 | =end original |
5445 | 5315 | |
5446 | 5316 | eval に対して、コンパイルされた位置を元にした「ファイル」名を提供します。 |
5447 | 5317 | |
5448 | 5318 | =item 0x200 |
5449 | 5319 | |
5450 | 5320 | =begin original |
5451 | 5321 | |
5452 | 5322 | Provide informative names to anonymous subroutines based on the place they |
5453 | 5323 | were compiled. |
5454 | 5324 | |
5455 | 5325 | =end original |
5456 | 5326 | |
5457 | 5327 | 無名サブルーチンに対して、 |
5458 | 5328 | コンパイルされた位置を基にした参考名を提供します。 |
5459 | 5329 | |
5460 | 5330 | =item 0x400 |
5461 | 5331 | |
5462 | 5332 | =begin original |
5463 | 5333 | |
5464 | 5334 | Save source code lines into C<@{"_<$filename"}>. |
5465 | 5335 | |
5466 | 5336 | =end original |
5467 | 5337 | |
5468 | 5338 | ソースコードの行数を C<@{"_<$filename"}> に保存します。 |
5469 | 5339 | |
5470 | 5340 | =item 0x800 |
5471 | 5341 | |
5472 | 5342 | =begin original |
5473 | 5343 | |
5474 | 5344 | When saving source, include evals that generate no subroutines. |
5475 | 5345 | |
5476 | 5346 | =end original |
5477 | 5347 | |
5478 | 5348 | ソースを保存するときに、サブルーチンがない eval を含みます。 |
5479 | 5349 | |
5480 | 5350 | =item 0x1000 |
5481 | 5351 | |
5482 | 5352 | =begin original |
5483 | 5353 | |
5484 | 5354 | When saving source, include source that did not compile. |
5485 | 5355 | |
5486 | 5356 | =end original |
5487 | 5357 | |
5488 | 5358 | ソースを保存するときに、コンパイルしていないソースを含みます。 |
5489 | 5359 | |
5490 | 5360 | =back |
5491 | 5361 | |
5492 | 5362 | =begin original |
5493 | 5363 | |
5494 | 5364 | Some bits may be relevant at compile-time only, some at |
5495 | 5365 | run-time only. This is a new mechanism and the details may change. |
5496 | 5366 | See also L<perldebguts>. |
5497 | 5367 | |
5498 | 5368 | =end original |
5499 | 5369 | |
5500 | 5370 | 一部のビットはコンパイル時にのみまたは実行時にのみ意味があります。 |
5501 | 5371 | これは新しい機構であり、詳細は変更されるかもしれません。 |
5502 | 5372 | L<perldebguts> も参照してください。 |
5503 | 5373 | |
5504 | 5374 | =item ${^TAINT} |
5505 | 5375 | X<${^TAINT}> |
5506 | 5376 | |
5507 | 5377 | =begin original |
5508 | 5378 | |
5509 | 5379 | Reflects if taint mode is on or off. 1 for on (the program was run with |
5510 | 5380 | B<-T>), 0 for off, -1 when only taint warnings are enabled (i.e. with |
5511 | 5381 | B<-t> or B<-TU>). |
5512 | 5382 | |
5513 | 5383 | =end original |
5514 | 5384 | |
5515 | 5385 | 汚染検査モードのオン・オフを反映します。 |
5516 | 5386 | 1 はオン(プログラムは B<-T> 付きで実行されている)、0 はオフ、-1 は汚染 |
5517 | 5387 | 警告のみが有効になっている(つまり B<-t> か B<-TU>)ことを意味します。 |
5518 | 5388 | |
5519 | 5389 | =begin original |
5520 | 5390 | |
5521 | 5391 | This variable is read-only. |
5522 | 5392 | |
5523 | 5393 | =end original |
5524 | 5394 | |
5525 | 5395 | この変数は読み込み専用です。 |
5526 | 5396 | |
5527 | 5397 | =begin original |
5528 | 5398 | |
5529 | 5399 | This variable was added in Perl v5.8.0. |
5530 | 5400 | |
5531 | 5401 | =end original |
5532 | 5402 | |
5533 | 5403 | この変数は Perl v5.8.0 で追加されました。 |
5534 | 5404 | |
5535 | 5405 | =item ${^SAFE_LOCALES} |
5536 | 5406 | X<${^SAFE_LOCALES}> |
5537 | 5407 | |
5538 | 5408 | =begin original |
5539 | 5409 | |
5540 | 5410 | Reflects if safe locale operations are available to this perl (when the |
5541 | 5411 | value is 1) or not (the value is 0). This variable is always 1 if the |
5542 | 5412 | perl has been compiled without threads. It is also 1 if this perl is |
5543 | 5413 | using thread-safe locale operations. Note that an individual thread may |
5544 | 5414 | choose to use the global locale (generally unsafe) by calling |
5545 | 5415 | L<perlapi/switch_to_global_locale>. This variable currently is still |
5546 | 5416 | set to 1 in such threads. |
5547 | 5417 | |
5548 | 5418 | =end original |
5549 | 5419 | |
5550 | 5420 | この perl で安全なロケール操作が利用可能 (値が 1 の場合) かそうでない |
5551 | 5421 | (値が 0 の場合) かを反映します。 |
5552 | 5422 | この変数は、perl がスレッドなしでコンパイルされている場合は常に 1 です。 |
5553 | 5423 | また、perl がスレッドセーフなロケール操作を使っている場合は 1 です。 |
5554 | 5424 | 個々のスレッドは L<perlapi/switch_to_global_locale> を呼び出すことで |
5555 | 5425 | (一般的にはスレッドセーフでない) グローバルなロケールを使うことを |
5556 | 5426 | 選ぶかも知れないことに注意してください。 |
5557 | 5427 | この変数はそのようなスレッドでも 1 のままです。 |
5558 | 5428 | |
5559 | 5429 | =begin original |
5560 | 5430 | |
5561 | 5431 | This variable is read-only. |
5562 | 5432 | |
5563 | 5433 | =end original |
5564 | 5434 | |
5565 | 5435 | この変数は読み込み専用です。 |
5566 | 5436 | |
5567 | 5437 | =begin original |
5568 | 5438 | |
5569 | 5439 | This variable was added in Perl v5.28.0. |
5570 | 5440 | |
5571 | 5441 | =end original |
5572 | 5442 | |
5573 | 5443 | この変数は Perl v5.28.0 で追加されました。 |
5574 | 5444 | |
5575 | 5445 | =item ${^UNICODE} |
5576 | 5446 | X<${^UNICODE}> |
5577 | 5447 | |
5578 | 5448 | =begin original |
5579 | 5449 | |
5580 | 5450 | Reflects certain Unicode settings of Perl. See L<perlrun> |
5581 | 5451 | documentation for the C<-C> switch for more information about |
5582 | 5452 | the possible values. |
5583 | 5453 | |
5584 | 5454 | =end original |
5585 | 5455 | |
5586 | 5456 | Perl のいくつかの Unicode 設定を反映します。 |
5587 | 5457 | 設定できる値に関するさらなる情報については L<perlrun> の C<-C> オプションを |
5588 | 5458 | 参照してください。 |
5589 | 5459 | |
5590 | 5460 | =begin original |
5591 | 5461 | |
5592 | 5462 | This variable is set during Perl startup and is thereafter read-only. |
5593 | 5463 | |
5594 | 5464 | =end original |
5595 | 5465 | |
5596 | 5466 | この変数は Perl 起動時に設定され、その後は読み込み専用です。 |
5597 | 5467 | |
5598 | 5468 | =begin original |
5599 | 5469 | |
5600 | 5470 | This variable was added in Perl v5.8.2. |
5601 | 5471 | |
5602 | 5472 | =end original |
5603 | 5473 | |
5604 | 5474 | この変数は Perl v5.8.2 で追加されました。 |
5605 | 5475 | |
5606 | 5476 | =item ${^UTF8CACHE} |
5607 | 5477 | X<${^UTF8CACHE}> |
5608 | 5478 | |
5609 | 5479 | =begin original |
5610 | 5480 | |
5611 | 5481 | This variable controls the state of the internal UTF-8 offset caching code. |
5612 | 5482 | 1 for on (the default), 0 for off, -1 to debug the caching code by checking |
5613 | 5483 | all its results against linear scans, and panicking on any discrepancy. |
5614 | 5484 | |
5615 | 5485 | =end original |
5616 | 5486 | |
5617 | 5487 | この変数は内部 UTF-8 オフセットキャッシュコードの状態を制御します。 |
5618 | 5488 | 1 はオン(デフォルト)、0 はオフ、-1 は全ての結果を線形走査と比較して、 |
5619 | 5489 | 矛盾があれば異常終了する、という形でキャッシュコードをデバッグします。 |
5620 | 5490 | |
5621 | 5491 | =begin original |
5622 | 5492 | |
5623 | 5493 | This variable was added in Perl v5.8.9. It is subject to change or |
5624 | 5494 | removal without notice, but is currently used to avoid recalculating the |
5625 | 5495 | boundaries of multi-byte UTF-8-encoded characters. |
5626 | 5496 | |
5627 | 5497 | =end original |
5628 | 5498 | |
5629 | 5499 | この変数は Perl v5.8.9 で追加されました。 |
5630 | 5500 | これは予告なく変更されたり削除されたりするかもしれませんが、現在のところ |
5631 | 5501 | 複数バイト UTF-8 エンコード文字の境界の再計算を避けるために使われます。 |
5632 | 5502 | |
5633 | 5503 | =item ${^UTF8LOCALE} |
5634 | 5504 | X<${^UTF8LOCALE}> |
5635 | 5505 | |
5636 | 5506 | =begin original |
5637 | 5507 | |
5638 | 5508 | This variable indicates whether a UTF-8 locale was detected by perl at |
5639 | 5509 | startup. This information is used by perl when it's in |
5640 | 5510 | adjust-utf8ness-to-locale mode (as when run with the C<-CL> command-line |
5641 | 5511 | switch); see L<perlrun> for more info on this. |
5642 | 5512 | |
5643 | 5513 | =end original |
5644 | 5514 | |
5645 | 5515 | この変数は、起動時に perl によって UTF-8 ロケールが検出されたかどうかを |
5646 | 5516 | 示します。 |
5647 | 5517 | この情報は(C<-CL> コマンドラインスイッチで起動されることによって) |
5648 | 5518 | 「utf8 性をロケールに合わせる」モードのときに perl によって使われます; |
5649 | 5519 | これに関するさらなる情報は L<perlrun> を参照してください。 |
5650 | 5520 | |
5651 | 5521 | =begin original |
5652 | 5522 | |
5653 | 5523 | This variable was added in Perl v5.8.8. |
5654 | 5524 | |
5655 | 5525 | =end original |
5656 | 5526 | |
5657 | 5527 | この変数は Perl v5.8.8 で追加されました。 |
5658 | 5528 | |
5659 | 5529 | =back |
5660 | 5530 | |
5661 | 5531 | =head2 Deprecated and removed variables |
5662 | 5532 | |
5663 | 5533 | (非推奨および削除された変数) |
5664 | 5534 | |
5665 | 5535 | =begin original |
5666 | 5536 | |
5667 | 5537 | Deprecating a variable announces the intent of the perl maintainers to |
5668 | 5538 | eventually remove the variable from the language. It may still be |
5669 | 5539 | available despite its status. Using a deprecated variable triggers |
5670 | 5540 | a warning. |
5671 | 5541 | |
5672 | 5542 | =end original |
5673 | 5543 | |
5674 | 5544 | 非推奨となった変数は、perl のメンテナが最終的にこの変数を |
5675 | 5545 | 削除するということを意図して通知されます。 |
5676 | 5546 | その状態にも関わらず、まだ利用可能です。 |
5677 | 5547 | 非推奨となった変数を使うと警告が出ます。 |
5678 | 5548 | |
5679 | 5549 | =begin original |
5680 | 5550 | |
5681 | 5551 | Once a variable is removed, its use triggers an error telling you |
5682 | 5552 | the variable is unsupported. |
5683 | 5553 | |
5684 | 5554 | =end original |
5685 | 5555 | |
5686 | 5556 | 変数が削除された後で変数を使うと、この変数が非対応となったことを |
5687 | 5557 | 知らせるエラーが出ます。 |
5688 | 5558 | |
5689 | 5559 | =begin original |
5690 | 5560 | |
5691 | 5561 | See L<perldiag> for details about error messages. |
5692 | 5562 | |
5693 | 5563 | =end original |
5694 | 5564 | |
5695 | 5565 | エラーメッセージの詳細については L<perldiag> を参照してください。 |
5696 | 5566 | |
5697 | 5567 | =over 8 |
5698 | 5568 | |
5699 | 5569 | =item $# |
5700 | 5570 | X<$#> |
5701 | 5571 | |
5702 | 5572 | =begin original |
5703 | 5573 | |
5704 | 5574 | C<$#> was a variable that could be used to format printed numbers. |
5705 | 5575 | After a deprecation cycle, its magic was removed in Perl v5.10.0 and |
5706 | 5576 | using it now triggers a warning: C<$# is no longer supported>. |
5707 | 5577 | |
5708 | 5578 | =end original |
5709 | 5579 | |
5710 | 5580 | C<$#> は、表示番号をフォーマットするために使われていました。 |
5711 | 5581 | 非推奨化の後、このマジックは Perl v5.10.0 で取り除かれ、警告を |
5712 | 5582 | 引き起こします: C<$# is no longer supported>. |
5713 | 5583 | |
5714 | 5584 | =begin original |
5715 | 5585 | |
5716 | 5586 | This is not the sigil you use in front of an array name to get the |
5717 | 5587 | last index, like C<$#array>. That's still how you get the last index |
5718 | 5588 | of an array in Perl. The two have nothing to do with each other. |
5719 | 5589 | |
5720 | 5590 | =end original |
5721 | 5591 | |
5722 | 5592 | これは C<$#array> のように最後のインデックスを得るために配列名の前に付ける |
5723 | 5593 | 印ではありません。 |
5724 | 5594 | これは今でも Perl で配列の最後のインデックスを得る方法です。 |
5725 | 5595 | これら二つには互いに何の関係もありません。 |
5726 | 5596 | |
5727 | 5597 | =begin original |
5728 | 5598 | |
5729 | 5599 | Deprecated in Perl 5. |
5730 | 5600 | |
5731 | 5601 | =end original |
5732 | 5602 | |
5733 | 5603 | Perl 5 で非推奨となりました。 |
5734 | 5604 | |
5735 | 5605 | =begin original |
5736 | 5606 | |
5737 | 5607 | Removed in Perl v5.10.0. |
5738 | 5608 | |
5739 | 5609 | =end original |
5740 | 5610 | |
5741 | 5611 | Perl v5.10.0 で削除されました。 |
5742 | 5612 | |
5743 | 5613 | =item $* |
5744 | 5614 | X<$*> |
5745 | 5615 | |
5746 | 5616 | =begin original |
5747 | 5617 | |
5748 | 5618 | C<$*> was a variable that you could use to enable multiline matching. |
5749 | 5619 | After a deprecation cycle, its magic was removed in Perl v5.10.0. |
5750 | 5620 | Using it now triggers a warning: C<$* is no longer supported>. |
5751 | 5621 | You should use the C</s> and C</m> regexp modifiers instead. |
5752 | 5622 | |
5753 | 5623 | =end original |
5754 | 5624 | |
5755 | 5625 | C<$*> は複数行マッチングを有効にするために使われていた変数です。 |
5756 | 5626 | 非推奨化の後、このマジックは Perl v5.10.0 で削除されました。 |
5757 | 5627 | これを使うと警告を引き起こします: C<$* is no longer supported>。 |
5758 | 5628 | 代わりに C</s> と C</m> の正規表現修飾子を使うべきです。 |
5759 | 5629 | |
5760 | 5630 | =begin original |
5761 | 5631 | |
5762 | 5632 | Deprecated in Perl 5. |
5763 | 5633 | |
5764 | 5634 | =end original |
5765 | 5635 | |
5766 | 5636 | Perl 5 で非推奨となりました。 |
5767 | 5637 | |
5768 | 5638 | =begin original |
5769 | 5639 | |
5770 | 5640 | Removed in Perl v5.10.0. |
5771 | 5641 | |
5772 | 5642 | =end original |
5773 | 5643 | |
5774 | 5644 | Perl v5.10.0 で削除されました。 |
5775 | 5645 | |
5776 | 5646 | =item $[ |
5777 | 5647 | X<$[> |
5778 | 5648 | |
5779 | 5649 | =begin original |
5780 | 5650 | |
5781 | 5651 | This variable stores the index of the first element in an array, and |
5782 | 5652 | of the first character in a substring. The default is 0, but you could |
5783 | 5653 | theoretically set it to 1 to make Perl behave more like B<awk> (or Fortran) |
5784 | 5654 | when subscripting and when evaluating the index() and substr() functions. |
5785 | 5655 | |
5786 | 5656 | =end original |
5787 | 5657 | |
5788 | 5658 | この変数は配列の最初の要素や、文字列の最初の文字のインデックスを |
5789 | 5659 | 保管します。 |
5790 | 5660 | デフォルトは 0 ですが、理論的には、index() 関数や |
5791 | 5661 | substr() 関数を評価するときに、Perl の動作をより B<awk> |
5792 | 5662 | (や Fortran) に近づけるため、1 に設定することもできます。 |
5793 | 5663 | |
5794 | 5664 | =begin original |
5795 | 5665 | |
5796 | 5666 | As of release 5 of Perl, assignment to C<$[> is treated as a compiler |
5797 | 5667 | directive, and cannot influence the behavior of any other file. |
5798 | 5668 | (That's why you can only assign compile-time constants to it.) |
5799 | 5669 | Its use is highly discouraged. |
5800 | 5670 | |
5801 | 5671 | =end original |
5802 | 5672 | |
5803 | 5673 | Perl 5 からは C<$[> への代入は、コンパイラ指示子として扱われ、 |
5804 | 5674 | 他のファイルの動作に影響を与えることがなくなりました。 |
5805 | 5675 | (これが、コンパイル時定数しか代入できない理由です。) |
5806 | 5676 | この変数の使用は非推奨です。 |
5807 | 5677 | |
5808 | 5678 | =begin original |
5809 | 5679 | |
5810 | 5680 | Prior to Perl v5.10.0, assignment to C<$[> could be seen from outer lexical |
5811 | 5681 | scopes in the same file, unlike other compile-time directives (such as |
5812 | 5682 | L<strict>). Using local() on it would bind its value strictly to a lexical |
5813 | 5683 | block. Now it is always lexically scoped. |
5814 | 5684 | |
5815 | 5685 | =end original |
5816 | 5686 | |
5817 | 5687 | Perl v5.10.0 より前では、C<$[> は(L<strict> のような)その他のコンパイル時 |
5818 | 5688 | 指示子と異なり、同じファイルのレキシカルスコープの外側から見ることが |
5819 | 5689 | 出来ていました。 |
5820 | 5690 | これに local() を使うとこの値を厳密にレキシカルスコープの内側に限定します。 |
5821 | 5691 | 今では常にレキシカルスコープを持ちます。 |
5822 | 5692 | |
5823 | 5693 | =begin original |
5824 | 5694 | |
5825 | As of Perl v5.16.0, it is implemented by the L<arybase> module. | |
5695 | As of Perl v5.16.0, it is implemented by the L<arybase> module. See | |
5696 | L<arybase> for more details on its behaviour. | |
5826 | 5697 | |
5827 | 5698 | =end original |
5828 | 5699 | |
5829 | 5700 | Perl v5.16.0 から、これは L<arybase> モジュールで実装されています。 |
5701 | この振る舞いに関するさらなる詳細については L<arybase> を参照してください。 | |
5830 | 5702 | |
5831 | 5703 | =begin original |
5832 | 5704 | |
5833 | ||
5705 | Under C<use v5.16>, or C<no feature "array_base">, C<$[> no longer has any | |
5834 | ||
5706 | effect, and always contains 0. Assigning 0 to it is permitted, but any | |
5835 | ||
5707 | other value will produce an error. | |
5836 | 5708 | |
5837 | 5709 | =end original |
5838 | 5710 | |
5839 | ||
5711 | C<use v5.16> または C<no feature "array_base"> の基では、C<$[> は | |
5840 | ||
5712 | もはや何の効果もなく、常に 0 が入っています。 | |
5841 | 5713 | これに 0 を代入することは許されますが、それ以外の値はエラーを引き起こします。 |
5842 | 5714 | |
5843 | 5715 | =begin original |
5844 | 5716 | |
5845 | 5717 | Mnemonic: [ begins subscripts. |
5846 | 5718 | |
5847 | 5719 | =end original |
5848 | 5720 | |
5849 | 5721 | 記憶法: [ は添え字付けの始め。 |
5850 | 5722 | |
5851 | 5723 | =begin original |
5852 | 5724 | |
5853 | 5725 | Deprecated in Perl v5.12.0. |
5854 | 5726 | |
5855 | 5727 | =end original |
5856 | 5728 | |
5857 | 5729 | Perl v5.12.0 で非推奨となりました。 |
5730 | ||
5731 | =begin original | |
5732 | ||
5733 | Assigning a non-zero value be fatal in Perl v5.30.0. | |
5734 | ||
5735 | =end original | |
5736 | ||
5737 | Perl v5.30.0 から、0 以外の値を代入すると致命的エラーになります。 | |
5858 | 5738 | |
5859 | 5739 | =back |
5860 | 5740 | |
5861 | 5741 | =cut |
5862 | 5742 | |
5863 | 5743 | =begin meta |
5864 | 5744 | |
5865 | 5745 | Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp> (5.000) |
5866 | 5746 | Update: Kentaro Shirakata <argrath@ub32.org> (5.6.1-) |
5867 | 5747 | Status: completed |
5868 | 5748 | |
5869 | 5749 | =end meta |