perlfunc > 5.20.1 との差分

perlfunc 5.20.1 と 5.16.1 の差分

11
22=encoding euc-jp
33
44=head1 NAME
55X<function>
66
77=begin original
88
99perlfunc - Perl builtin functions
1010
1111=end original
1212
1313perlfunc - Perl 組み込み関数
1414
1515=head1 DESCRIPTION
1616
1717=begin original
1818
1919The functions in this section can serve as terms in an expression.
2020They fall into two major categories: list operators and named unary
2121operators. These differ in their precedence relationship with a
2222following comma. (See the precedence table in L<perlop>.) List
2323operators take more than one argument, while unary operators can never
2424take more than one argument. Thus, a comma terminates the argument of
2525a unary operator, but merely separates the arguments of a list
2626operator. A unary operator generally provides scalar context to its
2727argument, while a list operator may provide either scalar or list
2828contexts for its arguments. If it does both, scalar arguments
2929come first and list argument follow, and there can only ever
3030be one such list argument. For instance, splice() has three scalar
3131arguments followed by a list, whereas gethostbyname() has four scalar
3232arguments.
3333
3434=end original
3535
3636この節の関数は、式の中で項として使うことができます。
3737これらは、大きく二つに分けられます:
3838リスト演算子と名前付き単項演算子です。
3939これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。
4040(L<perlop> の優先順位の表を参照してください。)
4141リスト演算子は 2 個以上の引数をとるのに対して、単項演算子が複数の引数を
4242とることはありません。
4343つまり、コンマは単項演算子の引数の終わりとなりますが、リスト演算子の
4444場合には、引数の区切りでしかありません。
4545単項演算子は一般に、引数に対してスカラコンテキストを与えるのに対して、
4646スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、
4747リストコンテキストを与える場合もあります。
4848一つのリスト演算子が両方のコンテキストを与える場合には、スカラ引数が
4949いくつか並び、最後にリスト引数が一つ続きます;
5050そしてそのようなリスト引数は一つだけしかありません。
5151たとえば、splice() は三つのスカラ引数に一つのリスト引数が続きます;
5252一方 gethostbyname() は四つのスカラ引数を持ちます。
5353
5454=begin original
5555
5656In the syntax descriptions that follow, list operators that expect a
5757list (and provide list context for elements of the list) are shown
5858with LIST as an argument. Such a list may consist of any combination
5959of scalar arguments or list values; the list values will be included
6060in the list as if each individual element were interpolated at that
6161point in the list, forming a longer single-dimensional list value.
6262Commas should separate literal elements of the LIST.
6363
6464=end original
6565
6666後に載せる構文記述では、リストをとり (そのリストの要素にリストコンテキストを
6767与える)リスト演算子は、引数として LIST をとるように書いています;
6868そのようなリストには、任意のスカラ引数の組み合わせやリスト値を
6969含めることができ、リスト値はリストの中に、個々の要素が展開されたように
7070埋め込まれます。
71711 次元の長いリスト値が形成されることになります。
7272LIST のリテラルな要素は、コンマで区切られます。
7373
7474=begin original
7575
7676Any function in the list below may be used either with or without
7777parentheses around its arguments. (The syntax descriptions omit the
7878parentheses.) If you use parentheses, the simple but occasionally
7979surprising rule is this: It I<looks> like a function, therefore it I<is> a
8080function, and precedence doesn't matter. Otherwise it's a list
8181operator or unary operator, and precedence does matter. Whitespace
8282between the function and left parenthesis doesn't count, so sometimes
8383you need to be careful:
8484
8585=end original
8686
8787以下のリストの関数はすべて、引数の前後の括弧は省略可能となっています。
8888(構文記述では省略しています。)
8989括弧を使うときには、単純な、(しかし、ときには驚く結果となる規則が
9090適用できます:
9191I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。
9292そう見えなければ、それはリスト演算子か単項演算子で、優先順位が関係します。
9393関数と開き括弧の間の空白は関係ありませんので、ときに
9494気を付けなければなりません:
9595
9696 print 1+2+4; # Prints 7.
9797 print(1+2) + 4; # Prints 3.
9898 print (1+2)+4; # Also prints 3!
9999 print +(1+2)+4; # Prints 7.
100100 print ((1+2)+4); # Prints 7.
101101
102102=begin original
103103
104104If you run Perl with the B<-w> switch it can warn you about this. For
105105example, the third line above produces:
106106
107107=end original
108108
109109Perl に B<-w> スイッチを付けて実行すれば、こういったものには警告を
110110出してくれます。
111111たとえば、上記の三つめは、以下のような警告が出ます:
112112
113113 print (...) interpreted as function at - line 1.
114114 Useless use of integer addition in void context at - line 1.
115115
116116=begin original
117117
118118A few functions take no arguments at all, and therefore work as neither
119119unary nor list operators. These include such functions as C<time>
120120and C<endpwent>. For example, C<time+86_400> always means
121121C<time() + 86_400>.
122122
123123=end original
124124
125125いくつかの関数は引数を全くとらないので、単項演算子としても
126126リスト演算子としても動作しません。
127127このような関数としては C<time> や C<endpwent> があります。
128128例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。
129129
130130=begin original
131131
132132For functions that can be used in either a scalar or list context,
133133nonabortive failure is generally indicated in scalar context by
134134returning the undefined value, and in list context by returning the
135135empty list.
136136
137137=end original
138138
139139スカラコンテキストでも、リストコンテキストでも使える関数は、致命的でない
140140エラーを示すために、スカラコンテキストでは未定義値を返し、
141141リストコンテキストでは空リストを返します。
142142
143143=begin original
144144
145145Remember the following important rule: There is B<no rule> that relates
146146the behavior of an expression in list context to its behavior in scalar
147147context, or vice versa. It might do two totally different things.
148148Each operator and function decides which sort of value would be most
149149appropriate to return in scalar context. Some operators return the
150150length of the list that would have been returned in list context. Some
151151operators return the first value in the list. Some operators return the
152152last value in the list. Some operators return a count of successful
153153operations. In general, they do what you want, unless you want
154154consistency.
155155X<context>
156156
157157=end original
158158
159159以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの
160160振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に
161161B<ルールはありません>。
1621622 つの全く異なったことがあります。
163163それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と
164164思われる値を返します。
165165リストコンテキストで返す時のリストの長さを返す演算子もあります。
166166リストの最初の値を返す演算子もあります。
167167リストの最後の値を返す演算子もあります。
168168成功した操作の数を返す演算子もあります。
169169一般的には、一貫性を求めない限り、こちらが求めることをします。
170170X<context>
171171
172172=begin original
173173
174174A named array in scalar context is quite different from what would at
175175first glance appear to be a list in scalar context. You can't get a list
176176like C<(1,2,3)> into being in scalar context, because the compiler knows
177177the context at compile time. It would generate the scalar comma operator
178178there, not the list construction version of the comma. That means it
179179was never a list to start with.
180180
181181=end original
182182
183183スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを
184184一目見たものとは全く違います。
185185コンパイラはコンパイル時にコンテキストを知っているので、
186186C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。
187187これはスカラコンマ演算子を生成し、コンマのリスト作成版ではありません。
188188これは初めからリストであることはないことを意味します。
189189
190190=begin original
191191
192192In general, functions in Perl that serve as wrappers for system calls ("syscalls")
193193of the same name (like chown(2), fork(2), closedir(2), etc.) return
194194true when they succeed and C<undef> otherwise, as is usually mentioned
195195in the descriptions below. This is different from the C interfaces,
196196which return C<-1> on failure. Exceptions to this rule include C<wait>,
197197C<waitpid>, and C<syscall>. System calls also set the special C<$!>
198198variable on failure. Other functions do not, except accidentally.
199199
200200=end original
201201
202202一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数
203203(chown(2), fork(2), closedir(2) など)は、以下に述べるように、
204204成功時に真を返し、そうでなければ C<undef> を返します。
205205これは失敗時に C<-1> を返す C のインターフェースとは違います。
206206このルールの例外は C<wait>, C<waitpid>, C<syscall> です。
207207システムコールは失敗時に特殊変数 C<$!> をセットします。
208208その他の関数は、事故を除いて、セットしません。
209209
210210=begin original
211211
212212Extension modules can also hook into the Perl parser to define new
213213kinds of keyword-headed expression. These may look like functions, but
214214may also look completely different. The syntax following the keyword
215215is defined entirely by the extension. If you are an implementor, see
216216L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such
217217a module, see the module's documentation for details of the syntax that
218218it defines.
219219
220220=end original
221221
222222エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を
223223定義するために Perl パーサをフックできます。
224224これらは関数のように見えるかもしれませんが、全く別物かもしれません。
225225キーワード以降の文法は完全にエクステンションによって定義されます。
226226もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を
227227参照してください。
228228もしあなたがそのようなモジュールを使っているなら、
229229定義されている文法の詳細についてはモジュールの文書を参照してください。
230230
231231=head2 Perl Functions by Category
232232X<function>
233233
234234(カテゴリ別の Perl 関数)
235235
236236=begin original
237237
238238Here are Perl's functions (including things that look like
239239functions, like some keywords and named operators)
240240arranged by category. Some functions appear in more
241241than one place.
242242
243243=end original
244244
245245以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、
246246関数のように見えるものも含みます)を示します。
247247複数の場所に現れる関数もあります。
248248
249249=over 4
250250
251251=item Functions for SCALARs or strings
252252X<scalar> X<string> X<character>
253253
254254(スカラや文字列のための関数)
255255
256256=for Pod::Functions =String
257257
258258C<chomp>, C<chop>, C<chr>, C<crypt>, C<fc>, C<hex>, C<index>, C<lc>,
259259C<lcfirst>, C<length>, C<oct>, C<ord>, C<pack>, C<q//>, C<qq//>, C<reverse>,
260260C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///>
261261
262262=begin original
263263
264264C<fc> is available only if the C<"fc"> feature is enabled or if it is
265265prefixed with C<CORE::>. The C<"fc"> feature is enabled automatically
266266with a C<use v5.16> (or higher) declaration in the current scope.
267267
268268=end original
269269
270270C<fc> は C<"fc"> 機能が有効か C<CORE::> が前置されたときにのみ利用可能です。
271271C<"fc"> 機能は現在のスコープで C<use v5.16> (またはそれ以上) が宣言されると
272272自動的に有効になります。
273273
274274=item Regular expressions and pattern matching
275275X<regular expression> X<regex> X<regexp>
276276
277277(正規表現とパターンマッチング)
278278
279279=for Pod::Functions =Regexp
280280
281281C<m//>, C<pos>, C<qr//>, C<quotemeta>, C<s///>, C<split>, C<study>
282282
283283=item Numeric functions
284284X<numeric> X<number> X<trigonometric> X<trigonometry>
285285
286286(数値関数)
287287
288288=for Pod::Functions =Math
289289
290290C<abs>, C<atan2>, C<cos>, C<exp>, C<hex>, C<int>, C<log>, C<oct>, C<rand>,
291291C<sin>, C<sqrt>, C<srand>
292292
293293=item Functions for real @ARRAYs
294294X<array>
295295
296296(実配列のための関数)
297297
298298=for Pod::Functions =ARRAY
299299
300300C<each>, C<keys>, C<pop>, C<push>, C<shift>, C<splice>, C<unshift>, C<values>
301301
302302=item Functions for list data
303303X<list>
304304
305305(リストデータのための関数)
306306
307307=for Pod::Functions =LIST
308308
309309C<grep>, C<join>, C<map>, C<qw//>, C<reverse>, C<sort>, C<unpack>
310310
311311=item Functions for real %HASHes
312312X<hash>
313313
314314(実ハッシュのための関数)
315315
316316=for Pod::Functions =HASH
317317
318318C<delete>, C<each>, C<exists>, C<keys>, C<values>
319319
320320=item Input and output functions
321321X<I/O> X<input> X<output> X<dbm>
322322
323323(入出力関数)
324324
325325=for Pod::Functions =I/O
326326
327327C<binmode>, C<close>, C<closedir>, C<dbmclose>, C<dbmopen>, C<die>, C<eof>,
328328C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>,
329329C<readdir>, C<readline> C<rewinddir>, C<say>, C<seek>, C<seekdir>, C<select>,
330330C<syscall>, C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>,
331331C<truncate>, C<warn>, C<write>
332332
333333=begin original
334334
335335C<say> is available only if the C<"say"> feature is enabled or if it is
336336prefixed with C<CORE::>. The C<"say"> feature is enabled automatically
337337with a C<use v5.10> (or higher) declaration in the current scope.
338338
339339=end original
340340
341341C<say> は C<"say"> 機能が有効か C<CORE::> が前置されたときにのみ利用可能です。
342342C<"say"> 機能は現在のスコープで C<use v5.10> (またはそれ以上) が宣言されると
343343自動的に有効になります。
344344
345345=item Functions for fixed-length data or records
346346
347347(固定長データやレコードのための関数)
348348
349349=for Pod::Functions =Binary
350350
351351C<pack>, C<read>, C<syscall>, C<sysread>, C<sysseek>, C<syswrite>, C<unpack>,
352352C<vec>
353353
354354=item Functions for filehandles, files, or directories
355355X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink>
356356
357357(ファイルハンドル、ファイル、ディレクトリのための関数)
358358
359359=for Pod::Functions =File
360360
361361C<-I<X>>, C<chdir>, C<chmod>, C<chown>, C<chroot>, C<fcntl>, C<glob>,
362362C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>,
363363C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<sysopen>,
364364C<umask>, C<unlink>, C<utime>
365365
366366=item Keywords related to the control flow of your Perl program
367367X<control flow>
368368
369369(プログラムの流れを制御することに関連するキーワード)
370370
371371=for Pod::Functions =Flow
372372
373373C<break>, C<caller>, C<continue>, C<die>, C<do>,
374374C<dump>, C<eval>, C<evalbytes> C<exit>,
375375C<__FILE__>, C<goto>, C<last>, C<__LINE__>, C<next>, C<__PACKAGE__>,
376376C<redo>, C<return>, C<sub>, C<__SUB__>, C<wantarray>
377377
378378=begin original
379379
380380C<break> is available only if you enable the experimental C<"switch">
381feature or use the C<CORE::> prefix. The C<"switch"> feature also enables
381feature or use the C<CORE::> prefix. The C<"switch"> feature also enables
382382the C<default>, C<given> and C<when> statements, which are documented in
383L<perlsyn/"Switch Statements">. The C<"switch"> feature is enabled
383L<perlsyn/"Switch Statements">. The C<"switch"> feature is enabled
384384automatically with a C<use v5.10> (or higher) declaration in the current
385scope. In Perl v5.14 and earlier, C<continue> required the C<"switch">
385scope. In Perl v5.14 and earlier, C<continue> required the C<"switch">
386386feature, like the other keywords.
387387
388388=end original
389389
390390C<break> は C<"switch"> 機能が有効か C<CORE::> 接頭辞を使ったときにのみ
391391利用可能です。
392392C<"switch"> 機能は L<perlsyn/"Switch Statements"> で文書化されている
393393C<default>, C<given>, C<when> 文も有効にします。
394394C<"switch"> 機能は現在のスコープで C<use v5.10> (またはそれ以上) が
395395宣言されると自動的に有効になります。
396396Perl v5.14 以前では、C<continue> は他のキーワードと同様に C<"switch"> 機能が
397397必要です。
398398
399399=begin original
400400
401C<evalbytes> is only available with the C<"evalbytes"> feature (see
401C<evalbytes> is only available with with the C<"evalbytes"> feature (see
402402L<feature>) or if prefixed with C<CORE::>. C<__SUB__> is only available
403with the C<"current_sub"> feature or if prefixed with C<CORE::>. Both
403with with the C<"current_sub"> feature or if prefixed with C<CORE::>. Both
404404the C<"evalbytes"> and C<"current_sub"> features are enabled automatically
405405with a C<use v5.16> (or higher) declaration in the current scope.
406406
407407=end original
408408
409409C<evalbytes> は C<"evalbytes"> 機能 (L<feature> 参照) が有効か C<CORE::> が
410410前置されたときにのみ利用可能です。
411411C<__SUB__> は C<"current_sub"> 機能が有効か C<CORE::> が前置されたときにのみ
412412利用可能です。
413413C<"evalbytes"> と C<"current_sub"> の両方の機能は現在のスコープで
414414C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
415415
416416=item Keywords related to scoping
417417
418418(スコープに関するキーワード)
419419
420420=for Pod::Functions =Namespace
421421
422422C<caller>, C<import>, C<local>, C<my>, C<our>, C<package>, C<state>, C<use>
423423
424424=begin original
425425
426426C<state> is available only if the C<"state"> feature is enabled or if it is
427427prefixed with C<CORE::>. The C<"state"> feature is enabled automatically
428428with a C<use v5.10> (or higher) declaration in the current scope.
429429
430430=end original
431431
432432C<state> は C<"state"> 機能が有効か C<CORE::> を前置した場合にのみ
433433利用可能です。
434434C<"state"> 機能は現在のスコープで C<use v5.10> (またはそれ以上) を宣言した
435435場合自動的に有効になります。
436436
437437=item Miscellaneous functions
438438
439439(さまざまな関数)
440440
441441=for Pod::Functions =Misc
442442
443443C<defined>, C<formline>, C<lock>, C<prototype>, C<reset>, C<scalar>, C<undef>
444444
445445=item Functions for processes and process groups
446446X<process> X<pid> X<process id>
447447
448448(プロセスとプロセスグループのための関数)
449449
450450=for Pod::Functions =Process
451451
452452C<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>,
453453C<pipe>, C<qx//>, C<readpipe>, C<setpgrp>,
454454C<setpriority>, C<sleep>, C<system>,
455455C<times>, C<wait>, C<waitpid>
456456
457457=item Keywords related to Perl modules
458458X<module>
459459
460460(Perl モジュールに関するキーワード)
461461
462462=for Pod::Functions =Modules
463463
464464C<do>, C<import>, C<no>, C<package>, C<require>, C<use>
465465
466466=item Keywords related to classes and object-orientation
467467X<object> X<class> X<package>
468468
469469(クラスとオブジェクト指向に関するキーワード)
470470
471471=for Pod::Functions =Objects
472472
473473C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>,
474474C<untie>, C<use>
475475
476476=item Low-level socket functions
477477X<socket> X<sock>
478478
479479(低レベルソケット関数)
480480
481481=for Pod::Functions =Socket
482482
483483C<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>,
484484C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>,
485485C<socket>, C<socketpair>
486486
487487=item System V interprocess communication functions
488488X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message>
489489
490490(System V プロセス間通信関数)
491491
492492=for Pod::Functions =SysV
493493
494494C<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>,
495495C<shmctl>, C<shmget>, C<shmread>, C<shmwrite>
496496
497497=item Fetching user and group info
498498X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd>
499499
500500(ユーザーとグループの情報取得)
501501
502502=for Pod::Functions =User
503503
504504C<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>,
505505C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>,
506506C<getpwuid>, C<setgrent>, C<setpwent>
507507
508508=item Fetching network info
509509X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service>
510510
511511(ネットワーク情報取得)
512512
513513=for Pod::Functions =Network
514514
515515C<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>,
516516C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
517517C<getprotobyname>, C<getprotobynumber>, C<getprotoent>,
518518C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>,
519519C<setnetent>, C<setprotoent>, C<setservent>
520520
521521=item Time-related functions
522522X<time> X<date>
523523
524524(時刻に関する関数)
525525
526526=for Pod::Functions =Time
527527
528528C<gmtime>, C<localtime>, C<time>, C<times>
529529
530530=item Non-function keywords
531531
532532=for Pod::Functions =!Non-functions
533533
534534C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>,
535535C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>,
536536C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>,
537537C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>,
538538C<while>, C<x>, C<xor>
539539
540540=back
541541
542542=head2 Portability
543543X<portability> X<Unix> X<portable>
544544
545545(移植性)
546546
547547=begin original
548548
549549Perl was born in Unix and can therefore access all common Unix
550550system calls. In non-Unix environments, the functionality of some
551551Unix system calls may not be available or details of the available
552552functionality may differ slightly. The Perl functions affected
553553by this are:
554554
555555=end original
556556
557557Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに
558558アクセスします。
559559非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、
560560使える機能の詳細が多少異なったりします。
561561これによる影響を受ける Perl 関数は以下のものです:
562562
563563C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>,
564564C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>,
565565C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>,
566566C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostbyname>,
567567C<gethostent>, C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
568568C<getppid>, C<getpgrp>, C<getpriority>, C<getprotobynumber>,
569569C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>,
570570C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>,
571571C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>,
572572C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>,
573573C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>,
574574C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>,
575575C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>,
576576C<shmwrite>, C<socket>, C<socketpair>,
577577C<stat>, C<symlink>, C<syscall>, C<sysopen>, C<system>,
578578C<times>, C<truncate>, C<umask>, C<unlink>,
579579C<utime>, C<wait>, C<waitpid>
580580
581581=begin original
582582
583583For more information about the portability of these functions, see
584584L<perlport> and other available platform-specific documentation.
585585
586586=end original
587587
588588これらの関数の移植性に関するさらなる情報については、
589589L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。
590590
591591=head2 Alphabetical Listing of Perl Functions
592592
593593=over
594594
595595=item -X FILEHANDLE
596596X<-r>X<-w>X<-x>X<-o>X<-R>X<-W>X<-X>X<-O>X<-e>X<-z>X<-s>X<-f>X<-d>X<-l>X<-p>
597597X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
598598
599599=item -X EXPR
600600
601601=item -X DIRHANDLE
602602
603603=item -X
604604
605605=for Pod::Functions a file test (-r, -x, etc)
606606
607607=begin original
608608
609609A file test, where X is one of the letters listed below. This unary
610610operator takes one argument, either a filename, a filehandle, or a dirhandle,
611611and tests the associated file to see if something is true about it. If the
612612argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN.
613Unless otherwise documented, it returns C<1> for true and C<''> for false.
613Unless otherwise documented, it returns C<1> for true and C<''> for false, or
614If the file doesn't exist or can't be examined, it returns C<undef> and
614the undefined value if the file doesn't exist. Despite the funny
615sets C<$!> (errno). Despite the funny names, precedence is the same as any
615names, precedence is the same as any other named unary operator. The
616other named unary operator. The operator may be any of:
616operator may be any of:
617617
618618=end original
619619
620620X は以下にあげる文字で、ファイルテストを行ないます。
621この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、
621この単項演算子は、ファイル名かファイルハンドルを唯一の
622「あること」について真であるか否かを判定した結果を返します。
622引数として動作し、「あること」について真であるか否かを
623判定した結果を返します。
623624引数が省略されると、C<-t> では STDIN を調べますが、その他は C<$_> を調べます。
624特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。
625特に記述されていなければ、真として C<1> を返し、偽として
625ファイルが存在しないか、テスト出来なければ、C<undef> を返し、C<$!> (errno) を
626C<''> を返し、ファイルが存在しなければ、未定義値を返します。
626設定します。
627627みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、
628628他の単項演算子と同じく、引数を括弧で括ることもできます。
629629演算子には以下のものがあります:
630630
631631=begin original
632632
633633 -r File is readable by effective uid/gid.
634634 -w File is writable by effective uid/gid.
635635 -x File is executable by effective uid/gid.
636636 -o File is owned by effective uid.
637637
638638=end original
639639
640640 -r ファイルが実効 uid/gid で読み出し可。
641641 -w ファイルが実効 uid/gid で書き込み可。
642642 -x ファイルが実効 uid/gid で実行可。
643643 -o ファイルが実効 uid の所有物。
644644
645645=begin original
646646
647647 -R File is readable by real uid/gid.
648648 -W File is writable by real uid/gid.
649649 -X File is executable by real uid/gid.
650650 -O File is owned by real uid.
651651
652652=end original
653653
654654 -R ファイルが実 uid/gid で読み出し可。
655655 -W ファイルが実 uid/gid で書き込み可。
656656 -X ファイルが実 uid/gid で実行可。
657657 -O ファイルが実 uid の所有物。
658658
659659=begin original
660660
661661 -e File exists.
662662 -z File has zero size (is empty).
663663 -s File has nonzero size (returns size in bytes).
664664
665665=end original
666666
667667 -e ファイルが存在する。
668668 -z ファイルの大きさがゼロ(空)。
669669 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)。
670670
671671=begin original
672672
673673 -f File is a plain file.
674674 -d File is a directory.
675 -l File is a symbolic link (false if symlinks aren't
675 -l File is a symbolic link.
676 supported by the file system).
677676 -p File is a named pipe (FIFO), or Filehandle is a pipe.
678677 -S File is a socket.
679678 -b File is a block special file.
680679 -c File is a character special file.
681680 -t Filehandle is opened to a tty.
682681
683682=end original
684683
685684 -f ファイルは通常ファイル。
686685 -d ファイルはディレクトリ。
687 -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)
686 -l ファイルはシンボリックリンク。
688687 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ。
689688 -S ファイルはソケット。
690689 -b ファイルはブロック特殊ファイル。
691690 -c ファイルはキャラクタ特殊ファイル。
692691 -t ファイルハンドルは tty にオープンされている。
693692
694693=begin original
695694
696695 -u File has setuid bit set.
697696 -g File has setgid bit set.
698697 -k File has sticky bit set.
699698
700699=end original
701700
702701 -u ファイルの setuid ビットがセットされている。
703702 -g ファイルの setgid ビットがセットされている。
704703 -k ファイルの sticky ビットがセットされている。
705704
706705=begin original
707706
708 -T File is an ASCII or UTF-8 text file (heuristic guess).
707 -T File is an ASCII text file (heuristic guess).
709708 -B File is a "binary" file (opposite of -T).
710709
711710=end original
712711
713 -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)。
712 -T ファイルは ASCII テキストファイル (発見的に推測します)。
714713 -B ファイルは「バイナリ」ファイル (-T の反対)。
715714
716715=begin original
717716
718717 -M Script start time minus file modification time, in days.
719718 -A Same for access time.
720 -C Same for inode change time (Unix, may differ for other
719 -C Same for inode change time (Unix, may differ for other platforms)
721 platforms)
722720
723721=end original
724722
725723 -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)。
726724 -A 同様にアクセスがあってからの日数。
727 -C 同様に(Unix では) inode が変更されてからの日数(それ以外の
725 -C 同様に(Unix では) inode が変更されてからの日数(それ以外のプラットフォームでは違うかもしれません)。
728 プラットフォームでは違うかもしれません)。
729726
730727=begin original
731728
732729Example:
733730
734731=end original
735732
736733例:
737734
738735 while (<>) {
739736 chomp;
740737 next unless -f $_; # ignore specials
741738 #...
742739 }
743740
744741=begin original
745742
746743Note that C<-s/a/b/> does not do a negated substitution. Saying
747744C<-exp($foo)> still works as expected, however: only single letters
748745following a minus are interpreted as file tests.
749746
750747=end original
751748
752749C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。
753750しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に
754751英字が 1 字続くときにのみ、ファイルテストと解釈されます。
755752
756753=begin original
757754
758755These operators are exempt from the "looks like a function rule" described
759756above. That is, an opening parenthesis after the operator does not affect
760757how much of the following code constitutes the argument. Put the opening
761758parentheses before the operator to separate it from code that follows (this
762759applies only to operators with higher precedence than unary operators, of
763760course):
764761
765762=end original
766763
767764これらの演算子は上述の「関数のように見えるルール」から免除されます。
768765つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を
769766構成するかに影響を与えません。
770767演算子を引き続くコードから分離するには、演算子の前に開きかっこを
771768置いてください (これはもちろん、単項演算子より高い優先順位を持つ
772769演算子にのみ適用されます):
773770
774771 -s($file) + 1024 # probably wrong; same as -s($file + 1024)
775772 (-s $file) + 1024 # correct
776773
777774=begin original
778775
779776The interpretation of the file permission operators C<-r>, C<-R>,
780777C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode
781778of the file and the uids and gids of the user. There may be other
782779reasons you can't actually read, write, or execute the file: for
783780example network filesystem access controls, ACLs (access control lists),
784781read-only filesystems, and unrecognized executable formats. Note
785782that the use of these six specific operators to verify if some operation
786783is possible is usually a mistake, because it may be open to race
787784conditions.
788785
789786=end original
790787
791788ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>,
792789C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と
793790実効/実 gid のみから判断されます。
794791実際にファイルが読めたり、書けたり、実行できたりするためには、
795792別の条件が必要かもしれません:
796793例えば、ネットワークファイルシステムアクセスコントロール、
797794ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、
798795認識できない実行ファイルフォーマット、などです。
799796これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは
800797通常は誤りであることに注意してください; なぜなら、これらは競合条件を
801798招きやすいからです。
802799
803800=begin original
804801
805802Also note that, for the superuser on the local filesystems, the C<-r>,
806803C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1
807804if any execute bit is set in the mode. Scripts run by the superuser
808805may thus need to do a stat() to determine the actual mode of the file,
809806or temporarily set their effective uid to something else.
810807
811808=end original
812809
813810ローカルファイルシステムのスーパーユーザには、
814811C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の
815812いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が
816813返ることにも注意してください。
817814スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、
818815stat() を行なうか、実効 uid を一時的に別のものにする
819816必要があるでしょう。
820817
821818=begin original
822819
823820If you are using ACLs, there is a pragma called C<filetest> that may
824821produce more accurate results than the bare stat() mode bits.
825822When under C<use filetest 'access'> the above-mentioned filetests
826823test whether the permission can(not) be granted using the
827824access(2) family of system calls. Also note that the C<-x> and C<-X> may
828825under this pragma return true even if there are no execute permission
829826bits set (nor any extra execute permission ACLs). This strangeness is
830827due to the underlying system calls' definitions. Note also that, due to
831828the implementation of C<use filetest 'access'>, the C<_> special
832829filehandle won't cache the results of the file tests when this pragma is
833830in effect. Read the documentation for the C<filetest> pragma for more
834831information.
835832
836833=end original
837834
838835ACL を使っている場合は、生の stat() モードビットより
839836精度の高い結果を作成する C<filetest> プラグマがあります。
840837C<use filetest 'access'> とした場合、上述したファイルテストは
841838システムコールの access(2) ファミリーを使って権限が与えられているか
842839どうかをテストします。
843840また、このプラグマが指定されている場合、C<-x> と C<-X> は
844841たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない
845842場合でも真を返すことに注意してください。
846843この挙動は使用するシステムコールの定義によるものです。
847844C<use filetest 'access'> の実装により、このプラグマが有効の場合は
848845C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに
849846注意してください。
850847さらなる情報については C<filetest> プラグマのドキュメントを
851848参照してください。
852849
853850=begin original
854851
855The C<-T> and C<-B> switches work as follows. The first block or so of
852The C<-T> and C<-B> switches work as follows. The first block or so of the
856the file is examined to see if it is valid UTF-8 that includes non-ASCII
853file is examined for odd characters such as strange control codes or
857characters. If, so it's a C<-T> file. Otherwise, that same portion of
854characters with the high bit set. If too many strange characters (>30%)
858the file is examined for odd characters such as strange control codes or
855are found, it's a C<-B> file; otherwise it's a C<-T> file. Also, any file
859characters with the high bit set. If more than a third of the
856containing a zero byte in the first block is considered a binary file. If C<-T>
860characters are strange, it's a C<-B> file; otherwise it's a C<-T> file.
857or C<-B> is used on a filehandle, the current IO buffer is examined
861Also, any file containing a zero byte in the examined portion is
862considered a binary file. (If executed within the scope of a L<S<use
863locale>|perllocale> which includes C<LC_CTYPE>, odd characters are
864anything that isn't a printable nor space in the current locale.) If
865C<-T> or C<-B> is used on a filehandle, the current IO buffer is
866examined
867858rather than the first block. Both C<-T> and C<-B> return true on an empty
868859file, or a file at EOF when testing a filehandle. Because you have to
869860read a file to do the C<-T> test, on most occasions you want to use a C<-f>
870861against the file first, as in C<next unless -f $file && -T $file>.
871862
872863=end original
873864
874865ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。
875ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを
866ファイルの最初の数ブロックを調べて、変わった制御コードや
876調べます。
877もしそうなら、それは C<-T> ファイルです。
878さもなければ、ファイルの同じ位置から、変わった制御コードや
879867上位ビットがセットされているような、通常のテキストには現れない文字を探します。
880三分一以上がおかしな文字ならそれは C<-B> ファイルです;
868ような文字たくさん (>30%) 見つかるようあれば、
881さもなければ C<-T> ファイルです
869そのファイルは C<-B> ファイルであると判断されま;
882また、調べた位置にヌル文字が含まファイルも、バイナリファイル
870さもなけば C<-T> ファイルとなります。
883みなされす。
871最初のブロックにヌル文字が含れるファイルも、
884(C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、
872バイナリファイルとみなされます。
885おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。)
886873C<-T> や C<-B> をファイルハンドルに対して用いると、
887874最初のブロックを調べる代わりに、IO バッファを調べます。
888875調べたファイルの中身が何もないときや、
889876ファイルハンドルを調べたときに EOF に達して
890877いたときには、C<-T> も C<-B> も「真」を返します。
891878C<-T> テストをするためにはファイルを読み込まないといけないので、
892879たいていは C<next unless -f $file && -T $file> というような形で
893880まず調べたいファイルに対して C<-f> を使いたいはずです。
894881
895882=begin original
896883
897884If any of the file tests (or either the C<stat> or C<lstat> operator) is given
898885the special filehandle consisting of a solitary underline, then the stat
899886structure of the previous file test (or stat operator) is used, saving
900887a system call. (This doesn't work with C<-t>, and you need to remember
901888that lstat() and C<-l> leave values in the stat structure for the
902889symbolic link, not the real file.) (Also, if the stat buffer was filled by
903890an C<lstat> call, C<-T> and C<-B> will reset it with the results of C<stat _>).
904891Example:
905892
906893=end original
907894
908895どのファイルテスト (あるいは、C<stat> や C<lstat>) 演算子にも、
909896下線だけから成る特別なファイルハンドルを与えると、
910897前回のファイルテスト (や stat) の stat 構造体が使われ、
911898システムコールを省きます。
912899(C<-t> には使えませんし、lstat() や C<-l> は実ファイルではなく、
913900シンボリックリンクの情報を stat 構造体に残すことを
914901覚えておく必要があります。)
915902(また、stat バッファが C<lstat> 呼び出しで埋まった場合、
916903C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。
917904例:
918905
919906 print "Can do.\n" if -r $a || -w _ || -x _;
920907
921908 stat($filename);
922909 print "Readable\n" if -r _;
923910 print "Writable\n" if -w _;
924911 print "Executable\n" if -x _;
925912 print "Setuid\n" if -u _;
926913 print "Setgid\n" if -g _;
927914 print "Sticky\n" if -k _;
928915 print "Text\n" if -T _;
929916 print "Binary\n" if -B _;
930917
931918=begin original
932919
933As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file
920As of Perl 5.9.1, as a form of purely syntactic sugar, you can stack file
934921test operators, in a way that C<-f -w -x $file> is equivalent to
935C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use
922C<-x $file && -w _ && -f _>. (This is only fancy fancy: if you use
936923the return value of C<-f $file> as an argument to another filetest
937924operator, no special magic will happen.)
938925
939926=end original
940927
941Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
928Perl 5.9.1 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
942929スタックさせることができるので、C<-f -w -x $file> は
943930C<-x $file && -w _ && -f _> と等価です。
944931(これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト
945932演算子の引数として使う場合は、何の特別なことも起きません。)
946933
947934=begin original
948935
949936Portability issues: L<perlport/-X>.
950937
951938=end original
952939
953940移植性の問題: L<perlport/-X>。
954941
955942=begin original
956943
957944To avoid confusing would-be users of your code with mysterious
958945syntax errors, put something like this at the top of your script:
959946
960947=end original
961948
962949あなたのコードのユーザーが不思議な文法エラーで混乱することを
963950避けるために、スクリプトの先頭に以下のようなことを書いてください:
964951
965952 use 5.010; # so filetest ops can stack
966953
967954=item abs VALUE
968955X<abs> X<absolute>
969956
970957=item abs
971958
972959=for Pod::Functions absolute value function
973960
974961=begin original
975962
976963Returns the absolute value of its argument.
977964If VALUE is omitted, uses C<$_>.
978965
979966=end original
980967
981968引数の絶対値を返します。
982969VALUE が省略された場合は、C<$_> を使います。
983970
984971=item accept NEWSOCKET,GENERICSOCKET
985972X<accept>
986973
987974=for Pod::Functions accept an incoming socket connect
988975
989976=begin original
990977
991978Accepts an incoming socket connect, just as accept(2)
992979does. Returns the packed address if it succeeded, false otherwise.
993980See the example in L<perlipc/"Sockets: Client/Server Communication">.
994981
995982=end original
996983
997984accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。
998985成功時にはパックされたアドレスを返し、失敗すれば偽を返します。
999986L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
1000987
1001988=begin original
1002989
1003990On systems that support a close-on-exec flag on files, the flag will
1004991be set for the newly opened file descriptor, as determined by the
1005992value of $^F. See L<perlvar/$^F>.
1006993
1007994=end original
1008995
1009996ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1010997フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
1011998セットされます。
1012999L<perlvar/$^F> を参照してください。
10131000
10141001=item alarm SECONDS
10151002X<alarm>
10161003X<SIGALRM>
10171004X<timer>
10181005
10191006=item alarm
10201007
10211008=for Pod::Functions schedule a SIGALRM
10221009
10231010=begin original
10241011
10251012Arranges to have a SIGALRM delivered to this process after the
10261013specified number of wallclock seconds has elapsed. If SECONDS is not
10271014specified, the value stored in C<$_> is used. (On some machines,
10281015unfortunately, the elapsed time may be up to one second less or more
10291016than you specified because of how seconds are counted, and process
10301017scheduling may delay the delivery of the signal even further.)
10311018
10321019=end original
10331020
10341021指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が
10351022送られてくるようにします。
10361023SECONDS が指定されていない場合は、C<$_> に格納されている値を使います。
10371024(マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で
103810251 秒ずれます。)
10391026
10401027=begin original
10411028
10421029Only one timer may be counting at once. Each call disables the
10431030previous timer, and an argument of C<0> may be supplied to cancel the
10441031previous timer without starting a new one. The returned value is the
10451032amount of time remaining on the previous timer.
10461033
10471034=end original
10481035
10491036一度には一つのタイマだけが設定可能です。
10501037呼び出しを行なう度に、以前のタイマを無効にしますし、
10511038新しくタイマを起動しないで以前のタイマをキャンセルするために
10521039引数に C<0> を指定して呼び出すことができます。
10531040以前のタイマの残り時間が、返り値となります。
10541041
10551042=begin original
10561043
10571044For delays of finer granularity than one second, the Time::HiRes module
10581045(from CPAN, and starting from Perl 5.8 part of the standard
10591046distribution) provides ualarm(). You may also use Perl's four-argument
10601047version of select() leaving the first three arguments undefined, or you
10611048might be able to use the C<syscall> interface to access setitimer(2) if
10621049your system supports it. See L<perlfaq8> for details.
10631050
10641051=end original
10651052
106610531 秒より精度の高いスリープを行なうには、
10671054Time::HiRes モジュール(CPAN から、また Perl 5.8 からは
10681055標準配布されています) が ualarm() を提供します。
10691056Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、
10701057setitimer(2) をサポートしているシステムでは、Perl の
10711058C<syscall> インタフェースを使ってアクセスすることもできます。
10721059詳しくは L<perlfaq8> を参照してください。
10731060
10741061=begin original
10751062
10761063It is usually a mistake to intermix C<alarm> and C<sleep> calls, because
10771064C<sleep> may be internally implemented on your system with C<alarm>.
10781065
10791066=end original
10801067
10811068C<alarm> と C<sleep> を混ぜて使うのは普通は間違いです; なぜなら、
10821069C<sleep> は内部的に C<alarm> を使って内部的に実装されているかも
10831070しれないからです。
10841071
10851072=begin original
10861073
10871074If you want to use C<alarm> to time out a system call you need to use an
10881075C<eval>/C<die> pair. You can't rely on the alarm causing the system call to
10891076fail with C<$!> set to C<EINTR> because Perl sets up signal handlers to
10901077restart system calls on some systems. Using C<eval>/C<die> always works,
10911078modulo the caveats given in L<perlipc/"Signals">.
10921079
10931080=end original
10941081
10951082C<alarm> をシステムコールの時間切れのために使いたいなら、
10961083C<eval>/C<die> のペアで使う必要があります。
10971084システムコールが失敗したときに C<$!> に C<EINTR> がセットされることに
10981085頼ってはいけません; なぜならシステムによっては Perl は
10991086システムコールを再開するためにシグナルハンドラを設定するからです。
11001087C<eval>/C<die> は常にうまく動きます; 注意点については
11011088L<perlipc/"Signals"> を参照してください。
11021089
11031090 eval {
11041091 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
11051092 alarm $timeout;
11061093 $nread = sysread SOCKET, $buffer, $size;
11071094 alarm 0;
11081095 };
11091096 if ($@) {
11101097 die unless $@ eq "alarm\n"; # propagate unexpected errors
11111098 # timed out
11121099 }
11131100 else {
11141101 # didn't
11151102 }
11161103
11171104=begin original
11181105
11191106For more information see L<perlipc>.
11201107
11211108=end original
11221109
11231110さらなる情報については L<perlipc> を参照してください。
11241111
11251112=begin original
11261113
11271114Portability issues: L<perlport/alarm>.
11281115
11291116=end original
11301117
11311118移植性の問題: L<perlport/alarm>。
11321119
11331120=item atan2 Y,X
11341121X<atan2> X<arctangent> X<tan> X<tangent>
11351122
11361123=for Pod::Functions arctangent of Y/X in the range -PI to PI
11371124
11381125=begin original
11391126
11401127Returns the arctangent of Y/X in the range -PI to PI.
11411128
11421129=end original
11431130
11441131-πからπの範囲で Y/X の逆正接を返します。
11451132
11461133=begin original
11471134
11481135For the tangent operation, you may use the C<Math::Trig::tan>
11491136function, or use the familiar relation:
11501137
11511138=end original
11521139
11531140正接を求めたいときは、C<Math::Trig::tan> を使うか、
11541141以下のよく知られた関係を使ってください。
11551142
11561143 sub tan { sin($_[0]) / cos($_[0]) }
11571144
11581145=begin original
11591146
11601147The return value for C<atan2(0,0)> is implementation-defined; consult
11611148your atan2(3) manpage for more information.
11621149
11631150=end original
11641151
11651152C<atan2(0,0)> の返り値は実装依存です; さらなる情報については
11661153atan2(3) man ページを参照してください。
11671154
11681155=begin original
11691156
11701157Portability issues: L<perlport/atan2>.
11711158
11721159=end original
11731160
11741161移植性の問題: L<perlport/atan2>。
11751162
11761163=item bind SOCKET,NAME
11771164X<bind>
11781165
11791166=for Pod::Functions binds an address to a socket
11801167
11811168=begin original
11821169
11831170Binds a network address to a socket, just as bind(2)
11841171does. Returns true if it succeeded, false otherwise. NAME should be a
11851172packed address of the appropriate type for the socket. See the examples in
11861173L<perlipc/"Sockets: Client/Server Communication">.
11871174
11881175=end original
11891176
11901177bind(2) システムコールと同様に、ネットワークアドレスをソケットに結び付けます。
11911178成功時には真を、さもなければ偽を返します。
11921179NAME は、ソケットに対する、適切な型のパックされた
11931180アドレスでなければなりません。
11941181L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
11951182
11961183=item binmode FILEHANDLE, LAYER
11971184X<binmode> X<binary> X<text> X<DOS> X<Windows>
11981185
11991186=item binmode FILEHANDLE
12001187
12011188=for Pod::Functions prepare binary files for I/O
12021189
12031190=begin original
12041191
12051192Arranges for FILEHANDLE to be read or written in "binary" or "text"
12061193mode on systems where the run-time libraries distinguish between
12071194binary and text files. If FILEHANDLE is an expression, the value is
12081195taken as the name of the filehandle. Returns true on success,
12091196otherwise it returns C<undef> and sets C<$!> (errno).
12101197
12111198=end original
12121199
12131200バイナリファイルとテキストファイルを区別する OS において、
12141201FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように
12151202指定します。
12161203FILEHANDLE が式である場合には、その式の値がファイルハンドルの
12171204名前として使われます。
12181205成功時には真を返し、失敗時には C<undef> を返して C<$!> (errno) を設定します。
12191206
12201207=begin original
12211208
12221209On some systems (in general, DOS- and Windows-based systems) binmode()
12231210is necessary when you're not working with a text file. For the sake
12241211of portability it is a good idea always to use it when appropriate,
12251212and never to use it when it isn't appropriate. Also, people can
12261213set their I/O to be by default UTF8-encoded Unicode, not bytes.
12271214
12281215=end original
12291216
12301217テキストファイルでないものを扱う場合に binmode() が必要な
12311218システムもあります(一般的には DOS と Windows ベースのシステムです)。
12321219移植性のために、適切なときには常にこれを使い、適切でないときには
12331220決して使わないというのは良い考えです。
12341221また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
12351222Unicode にセットすることも出来ます。
12361223
12371224=begin original
12381225
12391226In other words: regardless of platform, use binmode() on binary data,
12401227like images, for example.
12411228
12421229=end original
12431230
12441231言い換えると: プラットフォームに関わらず、
12451232例えばイメージのようなバイナリファイルに対しては binmode() を
12461233使ってください。
12471234
12481235=begin original
12491236
12501237If LAYER is present it is a single string, but may contain multiple
12511238directives. The directives alter the behaviour of the filehandle.
12521239When LAYER is present, using binmode on a text file makes sense.
12531240
12541241=end original
12551242
12561243LAYER が存在すると、それは単一の文字列ですが、複数の指示子を
12571244含むことができます。
12581245指示子はファイルハンドルの振る舞いを変更します。
12591246LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。
12601247
12611248=begin original
12621249
12631250If LAYER is omitted or specified as C<:raw> the filehandle is made
12641251suitable for passing binary data. This includes turning off possible CRLF
12651252translation and marking it as bytes (as opposed to Unicode characters).
12661253Note that, despite what may be implied in I<"Programming Perl"> (the
12671254Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>.
12681255Other layers that would affect the binary nature of the stream are
12691256I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the
12701257PERLIO environment variable.
12711258
12721259=end original
12731260
12741261LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ
12751262データの通過に適するように設定されます。
12761263これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく)
12771264バイトであるとマークしたりすることを含みます。
12781265I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、
12791266C<:raw> は単なる C<:crlf> の I<逆ではありません>。
12801267ストリームのバイナリとしての性質に影響を与える
12811268I<その他の層も無効にされます>。
12821269L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。
12831270
12841271=begin original
12851272
12861273The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the
12871274form C<:...>, are called I/O I<layers>. The C<open> pragma can be used to
12881275establish default I/O layers. See L<open>.
12891276
12901277=end original
12911278
12921279C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は
12931280I/O I<層> が呼び出されます。
12941281C<open> プラグマはデフォルト I/O 層を指定するために使われます。
12951282L<open> を参照してください。
12961283
12971284=begin original
12981285
12991286I<The LAYER parameter of the binmode() function is described as "DISCIPLINE"
13001287in "Programming Perl, 3rd Edition". However, since the publishing of this
13011288book, by many known as "Camel III", the consensus of the naming of this
13021289functionality has moved from "discipline" to "layer". All documentation
13031290of this version of Perl therefore refers to "layers" rather than to
13041291"disciplines". Now back to the regularly scheduled documentation...>
13051292
13061293=end original
13071294
13081295I<binmode() 関数の LAYER パラメータは 「プログラミングPerl 第3版」では
13091296「ディシプリン(DISCIPLINE)」と表現されていました。
13101297しかし、「ラクダ本第3版」として知られているこの本の出版後、この機能の名前は
13111298「ディシプリン」から「層」に変更することで合意されました。
13121299従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく
13131300「層」と記述されています。では通常の解説に戻ります…>
13141301
13151302=begin original
13161303
13171304To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>.
13181305C<:utf8> just marks the data as UTF-8 without further checking,
13191306while C<:encoding(UTF-8)> checks the data for actually being valid
13201307UTF-8. More details can be found in L<PerlIO::encoding>.
13211308
13221309=end original
13231310
13241311FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か
13251312C<:encoding(UTF-8)> を使ってください。
13261313C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、
13271314C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。
13281315さらなる詳細は L<PerlIO::encoding> にあります。
13291316
13301317=begin original
13311318
13321319In general, binmode() should be called after open() but before any I/O
13331320is done on the filehandle. Calling binmode() normally flushes any
13341321pending buffered output data (and perhaps pending input data) on the
13351322handle. An exception to this is the C<:encoding> layer that
13361323changes the default character encoding of the handle; see L</open>.
13371324The C<:encoding> layer sometimes needs to be called in
13381325mid-stream, and it doesn't flush the stream. The C<:encoding>
13391326also implicitly pushes on top of itself the C<:utf8> layer because
13401327internally Perl operates on UTF8-encoded Unicode characters.
13411328
13421329=end original
13431330
13441331一般的に binmode() は open() を呼び出した後、このファイルハンドルに対する
13451332I/O 操作をする前に呼び出すべきです。
13461333binmode() を呼び出すと、普通はこのファイルハンドルに対して
13471334バッファリングされている全ての出力データ
13481335(およびおそらくは入力データ)をフラッシュします。
13491336例外は、このハンドルに対するデフォルト文字エンコーディングを変更する
13501337C<:encoding> 層です; L</open> を参照してください。
13511338C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、
13521339それによってストリームはフラッシュされません。
13531340Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、
13541341C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。
13551342
13561343=begin original
13571344
13581345The operating system, device drivers, C libraries, and Perl run-time
13591346system all conspire to let the programmer treat a single
13601347character (C<\n>) as the line terminator, irrespective of external
13611348representation. On many operating systems, the native text file
13621349representation matches the internal representation, but on some
13631350platforms the external representation of C<\n> is made up of more than
13641351one character.
13651352
13661353=end original
13671354
13681355オペレーティングシステム、デバイスドライバ、C ライブラリ、
13691356Perl ランタイムシステムは全て、プログラマが外部表現に関わらず
137013571 文字 (C<\n>) を行終端として扱えるように協調作業します。
13711358多くのオペレーティングシステムでは、ネイティブテキストファイル表現は
13721359内部表現と同じですが、C<\n> の外部表現が複数文字になる
13731360プラットフォームもあります。
13741361
13751362=begin original
13761363
13771364All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use
13781365a single character to end each line in the external representation of text
13791366(even though that single character is CARRIAGE RETURN on old, pre-Darwin
13801367flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other
13811368systems like OS/2, DOS, and the various flavors of MS-Windows, your program
13821369sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the
13831370two characters C<\cM\cJ>. That means that if you don't use binmode() on
13841371these systems, C<\cM\cJ> sequences on disk will be converted to C<\n> on
13851372input, and any C<\n> in your program will be converted back to C<\cM\cJ> on
13861373output. This is what you want for text files, but it can be disastrous for
13871374binary files.
13881375
13891376=end original
13901377
13911378全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは
13921379テキストの外部表現として各行の末尾に一つの文字を
13931380使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、
13941381Unix とほとんどのVMS のファイルでは改行です)。
13951382VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、
13961383プログラムからは C<\n> は単純に C<\cJ> に見えますが、
13971384テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。
13981385つまり、もしこれらのシステムで binmode() を使わないと、
13991386ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
14001387プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。
14011388これはテキストファイルの場合は思い通りの結果でしょうが、
14021389バイナリファイルの場合は悲惨です。
14031390
14041391=begin original
14051392
14061393Another consequence of using binmode() (on some systems) is that
14071394special end-of-file markers will be seen as part of the data stream.
14081395For systems from the Microsoft family this means that, if your binary
14091396data contain C<\cZ>, the I/O subsystem will regard it as the end of
14101397the file, unless you use binmode().
14111398
14121399=end original
14131400
14141401binmode() を(いくつかのシステムで)使うことによるその他の作用としては、
14151402特別なファイル終端マーカーがデータストリームの一部として
14161403見られることです。
14171404Microsoft ファミリーのシステムでは、binmode() を使っていないと
14181405もしバイナリデータに C<\cZ> が含まれていたときに、I/O サブシステムが
14191406これをファイル終端とみなすことを意味します。
14201407
14211408=begin original
14221409
14231410binmode() is important not only for readline() and print() operations,
14241411but also when using read(), seek(), sysread(), syswrite() and tell()
14251412(see L<perlport> for more details). See the C<$/> and C<$\> variables
14261413in L<perlvar> for how to manually set your input and output
14271414line-termination sequences.
14281415
14291416=end original
14301417
14311418binmode() は readline() と print() 操作にだけではなく、
14321419read(), seek(), sysread(), syswrite(), tell() を使うときにも重要です
14331420(詳細は L<perlport> を参照してください)。
14341421入出力の行端末シーケンスを手動でセットする方法については
14351422L<perlvar> の C<$/> 変数と C<$\> 変数を参照してください。
14361423
14371424=begin original
14381425
14391426Portability issues: L<perlport/binmode>.
14401427
14411428=end original
14421429
14431430移植性の問題: L<perlport/binmode>。
14441431
14451432=item bless REF,CLASSNAME
14461433X<bless>
14471434
14481435=item bless REF
14491436
14501437=for Pod::Functions create an object
14511438
14521439=begin original
14531440
14541441This function tells the thingy referenced by REF that it is now an object
14551442in the CLASSNAME package. If CLASSNAME is omitted, the current package
14561443is used. Because a C<bless> is often the last thing in a constructor,
14571444it returns the reference for convenience. Always use the two-argument
14581445version if a derived class might inherit the function doing the blessing.
1459See L<perlobj> for more about the blessing (and blessings) of objects.
1446SeeL<perlobj> for more about the blessing (and blessings) of objects.
14601447
14611448=end original
14621449
14631450この関数は、REF で渡された オブジェクトに対し、
14641451CLASSNAME 内のオブジェクトとなったことを伝えます。
14651452CLASSNAME が省略された場合には、その時点のパッケージとなります。
14661453C<bless> は通常、コンストラクタの最後に置かれますので、
14671454簡便のためにそのリファレンスを返します。
14681455派生クラスが bless される関数を継承する場合は、
14691456常に 2 引数版を使ってください。
14701457オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を
14711458参照してください。
14721459
14731460=begin original
14741461
14751462Consider always blessing objects in CLASSNAMEs that are mixed case.
14761463Namespaces with all lowercase names are considered reserved for
14771464Perl pragmata. Builtin types have all uppercase names. To prevent
14781465confusion, you may wish to avoid such package names as well. Make sure
14791466that CLASSNAME is a true value.
14801467
14811468=end original
14821469
14831470大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを
14841471考慮してください。
14851472全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。
14861473組み込みの型は全て大文字の名前を持ちます。
14871474混乱を避けるために、
14881475パッケージ名としてこのような名前は避けるべきです。
14891476CLASSNAME は真の値を持つようにしてください。
14901477
14911478=begin original
14921479
14931480See L<perlmod/"Perl Modules">.
14941481
14951482=end original
14961483
14971484L<perlmod/"Perl Modules"> を参照してください。
14981485
14991486=item break
15001487
15011488=for Pod::Functions +switch break out of a C<given> block
15021489
15031490=begin original
15041491
15051492Break out of a C<given()> block.
15061493
15071494=end original
15081495
15091496C<given()> ブロックから脱出します。
15101497
15111498=begin original
15121499
1513This keyword is enabled by the C<"switch"> feature; see L<feature> for
1500This keyword is enabled by the C<"switch"> feature: see
1514more information on C<"switch">. You can also access it by prefixing it
1501L<feature> for more information. You can also access it by
1515with C<CORE::>. Alternatively, include a C<use v5.10> or later to the
1502prefixing it with C<CORE::>. Alternately, include a C<use
1516current scope.
1503v5.10> or later to the current scope.
15171504
15181505=end original
15191506
1520このキーワードは C<"switch"> 機能によって有効になります; C<"switch"> に関する
1507このキーワードは C<"switch"> 機能によって有効になります:
15211508さらなる情報については L<feature> を参照してください。
15221509C<CORE::> を前置することによってもアクセスできます。
15231510または、現在のスコープに C<use v5.10> 以降を含めてください。
15241511
15251512=item caller EXPR
15261513X<caller> X<call stack> X<stack> X<stack trace>
15271514
15281515=item caller
15291516
15301517=for Pod::Functions get context of the current subroutine call
15311518
15321519=begin original
15331520
1534Returns the context of the current pure perl subroutine call. In scalar
1521Returns the context of the current subroutine call. In scalar context,
1535context, returns the caller's package name if there I<is> a caller (that is, if
1522returns the caller's package name if there I<is> a caller (that is, if
15361523we're in a subroutine or C<eval> or C<require>) and the undefined value
1537otherwise. caller never returns XS subs and they are skipped. The next pure
1524otherwise. In list context, returns
1538perl sub will appear instead of the XS sub in caller's return values. In list
1539context, caller returns
15401525
15411526=end original
15421527
1543その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。
1528その時点のサブルーチン呼び出しのコンテキストを返します。
15441529スカラコンテキストでは、呼び元が I<ある> 場合
15451530(サブルーチン、C<eval>、C<require> の中にいるとき) には
15461531呼び出し元のパッケージ名を返し、その他のときには未定義値を返します。
1547caller は XS サブルーチを返すことなくそれらは飛ばされます
1532リストコテキストでは、以下を返します:
1548XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に
1549なります。
1550リストコンテキストでは、caller は以下を返します:
15511533
15521534 # 0 1 2
15531535 ($package, $filename, $line) = caller;
15541536
15551537=begin original
15561538
15571539With EXPR, it returns some extra information that the debugger uses to
15581540print a stack trace. The value of EXPR indicates how many call frames
15591541to go back before the current one.
15601542
15611543=end original
15621544
15631545EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。
15641546EXPR の値は、現状から数えて、
15651547いくつ前のコールフレームまで戻るかを示します。
15661548
15671549 # 0 1 2 3 4
15681550 ($package, $filename, $line, $subroutine, $hasargs,
15691551
15701552 # 5 6 7 8 9 10
15711553 $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
15721554 = caller($i);
15731555
15741556=begin original
15751557
1576Here, $subroutine is the function that the caller called (rather than the
1558Here $subroutine may be C<(eval)> if the frame is not a subroutine
1577function containing the caller). Note that $subroutine may be C<(eval)> if
1559call, but an C<eval>. In such a case additional elements $evaltext and
1578the frame is not a subroutine call, but an C<eval>. In such a case
1579additional elements $evaltext and
15801560C<$is_require> are set: C<$is_require> is true if the frame is created by a
15811561C<require> or C<use> statement, $evaltext contains the text of the
15821562C<eval EXPR> statement. In particular, for an C<eval BLOCK> statement,
15831563$subroutine is C<(eval)>, but $evaltext is undefined. (Note also that
15841564each C<use> statement creates a C<require> frame inside an C<eval EXPR>
15851565frame.) $subroutine may also be C<(unknown)> if this particular
15861566subroutine happens to have been deleted from the symbol table.
15871567C<$hasargs> is true if a new instance of C<@_> was set up for the frame.
15881568C<$hints> and C<$bitmask> contain pragmatic hints that the caller was
1589compiled with. C<$hints> corresponds to C<$^H>, and C<$bitmask>
1569compiled with. The C<$hints> and C<$bitmask> values are subject to change
1590corresponds to C<${^WARNING_BITS}>. The
1570between versions of Perl, and are not meant for external use.
1591C<$hints> and C<$bitmask> values are subject
1592to change between versions of Perl, and are not meant for external use.
15931571
15941572=end original
15951573
1596ここ、$subroutine 、(caller を含む関数ではなく) caller が呼び出し
1574もしフレームがサブルーチン呼び出しではなく C<eval> だっ場合、この
1597関数です。
1575$subroutine は C<(eval)> になります。
1598フレームがサブルーチン呼び出しではなく C<eval> だった場合、この
1599$subroutine は C<(eval)> になることに注意してください。
16001576この場合、追加の要素である $evaltext と C<$is_require> がセットされます:
16011577C<$is_require> はフレームが C<require> または C<use> で作られた場合に
16021578真になり、$evaltext は C<eval EXPR> のテキストが入ります。
16031579特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、
16041580$evaltext は未定義値になります。
16051581(それぞれの C<use> は C<eval EXPR> の中で C<require> フレームを作ることに
16061582注意してください。)
16071583$subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は
16081584C<(unknown)> になります。
1609C<$hasargs> はこのフレーム用に C<@_> の新しい実体が設定された場合に
1585C<$hasargs> はこのフレーム用に C<@_> の新しい実体が設定された場合に真となります。
1610真となります。
16111586C<$hints> と C<$bitmask> は caller がコンパイルされたときの
16121587実際的なヒントを含みます。
1613C<$hints> は C<$^H> に対応し、C<$bitmask> は C<${^WARNING_BITS}> に
1614対応します。
16151588C<$hints> は C<$bitmask> は Perl のバージョンによって変更される
16161589可能性があるので、外部での使用を想定していません。
16171590
16181591=begin original
16191592
16201593C<$hinthash> is a reference to a hash containing the value of C<%^H> when the
16211594caller was compiled, or C<undef> if C<%^H> was empty. Do not modify the values
16221595of this hash, as they are the actual values stored in the optree.
16231596
16241597=end original
16251598
16261599C<$hinthash> は、caller がコンパイルされた時の C<%^H> の値を含む
16271600ハッシュへのリファレンスか、あるいは C<%^H> が空の場合は C<undef> です。
16281601このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。
16291602
16301603=begin original
16311604
16321605Furthermore, when called from within the DB package in
16331606list context, and with an argument, caller returns more
16341607detailed information: it sets the list variable C<@DB::args> to be the
16351608arguments with which the subroutine was invoked.
16361609
16371610=end original
16381611
16391612さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、
16401613caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を
16411614変数 C<@DB::args> に設定します。
16421615
16431616=begin original
16441617
16451618Be aware that the optimizer might have optimized call frames away before
16461619C<caller> had a chance to get the information. That means that C<caller(N)>
16471620might not return information about the call frame you expect it to, for
16481621C<< N > 1 >>. In particular, C<@DB::args> might have information from the
16491622previous time C<caller> was called.
16501623
16511624=end original
16521625
16531626C<caller> が情報を得る前にオプティマイザが呼び出しフレームを最適化して
16541627しまうかもしれないことに注意してください。
16551628これは、C<caller(N)> が C<< N > 1 >> のとき、
16561629あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。
16571630特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を
16581631持っているかもしれません。
16591632
16601633=begin original
16611634
16621635Be aware that setting C<@DB::args> is I<best effort>, intended for
16631636debugging or generating backtraces, and should not be relied upon. In
16641637particular, as C<@_> contains aliases to the caller's arguments, Perl does
16651638not take a copy of C<@_>, so C<@DB::args> will contain modifications the
16661639subroutine makes to C<@_> or its contents, not the original values at call
16671640time. C<@DB::args>, like C<@_>, does not hold explicit references to its
16681641elements, so under certain cases its elements may have become freed and
16691642reallocated for other variables or temporary values. Finally, a side effect
16701643of the current implementation is that the effects of C<shift @_> can
16711644I<normally> be undone (but not C<pop @_> or other splicing, I<and> not if a
16721645reference to C<@_> has been taken, I<and> subject to the caveat about reallocated
16731646elements), so C<@DB::args> is actually a hybrid of the current state and
16741647initial state of C<@_>. Buyer beware.
16751648
16761649=end original
16771650
16781651C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの
16791652生成を目的としていて、これに依存するべきではないということにも
16801653注意してください。
16811654特に、C<@_> は呼び出し元の引数へのエイリアスを含んでいるので、Perl は
16821655C<@_> のコピーを取らず、従って C<@DB::args> はサブルーチンが
16831656C<@_> やその内容に行った変更を含んでいて、呼び出し時の元の値ではありません。
16841657C<@DB::args> は、C<@_> と同様、その要素への明示的なリファレンスを
16851658保持しないので、ある種の状況では、解放されて他の変数や一時的な値のために
16861659再割り当てされているかもしれません。
16871660最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない
16881661(しかし C<pop @_> やその他の splice は違い、I<そして> もし
16891662C<@_> のリファレンスが取られると違い、I<そして> 再割り当てされた要素に関する
16901663問題になりやすいです)ことなので、C<@DB::args> は実際には現在の状態と
16911664C<@_> の初期状態との合成物となります。
16921665ご用心を。
16931666
16941667=item chdir EXPR
16951668X<chdir>
16961669X<cd>
16971670X<directory, change>
16981671
16991672=item chdir FILEHANDLE
17001673
17011674=item chdir DIRHANDLE
17021675
17031676=item chdir
17041677
17051678=for Pod::Functions change your current working directory
17061679
17071680=begin original
17081681
17091682Changes the working directory to EXPR, if possible. If EXPR is omitted,
17101683changes to the directory specified by C<$ENV{HOME}>, if set; if not,
17111684changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the
17121685variable C<$ENV{SYS$LOGIN}> is also checked, and used if it is set.) If
17131686neither is set, C<chdir> does nothing. It returns true on success,
17141687false otherwise. See the example under C<die>.
17151688
17161689=end original
17171690
17181691(可能であれば、) カレントディレクトリを EXPR に移します。
17191692EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに
17201693移ります; そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに
17211694移ります。
17221695(VMS では C<$ENV{SYS$LOGIN}> もチェックされ、もしセットされていれば
17231696使われます。)
17241697どちらも設定されていなければ、C<chdir> は何もしません。
17251698成功時には真を返し、そうでなければ偽を返します。
17261699C<die> の項の例を参照してください。
17271700
17281701=begin original
17291702
17301703On systems that support fchdir(2), you may pass a filehandle or
17311704directory handle as the argument. On systems that don't support fchdir(2),
17321705passing handles raises an exception.
17331706
17341707=end original
17351708
17361709fchdir(2) に対応しているシステムでは、ファイルハンドルや
17371710ディレクトリハンドルを引数として渡せます。
17381711fchdir に対応していないシステムでは、ハンドルを渡すと例外が発生します。
17391712
17401713=item chmod LIST
17411714X<chmod> X<permission> X<mode>
17421715
17431716=for Pod::Functions changes the permissions on a list of files
17441717
17451718=begin original
17461719
17471720Changes the permissions of a list of files. The first element of the
17481721list must be the numeric mode, which should probably be an octal
17491722number, and which definitely should I<not> be a string of octal digits:
17501723C<0644> is okay, but C<"0644"> is not. Returns the number of files
17511724successfully changed. See also L</oct> if all you have is a string.
17521725
17531726=end original
17541727
17551728LIST に含まれるファイルの、パーミッションを変更します。
17561729LIST の最初の要素は、数値表現のモードでなければなりません;
17571730恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の
17581731C<文字列ではいけません>: C<0644> は OK ですが、 C<'0644'> は
17591732だめ、ということです。
17601733変更に成功したファイルの数を返します。
17611734文字列を使いたい場合は、L</oct> を参照してください。
17621735
17631736 $cnt = chmod 0755, "foo", "bar";
17641737 chmod 0755, @executables;
17651738 $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
17661739 # --w----r-T
17671740 $mode = "0644"; chmod oct($mode), "foo"; # this is better
17681741 $mode = 0644; chmod $mode, "foo"; # this is best
17691742
17701743=begin original
17711744
17721745On systems that support fchmod(2), you may pass filehandles among the
17731746files. On systems that don't support fchmod(2), passing filehandles raises
17741747an exception. Filehandles must be passed as globs or glob references to be
17751748recognized; barewords are considered filenames.
17761749
17771750=end original
17781751
17791752fchmod(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。
17801753fchmod(2) に対応していないシステムでは、ファイルハンドルを渡すと
17811754例外が発生します。
17821755ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
17831756渡されなければなりません;
17841757裸の単語はファイル名として扱われます。
17851758
17861759 open(my $fh, "<", "foo");
17871760 my $perm = (stat $fh)[2] & 07777;
17881761 chmod($perm | 0600, $fh);
17891762
17901763=begin original
17911764
17921765You can also import the symbolic C<S_I*> constants from the C<Fcntl>
17931766module:
17941767
17951768=end original
17961769
17971770C<Fcntl> モジュールから C<S_I*> シンボル定数をインポートすることもできます:
17981771
17991772 use Fcntl qw( :mode );
18001773 chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
18011774 # Identical to the chmod 0755 of the example above.
18021775
18031776=begin original
18041777
18051778Portability issues: L<perlport/chmod>.
18061779
18071780=end original
18081781
18091782移植性の問題: L<perlport/chmod>。
18101783
18111784=item chomp VARIABLE
18121785X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol>
18131786
18141787=item chomp( LIST )
18151788
18161789=item chomp
18171790
18181791=for Pod::Functions remove a trailing record separator from a string
18191792
18201793=begin original
18211794
18221795This safer version of L</chop> removes any trailing string
18231796that corresponds to the current value of C<$/> (also known as
18241797$INPUT_RECORD_SEPARATOR in the C<English> module). It returns the total
18251798number of characters removed from all its arguments. It's often used to
18261799remove the newline from the end of an input record when you're worried
18271800that the final record may be missing its newline. When in paragraph
18281801mode (C<$/ = "">), it removes all trailing newlines from the string.
18291802When in slurp mode (C<$/ = undef>) or fixed-length record mode (C<$/> is
18301803a reference to an integer or the like; see L<perlvar>) chomp() won't
18311804remove anything.
18321805If VARIABLE is omitted, it chomps C<$_>. Example:
18331806
18341807=end original
18351808
18361809より安全な C<chop> (以下を参照してください) です; C<$/>
18371810(C<English> モジュールでは、$INPUT_RECORD_SEPARATOR とも言う) のその時点の
18381811値に対応する行末文字を削除します。
18391812全ての引数から削除した文字数の合計を返します。
18401813入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が
18411814入っているのかわからないような場合に、使用できます。
18421815段落モード (C<$/ = "">) では、レコードの最後の改行をすべて取り除きます。
18431816吸い込みモード (C<$/ = undef>) や 固定長レコードモード
18441817(C<$/> が整数へのリファレンスや類似のものの場合; L<perlvar>を参照してください)
18451818では、chomp() は何も取り除きません。
18461819VARIABLE が省略されると、$_ を対象として chomp します。
18471820例:
18481821
18491822 while (<>) {
18501823 chomp; # avoid \n on last field
18511824 @array = split(/:/);
18521825 # ...
18531826 }
18541827
18551828=begin original
18561829
1857If VARIABLE is a hash, it chomps the hash's values, but not its keys,
1830If VARIABLE is a hash, it chomps the hash's values, but not its keys.
1858resetting the C<each> iterator in the process.
18591831
18601832=end original
18611833
1862VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し
1834VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp します。
1863このプロセスの C<each> 反復子をリセットします。
18641835
18651836=begin original
18661837
18671838You can actually chomp anything that's an lvalue, including an assignment:
18681839
18691840=end original
18701841
18711842左辺値であれば、代入を含めて、任意のものを chomp できます:
18721843
18731844 chomp($cwd = `pwd`);
18741845 chomp($answer = <STDIN>);
18751846
18761847=begin original
18771848
18781849If you chomp a list, each element is chomped, and the total number of
18791850characters removed is returned.
18801851
18811852=end original
18821853
18831854リストを chomp すると、個々の要素が chomp され、
18841855削除された文字数の合計が返されます。
18851856
18861857=begin original
18871858
18881859Note that parentheses are necessary when you're chomping anything
18891860that is not a simple variable. This is because C<chomp $cwd = `pwd`;>
18901861is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as
18911862C<chomp( $cwd = `pwd` )> which you might expect. Similarly,
18921863C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than
18931864as C<chomp($a, $b)>.
18941865
18951866=end original
18961867
18971868単純な変数以外のものを chomp する場合はかっこが必要であることに
18981869注意してください。
18991870これは、C<chomp $cwd = `pwd`;> は、予測している
19001871C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と
19011872解釈されるからです。
19021873同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b>
19031874と解釈されます。
19041875
19051876=item chop VARIABLE
19061877X<chop>
19071878
19081879=item chop( LIST )
19091880
19101881=item chop
19111882
19121883=for Pod::Functions remove the last character from a string
19131884
19141885=begin original
19151886
19161887Chops off the last character of a string and returns the character
19171888chopped. It is much more efficient than C<s/.$//s> because it neither
19181889scans nor copies the string. If VARIABLE is omitted, chops C<$_>.
1919If VARIABLE is a hash, it chops the hash's values, but not its keys,
1890If VARIABLE is a hash, it chops the hash's values, but not its keys.
1920resetting the C<each> iterator in the process.
19211891
19221892=end original
19231893
19241894文字列の最後の文字を切り捨てて、その切り取った文字を返します。
19251895文字列の検索もコピーも行ないませんので
19261896C<s/.$//s> よりも、ずっと効率的です。
19271897VARIABLE が省略されると、C<$_> を対象として chop します。
1928VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、
1898VARIABLE がハッシュの場合、ハッシュの value を chop しますが
1929このプロセスの C<each> 反復子をリセットしま
1899key は chop しません
19301900
19311901=begin original
19321902
19331903You can actually chop anything that's an lvalue, including an assignment.
19341904
19351905=end original
19361906
19371907実際のところ、代入を含む左辺値となりうるなんでも chop できます。
19381908
19391909=begin original
19401910
19411911If you chop a list, each element is chopped. Only the value of the
19421912last C<chop> is returned.
19431913
19441914=end original
19451915
19461916リストを chop すると、個々の要素が chop されます。
19471917最後の C<chop> の値だけが返されます。
19481918
19491919=begin original
19501920
19511921Note that C<chop> returns the last character. To return all but the last
19521922character, use C<substr($string, 0, -1)>.
19531923
19541924=end original
19551925
19561926C<chop> は最後の文字を返すことに注意してください。
19571927最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を
19581928使ってください。
19591929
19601930=begin original
19611931
19621932See also L</chomp>.
19631933
19641934=end original
19651935
19661936L</chomp> も参照してください。
19671937
19681938=item chown LIST
19691939X<chown> X<owner> X<user> X<group>
19701940
19711941=for Pod::Functions change the ownership on a list of files
19721942
19731943=begin original
19741944
19751945Changes the owner (and group) of a list of files. The first two
19761946elements of the list must be the I<numeric> uid and gid, in that
19771947order. A value of -1 in either position is interpreted by most
19781948systems to leave that value unchanged. Returns the number of files
19791949successfully changed.
19801950
19811951=end original
19821952
19831953LIST に含まれるファイルの所有者 (とグループ) を変更します。
19841954LIST の最初の二つの要素には、I<数値表現> の uid と gid を
19851955この順序で与えなければなりません。
19861956どちらかの値を -1 にすると、ほとんどのシステムではその値は
19871957変更しないと解釈します。
19881958変更に成功したファイルの数を返します。
19891959
19901960 $cnt = chown $uid, $gid, 'foo', 'bar';
19911961 chown $uid, $gid, @filenames;
19921962
19931963=begin original
19941964
19951965On systems that support fchown(2), you may pass filehandles among the
19961966files. On systems that don't support fchown(2), passing filehandles raises
19971967an exception. Filehandles must be passed as globs or glob references to be
19981968recognized; barewords are considered filenames.
19991969
20001970=end original
20011971
20021972fchown(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。
20031973fchown(2) に対応していないシステムでは、ファイルハンドルを渡すと
20041974例外が発生します。
20051975ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
20061976渡されなければなりません; 裸の単語はファイル名として扱われます。
20071977
20081978=begin original
20091979
20101980Here's an example that looks up nonnumeric uids in the passwd file:
20111981
20121982=end original
20131983
20141984passwd ファイルから数値表現でない uid を検索する例を
20151985示します:
20161986
20171987 print "User: ";
20181988 chomp($user = <STDIN>);
20191989 print "Files: ";
20201990 chomp($pattern = <STDIN>);
20211991
20221992 ($login,$pass,$uid,$gid) = getpwnam($user)
20231993 or die "$user not in passwd file";
20241994
20251995 @ary = glob($pattern); # expand filenames
20261996 chown $uid, $gid, @ary;
20271997
20281998=begin original
20291999
20302000On most systems, you are not allowed to change the ownership of the
20312001file unless you're the superuser, although you should be able to change
20322002the group to any of your secondary groups. On insecure systems, these
20332003restrictions may be relaxed, but this is not a portable assumption.
20342004On POSIX systems, you can detect this condition this way:
20352005
20362006=end original
20372007
20382008ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を
20392009変更できますが、グループは実行者の副グループに変更できるべきです。
20402010安全でないシステムでは、この制限はゆるめられています; しかしこれは
20412011移植性のある仮定ではありません。
20422012POSIX システムでは、以下のようにしてこの条件を検出できます:
20432013
20442014 use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
20452015 $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED);
20462016
20472017=begin original
20482018
2049Portability issues: L<perlport/chown>.
2019Portability issues: L<perlport/chmod>.
20502020
20512021=end original
20522022
2053移植性の問題: L<perlport/chown>。
2023移植性の問題: L<perlport/chmod>。
20542024
20552025=item chr NUMBER
20562026X<chr> X<character> X<ASCII> X<Unicode>
20572027
20582028=item chr
20592029
20602030=for Pod::Functions get character this number represents
20612031
20622032=begin original
20632033
20642034Returns the character represented by that NUMBER in the character set.
20652035For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and
20662036chr(0x263a) is a Unicode smiley face.
20672037
20682038=end original
20692039
20702040特定の文字セットでの NUMBER で表わされる文字を返します。
20712041たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります;
20722042chr(0x263a) は Unicode のスマイリーフェイスです。
20732043
20742044=begin original
20752045
20762046Negative values give the Unicode replacement character (chr(0xfffd)),
20772047except under the L<bytes> pragma, where the low eight bits of the value
20782048(truncated to an integer) are used.
20792049
20802050=end original
20812051
20822052負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、
20832053L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが
20842054使われます。
20852055
20862056=begin original
20872057
20882058If NUMBER is omitted, uses C<$_>.
20892059
20902060=end original
20912061
20922062NUMBER が省略された場合、C<$_> を使います。
20932063
20942064=begin original
20952065
20962066For the reverse, use L</ord>.
20972067
20982068=end original
20992069
21002070逆を行うためには、L</ord> を参照してください。
21012071
21022072=begin original
21032073
21042074Note that characters from 128 to 255 (inclusive) are by default
21052075internally not encoded as UTF-8 for backward compatibility reasons.
21062076
21072077=end original
21082078
21092079128 から 255 までの文字は過去との互換性のために
21102080デフォルトでは UTF-8 Unicode にエンコードされません。
21112081
21122082=begin original
21132083
21142084See L<perlunicode> for more about Unicode.
21152085
21162086=end original
21172087
21182088Unicode については L<perlunicode> を参照してください。
21192089
21202090=item chroot FILENAME
21212091X<chroot> X<root>
21222092
21232093=item chroot
21242094
21252095=for Pod::Functions make directory new root for path lookups
21262096
21272097=begin original
21282098
21292099This function works like the system call by the same name: it makes the
21302100named directory the new root directory for all further pathnames that
21312101begin with a C</> by your process and all its children. (It doesn't
21322102change your current working directory, which is unaffected.) For security
21332103reasons, this call is restricted to the superuser. If FILENAME is
21342104omitted, does a C<chroot> to C<$_>.
21352105
21362106=end original
21372107
21382108同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに
21392109対して、C</>で始まるパス名に関して指定されたディレクトリを新しい
21402110ルートディレクトリとして扱います。
21412111(これはカレントディレクトリを変更しません; カレントディレクトリは
21422112そのままです。)
21432113セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。
21442114FILENAME を省略すると、C<$_> へ C<chroot> します。
21452115
21462116=begin original
21472117
2148B<NOTE:> It is good security practice to do C<chdir("/")> (to the root
2149directory) immediately after a C<chroot()>.
2150
2151=end original
2152
2153B<注意:> C<chroot()> の直後に (ルートディレクトリに) C<chdir("/")> するのは
2154セキュリティ上の良い習慣です。
2155
2156=begin original
2157
21582118Portability issues: L<perlport/chroot>.
21592119
21602120=end original
21612121
21622122移植性の問題: L<perlport/chroot>。
21632123
21642124=item close FILEHANDLE
21652125X<close>
21662126
21672127=item close
21682128
21692129=for Pod::Functions close file (or pipe or socket) handle
21702130
21712131=begin original
21722132
21732133Closes the file or pipe associated with the filehandle, flushes the IO
21742134buffers, and closes the system file descriptor. Returns true if those
21752135operations succeed and if no error was reported by any PerlIO
21762136layer. Closes the currently selected filehandle if the argument is
21772137omitted.
21782138
21792139=end original
21802140
21812141FILEHANDLE に対応したファイルまたはパイプをクローズして、
21822142IO バッファをフラッシュし、システムファイル記述子をクローズします。
21832143操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。
21842144引数が省略された場合、現在選択されているファイルハンドルをクローズします。
21852145
21862146=begin original
21872147
21882148You don't have to close FILEHANDLE if you are immediately going to do
21892149another C<open> on it, because C<open> closes it for you. (See
21902150L<open|/open FILEHANDLE>.) However, an explicit C<close> on an input file resets the line
21912151counter (C<$.>), while the implicit close done by C<open> does not.
21922152
21932153=end original
21942154
21952155クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう
21962156場合には、C<open> が自動的に C<close> を行ないますので、
21972157close FILEHANDLE する必要はありません。
21982158(L<open|/open FILEHANDLE> を参照してください。)
21992159ただし、明示的にクローズを行なったときにのみ入力ファイルの
22002160行番号 (C<$.>) のリセットが行なわれ、C<open> によって行なわれる
22012161暗黙の C<close> では行なわれません。
22022162
22032163=begin original
22042164
22052165If the filehandle came from a piped open, C<close> returns false if one of
22062166the other syscalls involved fails or if its program exits with non-zero
22072167status. If the only problem was that the program exited non-zero, C<$!>
22082168will be set to C<0>. Closing a pipe also waits for the process executing
22092169on the pipe to exit--in case you wish to look at the output of the pipe
22102170afterwards--and implicitly puts the exit status value of that command into
22112171C<$?> and C<${^CHILD_ERROR_NATIVE}>.
22122172
22132173=end original
22142174
22152175ファイルハンドルがパイプつきオープンなら、C<close> はその他の
22162176システムコールが失敗したりプログラムが非ゼロのステータスで終了した場合にも
22172177偽を返します。
22182178プログラムが非ゼロで終了しただけの場合は、C<$!>がC<0>にセットされます。
22192179後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で
22202180実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を
22212181C<$?> と C<${^CHILD_ERROR_NATIVE}> に設定します。
22222182
22232183=begin original
22242184
22252185If there are multiple threads running, C<close> on a filehandle from a
22262186piped open returns true without waiting for the child process to terminate,
22272187if the filehandle is still open in another thread.
22282188
22292189=end original
22302190
22312191複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する
22322192C<close> は、そのファイルハンドルが他のスレッドでまだ開かれている場合、
22332193子プロセスの終了を待たずに真を返します。
22342194
22352195=begin original
22362196
22372197Closing the read end of a pipe before the process writing to it at the
22382198other end is done writing results in the writer receiving a SIGPIPE. If
22392199the other end can't handle that, be sure to read all the data before
22402200closing the pipe.
22412201
22422202=end original
22432203
22442204書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、
22452205書き込み側に SIGPIPE が配送されます。
22462206書き込み側がこれを扱えない場合、パイプを閉じる前に
22472207確実に全てのデータが読み込まれるようにする必要があります。
22482208
22492209=begin original
22502210
22512211Example:
22522212
22532213=end original
22542214
22552215例:
22562216
22572217 open(OUTPUT, '|sort >foo') # pipe to sort
22582218 or die "Can't start sort: $!";
22592219 #... # print stuff to output
22602220 close OUTPUT # wait for sort to finish
22612221 or warn $! ? "Error closing sort pipe: $!"
22622222 : "Exit status $? from sort";
22632223 open(INPUT, 'foo') # get sort's results
22642224 or die "Can't open 'foo' for input: $!";
22652225
22662226=begin original
22672227
22682228FILEHANDLE may be an expression whose value can be used as an indirect
22692229filehandle, usually the real filehandle name or an autovivified handle.
22702230
22712231=end original
22722232
22732233FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと
22742234して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。
22752235
22762236=item closedir DIRHANDLE
22772237X<closedir>
22782238
22792239=for Pod::Functions close directory handle
22802240
22812241=begin original
22822242
22832243Closes a directory opened by C<opendir> and returns the success of that
22842244system call.
22852245
22862246=end original
22872247
22882248C<opendir> でオープンしたディレクトリをクローズし、
22892249システムコールの返り値を返します。
22902250
22912251=item connect SOCKET,NAME
22922252X<connect>
22932253
22942254=for Pod::Functions connect to a remote socket
22952255
22962256=begin original
22972257
22982258Attempts to connect to a remote socket, just like connect(2).
22992259Returns true if it succeeded, false otherwise. NAME should be a
23002260packed address of the appropriate type for the socket. See the examples in
23012261L<perlipc/"Sockets: Client/Server Communication">.
23022262
23032263=end original
23042264
23052265connect(2) システムコールと同様に、リモートソケットへの接続を試みます。
23062266成功時には真を、さもなければ偽を返します。
23072267NAME は、ソケットに対する、適切な型のパックされた
23082268アドレスでなければなりません。
23092269L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
23102270
23112271=item continue BLOCK
23122272X<continue>
23132273
23142274=item continue
23152275
23162276=for Pod::Functions optional trailing block in a while or foreach
23172277
23182278=begin original
23192279
23202280When followed by a BLOCK, C<continue> is actually a
23212281flow control statement rather than a function. If
23222282there is a C<continue> BLOCK attached to a BLOCK (typically in a C<while> or
23232283C<foreach>), it is always executed just before the conditional is about to
23242284be evaluated again, just like the third part of a C<for> loop in C. Thus
23252285it can be used to increment a loop variable, even when the loop has been
23262286continued via the C<next> statement (which is similar to the C C<continue>
23272287statement).
23282288
23292289=end original
23302290
23312291BLOCK が引き続く場合、C<continue> は実際には関数ではなく、実行制御文です。
2332C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)に
2292C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)にあると、
2333あると、これは条件文が再評価される直前に常に実行されます; これは C における
2293これは条件文が再評価される直前に常に実行されます; これは C における
23342294C<for> ループの 3 番目の部分と同様です。
23352295従って、これは C<next> 文 (これは C の C<continue> 文と似ています) を使って
23362296ループが繰り返されるときでもループ変数を増やしたいときに使えます。
23372297
23382298=begin original
23392299
23402300C<last>, C<next>, or C<redo> may appear within a C<continue>
23412301block; C<last> and C<redo> behave as if they had been executed within
23422302the main block. So will C<next>, but since it will execute a C<continue>
23432303block, it may be more entertaining.
23442304
23452305=end original
23462306
23472307C<last>, C<next>, C<redo> が C<continue> ブロック内に現れる可能性があります;
23482308C<last> と C<redo> はメインブロックの中で実行されたのと同じように振舞います。
23492309C<next> の場合は、C<continue> ブロックを実行することになるので、
23502310より面白いことになります。
23512311
23522312 while (EXPR) {
23532313 ### redo always comes here
23542314 do_something;
23552315 } continue {
23562316 ### next always comes here
23572317 do_something_else;
23582318 # then back the top to re-check EXPR
23592319 }
23602320 ### last always comes here
23612321
23622322=begin original
23632323
23642324Omitting the C<continue> section is equivalent to using an
23652325empty one, logically enough, so C<next> goes directly back
23662326to check the condition at the top of the loop.
23672327
23682328=end original
23692329
23702330C<continue> 節を省略するのは、空の節を指定したのと同じで、
23712331論理的には十分なので、この場合、C<next> は直接ループ先頭の
23722332条件チェックに戻ります。
23732333
23742334=begin original
23752335
23762336When there is no BLOCK, C<continue> is a function that
23772337falls through the current C<when> or C<default> block instead of iterating
23782338a dynamically enclosing C<foreach> or exiting a lexically enclosing C<given>.
23792339In Perl 5.14 and earlier, this form of C<continue> was
23802340only available when the C<"switch"> feature was enabled.
23812341See L<feature> and L<perlsyn/"Switch Statements"> for more
23822342information.
23832343
23842344=end original
23852345
23862346BLOCK がなければ、C<continue> は動的に囲まれた C<foreach> や
23872347レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または
23882348C<default> のブロックを通り抜けるための文です。
23892349Perl 5.14 以前では、この形式の C<continue> は C<"switch"> 機能が有効の
23902350場合にのみ利用可能です。
23912351さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を
23922352参照してください。
23932353
23942354=item cos EXPR
23952355X<cos> X<cosine> X<acos> X<arccosine>
23962356
23972357=item cos
23982358
23992359=for Pod::Functions cosine function
24002360
24012361=begin original
24022362
24032363Returns the cosine of EXPR (expressed in radians). If EXPR is omitted,
24042364takes the cosine of C<$_>.
24052365
24062366=end original
24072367
24082368(ラジアンで示した) EXPR の余弦を返します。
24092369EXPR が省略されたときには、C<$_> の余弦を取ります。
24102370
24112371=begin original
24122372
24132373For the inverse cosine operation, you may use the C<Math::Trig::acos()>
24142374function, or use this relation:
24152375
24162376=end original
24172377
24182378逆余弦を求めるためには、C<Math::Trig::acos()> 関数を使うか、
24192379以下の関係を使ってください。
24202380
24212381 sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
24222382
24232383=item crypt PLAINTEXT,SALT
24242384X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password>
24252385X<decrypt> X<cryptography> X<passwd> X<encrypt>
24262386
24272387=for Pod::Functions one-way passwd-style encryption
24282388
24292389=begin original
24302390
24312391Creates a digest string exactly like the crypt(3) function in the C
24322392library (assuming that you actually have a version there that has not
24332393been extirpated as a potential munition).
24342394
24352395=end original
24362396
24372397C ライブラリの crypt(3) 関数と全く同じように、ダイジェスト文字列を
24382398作成します(一時的な必需品として、まだ絶滅していないバージョンを
24392399持っていると仮定しています)。
24402400
24412401=begin original
24422402
24432403crypt() is a one-way hash function. The PLAINTEXT and SALT are turned
24442404into a short string, called a digest, which is returned. The same
24452405PLAINTEXT and SALT will always return the same string, but there is no
24462406(known) way to get the original PLAINTEXT from the hash. Small
24472407changes in the PLAINTEXT or SALT will result in large changes in the
24482408digest.
24492409
24502410=end original
24512411
24522412crypt() は一方向ハッシュ関数です。
24532413PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、
24542414それが返されます。
24552415PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから
24562416元の PLAINTEXT を得る(既知の)方法はありません。
24572417PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。
24582418
24592419=begin original
24602420
24612421There is no decrypt function. This function isn't all that useful for
24622422cryptography (for that, look for F<Crypt> modules on your nearby CPAN
24632423mirror) and the name "crypt" is a bit of a misnomer. Instead it is
24642424primarily used to check if two pieces of text are the same without
24652425having to transmit or store the text itself. An example is checking
24662426if a correct password is given. The digest of the password is stored,
24672427not the password itself. The user types in a password that is
24682428crypt()'d with the same salt as the stored digest. If the two digests
24692429match, the password is correct.
24702430
24712431=end original
24722432
24732433復号化関数はありません。
24742434この関数は暗号化のためにはまったく役に立ちません(このためには、
24752435お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、
24762436"crypt" という名前は少し間違った名前です。
24772437その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを
24782438転送したり保管したりせずにチェックするために使います。
24792439例としては、正しいパスワードが与えられたかどうかをチェックがあります。
24802440パスワード自身ではなく、パスワードのダイジェストが保管されます。
24812441ユーザーがパスワードを入力すると、保管されているダイジェストと同じ
24822442salt で crypt() します。
24832443二つのダイジェストが同じなら、パスワードは正しいです。
24842444
24852445=begin original
24862446
24872447When verifying an existing digest string you should use the digest as
24882448the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used
24892449to create the digest is visible as part of the digest. This ensures
24902450crypt() will hash the new string with the same salt as the digest.
24912451This allows your code to work with the standard L<crypt|/crypt> and
24922452with more exotic implementations. In other words, assume
24932453nothing about the returned string itself nor about how many bytes
24942454of SALT may matter.
24952455
24962456=end original
24972457
24982458すでにあるダイジェスト文字列を検証するには、ダイジェストを
24992459(C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。
25002460ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。
25012461これにより、crypt() は同じ salt で新しい文字列をダイジェストとして
25022462ハッシュ化できるようにします。
25032463これによって標準的な C<crypt|/crypt> や、より風変わりな実装でも動作します。
25042464言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、
25052465どのような仮定もしてはいけません。
25062466
25072467=begin original
25082468
25092469Traditionally the result is a string of 13 bytes: two first bytes of
25102470the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
25112471the first eight bytes of PLAINTEXT mattered. But alternative
25122472hashing schemes (like MD5), higher level security schemes (like C2),
25132473and implementations on non-Unix platforms may produce different
25142474strings.
25152475
25162476=end original
25172477
25182478伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて
25192479集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の
252024808 バイトだけが意味があります。
25212481しかし、(MD5 のように) 異なったハッシュ手法、
25222482(C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの
25232483実装などでは異なった文字列が生成されることがあります。
25242484
25252485=begin original
25262486
25272487When choosing a new salt create a random two character string whose
25282488characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.',
25292489'/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of
25302490characters is just a recommendation; the characters allowed in
25312491the salt depend solely on your system's crypt library, and Perl can't
25322492restrict what salts C<crypt()> accepts.
25332493
25342494=end original
25352495
25362496新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から
2537(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の
2497(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> のようにして)
2538ようにして)ランダムに2 つの文字を選びます。
2498ランダムに2 つの文字を選びます。
25392499この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化
25402500ライブラリだけに依存し、Perl は C<crypt()> がどのような salt を受け付けるかに
25412501ついて制限しません。
25422502
25432503=begin original
25442504
25452505Here's an example that makes sure that whoever runs this program knows
25462506their password:
25472507
25482508=end original
25492509
25502510プログラムを実行する人が、
25512511自分のパスワードを知っていることを確認する例です:
25522512
25532513 $pwd = (getpwuid($<))[1];
25542514
25552515 system "stty -echo";
25562516 print "Password: ";
25572517 chomp($word = <STDIN>);
25582518 print "\n";
25592519 system "stty echo";
25602520
25612521 if (crypt($word, $pwd) ne $pwd) {
25622522 die "Sorry...\n";
25632523 } else {
25642524 print "ok\n";
25652525 }
25662526
25672527=begin original
25682528
25692529Of course, typing in your own password to whoever asks you
25702530for it is unwise.
25712531
25722532=end original
25732533
25742534もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。
25752535
25762536=begin original
25772537
25782538The L<crypt|/crypt> function is unsuitable for hashing large quantities
25792539of data, not least of all because you can't get the information
25802540back. Look at the L<Digest> module for more robust algorithms.
25812541
25822542=end original
25832543
25842544L<crypt|/crypt> 関数は大量のデータのハッシュ化には向いていません; これは
25852545情報を戻せないという理由だけではありません。
25862546より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。
25872547
25882548=begin original
25892549
25902550If using crypt() on a Unicode string (which I<potentially> has
25912551characters with codepoints above 255), Perl tries to make sense
25922552of the situation by trying to downgrade (a copy of)
25932553the string back to an eight-bit byte string before calling crypt()
25942554(on that copy). If that works, good. If not, crypt() dies with
25952555C<Wide character in crypt>.
25962556
25972557=end original
25982558
25992559Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を
26002560含みます)に crypt() を使った場合、Perl は crypt() を呼び出す前に与えられた
26012561文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る)
26022562ことで状況のつじつまを合わせようとします。
26032563うまく動けば、それでよし。
26042564動かなければ、crypt() は C<Wide character in crypt> というメッセージと共に
26052565die します。
26062566
26072567=begin original
26082568
26092569Portability issues: L<perlport/crypt>.
26102570
26112571=end original
26122572
26132573移植性の問題: L<perlport/crypt>。
26142574
26152575=item dbmclose HASH
26162576X<dbmclose>
26172577
26182578=for Pod::Functions breaks binding on a tied dbm file
26192579
26202580=begin original
26212581
26222582[This function has been largely superseded by the C<untie> function.]
26232583
26242584=end original
26252585
26262586[この関数は、C<untie> 関数に大きくとって代わられました。]
26272587
26282588=begin original
26292589
26302590Breaks the binding between a DBM file and a hash.
26312591
26322592=end original
26332593
26342594DBM ファイルとハッシュの連結をはずします。
26352595
26362596=begin original
26372597
26382598Portability issues: L<perlport/dbmclose>.
26392599
26402600=end original
26412601
26422602移植性の問題: L<perlport/dbmclose>。
26432603
26442604=item dbmopen HASH,DBNAME,MASK
26452605X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm>
26462606
26472607=for Pod::Functions create binding on a tied dbm file
26482608
26492609=begin original
26502610
26512611[This function has been largely superseded by the
26522612L<tie|/tie VARIABLE,CLASSNAME,LIST> function.]
26532613
26542614=end original
26552615
26562616[この関数は、L<tie|/tie VARIABLE,CLASSNAME,LIST> 関数に
26572617大きくとって代わられました。]
26582618
26592619=begin original
26602620
26612621This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a
26622622hash. HASH is the name of the hash. (Unlike normal C<open>, the first
26632623argument is I<not> a filehandle, even though it looks like one). DBNAME
26642624is the name of the database (without the F<.dir> or F<.pag> extension if
26652625any). If the database does not exist, it is created with protection
26662626specified by MASK (as modified by the C<umask>). To prevent creation of
26672627the database if it doesn't exist, you may specify a MODE
26682628of 0, and the function will return a false value if it
26692629can't find an existing database. If your system supports
26702630only the older DBM functions, you may make only one C<dbmopen> call in your
26712631program. In older versions of Perl, if your system had neither DBM nor
26722632ndbm, calling C<dbmopen> produced a fatal error; it now falls back to
26732633sdbm(3).
26742634
26752635=end original
26762636
26772637dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは Berkeley DB ファイルを
26782638連想配列に結び付けます。
26792639HASH は、その連想配列の名前です。
26802640(普通の C<open> とは違って、最初の引数はファイルハンドル I<ではありません>;
26812641まあ、似たようなものですが)。
26822642DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても
26832643つけません)。
26842644データベースが存在しなければ、MODE MASK (を C<umask> で修正したもの) で
26852645指定されたモードで作られます。
26862646存在しないときにデータベースを作成しないようにするには、MODE に 0 を
26872647設定でき、データベースを見つけられなかった場合は関数は偽を返します。
26882648古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ
26892649dbmopen() を実行することができます。
26902650昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、
26912651dbmopen() を呼び出すと致命的エラーになります; 現在では sdbm(3) に
26922652フォールバックします。
26932653
26942654=begin original
26952655
26962656If you don't have write access to the DBM file, you can only read hash
26972657variables, not set them. If you want to test whether you can write,
26982658either use file tests or try setting a dummy hash entry inside an C<eval>
26992659to trap the error.
27002660
27012661=end original
27022662
27032663DBM ファイルに対して、書き込み権が無いときには、ハッシュ
27042664配列を読みだすことだけができ、設定することはできません。
27052665書けるか否かを調べたい場合には、ファイルテスト
27062666演算子を使うか、エラーをトラップするための C<eval> の中で、
27072667ダミーのハッシュエントリを設定してみることになります。
27082668
27092669=begin original
27102670
27112671Note that functions such as C<keys> and C<values> may return huge lists
27122672when used on large DBM files. You may prefer to use the C<each>
27132673function to iterate over large DBM files. Example:
27142674
27152675=end original
27162676
27172677大きな DBM ファイルを扱うときには、C<keys> や C<values> のような関数は、
27182678巨大なリストを返します。
27192679大きな DBM ファイルでは、C<each> 関数を使って繰り返しを行なった方が
27202680良いかもしれません。
27212681例:
27222682
27232683 # print out history file offsets
27242684 dbmopen(%HIST,'/usr/lib/news/history',0666);
27252685 while (($key,$val) = each %HIST) {
27262686 print $key, ' = ', unpack('L',$val), "\n";
27272687 }
27282688 dbmclose(%HIST);
27292689
27302690=begin original
27312691
27322692See also L<AnyDBM_File> for a more general description of the pros and
27332693cons of the various dbm approaches, as well as L<DB_File> for a particularly
27342694rich implementation.
27352695
27362696=end original
27372697
27382698様々な dbm 手法に対する利点欠点に関するより一般的な記述および
27392699特にリッチな実装である L<DB_File> に関しては
27402700L<AnyDBM_File> も参照してください。
27412701
27422702=begin original
27432703
27442704You can control which DBM library you use by loading that library
27452705before you call dbmopen():
27462706
27472707=end original
27482708
27492709dbmopen() を呼び出す前にライブラリを読み込むことで、
27502710どの DBM ライブラリを使うかを制御できます:
27512711
27522712 use DB_File;
27532713 dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
27542714 or die "Can't open netscape history file: $!";
27552715
27562716=begin original
27572717
27582718Portability issues: L<perlport/dbmopen>.
27592719
27602720=end original
27612721
27622722移植性の問題: L<perlport/dbmopen>。
27632723
27642724=item defined EXPR
27652725X<defined> X<undef> X<undefined>
27662726
27672727=item defined
27682728
27692729=for Pod::Functions test whether a value, variable, or function is defined
27702730
27712731=begin original
27722732
27732733Returns a Boolean value telling whether EXPR has a value other than
27742734the undefined value C<undef>. If EXPR is not present, C<$_> is
27752735checked.
27762736
27772737=end original
27782738
27792739左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、ブール値を
27802740返します。
27812741EXPR がない場合は、C<$_> がチェックされます。
27822742
27832743=begin original
27842744
27852745Many operations return C<undef> to indicate failure, end of file,
27862746system error, uninitialized variable, and other exceptional
27872747conditions. This function allows you to distinguish C<undef> from
27882748other values. (A simple Boolean test will not distinguish among
27892749C<undef>, zero, the empty string, and C<"0">, which are all equally
27902750false.) Note that since C<undef> is a valid scalar, its presence
27912751doesn't I<necessarily> indicate an exceptional condition: C<pop>
27922752returns C<undef> when its argument is an empty array, I<or> when the
27932753element to return happens to be C<undef>.
27942754
27952755=end original
27962756
27972757多くの演算子が、EOF や未初期化変数、システムエラーといった、
27982758例外的な条件で C<undef> を返すようになっています。
27992759この関数は、他の値と C<undef> とを区別するために使えます。
28002760(単純な真偽値テストでは、C<undef>、0、C<"0"> のいずれも偽を返すので、
28012761区別することができません。)
28022762C<undef> は有効なスカラ値なので、その存在が I<必ずしも>
28032763例外的な状況を表すとは限らないということに注意してください:
28042764C<pop> は引数が空の配列だったときに C<undef> を返しますが、
28052765I<あるいは> 返すべき要素がたまたま C<undef> だったのかもしれません。
28062766
28072767=begin original
28082768
28092769You may also use C<defined(&func)> to check whether subroutine C<&func>
28102770has ever been defined. The return value is unaffected by any forward
28112771declarations of C<&func>. A subroutine that is not defined
28122772may still be callable: its package may have an C<AUTOLOAD> method that
28132773makes it spring into existence the first time that it is called; see
28142774L<perlsub>.
28152775
28162776=end original
28172777
28182778C<defined(&func)> とすることでサブルーチン C<&func> の存在を、
28192779確かめることもできます。
28202780返り値は C<&func> の前方定義には影響されません。
28212781定義されていないサブルーチンも呼び出し可能です:
28222782最初に呼び出されたときに存在するようにするための
28232783C<AUTOLOAD> メソッドを持ったパッケージかもしれません;
28242784L<perlsub> を参照してください。
28252785
28262786=begin original
28272787
28282788Use of C<defined> on aggregates (hashes and arrays) is deprecated. It
28292789used to report whether memory for that aggregate had ever been
28302790allocated. This behavior may disappear in future versions of Perl.
28312791You should instead use a simple test for size:
28322792
28332793=end original
28342794
28352795集合(ハッシュや配列)への C<defined> の使用は非推奨です。
28362796これはその集合にメモリが割り当てられたかを報告するのに
28372797用いられていました。
28382798この振る舞いは将来のバージョンの Perl では消滅するかもしれません。
28392799代わりにサイズに対する簡単なテストを使うべきです。
28402800
28412801 if (@an_array) { print "has array elements\n" }
28422802 if (%a_hash) { print "has hash members\n" }
28432803
28442804=begin original
28452805
28462806When used on a hash element, it tells you whether the value is defined,
28472807not whether the key exists in the hash. Use L</exists> for the latter
28482808purpose.
28492809
28502810=end original
28512811
28522812ハッシュの要素に対して用いると、value が定義されているか否かを
28532813返すものであって、ハッシュに key が存在するか否かを返すのではありません。
28542814この用途には、L</exists> を使ってください。
28552815
28562816=begin original
28572817
28582818Examples:
28592819
28602820=end original
28612821
28622822例:
28632823
28642824 print if defined $switch{D};
28652825 print "$val\n" while defined($val = pop(@ary));
28662826 die "Can't readlink $sym: $!"
28672827 unless defined($value = readlink $sym);
28682828 sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
28692829 $debugging = 0 unless defined $debugging;
28702830
28712831=begin original
28722832
28732833Note: Many folks tend to overuse C<defined> and are then surprised to
28742834discover that the number C<0> and C<""> (the zero-length string) are, in fact,
28752835defined values. For example, if you say
28762836
28772837=end original
28782838
28792839注意: 多くの人々が C<defined> を使いすぎて、C<0> と C<"">(空文字列) が
28802840実際のところ定義された値であることに驚くようです。
28812841例えば、以下のように書くと:
28822842
28832843 "ab" =~ /a(.*)b/;
28842844
28852845=begin original
28862846
28872847The pattern match succeeds and C<$1> is defined, although it
28882848matched "nothing". It didn't really fail to match anything. Rather, it
28892849matched something that happened to be zero characters long. This is all
28902850very above-board and honest. When a function returns an undefined value,
28912851it's an admission that it couldn't give you an honest answer. So you
28922852should use C<defined> only when questioning the integrity of what
28932853you're trying to do. At other times, a simple comparison to C<0> or C<""> is
28942854what you want.
28952855
28962856=end original
28972857
28982858パターンマッチングが成功し、C<$1> が定義されても、実際には
28992859「なし」にマッチしています。
29002860しかしこれは何にもマッチしていないわけではありません。
29012861何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。
29022862これは非常に率直で正直なことです。
29032863関数が未定義値を返すとき、正直な答えを返すことができないことを
29042864告白しています。
29052865ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ
29062866C<defined> を使うべきです。
29072867その他の場合では、単に C<0> または C<""> と比較するというのがあなたの
29082868求めているものです。
29092869
29102870=begin original
29112871
29122872See also L</undef>, L</exists>, L</ref>.
29132873
29142874=end original
29152875
29162876L</undef>, L</exists>, L</ref> も参照してください。
29172877
29182878=item delete EXPR
29192879X<delete>
29202880
29212881=for Pod::Functions deletes a value from a hash
29222882
29232883=begin original
29242884
29252885Given an expression that specifies an element or slice of a hash, C<delete>
29262886deletes the specified elements from that hash so that exists() on that element
29272887no longer returns true. Setting a hash element to the undefined value does
29282888not remove its key, but deleting it does; see L</exists>.
29292889
29302890=end original
29312891
29322892ハッシュの要素やスライスを指定する式を取り、C<delete> は
29332893指定された要素をハッシュから削除するので、
29342894その要素に対する exists() はもはや真を返さなくなります。
29352895ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、
29362896delete では削除されます; L</exists> を参照してください。
29372897
29382898=begin original
29392899
29402900In list context, returns the value or values deleted, or the last such
29412901element in scalar context. The return list's length always matches that of
29422902the argument list: deleting non-existent elements returns the undefined value
29432903in their corresponding positions.
29442904
29452905=end original
29462906
29472907リストコンテキストでは削除された要素を返し、スカラコンテキストでは
29482908削除された要素のうち最後のものを返します。
29492909返されたリストの長さは常に引数リストの長さと一致します:
29502910存在しない要素を削除すると、対応する位置に未定義値をセットして返します。
29512911
29522912=begin original
29532913
29542914delete() may also be used on arrays and array slices, but its behavior is less
29552915straightforward. Although exists() will return false for deleted entries,
29562916deleting array elements never changes indices of existing values; use shift()
2957or splice() for that. However, if any deleted elements fall at the end of an
2917or splice() for that. However, if all deleted elements fall at the end of an
29582918array, the array's size shrinks to the position of the highest element that
2959still tests true for exists(), or to 0 if none do. In other words, an
2919still tests true for exists(), or to 0 if none do.
2960array won't have trailing nonexistent elements after a delete.
29612920
29622921=end original
29632922
29642923delete() は配列や配列のスライスに対しても使えますが、その振る舞いは
29652924あまり直感的ではありません。
29662925削除されたエントリに対しては exists() は偽を返しますが、
29672926配列要素を削除しても、存在する値の添え字は変わりません; このためには
29682927shift() や splice() を使ってください。
2969しかし、削除された要素が配列の末尾であった場合、配列のサイズは
2928しかし、全ての削除された要素が配列の末尾であった場合、配列のサイズは
29702929exists() が真となる最大位置の要素(それがない場合は 0)に切り詰められます。
2971言い換えると、delete の後には配列の末尾に値のない要素はありません。
29722930
29732931=begin original
29742932
29752933B<WARNING:> Calling delete on array values is deprecated and likely to
29762934be removed in a future version of Perl.
29772935
29782936=end original
29792937
29802938B<警告:> 配列の値に対して delete を呼び出すことは非推奨で、将来の
29812939バージョンの Perl では削除される予定です。
29822940
29832941=begin original
29842942
29852943Deleting from C<%ENV> modifies the environment. Deleting from a hash tied to
29862944a DBM file deletes the entry from the DBM file. Deleting from a C<tied> hash
29872945or array may not necessarily return anything; it depends on the implementation
29882946of the C<tied> package's DELETE method, which may do whatever it pleases.
29892947
29902948=end original
29912949
29922950C<%ENV> から削除を行なうと、実際に環境変数を変更します。
29932951DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを
29942952削除します。
29952953しかし、C<tie> されたハッシュや配列からの削除は、
29962954値を返すとは限りません; これは C<tie> されたパッケージの DELETE
29972955メソッドの実装に依存するので、どんなことでも起こります。
29982956
29992957=begin original
30002958
30012959The C<delete local EXPR> construct localizes the deletion to the current
30022960block at run time. Until the block exits, elements locally deleted
30032961temporarily no longer exist. See L<perlsub/"Localized deletion of elements
30042962of composite types">.
30052963
30062964=end original
30072965
30082966C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。
30092967ブロックから出るまで、ローカルで削除された要素は存在しなくなります。
30102968L<perlsub/"Localized deletion of elements of composite types"> を
30112969参照してください。
30122970
30132971 %hash = (foo => 11, bar => 22, baz => 33);
3014 $scalar = delete $hash{foo}; # $scalar is 11
2972 $scalar = delete $hash{foo}; # $scalar is 11
3015 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
2973 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
3016 @array = delete @hash{qw(foo baz)}; # @array is (undef,33)
2974 @array = delete @hash{qw(foo bar baz)}; # @array is (undef,undef,33)
30172975
30182976=begin original
30192977
30202978The following (inefficiently) deletes all the values of %HASH and @ARRAY:
30212979
30222980=end original
30232981
30242982以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します:
30252983
30262984 foreach $key (keys %HASH) {
30272985 delete $HASH{$key};
30282986 }
30292987
30302988 foreach $index (0 .. $#ARRAY) {
30312989 delete $ARRAY[$index];
30322990 }
30332991
30342992=begin original
30352993
30362994And so do these:
30372995
30382996=end original
30392997
30402998そして以下のようにもできます:
30412999
30423000 delete @HASH{keys %HASH};
30433001
30443002 delete @ARRAY[0 .. $#ARRAY];
30453003
30463004=begin original
30473005
30483006But both are slower than assigning the empty list
30493007or undefining %HASH or @ARRAY, which is the customary
30503008way to empty out an aggregate:
30513009
30523010=end original
30533011
30543012しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、
30553013単に空リストを代入するか、%HASH や @ARRAY を
30563014undef するより遅いです:
30573015
30583016 %HASH = (); # completely empty %HASH
30593017 undef %HASH; # forget %HASH ever existed
30603018
30613019 @ARRAY = (); # completely empty @ARRAY
30623020 undef @ARRAY; # forget @ARRAY ever existed
30633021
30643022=begin original
30653023
30663024The EXPR can be arbitrarily complicated provided its
30673025final operation is an element or slice of an aggregate:
30683026
30693027=end original
30703028
30713029最終的な操作が集合の要素かスライスである限りは、
30723030いずれかである限りは、EXPR には任意の複雑な式を置くことができます:
30733031
30743032 delete $ref->[$x][$y]{$key};
30753033 delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};
30763034
30773035 delete $ref->[$x][$y][$index];
30783036 delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
30793037
30803038=item die LIST
30813039X<die> X<throw> X<exception> X<raise> X<$@> X<abort>
30823040
30833041=for Pod::Functions raise an exception or bail out
30843042
30853043=begin original
30863044
30873045C<die> raises an exception. Inside an C<eval> the error message is stuffed
30883046into C<$@> and the C<eval> is terminated with the undefined value.
30893047If the exception is outside of all enclosing C<eval>s, then the uncaught
30903048exception prints LIST to C<STDERR> and exits with a non-zero value. If you
30913049need to exit the process with a specific exit code, see L</exit>.
30923050
30933051=end original
30943052
30953053C<die> は例外を発生させます。
30963054C<eval> の中で使用すると、エラーメッセージが C<$@> に入り、C<eval> は
30973055未定義値を返して終了します。
30983056例外が全ての C<eval> の外側の場合は、捕捉されなかった例外は LIST を
30993057C<STDERR> に表示して、非 0 の値で終了します。
31003058特定の終了コードでプロセスを終了させる必要がある場合は、L</exit> を
31013059参照してください。
31023060
31033061=begin original
31043062
31053063Equivalent examples:
31063064
31073065=end original
31083066
31093067等価な例:
31103068
31113069 die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
31123070 chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
31133071
31143072=begin original
31153073
31163074If the last element of LIST does not end in a newline, the current
31173075script line number and input line number (if any) are also printed,
31183076and a newline is supplied. Note that the "input line number" (also
31193077known as "chunk") is subject to whatever notion of "line" happens to
31203078be currently in effect, and is also available as the special variable
31213079C<$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
31223080
31233081=end original
31243082
31253083LIST の最後の要素が改行で終わっていなければ、その時点のスクリプト名と
31263084スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が、続けて
31273085表示されます。
31283086「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると
31293087仮定しています; また特殊変数 C<$.> でも利用可能です。
31303088L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。
31313089
31323090=begin original
31333091
31343092Hint: sometimes appending C<", stopped"> to your message will cause it
31353093to make better sense when the string C<"at foo line 123"> is appended.
31363094Suppose you are running script "canasta".
31373095
31383096=end original
31393097
31403098ヒント: メッセージの最後を C<", stopped"> のようなもので
31413099終わるようにしておけば、C<"at foo line 123"> のように
31423100追加されて、わかりやすくなります。
31433101"canasta" というスクリプトを実行しているとします。
31443102
31453103 die "/etc/games is no good";
31463104 die "/etc/games is no good, stopped";
31473105
31483106=begin original
31493107
31503108produce, respectively
31513109
31523110=end original
31533111
31543112これは、それぞれ以下のように表示します。
31553113
31563114 /etc/games is no good at canasta line 123.
31573115 /etc/games is no good, stopped at canasta line 123.
31583116
31593117=begin original
31603118
31613119If the output is empty and C<$@> already contains a value (typically from a
31623120previous eval) that value is reused after appending C<"\t...propagated">.
31633121This is useful for propagating exceptions:
31643122
31653123=end original
31663124
31673125出力が空で C<$@> が(典型的には前回の eval で)既に値を持っている場合、
31683126値は C<"\t...propagated"> を追加した後再利用されます。
31693127これは例外を伝播させる場合に有効です:
31703128
31713129 eval { ... };
31723130 die unless $@ =~ /Expected exception/;
31733131
31743132=begin original
31753133
31763134If the output is empty and C<$@> contains an object reference that has a
31773135C<PROPAGATE> method, that method will be called with additional file
31783136and line number parameters. The return value replaces the value in
31793137C<$@>; i.e., as if C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >>
31803138were called.
31813139
31823140=end original
31833141
31843142出力が空で、C<$@> が C<PROPAGATE> メソッドを含むオブジェクトへの
31853143リファレンスを含む場合、このメソッドが追加ファイルと行番号を引数として
31863144呼び出されます。
31873145返り値は C<$@> の値を置き換えます;
31883146つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が
31893147呼び出されたかのようになります。
31903148
31913149=begin original
31923150
31933151If C<$@> is empty then the string C<"Died"> is used.
31943152
31953153=end original
31963154
31973155C<$@> が空の場合、C<"Died"> が使われます。
31983156
31993157=begin original
32003158
32013159If an uncaught exception results in interpreter exit, the exit code is
32023160determined from the values of C<$!> and C<$?> with this pseudocode:
32033161
32043162=end original
32053163
32063164例外が捕捉されないとインタプリタは終了し、終了コードは以下の
32073165擬似コードのように、C<$!> と C<$?> の値から決定されます:
32083166
32093167 exit $! if $!; # errno
32103168 exit $? >> 8 if $? >> 8; # child exit status
32113169 exit 255; # last resort
32123170
32133171=begin original
32143172
32153173The intent is to squeeze as much possible information about the likely cause
32163174into the limited space of the system exit
32173175code. However, as C<$!> is the value
32183176of C's C<errno>, which can be set by any system call, this means that the value
32193177of the exit code used by C<die> can be non-predictable, so should not be relied
32203178upon, other than to be non-zero.
32213179
32223180=end original
32233181
32243182この意図は、できるだけ多くの似たような原因に関する情報を、システム終了
32253183コードという限られた領域に圧縮することです。
32263184しかし、C<$!> はシステムコールによって設定される可能性がある C の
32273185C<errno> の値であり、C<die> によって使われる終了コードの値は
32283186予測不能であることを意味するので、非 0 ということ以上にこの値に
32293187依存するべきではありません。
32303188
32313189=begin original
32323190
32333191You can also call C<die> with a reference argument, and if this is trapped
32343192within an C<eval>, C<$@> contains that reference. This permits more
32353193elaborate exception handling using objects that maintain arbitrary state
32363194about the exception. Such a scheme is sometimes preferable to matching
32373195particular string values of C<$@> with regular expressions. Because C<$@>
32383196is a global variable and C<eval> may be used within object implementations,
32393197be careful that analyzing the error object doesn't replace the reference in
32403198the global variable. It's easiest to make a local copy of the reference
32413199before any manipulations. Here's an example:
32423200
32433201=end original
32443202
32453203die() はリファレンス引数と共に呼び出すこともでき、これが
32463204eval() 内部でトラップされた場合、C<$@> はそのリファレンスを持ちます。
32473205これは、例外の性質について任意の状態を管理するオブジェクトを使った
32483206より複雑な例外処理の実装を可能にします。
32493207このようなスキームは C<$@> の特定の文字列値を正規表現を使って
32503208マッチングするときに時々好まれます。
32513209C<$@> はグローバル変数で、C<eval> はオブジェクト実装の内部で
32523210使われることがあるので、エラーオブジェクトの解析はグローバル変数の
32533211リファレンスを置き換えないことに注意を払わなければなりません。
32543212他の操作をする前にリファレンスのローカルコピーを
32553213作るのが一番簡単です。
32563214以下に例を示します:
32573215
32583216 use Scalar::Util "blessed";
32593217
32603218 eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) };
32613219 if (my $ev_err = $@) {
3262 if (blessed($ev_err)
3220 if (blessed($ev_err) && $ev_err->isa("Some::Module::Exception")) {
3263 && $ev_err->isa("Some::Module::Exception")) {
32643221 # handle Some::Module::Exception
32653222 }
32663223 else {
32673224 # handle all other possible exceptions
32683225 }
32693226 }
32703227
32713228=begin original
32723229
32733230Because Perl stringifies uncaught exception messages before display,
32743231you'll probably want to overload stringification operations on
32753232exception objects. See L<overload> for details about that.
32763233
32773234=end original
32783235
32793236perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、
32803237このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと
32813238思うかもしれません。
32823239これに関する詳細は L<overload> を参照してください。
32833240
32843241=begin original
32853242
32863243You can arrange for a callback to be run just before the C<die>
32873244does its deed, by setting the C<$SIG{__DIE__}> hook. The associated
32883245handler is called with the error text and can change the error
32893246message, if it sees fit, by calling C<die> again. See
32903247L<perlvar/%SIG> for details on setting C<%SIG> entries, and
32913248L<"eval BLOCK"> for some examples. Although this feature was
32923249to be run only right before your program was to exit, this is not
32933250currently so: the C<$SIG{__DIE__}> hook is currently called
32943251even inside eval()ed blocks/strings! If one wants the hook to do
32953252nothing in such situations, put
32963253
32973254=end original
32983255
32993256C<$SIG{__DIE__}> フックをセットすることで、C<die> がその行動を行う
33003257直前に実行されるコールバックを設定できます。
33013258結び付けられたハンドラはエラーテキストと共に呼び出され、
33023259必要なら再び C<die> を呼び出すことでエラーテキストを変更できアス。
33033260C<%SIG> のエントリをセットする詳細については、L<perlvar/%SIG> を、
33043261例については L<"eval BLOCK"> を参照してください。
33053262この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、
33063263現在ではそうではありません:
33073264C<$SIG{__DIE__}> フックは eval() されたブロック/文字列の中でも
33083265呼ばれるのです!
33093266もしそのような状況で何もしなくない時は:
33103267
33113268 die @_ if $^S;
33123269
33133270=begin original
33143271
33153272as the first line of the handler (see L<perlvar/$^S>). Because
33163273this promotes strange action at a distance, this counterintuitive
33173274behavior may be fixed in a future release.
33183275
33193276=end original
33203277
33213278をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。
33223279これは離れたところで不思議な行動を引き起こすので、
33233280この直感的でない振る舞いは将来のリリースで修正されるかもしれません。
33243281
33253282=begin original
33263283
33273284See also exit(), warn(), and the Carp module.
33283285
33293286=end original
33303287
33313288exit() と warn() と Carp モジュールも参照してください。
33323289
33333290=item do BLOCK
33343291X<do> X<block>
33353292
33363293=for Pod::Functions turn a BLOCK into a TERM
33373294
33383295=begin original
33393296
33403297Not really a function. Returns the value of the last command in the
33413298sequence of commands indicated by BLOCK. When modified by the C<while> or
33423299C<until> loop modifier, executes the BLOCK once before testing the loop
33433300condition. (On other statements the loop modifiers test the conditional
33443301first.)
33453302
33463303=end original
33473304
33483305実際は関数ではありません。
33493306BLOCK で示されるコマンド列の最後の値を返します。
33503307C<while> や C<until> ループ修飾子で修飾すると、
33513308ループ条件を調べる前に 1 度、BLOCK を実行します。
33523309(これ以外の実行文は、ループ修飾子により、条件が最初に
33533310調べられます。)
33543311
33553312=begin original
33563313
33573314C<do BLOCK> does I<not> count as a loop, so the loop control statements
33583315C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
33593316See L<perlsyn> for alternative strategies.
33603317
33613318=end original
33623319
33633320C<do BLOCK> はループとしては I<扱われません>; 従って、C<next>, C<last>,
33643321C<redo> といったループ制御文はブロックから抜けたり
33653322再開することはできません。
33663323その他の戦略については L<perlsyn> を参照してください。
33673324
3325=item do SUBROUTINE(LIST)
3326X<do>
3327
3328=begin original
3329
3330This form of subroutine call is deprecated. SUBROUTINE can be a bareword,
3331a scalar variable or a subroutine beginning with C<&>.
3332
3333=end original
3334
3335この形のサブルーチン呼び出しは非推奨です。
3336SUBROUTINE には裸の単語、スカラ変数、C<&> で始まるサブルーチンが使えます。
3337
33683338=item do EXPR
33693339X<do>
33703340
33713341=begin original
33723342
33733343Uses the value of EXPR as a filename and executes the contents of the
33743344file as a Perl script.
33753345
33763346=end original
33773347
33783348EXPR の値をファイル名として用い、そのファイルの中身を
33793349Perl のスクリプトとして実行します。
33803350
33813351 do 'stat.pl';
33823352
33833353=begin original
33843354
3385is largely like
3355is just like
33863356
33873357=end original
33883358
3389だいたい以下のものと同じようなものですが、
3359は以下のものと同じようなものですが、
33903360
33913361 eval `cat stat.pl`;
33923362
33933363=begin original
33943364
3395except that it's more concise, runs no external processes, keeps track of
3365except that it's more efficient and concise, keeps track of the current
3396the current
33973366filename for error messages, searches the C<@INC> directories, and updates
33983367C<%INC> if the file is found. See L<perlvar/@INC> and L<perlvar/%INC> for
33993368these variables. It also differs in that code evaluated with C<do FILENAME>
34003369cannot see lexicals in the enclosing scope; C<eval STRING> does. It's the
34013370same, however, in that it does reparse the file every time you call it,
34023371so you probably don't want to do this inside a loop.
34033372
34043373=end original
34053374
3406より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、
3375より効率的で、簡潔であり、エラーメッセージでファイル名がわかる、
34073376カレントディレクトリでファイルが見つからなかったときに
34083377C<@INC> ディレクトリを検索する、ファイルがあったときに C<%INC> を更新する、
34093378といったことがあります。
34103379これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を
34113380参照してください。
34123381C<do FILENAME> で評価されたコードは、入れ子のスコープにある
34133382レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、
34143383という違いがあります。
34153384しかし、呼び出すたびにファイルを解析し直すという点では同じですから、
34163385ループ内でこれを使おうなどとは、間違っても思ったりしないように。
34173386
34183387=begin original
34193388
34203389If C<do> can read the file but cannot compile it, it returns C<undef> and sets
34213390an error message in C<$@>. If C<do> cannot read the file, it returns undef
34223391and sets C<$!> to the error. Always check C<$@> first, as compilation
34233392could fail in a way that also sets C<$!>. If the file is successfully
34243393compiled, C<do> returns the value of the last expression evaluated.
34253394
34263395=end original
34273396
34283397C<do> がファイルを読み込めたがコンパイルできなかった場合、
34293398C<undef> を返して C<$@> にエラーメッセージを設定します。
34303399C<do>がファイルを読み込めなかった場合、undef を返して C<$!> に
34313400エラーを設定します。
34323401コンパイルに失敗したときにも C<$!> が設定されるので、常に C<$@> を
34333402先にチェックします。
34343403ファイルのコンパイルに成功した場合、C<do> は最後に評価した表現の値を返します。
34353404
34363405=begin original
34373406
34383407Inclusion of library modules is better done with the
34393408C<use> and C<require> operators, which also do automatic error checking
34403409and raise an exception if there's a problem.
34413410
34423411=end original
34433412
34443413ライブラリモジュールのインクルードには、C<use> 演算子や C<require> 演算子を
34453414使った方がよいです; これらは自動的にエラーをチェックして、問題があれば例外を
34463415発生させます。
34473416
34483417=begin original
34493418
34503419You might like to use C<do> to read in a program configuration
34513420file. Manual error checking can be done this way:
34523421
34533422=end original
34543423
34553424C<do> をプログラム設定ファイルを読み込むのに使いたいかもしれません。
34563425手動のエラーチェックは以下のようにして行えます:
34573426
34583427 # read in config files: system first, then user
34593428 for $file ("/share/prog/defaults.rc",
34603429 "$ENV{HOME}/.someprogrc")
34613430 {
34623431 unless ($return = do $file) {
34633432 warn "couldn't parse $file: $@" if $@;
34643433 warn "couldn't do $file: $!" unless defined $return;
34653434 warn "couldn't run $file" unless $return;
34663435 }
34673436 }
34683437
34693438=item dump LABEL
34703439X<dump> X<core> X<undump>
34713440
3472=item dump EXPR
3473
34743441=item dump
34753442
34763443=for Pod::Functions create an immediate core dump
34773444
34783445=begin original
34793446
34803447This function causes an immediate core dump. See also the B<-u>
34813448command-line switch in L<perlrun>, which does the same thing.
34823449Primarily this is so that you can use the B<undump> program (not
34833450supplied) to turn your core dump into an executable binary after
34843451having initialized all your variables at the beginning of the
34853452program. When the new binary is executed it will begin by executing
34863453a C<goto LABEL> (with all the restrictions that C<goto> suffers).
34873454Think of it as a goto with an intervening core dump and reincarnation.
3488If C<LABEL> is omitted, restarts the program from the top. The
3455If C<LABEL> is omitted, restarts the program from the top.
3489C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be
3490computed at run time, being otherwise identical to C<dump LABEL>.
34913456
34923457=end original
34933458
34943459この関数は即座にコアダンプを行ないます。
34953460同様のことを行う L<perlrun> の B<-u> オプションも参照してください。
34963461プログラムの先頭で、
34973462すべての変数を初期化したあとのコアダンプを B<undump>
34983463プログラム(提供していません)を使って実行ファイルに返ることができます。
34993464この新しいバイナリが実行されると、C<goto LABEL> から始めます
35003465(C<goto> に関する制限はすべて適用されます)。
35013466コアダンプをはさんで再生する goto と考えてください。
35023467C<LABEL> が省略されると、プログラムを先頭から再開します。
3503Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される
3504名前が使えます; その他は C<dump LABEL> と同一です。
35053468
35063469=begin original
35073470
35083471B<WARNING>: Any files opened at the time of the dump will I<not>
35093472be open any more when the program is reincarnated, with possible
35103473resulting confusion by Perl.
35113474
35123475=end original
35133476
35143477B<警告>: dump 時点でオープンされていたファイルは、プログラムが
35153478再生されたときには、もはやオープンされていません; Perl を混乱させる可能性が
35163479あります。
35173480
35183481=begin original
35193482
35203483This function is now largely obsolete, mostly because it's very hard to
35213484convert a core file into an executable. That's why you should now invoke
35223485it as C<CORE::dump()>, if you don't want to be warned against a possible
35233486typo.
35243487
35253488=end original
35263489
35273490この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを
35283491実行形式に変換するのが非常に困難であることです。
35293492これが、今ではタイプミスの可能性を警告されたくないなら
35303493C<CORE::dump()> として起動するべき理由です。
35313494
35323495=begin original
35333496
3534Unlike most named operators, this has the same precedence as assignment.
3535It is also exempt from the looks-like-a-function rule, so
3536C<dump ("foo")."bar"> will cause "bar" to be part of the argument to
3537C<dump>.
3538
3539=end original
3540
3541ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
3542また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と
3543すると "bar" は C<dump> への引数の一部になります。
3544
3545=begin original
3546
35473497Portability issues: L<perlport/dump>.
35483498
35493499=end original
35503500
35513501移植性の問題: L<perlport/dump>。
35523502
35533503=item each HASH
35543504X<each> X<hash, iterator>
35553505
35563506=item each ARRAY
35573507X<array, iterator>
35583508
35593509=item each EXPR
35603510
35613511=for Pod::Functions retrieve the next key/value pair from a hash
35623512
35633513=begin original
35643514
35653515When called on a hash in list context, returns a 2-element list
35663516consisting of the key and value for the next element of a hash. In Perl
356735175.12 and later only, it will also return the index and value for the next
35683518element of an array so that you can iterate over it; older Perls consider
35693519this a syntax error. When called in scalar context, returns only the key
35703520(not the value) in a hash, or the index in an array.
35713521
35723522=end original
35733523
35743524ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、
35753525ハッシュのキーと値を返します。
35763526Perl 5.12 以降でのみ、配列のインデックスと値からなる
357735272 要素のリストを返すので、反復を行えます; より古い Perl ではこれは
35783528文法エラーと考えられます。
35793529スカラコンテキストで呼び出した場合は、
35803530ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。
35813531
35823532=begin original
35833533
35843534Hash entries are returned in an apparently random order. The actual random
3585order is specific to a given hash; the exact same series of operations
3535order is subject to change in future versions of Perl, but it is
3586on two hashes may result in a different order for each hash. Any insertion
3536guaranteed to be in the same order as either the C<keys> or C<values>
3587into the hash may change the order, as will any deletion, with the exception
3537function would produce on the same (unmodified) hash. Since Perl
3588that the most recent key returned by C<each> or C<keys> may be deleted
35385.8.2 the ordering can be different even between different runs of Perl
3589without changing the order. So long as a given hash is unmodified you may
3539for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
3590rely on C<keys>, C<values> and C<each> to repeatedly return the same order
3591as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
3592details on why hash order is randomized. Aside from the guarantees
3593provided here the exact details of Perl's hash algorithm and the hash
3594traversal order are subject to change in any release of Perl.
35953540
35963541=end original
35973542
3598ハッシュ要素は見かけ上、ランダムな順序で返されます。
3543ハッシュエントリは見かけ上、ランダムな順序で返されます。
3599実際のランダムな順ハッシュに固有です; 二つハッシュに全く同じ一連
3544実際のランダムな順perl 将来バージョンでは変わるかもしれませんが、
3600操作を行っも、ハッシュによっ異なった順序になります。
3545C<keys> や C<values> 関数が同じ(変更されいない)ハッシュに対し
3601ハッシュへ挿入によって序が変わることがあります; 削除も同様ですが、
3546生成すると同じ番であることは保証されます
3602C<each> または C<keys> によって返されたもっとも最近のキーは順序を
3547Perl 5.8.2 以降ではセキュリティ上の理由により、
3603ことなく削除できす。
3548実行される毎に順番はかもしれせん
3604ハッシュが変更されない限り、C<keys>, C<values>, C<each> が繰り返同じ順序で
3549(L<perlsec/"Algorithmic Complexity Attacks"> を参照てください)。
3605返すことに依存してもかまいません。
3606なぜハッシュの順序がランダム化されているかの詳細については
3607L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
3608ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
3609正確な詳細は Perl のリリースによって変更される可能性があります。
36103550
36113551=begin original
36123552
36133553After C<each> has returned all entries from the hash or array, the next
36143554call to C<each> returns the empty list in list context and C<undef> in
36153555scalar context; the next call following I<that> one restarts iteration.
36163556Each hash or array has its own internal iterator, accessed by C<each>,
36173557C<keys>, and C<values>. The iterator is implicitly reset when C<each> has
36183558reached the end as just described; it can be explicitly reset by calling
36193559C<keys> or C<values> on the hash or array. If you add or delete a hash's
3620elements while iterating over it, the effect on the iterator is
3560elements while iterating over it, entries may be skipped or duplicated--so
3621unspecified; for example, entries may be skipped or duplicated--so don't
3561don't do that. Exception: In the current implementation, it is always safe
3622do that. Exception: It is always safe to delete the item most recently
3562to delete the item most recently returned by C<each()>, so the following
3623returned by C<each()>, so the following code works properly:
3563code works properly:
36243564
36253565=end original
36263566
36273567C<each> がハッシュをすべて読み込んでしまった後、リストコンテキストでは
36283568空リストが返され、スカラコンテキストでは C<undef> が返されます;
36293569I<そのあと> もう一度呼び出すと、再び反復を始めます。
36303570ハッシュや配列毎にそれぞれ反復子があり、C<each>、C<keys>、C<values> で
36313571アクセスされます。
36323572反復子は、前述したように C<each> が要素をすべて読むことによって
36333573暗黙にリセットされます; また、ハッシュや配列に対して
36343574C<keys HASH>, C<values HASH> を呼び出すことで明示的にリセットできます。
36353575繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、
3636反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします--
3576要素が飛ばされたり重複したりするので、てはいけせん。
3637従って、していけません。
3577例外: 現在の実装で一番最近に C<each()> から返されたものを削除するのは常に
3638例外: 一番最近に C<each()> から返されたものを削除するのは常に
36393578安全です; これは以下のようなコードが正しく動くことを意味します:
36403579
36413580 while (($key, $value) = each %hash) {
36423581 print $key, "\n";
36433582 delete $hash{$key}; # This is safe
36443583 }
36453584
36463585=begin original
36473586
3648Tied hashes may have a different ordering behaviour to perl's hash
3649implementation.
3650
3651=end original
3652
3653tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。
3654
3655=begin original
3656
36573587This prints out your environment like the printenv(1) program,
36583588but in a different order:
36593589
36603590=end original
36613591
36623592これは、printenv(1) プログラムのように環境変数を表示しますが、
36633593順序は異なっています:
36643594
36653595 while (($key,$value) = each %ENV) {
36663596 print "$key=$value\n";
36673597 }
36683598
36693599=begin original
36703600
36713601Starting with Perl 5.14, C<each> can take a scalar EXPR, which must hold
36723602reference to an unblessed hash or array. The argument will be dereferenced
36733603automatically. This aspect of C<each> is considered highly experimental.
36743604The exact behaviour may change in a future version of Perl.
36753605
36763606=end original
36773607
36783608Perl 5.14 から、C<each> はスカラの EXPR を取ることができるようになりました;
36793609これは bless されていないハッシュや配列へのリファレンスでなければなりません。
36803610引数は自動的にデリファレンスされます。
36813611C<each> のこの動作は高度に実験的であると考えられています。
36823612正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
36833613
36843614 while (($key,$value) = each $hashref) { ... }
36853615
36863616=begin original
36873617
3688As of Perl 5.18 you can use a bare C<each> in a C<while> loop,
3689which will set C<$_> on every iteration.
3690
3691=end original
3692
3693Perl 5.18 から C<while> ループの中に裸の C<each> を書けます; これは
3694繰り返し毎に C<$_> を設定します。
3695
3696 while(each %ENV) {
3697 print "$_=$ENV{$_}\n";
3698 }
3699
3700=begin original
3701
37023618To avoid confusing would-be users of your code who are running earlier
37033619versions of Perl with mysterious syntax errors, put this sort of thing at
37043620the top of your file to signal that your code will work I<only> on Perls of
37053621a recent vintage:
37063622
37073623=end original
37083624
37093625あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
37103626文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
37113627I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
37123628書いてください:
37133629
37143630 use 5.012; # so keys/values/each work on arrays
37153631 use 5.014; # so keys/values/each work on scalars (experimental)
3716 use 5.018; # so each assigns to $_ in a lone while test
37173632
37183633=begin original
37193634
37203635See also C<keys>, C<values>, and C<sort>.
37213636
37223637=end original
37233638
37243639C<keys> や C<values> や C<sort> も参照してください。
37253640
37263641=item eof FILEHANDLE
37273642X<eof>
37283643X<end of file>
37293644X<end-of-file>
37303645
37313646=item eof ()
37323647
37333648=item eof
37343649
37353650=for Pod::Functions test a filehandle for its end
37363651
37373652=begin original
37383653
37393654Returns 1 if the next read on FILEHANDLE will return end of file I<or> if
37403655FILEHANDLE is not open. FILEHANDLE may be an expression whose value
37413656gives the real filehandle. (Note that this function actually
37423657reads a character and then C<ungetc>s it, so isn't useful in an
37433658interactive context.) Do not read from a terminal file (or call
37443659C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such
37453660as terminals may lose the end-of-file condition if you do.
37463661
37473662=end original
37483663
37493664次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、
37503665I<または> FILEHANDLE がオープンされていないと、1 を返します。
37513666FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。
37523667(この関数は、実際に文字を読み、C<ungetc> を行ないますので、
37533668対話型の場合には有用ではありません。)
37543669端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を
37553670呼び出したりしてはいけません。
37563671そのようなことをすると、端末のようなファイルタイプは
37573672EOF 状態を失ってしまうかもしれません。
37583673
37593674=begin original
37603675
37613676An C<eof> without an argument uses the last file read. Using C<eof()>
37623677with empty parentheses is different. It refers to the pseudo file
37633678formed from the files listed on the command line and accessed via the
37643679C<< <> >> operator. Since C<< <> >> isn't explicitly opened,
37653680as a normal filehandle is, an C<eof()> before C<< <> >> has been
37663681used will cause C<@ARGV> to be examined to determine if input is
37673682available. Similarly, an C<eof()> after C<< <> >> has returned
37683683end-of-file will assume you are processing another C<@ARGV> list,
37693684and if you haven't set C<@ARGV>, will read input from C<STDIN>;
37703685see L<perlop/"I/O Operators">.
37713686
37723687=end original
37733688
37743689引数を省略した C<eof> は、最後に読み込みを行なったファイルを使います。
37753690空の括弧をつけた C<eof()> は異なります。
37763691これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で
37773692アクセスされる擬似ファイルを示すために用いられます。
37783693通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、
37793694C<< <> >> を使う前に C<eof()> を使うと、
37803695入力が正常か確認するために C<@ARGV> がテストされます。
37813696同様に、C<< <> >> が EOF を返した後の C<eof()> は、
37823697他の C<@ARGV> リストを処理していると仮定し、もし C<@ARGV> を
37833698セットしていないときは C<STDIN> から読み込みます;
37843699L<perlop/"I/O Operators"> を参照してください。
37853700
37863701=begin original
37873702
37883703In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> can be used to
37893704detect the end of each file, whereas C<eof()> will detect the end
37903705of the very last file only. Examples:
37913706
37923707=end original
37933708
37943709C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、
37953710C<eof> か C<eof(ARGV)> を用いるのに対して
37963711C<eof()> は最後のファイルの終わりのみを調べます。
37973712例:
37983713
37993714 # reset line numbering on each input file
38003715 while (<>) {
38013716 next if /^\s*#/; # skip comments
38023717 print "$.\t$_";
38033718 } continue {
38043719 close ARGV if eof; # Not eof()!
38053720 }
38063721
38073722 # insert dashes just before last line of last file
38083723 while (<>) {
38093724 if (eof()) { # check for end of last file
38103725 print "--------------\n";
38113726 }
38123727 print;
3813 last if eof(); # needed if we're reading from a terminal
3728 last if eof(); # needed if we're reading from a terminal
38143729 }
38153730
38163731=begin original
38173732
38183733Practical hint: you almost never need to use C<eof> in Perl, because the
38193734input operators typically return C<undef> when they run out of data or
38203735encounter an error.
38213736
38223737=end original
38233738
38243739現実的なヒント: Perl で C<eof> が必要となることは、ほとんどありません;
38253740基本的には、データがなくなったときやエラーがあったときに、入力演算子が
38263741C<undef> を返してくれるからです。
38273742
38283743=item eval EXPR
38293744X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute>
38303745X<error, handling> X<exception, handling>
38313746
38323747=item eval BLOCK
38333748
38343749=item eval
38353750
38363751=for Pod::Functions catch exceptions or compile and run code
38373752
38383753=begin original
38393754
3840In the first form, often referred to as a "string eval", the return
3755In the first form, the return value of EXPR is parsed and executed as if it
3841value of EXPR is parsed and executed as if it
38423756were a little Perl program. The value of the expression (which is itself
38433757determined within scalar context) is first parsed, and if there were no
38443758errors, executed as a block within the lexical context of the current Perl
38453759program. This means, that in particular, any outer lexical variables are
38463760visible to it, and any package variable settings or subroutine and format
38473761definitions remain afterwards.
38483762
38493763=end original
38503764
3851第一の形式(しばしば「文字列 eval」として参照されます)では、EXPR の返り値が
3765第一の形式では、EXPR の返り値が Perl のプログラムであるかのように
3852Perl のプログラムであるかのように解析され、実行されます。
3766解析され、実行されます。
38533767式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、
3854エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして
3768エラーがなければ
3855実行されます。
3769Perl プログラムのレキシカルコンテキストの中のブロックとして実行されます。
38563770これは、特に、外側のレキシカル変数は見えていて、パッケージ変数の設定や
38573771サブルーチンやフォーマットの定義はその後も残っているということです。
38583772
38593773=begin original
38603774
38613775Note that the value is parsed every time the C<eval> executes.
38623776If EXPR is omitted, evaluates C<$_>. This form is typically used to
38633777delay parsing and subsequent execution of the text of EXPR until run time.
38643778
38653779=end original
38663780
38673781返される値は C<eval> が実行されるごとにパースされることに注意してください。
38683782EXPR が省略されると、C<$_> を評価します。
38693783この形は主に EXPR のテキストのパースと実行を実行時にまで
38703784遅延させるのに用います。
38713785
38723786=begin original
38733787
38743788If the C<unicode_eval> feature is enabled (which is the default under a
38753789C<use 5.16> or higher declaration), EXPR or C<$_> is treated as a string of
38763790characters, so C<use utf8> declarations have no effect, and source filters
38773791are forbidden. In the absence of the C<unicode_eval> feature, the string
38783792will sometimes be treated as characters and sometimes as bytes, depending
38793793on the internal encoding, and source filters activated within the C<eval>
38803794exhibit the erratic, but historical, behaviour of affecting some outer file
38813795scope that is still compiling. See also the L</evalbytes> keyword, which
38823796always treats its input as a byte stream and works properly with source
38833797filters, and the L<feature> pragma.
38843798
38853799=end original
38863800
38873801C<unicode_eval> 機能が有効の場合(これは C<use 5.16> またはそれ以上が
38883802宣言されている場合はデフォルトです)、EXPR や C<$_> は文字単位の文字列として
38893803扱われるので、C<use utf8> 宣言は無効で、ソースフィルタは禁止されます。
38903804C<unicode_eval> 機能がなければ、文字列は内部エンコーディングに依存して
38913805時々文字単位として扱われ、時々バイト単位で扱われます; そして C<eval> の
38923806中で有効になったソースフィルタは、まだコンパイル中である一部の外側のファイル
38933807スコープに影響を与えるという、間違っているけれども歴史的な振る舞いを
38943808見せます。
38953809入力を常にバイト列として扱い、ソースフィルタが適切に動作する
38963810L</evalbytes> キーワードおよび L<feature> プラグマを参照してください。
38973811
38983812=begin original
38993813
3900Problems can arise if the string expands a scalar containing a floating
3901point number. That scalar can expand to letters, such as C<"NaN"> or
3902C<"Infinity">; or, within the scope of a C<use locale>, the decimal
3903point character may be something other than a dot (such as a comma).
3904None of these are likely to parse as you are likely expecting.
3905
3906=end original
3907
3908文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。
3909そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に
3910展開されることがあります; または、C<use locale> のスコープの中では、
3911小数点文字は (カンマのような) ドット以外の文字かもしれません。
3912これらはどれもあなたがおそらく予測しているようにはパースされません。
3913
3914=begin original
3915
39163814In the second form, the code within the BLOCK is parsed only once--at the
39173815same time the code surrounding the C<eval> itself was parsed--and executed
39183816within the context of the current Perl program. This form is typically
39193817used to trap exceptions more efficiently than the first (see below), while
39203818also providing the benefit of checking the code within BLOCK at compile
39213819time.
39223820
39233821=end original
39243822
39253823第二の形式では、BLOCK 内部のコードは一度だけパースされ -- コードを
39263824囲む C<eval> 自身がパースされるのと同じ時点です -- 現在の Perl プログラムの
39273825コンテキストで実行されます。
39283826この形式は典型的には第一の形式より効率的に例外をトラップします(後述);
39293827また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。
39303828
39313829=begin original
39323830
39333831The final semicolon, if any, may be omitted from the value of EXPR or within
39343832the BLOCK.
39353833
39363834=end original
39373835
3938最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から
3836最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から省くことができます。
3939省くことができます。
39403837
39413838=begin original
39423839
39433840In both forms, the value returned is the value of the last expression
39443841evaluated inside the mini-program; a return statement may be also used, just
39453842as with subroutines. The expression providing the return value is evaluated
39463843in void, scalar, or list context, depending on the context of the C<eval>
39473844itself. See L</wantarray> for more on how the evaluation context can be
39483845determined.
39493846
39503847=end original
39513848
39523849どちらの形式でも、返される値はミニプログラムの内部で最後に評価された
39533850表現の値です; サブルーチンと同様、return 文も使えます。
39543851返り値として提供される表現は、C<eval> 自身のコンテキストに依存して
39553852無効・スカラ・リストのいずれかのコンテキストで評価されます。
39563853評価コンテキストの決定方法についての詳細は L</wantarray> を参照してください。
39573854
39583855=begin original
39593856
39603857If there is a syntax error or runtime error, or a C<die> statement is
39613858executed, C<eval> returns C<undef> in scalar context
39623859or an empty list in list context, and C<$@> is set to the error
39633860message. (Prior to 5.16, a bug caused C<undef> to be returned
39643861in list context for syntax errors, but not for runtime errors.)
39653862If there was no error, C<$@> is set to the empty string. A
39663863control flow operator like C<last> or C<goto> can bypass the setting of
39673864C<$@>. Beware that using C<eval> neither silences Perl from printing
39683865warnings to STDERR, nor does it stuff the text of warning messages into C<$@>.
39693866To do either of those, you have to use the C<$SIG{__WARN__}> facility, or
39703867turn off warnings inside the BLOCK or EXPR using S<C<no warnings 'all'>>.
3971See L</warn>, L<perlvar>, and L<warnings>.
3868See L</warn>, L<perlvar>, L<warnings> and L<perllexwarn>.
39723869
39733870=end original
39743871
39753872構文エラーや実行エラーが発生するか、C<die> 文が実行されると、
39763873C<eval> はスカラコンテキストでは C<undef> が、リストコンテキストでは
39773874空リスト が設定されます。
3978(5.16 以前では、バグによって、リストコンテキストで構文エラーの時には
3875(Prior to 5.16, a bug caused C<undef> to be returned
3979C<undef> を返していましたが、実行エラーの時には返していませんでした。)
3876in list context for syntax errors, but not for runtime errors.)
39803877エラーがなければ、C<$@> は空文字列に設定されます。
3981C<last> や C<goto> のようなフロー制御演算子は C<$@> の設定を回避できます。
3878A
3879control flow operator like C<last> or C<goto> can bypass the setting of
3880C<$@>.
39823881C<eval> を、STDERR に警告メッセージを表示させない目的や、
39833882警告メッセージを C<$@> に格納する目的では使わないでください。
39843883そのような用途では、C<$SIG{__WARN__}> 機能を使うか、
39853884S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を
39863885オフにする必要があります。
3987L</warn>, L<perlvar>, L<warnings>, L<warnings> を参照してください。
3886L</warn>, L<perlvar>, L<warnings>, L<perllexwarn> を参照してください。
39883887
39893888=begin original
39903889
39913890Note that, because C<eval> traps otherwise-fatal errors, it is useful for
39923891determining whether a particular feature (such as C<socket> or C<symlink>)
39933892is implemented. It is also Perl's exception-trapping mechanism, where
39943893the die operator is used to raise exceptions.
39953894
39963895=end original
39973896
39983897C<eval> は、致命的エラーとなるようなものをトラップすることができるので、
39993898(C<socket> や C<symlink> といった) 特定の機能が実装されているかを、
40003899調べるために使うことができることに注意してください。
40013900die 演算子が例外を発生させるものとすれば、これはまた、Perl の例外捕捉機能と
40023901捉えることもできます。
40033902
40043903=begin original
40053904
40063905If you want to trap errors when loading an XS module, some problems with
40073906the binary interface (such as Perl version skew) may be fatal even with
40083907C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See L<perlrun>.
40093908
40103909=end original
40113910
40123911XS モジュールのロード中のエラーをトラップしたいなら、
40133912(Perl バージョンの違いのような) バイナリインターフェースに関する問題に
40143913ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない C<eval> でも
40153914致命的エラーになるかもしれません。
40163915L<perlrun> を参照してください。
40173916
40183917=begin original
40193918
40203919If the code to be executed doesn't vary, you may use the eval-BLOCK
40213920form to trap run-time errors without incurring the penalty of
40223921recompiling each time. The error, if any, is still returned in C<$@>.
40233922Examples:
40243923
40253924=end original
40263925
40273926実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、
40283927実行時エラーのトラップを行なうために、
40293928eval-BLOCK 形式を使うことができます。
40303929エラーがあれば、やはり $@ に返されます。
40313930例:
40323931
40333932 # make divide-by-zero nonfatal
40343933 eval { $answer = $a / $b; }; warn $@ if $@;
40353934
40363935 # same thing, but less efficient
40373936 eval '$answer = $a / $b'; warn $@ if $@;
40383937
40393938 # a compile-time error
40403939 eval { $answer = }; # WRONG
40413940
40423941 # a run-time error
40433942 eval '$answer ='; # sets $@
40443943
40453944=begin original
40463945
40473946Using the C<eval{}> form as an exception trap in libraries does have some
40483947issues. Due to the current arguably broken state of C<__DIE__> hooks, you
40493948may wish not to trigger any C<__DIE__> hooks that user code may have installed.
40503949You can use the C<local $SIG{__DIE__}> construct for this purpose,
40513950as this example shows:
40523951
40533952=end original
40543953
40553954C<eval{}> 形式をライブラリの例外を捕捉するために使うときには
40563955問題があります。
40573956現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、
40583957ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。
40593958この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。
40603959
40613960 # a private exception trap for divide-by-zero
40623961 eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
40633962 warn $@ if $@;
40643963
40653964=begin original
40663965
40673966This is especially significant, given that C<__DIE__> hooks can call
40683967C<die> again, which has the effect of changing their error messages:
40693968
40703969=end original
40713970
40723971これは特に顕著です; 与えられた C<__DIE__> フックは C<die> をもう一度
40733972呼び出すことができ、これによってエラーメッセージを変える効果があります:
40743973
40753974 # __DIE__ hooks may modify error messages
40763975 {
40773976 local $SIG{'__DIE__'} =
40783977 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
40793978 eval { die "foo lives here" };
40803979 print $@ if $@; # prints "bar lives here"
40813980 }
40823981
40833982=begin original
40843983
40853984Because this promotes action at a distance, this counterintuitive behavior
40863985may be fixed in a future release.
40873986
40883987=end original
40893988
40903989これは距離の離れた行動であるため、この直感的でない振る舞いは
40913990将来のリリースでは修正されるかもしれません。
40923991
40933992=begin original
40943993
40953994With an C<eval>, you should be especially careful to remember what's
40963995being looked at when:
40973996
40983997=end original
40993998
41003999C<eval> では、以下のような場合に、
41014000何が調べられるかに特に注意しておくことが必要です:
41024001
41034002 eval $x; # CASE 1
41044003 eval "$x"; # CASE 2
41054004
41064005 eval '$x'; # CASE 3
41074006 eval { $x }; # CASE 4
41084007
41094008 eval "\$$x++"; # CASE 5
41104009 $$x++; # CASE 6
41114010
41124011=begin original
41134012
41144013Cases 1 and 2 above behave identically: they run the code contained in
41154014the variable $x. (Although case 2 has misleading double quotes making
41164015the reader wonder what else might be happening (nothing is).) Cases 3
41174016and 4 likewise behave in the same way: they run the code C<'$x'>, which
41184017does nothing but return the value of $x. (Case 4 is preferred for
41194018purely visual reasons, but it also has the advantage of compiling at
41204019compile-time instead of at run-time.) Case 5 is a place where
41214020normally you I<would> like to use double quotes, except that in this
41224021particular situation, you can just use symbolic references instead, as
41234022in case 6.
41244023
41254024=end original
41264025
41274026上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の
41284027コードを実行します。
41294028(ただし、CASE 2 では、必要のないダブルクォートによって、
41304029読む人が何が起こるか混乱することでしょう (何も起こりませんが)。)
41314030同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に
41324031何もしない C<$x> というコードを実行します
41334032(純粋に見た目の問題で、CASE 4 が好まれますが、
41344033実行時でなくコンパイル時にコンパイルされるという利点もあります)。
41354034CASE 5 の場合は、通常ダブルクォートを使用します。
41364035この状況を除けば、CASE 6 のように、単に
41374036シンボリックリファレンスを使えば良いでしょう。
41384037
41394038=begin original
41404039
41414040Before Perl 5.14, the assignment to C<$@> occurred before restoration
41424041of localized variables, which means that for your code to run on older
41434042versions, a temporary is required if you want to mask some but not all
41444043errors:
41454044
41464045=end original
41474046
41484047Perl 5.14 より前では、C<$@> への代入はローカル化された変数の復帰の前に
41494048起きるので、古いバージョンで実行される場合は、全てではなく一部だけの
41504049エラーをマスクしたい場合には一時変数が必要です:
41514050
41524051 # alter $@ on nefarious repugnancy only
41534052 {
41544053 my $e;
41554054 {
4156 local $@; # protect existing $@
4055 local $@; # protect existing $@
4157 eval { test_repugnancy() };
4056 eval { test_repugnancy() };
4158 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
4057 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
4159 $@ =~ /nefarious/ and $e = $@;
4058 $@ =~ /nefarious/ and $e = $@;
41604059 }
41614060 die $e if defined $e
41624061 }
41634062
41644063=begin original
41654064
41664065C<eval BLOCK> does I<not> count as a loop, so the loop control statements
41674066C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
41684067
41694068=end original
41704069
41714070C<eval BLOCK> はループとして I<扱われません>; 従って、C<next>, C<last>,
41724071C<redo> といったループ制御文でブロックから離れたり再実行したりはできません。
41734072
41744073=begin original
41754074
4176An C<eval ''> executed within a subroutine defined
4075An C<eval ''> executed within the C<DB> package doesn't see the usual
4177in the C<DB> package doesn't see the usual
41784076surrounding lexical scope, but rather the scope of the first non-DB piece
41794077of code that called it. You don't normally need to worry about this unless
41804078you are writing a Perl debugger.
41814079
41824080=end original
41834081
4184C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の
4082C<DB> パッケージ内で C<eval ''> を実行すると、通常の
41854083レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の
41864084スコープになります。
41874085Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は
41884086ありません。
41894087
41904088=item evalbytes EXPR
41914089X<evalbytes>
41924090
41934091=item evalbytes
41944092
41954093=for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream
41964094
41974095=begin original
41984096
41994097This function is like L</eval> with a string argument, except it always
42004098parses its argument, or C<$_> if EXPR is omitted, as a string of bytes. A
42014099string containing characters whose ordinal value exceeds 255 results in an
42024100error. Source filters activated within the evaluated code apply to the
42034101code itself.
42044102
42054103=end original
42064104
42074105この関数は文字列引数の L</eval> と同様ですが、引数(EXPR が省略された場合は
42084106C<$_>) を常にバイト単位のの文字列として扱います。
42094107序数が 255 を超える文字を含む文字列はエラーになります。
42104108eval されたコード内で有効になったソースフィルタはコード自体に適用されます。
42114109
42124110=begin original
42134111
42144112This function is only available under the C<evalbytes> feature, a
42154113C<use v5.16> (or higher) declaration, or with a C<CORE::> prefix. See
42164114L<feature> for more information.
42174115
42184116=end original
42194117
42204118この関数は C<evalbytes> 機能が有効か、C<use v5.16> (またはそれ以上) が
42214119宣言されるか、C<CORE::> 接頭辞付きの場合にのみ有効です。
42224120さらなる情報については L<feature> を参照してください。
42234121
42244122=item exec LIST
42254123X<exec> X<execute>
42264124
42274125=item exec PROGRAM LIST
42284126
42294127=for Pod::Functions abandon this program to run another
42304128
42314129=begin original
42324130
42334131The C<exec> function executes a system command I<and never returns>;
42344132use C<system> instead of C<exec> if you want it to return. It fails and
42354133returns false only if the command does not exist I<and> it is executed
42364134directly instead of via your system's command shell (see below).
42374135
42384136=end original
42394137
42404138C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>;
42414139戻って欲しい場合には、C<exec>ではなく C<system> 関数を使ってください。
42424140コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく
42434141直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。
42444142
42454143=begin original
42464144
42474145Since it's a common mistake to use C<exec> instead of C<system>, Perl
42484146warns you if C<exec> is called in void context and if there is a following
42494147statement that isn't C<die>, C<warn>, or C<exit> (if C<-w> is set--but
42504148you always do that, right?). If you I<really> want to follow an C<exec>
42514149with some other statement, you can use one of these styles to avoid the warning:
42524150
42534151=end original
42544152
42554153C<system> の代わりに C<exec> を使うというよくある間違いを防ぐために、
42564154C<exec> が無効コンテキストで呼び出されて、引き続く文が C<die>, C<warn>,
42574155C<exit> 以外の場合、Perl は警告を出します(C<-w> がセットされている場合 --
42584156でもいつもセットしてますよね?)。
42594157もし I<本当に> C<exec> の後に他の文を書きたい場合、以下のどちらかの
42604158スタイルを使うことで警告を回避できます:
42614159
42624160 exec ('foo') or print STDERR "couldn't exec foo: $!";
42634161 { exec ('foo') }; print STDERR "couldn't exec foo: $!";
42644162
42654163=begin original
42664164
4267If there is more than one argument in LIST, this calls execvp(3) with the
4165If there is more than one argument in LIST, or if LIST is an array
4268arguments in LIST. If there is only one element in LIST, the argument is
4166with more than one value, calls execvp(3) with the arguments in LIST.
4269checked for shell metacharacters, and if there are any, the entire
4167If there is only one scalar argument or an array with one element in it,
4270argument is passed to the system's command shell for parsing (this is
4168the argument is checked for shell metacharacters, and if there are any,
4271C</bin/sh -c> on Unix platforms, but varies on other platforms). If
4169the entire argument is passed to the system's command shell for parsing
4272there are no shell metacharacters in the argument, it is split into words
4170(this is C</bin/sh -c> on Unix platforms, but varies on other platforms).
4273and passed directly to C<execvp>, which is more efficient. Examples:
4171If there are no shell metacharacters in the argument, it is split into
4172words and passed directly to C<execvp>, which is more efficient.
4173Examples:
42744174
42754175=end original
42764176
4277LIST に複数の引数がある場合、LIST の引数を使って execvp(3) を呼び出します。
4177LIST に複数の引数がある場合、LIST が複の値持つ
4278LIST に要素が一つみの場合には、の引数からシェルのメタ文字チェックし
4178配列の場合には、LIST の引数を使ってexecvp(3) を呼び出します。
4279もしメタ文字があれば、引数全体をシステムコマンドシェル(これUnix で
41791 つのスカラ引数のみまた要素が一つの配列の場合に、その引数から
4180シェルのメタ文字をチェックし、もし、メタ文字があれば、
4181引数全体をシステムのコマンドシェル(これはUnix では
42804182C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。
42814183シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に
42824184渡されます; この方がより効率的です。
42834185例:
42844186
42854187 exec '/bin/echo', 'Your arguments are: ', @ARGV;
42864188 exec "sort $outfile | uniq";
42874189
42884190=begin original
42894191
42904192If you don't really want to execute the first argument, but want to lie
42914193to the program you are executing about its own name, you can specify
42924194the program you actually want to run as an "indirect object" (without a
4293comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always
4195comma) in front of the LIST. (This always forces interpretation of the
4294forces interpretation of the LIST as a multivalued list, even if there
4196LIST as a multivalued list, even if there is only a single scalar in
4295is only a single scalar in the list.) Example:
4197the list.) Example:
42964198
42974199=end original
42984200
4299第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の
4201第一引数に指定するものを本当に実行したいが、実行する
4300名前を教えたい場合には、C<exec PROGRAM LIST> ように、LIST の前に
4202プログラムに対して別の名前を教えたい場合には、LISTの前に
4301「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを
4203「間接オブジェクト」(コンマなし) として実際に
4302指定することができます。
4204実行したいプログラムを指定することができます。
4303(これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、
4205(これによって、LIST に単一のスカラしかなくても、複数
4304LIST の解釈を行ないます。)
4206値のリストであるように、LIST の解釈を行ないます。)
43054207例:
43064208
43074209 $shell = '/bin/csh';
43084210 exec $shell '-sh'; # pretend it's a login shell
43094211
43104212=begin original
43114213
43124214or, more directly,
43134215
43144216=end original
43154217
43164218あるいは、より直接的に、
43174219
43184220 exec {'/bin/csh'} '-sh'; # pretend it's a login shell
43194221
43204222=begin original
43214223
43224224When the arguments get executed via the system shell, results are
43234225subject to its quirks and capabilities. See L<perlop/"`STRING`">
43244226for details.
43254227
43264228=end original
43274229
43284230引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって
43294231変わります。
43304232詳細については L<perlop/"`STRING`"> を参照してください。
43314233
43324234=begin original
43334235
43344236Using an indirect object with C<exec> or C<system> is also more
43354237secure. This usage (which also works fine with system()) forces
43364238interpretation of the arguments as a multivalued list, even if the
43374239list had just one argument. That way you're safe from the shell
43384240expanding wildcards or splitting up words with whitespace in them.
43394241
43404242=end original
43414243
43424244C<exec> や C<system> で間接オブジェクトを使うのもより安全です。
43434245この使い方(system() でも同様にうまく動きます)は、たとえ引数が一つだけの
43444246場合も、複数の値を持つリストとして引数を解釈することを強制します。
43454247この方法で、シェルによるワイルドカード展開や、空白による単語の分割から
43464248守られます。
43474249
43484250 @args = ( "echo surprise" );
43494251
43504252 exec @args; # subject to shell escapes
43514253 # if @args == 1
43524254 exec { $args[0] } @args; # safe even with one-arg list
43534255
43544256=begin original
43554257
43564258The first version, the one without the indirect object, ran the I<echo>
43574259program, passing it C<"surprise"> an argument. The second version didn't;
43584260it tried to run a program named I<"echo surprise">, didn't find it, and set
43594261C<$?> to a non-zero value indicating failure.
43604262
43614263=end original
43624264
43634265間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、
43644266C<"surprise"> が引数として渡されます。
43654267二つ目のバージョンでは違います; I<"echo surprise"> という名前の
43664268プログラムを実行しようとして、見つからないので、失敗したことを示すために
43674269C<$?> に非 0 がセットされます。
43684270
43694271=begin original
43704272
4371On Windows, only the C<exec PROGRAM LIST> indirect object syntax will
4273Beginning with v5.6.0, Perl attempts to flush all files opened for
4372reliably avoid using the shell; C<exec LIST>, even with more than one
4274output before the exec, but this may not be supported on some platforms
4373element, will fall back to the shell if the first spawn fails.
4275(see L<perlport>). To be safe, you may need to set C<$|> ($AUTOFLUSH
4276in English) or call the C<autoflush()> method of C<IO::Handle> on any
4277open handles to avoid lost output.
43744278
43754279=end original
43764280
4377Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを
4378使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が
4379あっても、最初の spawn が失敗したときにシェルに
4380フォールバックすることがあります。
4381
4382=begin original
4383
4384Perl attempts to flush all files opened for output before the exec,
4385but this may not be supported on some platforms (see L<perlport>).
4386To be safe, you may need to set C<$|> ($AUTOFLUSH in English) or
4387call the C<autoflush()> method of C<IO::Handle> on any open handles
4388to avoid lost output.
4389
4390=end original
4391
43924281v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを
43934282フラッシュしようとしますが、これに対応していないプラットフォームもあります
43944283(L<perlport> を参照してください)。
43954284安全のためには、出力が重複するのを避けるために、全てのオープンしている
43964285ハンドルに対して C<$|> (English モジュールでは $AUTOFLUSH) を設定するか、
43974286C<IO::Handle> モジュールの C<autoflush()> メソッドをを呼ぶ必要が
43984287あるかもしれません。
43994288
44004289=begin original
44014290
44024291Note that C<exec> will not call your C<END> blocks, nor will it invoke
44034292C<DESTROY> methods on your objects.
44044293
44054294=end original
44064295
44074296C<exec> は C<END> ブロックや、オブジェクトの C<DESTROY> メソッドを
44084297起動しないことに注意してください。
44094298
44104299=begin original
44114300
44124301Portability issues: L<perlport/exec>.
44134302
44144303=end original
44154304
44164305移植性の問題: L<perlport/exec>。
44174306
44184307=item exists EXPR
44194308X<exists> X<autovivification>
44204309
44214310=for Pod::Functions test whether a hash key is present
44224311
44234312=begin original
44244313
44254314Given an expression that specifies an element of a hash, returns true if the
44264315specified element in the hash has ever been initialized, even if the
44274316corresponding value is undefined.
44284317
44294318=end original
44304319
44314320ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、
44324321たとえ対応する値が未定義でも真を返します。
44334322
44344323 print "Exists\n" if exists $hash{$key};
44354324 print "Defined\n" if defined $hash{$key};
44364325 print "True\n" if $hash{$key};
44374326
44384327=begin original
44394328
44404329exists may also be called on array elements, but its behavior is much less
44414330obvious and is strongly tied to the use of L</delete> on arrays. B<Be aware>
44424331that calling exists on array values is deprecated and likely to be removed in
44434332a future version of Perl.
44444333
44454334=end original
44464335
44474336exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに
44484337不明確で、配列に対する L</delete> の使用と強く結びついています。
44494338配列の値に対して exists を呼び出すのは非推奨であり、将来のバージョンの
44504339Perl では削除されるかもしれないことを B<注意してください> 。
44514340
44524341 print "Exists\n" if exists $array[$index];
44534342 print "Defined\n" if defined $array[$index];
44544343 print "True\n" if $array[$index];
44554344
44564345=begin original
44574346
44584347A hash or array element can be true only if it's defined and defined only if
44594348it exists, but the reverse doesn't necessarily hold true.
44604349
44614350=end original
44624351
44634352ハッシュまたは配列要素は、定義されているときにのみ真となり、
44644353存在しているときにのみ定義されますが、逆は必ずしも真ではありません。
44654354
44664355=begin original
44674356
44684357Given an expression that specifies the name of a subroutine,
44694358returns true if the specified subroutine has ever been declared, even
44704359if it is undefined. Mentioning a subroutine name for exists or defined
44714360does not count as declaring it. Note that a subroutine that does not
44724361exist may still be callable: its package may have an C<AUTOLOAD>
44734362method that makes it spring into existence the first time that it is
44744363called; see L<perlsub>.
44754364
44764365=end original
44774366
44784367引数としてサブルーチンの名前が指定された場合、
44794368指定されたサブルーチンが宣言されていれば(たとえ未定義でも)
44804369真を返します。
44814370exists や defined のために言及されているサブルーチン名は
44824371宣言としてのカウントに入りません。
44834372存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください:
44844373パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に
44854374存在を作り出すかもしれません; L<perlsub> を参照してください。
44864375
44874376 print "Exists\n" if exists &subroutine;
44884377 print "Defined\n" if defined &subroutine;
44894378
44904379=begin original
44914380
44924381Note that the EXPR can be arbitrarily complicated as long as the final
44934382operation is a hash or array key lookup or subroutine name:
44944383
44954384=end original
44964385
44974386最終的な操作がハッシュや配列の key による検索またはサブルーチン名である限りは、
44984387EXPR には任意の複雑な式を置くことができます:
44994388
45004389 if (exists $ref->{A}->{B}->{$key}) { }
45014390 if (exists $hash{A}{B}{$key}) { }
45024391
45034392 if (exists $ref->{A}->{B}->[$ix]) { }
45044393 if (exists $hash{A}{B}[$ix]) { }
45054394
45064395 if (exists &{$ref->{A}{B}{$key}}) { }
45074396
45084397=begin original
45094398
45104399Although the most deeply nested array or hash element will not spring into
45114400existence just because its existence was tested, any intervening ones will.
45124401Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring
45134402into existence due to the existence test for the $key element above.
45144403This happens anywhere the arrow operator is used, including even here:
45154404
45164405=end original
45174406
45184407最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは
45194408存在するようにはなりませんが、途中のものは存在するようになります。
45204409従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の
45214410存在をテストしたことによって存在するようになります。
45224411これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも
45234412起こります。
45244413
45254414 undef $ref;
45264415 if (exists $ref->{"Some key"}) { }
45274416 print $ref; # prints HASH(0x80d3d5c)
45284417
45294418=begin original
45304419
45314420This surprising autovivification in what does not at first--or even
45324421second--glance appear to be an lvalue context may be fixed in a future
45334422release.
45344423
45354424=end original
45364425
45374426一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの
45384427自動有効化は将来のリリースでは修正されるでしょう。
45394428
45404429=begin original
45414430
45424431Use of a subroutine call, rather than a subroutine name, as an argument
45434432to exists() is an error.
45444433
45454434=end original
45464435
45474436exists() の引数としてサブルーチン名でなくサブルーチン呼び出しを使うと、
45484437エラーになります。
45494438
45504439 exists &sub; # OK
45514440 exists &sub(); # Error
45524441
45534442=item exit EXPR
45544443X<exit> X<terminate> X<abort>
45554444
45564445=item exit
45574446
45584447=for Pod::Functions terminate this program
45594448
45604449=begin original
45614450
45624451Evaluates EXPR and exits immediately with that value. Example:
45634452
45644453=end original
45654454
45664455EXPR を評価し、即座にその値を持って終了します。
45674456例:
45684457
45694458 $ans = <STDIN>;
45704459 exit 0 if $ans =~ /^[Xx]/;
45714460
45724461=begin original
45734462
45744463See also C<die>. If EXPR is omitted, exits with C<0> status. The only
45754464universally recognized values for EXPR are C<0> for success and C<1>
45764465for error; other values are subject to interpretation depending on the
45774466environment in which the Perl program is running. For example, exiting
4578446769 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause
45794468the mailer to return the item undelivered, but that's not true everywhere.
45804469
45814470=end original
45824471
45834472C<die> も参照してください。
45844473EXPR が省略された場合には、ステータスを C<0> として終了します。
45854474EXPR の値として広く利用可能なのは C<0> が成功で C<1> が
45864475エラーということだけです; その他の値は、 Perl が実行される環境によって異なる
45874476解釈がされる可能性があります。
45884477例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると
45894478メーラーはアイテムを配達せずに差し戻しますが、
45904479これはいつでも真ではありません。
45914480
45924481=begin original
45934482
45944483Don't use C<exit> to abort a subroutine if there's any chance that
45954484someone might want to trap whatever error happened. Use C<die> instead,
45964485which can be trapped by an C<eval>.
45974486
45984487=end original
45994488
46004489誰かが発生したエラーをトラップしようと考えている可能性がある場合は、
46014490サブルーチンの中断に C<exit> を使わないでください。
46024491代わりに C<eval> でトラップできる C<die> を使ってください。
46034492
46044493=begin original
46054494
46064495The exit() function does not always exit immediately. It calls any
46074496defined C<END> routines first, but these C<END> routines may not
46084497themselves abort the exit. Likewise any object destructors that need to
46094498be called are called before the real exit. C<END> routines and destructors
46104499can change the exit status by modifying C<$?>. If this is a problem, you
46114500can call C<POSIX::_exit($status)> to avoid END and destructor processing.
46124501See L<perlmod> for details.
46134502
46144503=end original
46154504
46164505exit() 関数は常に直ちに終了するわけではありません。
46174506まず、定義されている END ルーチンを呼び出しますが、
46184507C<END> ルーチン自身は exit を止められません。
46194508同様に、呼び出す必要のあるオブジェクトデストラクタは
46204509すべて、実際の終了前に呼び出されます。
46214510C<END> ルーチンとデストラクタは C<$?> を修正することで終了コードを
46224511変更できます。
46234512これが問題になる場合は、END やデストラクタが実行されることを
46244513防ぐために C<POSIX::_exit($status)> を呼び出してください。
46254514詳しくは L<perlmod> を参照してください。
46264515
46274516=begin original
46284517
46294518Portability issues: L<perlport/exit>.
46304519
46314520=end original
46324521
46334522移植性の問題: L<perlport/exit>。
46344523
46354524=item exp EXPR
46364525X<exp> X<exponential> X<antilog> X<antilogarithm> X<e>
46374526
46384527=item exp
46394528
46404529=for Pod::Functions raise I<e> to a power
46414530
46424531=begin original
46434532
46444533Returns I<e> (the natural logarithm base) to the power of EXPR.
46454534If EXPR is omitted, gives C<exp($_)>.
46464535
46474536=end original
46484537
46494538I<e> (自然対数の底) の EXPR 乗を返します。
46504539EXPR を省略した場合には、C<exp($_)> を返します。
46514540
46524541=item fc EXPR
46534542X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold>
46544543
46554544=item fc
46564545
46574546=for Pod::Functions +fc return casefolded version of a string
46584547
46594548=begin original
46604549
46614550Returns the casefolded version of EXPR. This is the internal function
46624551implementing the C<\F> escape in double-quoted strings.
46634552
46644553=end original
46654554
46664555EXPR の畳み込み版を返します。
46674556これは、ダブルクォート文字列における、C<\F> エスケープを
46684557実装する内部関数です。
46694558
46704559=begin original
46714560
46724561Casefolding is the process of mapping strings to a form where case
46734562differences are erased; comparing two strings in their casefolded
46744563form is effectively a way of asking if two strings are equal,
46754564regardless of case.
46764565
46774566=end original
46784567
46794568畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です;
46804569畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に
46814570関わらず等しいかどうかを比較する効率的な方法です。
46824571
46834572=begin original
46844573
46854574Roughly, if you ever found yourself writing this
46864575
46874576=end original
46884577
46894578おおよそ、自分自身で以下のように書いていたとしても
46904579
4691 lc($this) eq lc($that) # Wrong!
4580 lc($this) eq lc($that) # Wrong!
46924581 # or
4693 uc($this) eq uc($that) # Also wrong!
4582 uc($this) eq uc($that) # Also wrong!
46944583 # or
4695 $this =~ /^\Q$that\E\z/i # Right!
4584 $this =~ /\Q$that/i # Right!
46964585
46974586=begin original
46984587
46994588Now you can write
47004589
47014590=end original
47024591
47034592今では以下のように書けます
47044593
47054594 fc($this) eq fc($that)
47064595
47074596=begin original
47084597
47094598And get the correct results.
47104599
47114600=end original
47124601
47134602そして正しい結果を得られます。
47144603
47154604=begin original
47164605
4717Perl only implements the full form of casefolding,
4606Perl only implements the full form of casefolding.
4718but you can access the simple folds using L<Unicode::UCD/casefold()> and
4719L<Unicode::UCD/prop_invmap()>.
47204607For further information on casefolding, refer to
47214608the Unicode Standard, specifically sections 3.13 C<Default Case Operations>,
472246094.2 C<Case-Normative>, and 5.18 C<Case Mappings>,
47234610available at L<http://www.unicode.org/versions/latest/>, as well as the
47244611Case Charts available at L<http://www.unicode.org/charts/case/>.
47254612
47264613=end original
47274614
4728Perl は完全な形式の畳み込みのみを実装していますが、
4615Perl は完全な形式の畳み込みのみを実装しています
4729L<Unicode::UCD/casefold()> と L<Unicode::UCD/prop_invmap()> を使って
4730単純なたたみ込みにアクセスできます。
47314616畳み込みに関するさらなる情報については、
47324617L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に
473346183.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18
47344619C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で
47354620利用可能なケース表を参照してください。
47364621
47374622=begin original
47384623
47394624If EXPR is omitted, uses C<$_>.
47404625
47414626=end original
47424627
47434628EXPR が省略されると、C<$_> を使います。
47444629
47454630=begin original
47464631
4747This function behaves the same way under various pragma, such as within
4632This function behaves the same way under various pragma, such as in a locale,
4748S<C<"use feature 'unicode_strings">>, as L</lc> does, with the single
4633as L</lc> does.
4749exception of C<fc> of LATIN CAPITAL LETTER SHARP S (U+1E9E) within the
4750scope of S<C<use locale>>. The foldcase of this character would
4751normally be C<"ss">, but as explained in the L</lc> section, case
4752changes that cross the 255/256 boundary are problematic under locales,
4753and are hence prohibited. Therefore, this function under locale returns
4754instead the string C<"\x{17F}\x{17F}">, which is the LATIN SMALL LETTER
4755LONG S. Since that character itself folds to C<"s">, the string of two
4756of them together should be equivalent to a single U+1E9E when foldcased.
47574634
47584635=end original
47594636
4760この関数は、S<C<"use feature 'unicode_strings">> のようなさまざまなプラグマの
4637この関数は、ロケールのようなさまざまなプラグマの影響下では、
4761影響下では、L</lc> と同様に振る舞います; 但し、S<C<use locale>> の
4638L</lc> と同様に振る舞います
4762スコープ内での LATIN CAPITAL LETTER SHARP S (U+1E9E) の C<fc> は例外です。
4763この文字の畳み込み文字は普通は C<"ss"> ですが、L</lc> の節で
4764説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は
4765問題があるので、禁止されています。
4766従って、ロケールの基ではこの関数は代わりに LATIN SMALL LETTER LONG S である
4767C<"\x{17F}\x{17F}"> を返します。
4768この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は
4769畳み込まれた場合は単一の U+1E9E と等価になります。
47704639
47714640=begin original
47724641
47734642While the Unicode Standard defines two additional forms of casefolding,
47744643one for Turkic languages and one that never maps one character into multiple
47754644characters, these are not provided by the Perl core; However, the CPAN module
47764645C<Unicode::Casing> may be used to provide an implementation.
47774646
47784647=end original
47794648
47804649Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して
47814650一つの文字が複数の文字にマッピングされないもの、を定義していますが、
47824651これらは Perl コアでは提供されません; しかし、CPAN モジュール
47834652C<Unicode::Casing> が実装を提供しています。
47844653
47854654=begin original
47864655
47874656This keyword is available only when the C<"fc"> feature is enabled,
4788or when prefixed with C<CORE::>; See L<feature>. Alternately,
4657or when prefixed with C<CORE::>; See L<feature>. Alternately,
47894658include a C<use v5.16> or later to the current scope.
47904659
47914660=end original
47924661
47934662このキーワードは C<"fc"> 機能が有効のときか、C<CORE::> が
47944663前置されたときにのみ利用可能です; L<feature> を参照してください。
47954664または、現在のスコープに C<use v5.16> またはそれ以上を含めてください。
47964665
47974666=item fcntl FILEHANDLE,FUNCTION,SCALAR
47984667X<fcntl>
47994668
48004669=for Pod::Functions file control system call
48014670
48024671=begin original
48034672
48044673Implements the fcntl(2) function. You'll probably have to say
48054674
48064675=end original
48074676
48084677fcntl(2) 関数を実装します。
48094678正しい定数定義を得るために、まず
48104679
48114680 use Fcntl;
48124681
48134682=begin original
48144683
48154684first to get the correct constant definitions. Argument processing and
48164685value returned work just like C<ioctl> below.
48174686For example:
48184687
48194688=end original
48204689
48214690と書くことが必要でしょう。
48224691引数の処理と返り値については、下記の C<ioctl> と同様に動作します。
48234692例えば:
48244693
48254694 use Fcntl;
48264695 fcntl($filehandle, F_GETFL, $packed_return_buffer)
48274696 or die "can't fcntl F_GETFL: $!";
48284697
48294698=begin original
48304699
48314700You don't have to check for C<defined> on the return from C<fcntl>.
48324701Like C<ioctl>, it maps a C<0> return from the system call into
48334702C<"0 but true"> in Perl. This string is true in boolean context and C<0>
48344703in numeric context. It is also exempt from the normal B<-w> warnings
48354704on improper numeric conversions.
48364705
48374706=end original
48384707
48394708C<fcntl> からの返り値のチェックに C<defined> を使う必要はありません。
48404709C<ioctl> と違って、C<fnctl> はシステムコールの結果が C<0> だった場合は
48414710C<"0 だが真">を返します。
48424711この文字列は真偽値コンテキストでは真となり、
48434712数値コンテキストでは C<0> になります。
48444713これはまた、不適切な数値変換に関する通常の B<-w> 警告を回避します。
48454714
48464715=begin original
48474716
48484717Note that C<fcntl> raises an exception if used on a machine that
48494718doesn't implement fcntl(2). See the Fcntl module or your fcntl(2)
48504719manpage to learn what functions are available on your system.
48514720
48524721=end original
48534722
48544723fcntl(2) が実装されていないマシンでは、C<fcntl>は例外を
48554724引き起こすことに注意してください。
48564725システムでどの関数が利用可能かについては Fcntl モジュールや
48574726fcntl(2) man ページを参照してください。
48584727
48594728=begin original
48604729
48614730Here's an example of setting a filehandle named C<REMOTE> to be
48624731non-blocking at the system level. You'll have to negotiate C<$|>
48634732on your own, though.
48644733
48654734=end original
48664735
48674736これは C<REMOTE> というファイルハンドルをシステムレベルで
48684737非ブロックモードにセットする例です。
48694738ただし、 C<$|> を自分で管理しなければなりません。
48704739
48714740 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
48724741
48734742 $flags = fcntl(REMOTE, F_GETFL, 0)
48744743 or die "Can't get flags for the socket: $!\n";
48754744
48764745 $flags = fcntl(REMOTE, F_SETFL, $flags | O_NONBLOCK)
48774746 or die "Can't set flags for the socket: $!\n";
48784747
48794748=begin original
48804749
48814750Portability issues: L<perlport/fcntl>.
48824751
48834752=end original
48844753
48854754移植性の問題: L<perlport/fcntl>。
48864755
48874756=item __FILE__
48884757X<__FILE__>
48894758
48904759=for Pod::Functions the name of the current source file
48914760
48924761=begin original
48934762
48944763A special token that returns the name of the file in which it occurs.
48954764
48964765=end original
48974766
48984767これが書いてあるファイルの名前を返す特殊トークン。
48994768
49004769=item fileno FILEHANDLE
49014770X<fileno>
49024771
49034772=for Pod::Functions return file descriptor from filehandle
49044773
49054774=begin original
49064775
49074776Returns the file descriptor for a filehandle, or undefined if the
49084777filehandle is not open. If there is no real file descriptor at the OS
49094778level, as can happen with filehandles connected to memory objects via
49104779C<open> with a reference for the third argument, -1 is returned.
49114780
49124781=end original
49134782
49144783ファイルハンドルに対するファイル記述子を返します; ファイルハンドルが
49154784オープンしていない場合は未定義値を返します。
49164785OS レベルで実際のファイル記述子がない(C<open> の第 3 引数にリファレンスを
49174786指定してファイルハンドルがメモリオブジェクトと結びつけられたときに
49184787起こります)場合、-1 が返されます。
49194788
49204789=begin original
49214790
49224791This is mainly useful for constructing
49234792bitmaps for C<select> and low-level POSIX tty-handling operations.
49244793If FILEHANDLE is an expression, the value is taken as an indirect
49254794filehandle, generally its name.
49264795
49274796=end original
49284797
49294798これは主に C<select> や低レベル POSIX tty 操作に対する、ビットマップを
49304799構成するときに便利です。
49314800FILEHANDLE が式であれば、
49324801その値が間接ファイルハンドル(普通は名前)として使われます。
49334802
49344803=begin original
49354804
49364805You can use this to find out whether two handles refer to the
49374806same underlying descriptor:
49384807
49394808=end original
49404809
49414810これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに
49424811使えます:
49434812
4944 if (fileno(THIS) != -1 && fileno(THIS) == fileno(THAT)) {
4813 if (fileno(THIS) == fileno(THAT)) {
49454814 print "THIS and THAT are dups\n";
4946 } elsif (fileno(THIS) != -1 && fileno(THAT) != -1) {
4947 print "THIS and THAT have different " .
4948 "underlying file descriptors\n";
4949 } else {
4950 print "At least one of THIS and THAT does " .
4951 "not have a real file descriptor\n";
49524815 }
49534816
49544817=item flock FILEHANDLE,OPERATION
49554818X<flock> X<lock> X<locking>
49564819
49574820=for Pod::Functions lock an entire file with an advisory lock
49584821
49594822=begin original
49604823
49614824Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true
49624825for success, false on failure. Produces a fatal error if used on a
49634826machine that doesn't implement flock(2), fcntl(2) locking, or lockf(3).
49644827C<flock> is Perl's portable file-locking interface, although it locks
49654828entire files only, not records.
49664829
49674830=end original
49684831
49694832FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。
49704833成功時には真を、失敗時には偽を返します。
49714834flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない
49724835マシンで使うと、致命的エラーが発生します。
49734836C<flock> は Perl の移植性のあるファイルロックインターフェースです;
49744837しかしレコードではなく、ファイル全体のみをロックします。
49754838
49764839=begin original
49774840
49784841Two potentially non-obvious but traditional C<flock> semantics are
49794842that it waits indefinitely until the lock is granted, and that its locks
49804843are B<merely advisory>. Such discretionary locks are more flexible, but
49814844offer fewer guarantees. This means that programs that do not also use
49824845C<flock> may modify files locked with C<flock>. See L<perlport>,
49834846your port's specific documentation, and your system-specific local manpages
49844847for details. It's best to assume traditional behavior if you're writing
49854848portable programs. (But if you're not, you should as always feel perfectly
49864849free to write for your own system's idiosyncrasies (sometimes called
49874850"features"). Slavish adherence to portability concerns shouldn't get
49884851in the way of your getting your job done.)
49894852
49904853=end original
49914854
49924855明白ではないものの、伝統的な C<flock> の動作としては、ロックが得られるまで
49934856無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。
49944857このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。
49954858これは、C<flock> を使わないプログラムが C<flock> でロックされたファイルを
49964859書き換えるかもしれないことを意味します。
49974860詳細については、L<perlport>、システム固有のドキュメント、システム固有の
49984861ローカルの man ページを参照してください。
49994862移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが
50004863ベストです。
50014864(しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば
50024865「仕様」と呼ばれます)に合わせて書くことも完全に自由です。
50034866盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは
50044867ありません。)
50054868
50064869=begin original
50074870
50084871OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with
50094872LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but
50104873you can use the symbolic names if you import them from the L<Fcntl> module,
50114874either individually, or as a group using the C<:flock> tag. LOCK_SH
50124875requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN
50134876releases a previously requested lock. If LOCK_NB is bitwise-or'ed with
50144877LOCK_SH or LOCK_EX, then C<flock> returns immediately rather than blocking
50154878waiting for the lock; check the return status to see if you got it.
50164879
50174880=end original
50184881
50194882OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と
50204883組み合わされることもあります。
50214884これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから
50224885シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、
50234886シンボル名をを使うことができます。
50244887LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は
50254888前回要求したロックを開放します。
50264889LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、C<flock> は
50274890ロックを取得するまで待つのではなく、すぐに返ります;
50284891ロックが取得できたかどうかは返り値を調べます。
50294892
50304893=begin original
50314894
50324895To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE
50334896before locking or unlocking it.
50344897
50354898=end original
50364899
50374900不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に
50384901FILEHANDLE をフラッシュします。
50394902
50404903=begin original
50414904
50424905Note that the emulation built with lockf(3) doesn't provide shared
50434906locks, and it requires that FILEHANDLE be open with write intent. These
50444907are the semantics that lockf(3) implements. Most if not all systems
50454908implement lockf(3) in terms of fcntl(2) locking, though, so the
50464909differing semantics shouldn't bite too many people.
50474910
50484911=end original
50494912
50504913lockf(3) で作成されたエミュレーションは共有ロックを提供せず、
50514914FILEHANDLE が書き込みモードで開いていることを必要とすることに
50524915注意してください。
50534916これは lockf(3) が実装している動作です。
50544917しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って
50554918lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは
50564919ないはずです。
50574920
50584921=begin original
50594922
50604923Note that the fcntl(2) emulation of flock(3) requires that FILEHANDLE
50614924be open with read intent to use LOCK_SH and requires that it be open
50624925with write intent to use LOCK_EX.
50634926
50644927=end original
50654928
50664929flock(3) の fcntl(2) エミュレーションは、 LOCK_SH を使うためには
50674930FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには
50684931書き込みで開いている必要があることに注意してください。
50694932
50704933=begin original
50714934
50724935Note also that some versions of C<flock> cannot lock things over the
50734936network; you would need to use the more system-specific C<fcntl> for
50744937that. If you like you can force Perl to ignore your system's flock(2)
50754938function, and so provide its own fcntl(2)-based emulation, by passing
50764939the switch C<-Ud_flock> to the F<Configure> program when you configure
50774940and build a new Perl.
50784941
50794942=end original
50804943
50814944ネットワーク越しにはロックできない C<flock> もあることに注意してください;
50824945このためには、よりシステム依存な C<fcntl> を使う必要があります。
50834946Perl にシステムの flock(2) 関数を無視させ、自身の fcntl(2) ベースの
50844947エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに
50854948F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。
50864949
50874950=begin original
50884951
50894952Here's a mailbox appender for BSD systems.
50904953
50914954=end original
50924955
50934956BSD システムでのメールボックスへの追加処理の例を示します。
50944957
5095 # import LOCK_* and SEEK_END constants
4958 use Fcntl qw(:flock SEEK_END); # import LOCK_* and SEEK_END constants
5096 use Fcntl qw(:flock SEEK_END);
50974959
50984960 sub lock {
50994961 my ($fh) = @_;
51004962 flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
51014963
51024964 # and, in case someone appended while we were waiting...
51034965 seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
51044966 }
51054967
51064968 sub unlock {
51074969 my ($fh) = @_;
51084970 flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
51094971 }
51104972
51114973 open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
51124974 or die "Can't open mailbox: $!";
51134975
51144976 lock($mbox);
51154977 print $mbox $msg,"\n\n";
51164978 unlock($mbox);
51174979
51184980=begin original
51194981
51204982On systems that support a real flock(2), locks are inherited across fork()
51214983calls, whereas those that must resort to the more capricious fcntl(2)
51224984function lose their locks, making it seriously harder to write servers.
51234985
51244986=end original
51254987
51264988真の flock(2) に対応しているシステムではロックは fork() を通して
51274989継承されるのに対して、より不安定な fcntl(2) に頼らなければならない場合、
51284990サーバを書くのは本当により難しくなります。
51294991
51304992=begin original
51314993
51324994See also L<DB_File> for other flock() examples.
51334995
51344996=end original
51354997
51364998その他の flock() の例としては L<DB_File> も参照してください。
51374999
51385000=begin original
51395001
51405002Portability issues: L<perlport/flock>.
51415003
51425004=end original
51435005
51445006移植性の問題: L<perlport/flock>。
51455007
51465008=item fork
51475009X<fork> X<child> X<parent>
51485010
51495011=for Pod::Functions create a new process just like this one
51505012
51515013=begin original
51525014
51535015Does a fork(2) system call to create a new process running the
51545016same program at the same point. It returns the child pid to the
51555017parent process, C<0> to the child process, or C<undef> if the fork is
51565018unsuccessful. File descriptors (and sometimes locks on those descriptors)
51575019are shared, while everything else is copied. On most systems supporting
51585020fork(), great care has gone into making it extremely efficient (for
51595021example, using copy-on-write technology on data pages), making it the
51605022dominant paradigm for multitasking over the last few decades.
51615023
51625024=end original
51635025
51645026同じプログラムの同じ地点から開始する新しいプロセスを作成するために
51655027システムコール fork(2) を行ないます。
51665028親プロセスには、チャイルドプロセスの pid を、
51675029チャイルドプロセスに C<0> を返しますが、
51685030fork に失敗したときには、C<undef>を返します。
51695031ファイル記述子(および記述子に関連するロック)は共有され、
51705032その他の全てはコピーされます。
51715033fork() に対応するほとんどのシステムでは、
51725034これを極めて効率的にするために多大な努力が払われてきました
51735035(例えば、データページへの copy-on-write テクノロジーなどです);
51745036これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。
51755037
51765038=begin original
51775039
5178Perl attempts to flush all files opened for
5040Beginning with v5.6.0, Perl attempts to flush all files opened for
51795041output before forking the child process, but this may not be supported
51805042on some platforms (see L<perlport>). To be safe, you may need to set
51815043C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method of
51825044C<IO::Handle> on any open handles to avoid duplicate output.
51835045
51845046=end original
51855047
51865048v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての
51875049ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも
51885050あります(L<perlport> を参照してください)。
51895051安全のためには、出力が重複するのを避けるために、
51905052全てのオープンしているハンドルに対して C<$|> (English モジュールでは
51915053$AUTOFLUSH) を設定するか、
51925054C<IO::Handle> モジュールの C<autoflush()>メソッドをを呼ぶ必要が
51935055あるかもしれません。
51945056
51955057=begin original
51965058
51975059If you C<fork> without ever waiting on your children, you will
51985060accumulate zombies. On some systems, you can avoid this by setting
51995061C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for more examples of
52005062forking and reaping moribund children.
52015063
52025064=end original
52035065
52045066チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、
52055067ゾンビをためこむことになります。
52065068C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを回避できるシステムもあります。
52075069fork と消滅しかけている子プロセスを回収するための更なる例については
52085070L<perlipc> も参照してください。
52095071
52105072=begin original
52115073
52125074Note that if your forked child inherits system file descriptors like
52135075STDIN and STDOUT that are actually connected by a pipe or socket, even
52145076if you exit, then the remote server (such as, say, a CGI script or a
52155077backgrounded job launched from a remote shell) won't think you're done.
52165078You should reopen those to F</dev/null> if it's any issue.
52175079
52185080=end original
52195081
52205082fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を
52215083継承する場合、(CGI スクリプトやリモートシェルといった
52225084バックグラウンドジョブのような)リモートサーバは考え通りに
52235085動かないであろうことに注意してください。
52245086このような場合ではこれらを F</dev/null> として再オープンするべきです。
52255087
52265088=begin original
52275089
52285090On some platforms such as Windows, where the fork() system call is not available,
52295091Perl can be built to emulate fork() in the Perl interpreter.
52305092The emulation is designed, at the level of the Perl program,
52315093to be as compatible as possible with the "Unix" fork().
52325094However it has limitations that have to be considered in code intended to be portable.
52335095See L<perlfork> for more details.
52345096
52355097=end original
52365098
52375099Windows のような fork() が利用不能なシステムでは、Perl は fork() を Perl
52385100インタプリタでエミュレートします。
52395101エミュレーションは Perl プログラムのレベルではできるだけ "Unix" fork() と
52405102互換性があるように設計されています。
52415103しかしコードが移植性があると考えられるように制限があります。
52425104さらなる詳細については L<perlfork> を参照してください。
52435105
52445106=begin original
52455107
52465108Portability issues: L<perlport/fork>.
52475109
52485110=end original
52495111
52505112移植性の問題: L<perlport/fork>。
52515113
52525114=item format
52535115X<format>
52545116
52555117=for Pod::Functions declare a picture format with use by the write() function
52565118
52575119=begin original
52585120
52595121Declare a picture format for use by the C<write> function. For
52605122example:
52615123
52625124=end original
52635125
52645126C<write> 関数で使うピクチャーフォーマットを宣言します。
52655127例えば:
52665128
52675129 format Something =
52685130 Test: @<<<<<<<< @||||| @>>>>>
52695131 $str, $%, '$' . int($num)
52705132 .
52715133
52725134 $str = "widget";
52735135 $num = $cost/$quantity;
52745136 $~ = 'Something';
52755137 write;
52765138
52775139=begin original
52785140
52795141See L<perlform> for many details and examples.
52805142
52815143=end original
52825144
52835145詳細と例については L<perlform> を参照してください。
52845146
52855147=item formline PICTURE,LIST
52865148X<formline>
52875149
52885150=for Pod::Functions internal function used for formats
52895151
52905152=begin original
52915153
52925154This is an internal function used by C<format>s, though you may call it,
52935155too. It formats (see L<perlform>) a list of values according to the
52945156contents of PICTURE, placing the output into the format output
52955157accumulator, C<$^A> (or C<$ACCUMULATOR> in English).
52965158Eventually, when a C<write> is done, the contents of
52975159C<$^A> are written to some filehandle. You could also read C<$^A>
52985160and then set C<$^A> back to C<"">. Note that a format typically
52995161does one C<formline> per line of form, but the C<formline> function itself
53005162doesn't care how many newlines are embedded in the PICTURE. This means
53015163that the C<~> and C<~~> tokens treat the entire PICTURE as a single line.
53025164You may therefore need to use multiple formlines to implement a single
53035165record format, just like the C<format> compiler.
53045166
53055167=end original
53065168
53075169これは、C<format> が使用する内部関数ですが、直接呼び出すこともできます。
53085170これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を
53095171参照してください)、結果をフォーマット出力アキュムレータC<$^A>
53105172(English モジュールでは C<$ACCUMULATOR>) に納めます。
53115173最終的に、C<write> が実行されると、C<$^A> の中身が、
53125174何らかのファイルハンドルに書き出されます。
53135175また、自分で C<$^A> を読んで、C<$^A> の内容を C<""> に戻してもかまいません。
53145176format は通常、1 行ごとに C<formline> を行ないますが、
53155177C<formline> 関数自身は、PICTURE の中にいくつの改行が入っているかは、
53165178関係がありません。
53175179これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。
53185180従って、1 レコードフォーマットを実装するためには
53195181フォーマットコンパイラのような複数 formline を使う必要があります。
53205182
53215183=begin original
53225184
53235185Be careful if you put double quotes around the picture, because an C<@>
53245186character may be taken to mean the beginning of an array name.
53255187C<formline> always returns true. See L<perlform> for other examples.
53265188
53275189=end original
53285190
53295191ダブルクォートで PICTURE を囲む場合には、C<@> という文字が
53305192配列名の始まりと解釈されますので、注意してください。
53315193C<formline> は常に真を返します。
53325194その他の例については L<perlform> を参照してください。
53335195
53345196=begin original
53355197
53365198If you are trying to use this instead of C<write> to capture the output,
53375199you may find it easier to open a filehandle to a scalar
53385200(C<< open $fh, ">", \$output >>) and write to that instead.
53395201
53405202=end original
53415203
53425204出力を捕捉するために C<write> の代わりにこれを使おうとした場合、
53435205スカラにファイルハンドルを開いて (C<< open $fh, ">", \$output >>)、
53445206代わりにここに出力する方が簡単であることに気付くでしょう。
53455207
53465208=item getc FILEHANDLE
53475209X<getc> X<getchar> X<character> X<file, read>
53485210
53495211=item getc
53505212
53515213=for Pod::Functions get the next character from the filehandle
53525214
53535215=begin original
53545216
53555217Returns the next character from the input file attached to FILEHANDLE,
53565218or the undefined value at end of file or if there was an error (in
53575219the latter case C<$!> is set). If FILEHANDLE is omitted, reads from
53585220STDIN. This is not particularly efficient. However, it cannot be
53595221used by itself to fetch single characters without waiting for the user
53605222to hit enter. For that, try something more like:
53615223
53625224=end original
53635225
53645226FILEHANDLE につながれている入力ファイルから、次の一文字を返します;
53655227ファイルの最後、またはエラーが発生した場合は、未定義値を返します
53665228(後者の場合は C<$!> がセットされます)。
53675229FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。
53685230これは特に効率的ではありません。
53695231しかし、これはユーザーがリターンキーを押すのを待つことなく
53705232一文字を読み込む用途には使えません。
53715233そのような場合には、以下のようなものを試して見てください:
53725234
53735235 if ($BSD_STYLE) {
53745236 system "stty cbreak </dev/tty >/dev/tty 2>&1";
53755237 }
53765238 else {
53775239 system "stty", '-icanon', 'eol', "\001";
53785240 }
53795241
53805242 $key = getc(STDIN);
53815243
53825244 if ($BSD_STYLE) {
53835245 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
53845246 }
53855247 else {
53865248 system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
53875249 }
53885250 print "\n";
53895251
53905252=begin original
53915253
53925254Determination of whether $BSD_STYLE should be set
53935255is left as an exercise to the reader.
53945256
53955257=end original
53965258
53975259$BSD_STYLE をセットするべきかどうかを決定する方法については
53985260読者への宿題として残しておきます。
53995261
54005262=begin original
54015263
54025264The C<POSIX::getattr> function can do this more portably on
54035265systems purporting POSIX compliance. See also the C<Term::ReadKey>
5404module from your nearest L<CPAN|http://www.cpan.org> site.
5266module from your nearest CPAN site; details on CPAN can be found under
5267L<perlmodlib/CPAN>.
54055268
54065269=end original
54075270
54085271C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムでこれを
54095272より移植性のある形で行います。
5410最寄りL<CPAN|http://www.cpan.org> サイトから C<Term::ReadKey> モジュールも
5273お近くの CPAN サイトから C<Term::ReadKey> モジュールも参照してください;
5411参照してください
5274CPAN に関する詳細は L<perlmodlib/CPAN> にあります
54125275
54135276=item getlogin
54145277X<getlogin> X<login>
54155278
54165279=for Pod::Functions return who logged in at this tty
54175280
54185281=begin original
54195282
54205283This implements the C library function of the same name, which on most
54215284systems returns the current login from F</etc/utmp>, if any. If it
54225285returns the empty string, use C<getpwuid>.
54235286
54245287=end original
54255288
54265289これは同じ名前の C ライブラリ関数を実装していて、
54275290多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。
54285291もし空文字列が返ってきた場合は、getpwuid() を使ってください。
54295292
54305293 $login = getlogin || getpwuid($<) || "Kilroy";
54315294
54325295=begin original
54335296
54345297Do not consider C<getlogin> for authentication: it is not as
54355298secure as C<getpwuid>.
54365299
54375300=end original
54385301
54395302C<getlogin> を認証に使ってはいけません: これは C<getpwuid> のように
54405303安全ではありません。
54415304
54425305=begin original
54435306
54445307Portability issues: L<perlport/getlogin>.
54455308
54465309=end original
54475310
54485311移植性の問題: L<perlport/getlogin>。
54495312
54505313=item getpeername SOCKET
54515314X<getpeername> X<peer>
54525315
54535316=for Pod::Functions find the other end of a socket connection
54545317
54555318=begin original
54565319
54575320Returns the packed sockaddr address of the other end of the SOCKET
54585321connection.
54595322
54605323=end original
54615324
54625325SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。
54635326
54645327 use Socket;
54655328 $hersockaddr = getpeername(SOCK);
54665329 ($port, $iaddr) = sockaddr_in($hersockaddr);
54675330 $herhostname = gethostbyaddr($iaddr, AF_INET);
54685331 $herstraddr = inet_ntoa($iaddr);
54695332
54705333=item getpgrp PID
54715334X<getpgrp> X<group>
54725335
54735336=for Pod::Functions get process group
54745337
54755338=begin original
54765339
54775340Returns the current process group for the specified PID. Use
54785341a PID of C<0> to get the current process group for the
54795342current process. Will raise an exception if used on a machine that
54805343doesn't implement getpgrp(2). If PID is omitted, returns the process
54815344group of the current process. Note that the POSIX version of C<getpgrp>
54825345does not accept a PID argument, so only C<PID==0> is truly portable.
54835346
54845347=end original
54855348
54865349指定された PID の現在のプロセスグループを返します。
54875350PID に C<0> を与えるとカレントプロセスの指定となります。
54885351getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。
54895352PID を省略するとカレントプロセスのプロセスグループを返します。
54905353POSIX 版の C<getpgrp> は PID 引数を受け付けないので、
54915354C<PID==0> のみが完全に移植性があります。
54925355
54935356=begin original
54945357
54955358Portability issues: L<perlport/getpgrp>.
54965359
54975360=end original
54985361
54995362移植性の問題: L<perlport/getpgrp>。
55005363
55015364=item getppid
55025365X<getppid> X<parent> X<pid>
55035366
55045367=for Pod::Functions get parent process ID
55055368
55065369=begin original
55075370
55085371Returns the process id of the parent process.
55095372
55105373=end original
55115374
55125375親プロセスのプロセス id を返します。
55135376
55145377=begin original
55155378
55165379Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
55175380around non-POSIX thread semantics the minority of Linux systems (and
55185381Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
5519has since been removed. See the documentation for L<$$|perlvar/$$> for
5382has since been removed. See the documentation for L<$$|perlvar/$$> for
55205383details.
55215384
55225385=end original
55235386
55245387Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は
55255388LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな
55265389Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。
55275390このエミュレーションは削除されました;
55285391詳しくは L<$$|perlvar/$$> の文書を参照してください。
55295392
55305393=begin original
55315394
55325395Portability issues: L<perlport/getppid>.
55335396
55345397=end original
55355398
55365399移植性の問題: L<perlport/getppid>。
55375400
55385401=item getpriority WHICH,WHO
55395402X<getpriority> X<priority> X<nice>
55405403
55415404=for Pod::Functions get current nice value
55425405
55435406=begin original
55445407
55455408Returns the current priority for a process, a process group, or a user.
55465409(See L<getpriority(2)>.) Will raise a fatal exception if used on a
55475410machine that doesn't implement getpriority(2).
55485411
55495412=end original
55505413
55515414プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。
55525415(L<getpriority(2)> を参照してください。)
55535416getpriority(2) を実装していない
55545417マシンで実行した場合には、致命的例外が発生します。
55555418
55565419=begin original
55575420
55585421Portability issues: L<perlport/getpriority>.
55595422
55605423=end original
55615424
55625425移植性の問題: L<perlport/getpriority>。
55635426
55645427=item getpwnam NAME
55655428X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname>
55665429X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr>
55675430X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent>
55685431X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent>
55695432X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent>
55705433X<endnetent> X<endprotoent> X<endservent>
55715434
55725435=for Pod::Functions get passwd record given user login name
55735436
55745437=item getgrnam NAME
55755438
55765439=for Pod::Functions get group record given group name
55775440
55785441=item gethostbyname NAME
55795442
55805443=for Pod::Functions get host record given name
55815444
55825445=item getnetbyname NAME
55835446
55845447=for Pod::Functions get networks record given name
55855448
55865449=item getprotobyname NAME
55875450
55885451=for Pod::Functions get protocol record given name
55895452
55905453=item getpwuid UID
55915454
55925455=for Pod::Functions get passwd record given user ID
55935456
55945457=item getgrgid GID
55955458
55965459=for Pod::Functions get group record given group user ID
55975460
55985461=item getservbyname NAME,PROTO
55995462
56005463=for Pod::Functions get services record given its name
56015464
56025465=item gethostbyaddr ADDR,ADDRTYPE
56035466
56045467=for Pod::Functions get host record given its address
56055468
56065469=item getnetbyaddr ADDR,ADDRTYPE
56075470
56085471=for Pod::Functions get network record given its address
56095472
56105473=item getprotobynumber NUMBER
56115474
56125475=for Pod::Functions get protocol record numeric protocol
56135476
56145477=item getservbyport PORT,PROTO
56155478
56165479=for Pod::Functions get services record given numeric port
56175480
56185481=item getpwent
56195482
56205483=for Pod::Functions get next passwd record
56215484
56225485=item getgrent
56235486
56245487=for Pod::Functions get next group record
56255488
56265489=item gethostent
56275490
56285491=for Pod::Functions get next hosts record
56295492
56305493=item getnetent
56315494
56325495=for Pod::Functions get next networks record
56335496
56345497=item getprotoent
56355498
56365499=for Pod::Functions get next protocols record
56375500
56385501=item getservent
56395502
56405503=for Pod::Functions get next services record
56415504
56425505=item setpwent
56435506
56445507=for Pod::Functions prepare passwd file for use
56455508
56465509=item setgrent
56475510
56485511=for Pod::Functions prepare group file for use
56495512
56505513=item sethostent STAYOPEN
56515514
56525515=for Pod::Functions prepare hosts file for use
56535516
56545517=item setnetent STAYOPEN
56555518
56565519=for Pod::Functions prepare networks file for use
56575520
56585521=item setprotoent STAYOPEN
56595522
56605523=for Pod::Functions prepare protocols file for use
56615524
56625525=item setservent STAYOPEN
56635526
56645527=for Pod::Functions prepare services file for use
56655528
56665529=item endpwent
56675530
56685531=for Pod::Functions be done using passwd file
56695532
56705533=item endgrent
56715534
56725535=for Pod::Functions be done using group file
56735536
56745537=item endhostent
56755538
56765539=for Pod::Functions be done using hosts file
56775540
56785541=item endnetent
56795542
56805543=for Pod::Functions be done using networks file
56815544
56825545=item endprotoent
56835546
56845547=for Pod::Functions be done using protocols file
56855548
56865549=item endservent
56875550
56885551=for Pod::Functions be done using services file
56895552
56905553=begin original
56915554
56925555These routines are the same as their counterparts in the
56935556system C library. In list context, the return values from the
56945557various get routines are as follows:
56955558
56965559=end original
56975560
56985561これらのルーチンは、システムの C ライブラリの同名の関数と同じです。
56995562リストコンテキストでは、さまざまな
57005563get ルーチンからの返り値は、次のようになります:
57015564
5702 # 0 1 2 3 4
5565 ($name,$passwd,$uid,$gid,
5703 ( $name, $passwd, $gid, $members ) = getgr*
5566 $quota,$comment,$gcos,$dir,$shell,$expire) = getpw*
5704 ( $name, $aliases, $addrtype, $net ) = getnet*
5567 ($name,$passwd,$gid,$members) = getgr*
5705 ( $name, $aliases, $port, $proto ) = getserv*
5568 ($name,$aliases,$addrtype,$length,@addrs) = gethost*
5706 ( $name, $aliases, $proto ) = getproto*
5569 ($name,$aliases,$addrtype,$net) = getnet*
5707 ( $name, $aliases, $addrtype, $length, @addrs ) = gethost*
5570 ($name,$aliases,$proto) = getproto*
5708 ( $name, $passwd, $uid, $gid, $quota,
5571 ($name,$aliases,$port,$proto) = getserv*
5709 $comment, $gcos, $dir, $shell, $expire ) = getpw*
5710 # 5 6 7 8 9
57115572
57125573=begin original
57135574
57145575(If the entry doesn't exist you get an empty list.)
57155576
57165577=end original
57175578
57185579(エントリが存在しなければ、空リストが返されます。)
57195580
57205581=begin original
57215582
57225583The exact meaning of the $gcos field varies but it usually contains
57235584the real name of the user (as opposed to the login name) and other
57245585information pertaining to the user. Beware, however, that in many
57255586system users are able to change this information and therefore it
57265587cannot be trusted and therefore the $gcos is tainted (see
57275588L<perlsec>). The $passwd and $shell, user's encrypted password and
57285589login shell, are also tainted, for the same reason.
57295590
57305591=end original
57315592
57325593$gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく)
57335594ユーザーの実際の名前とユーザーに付随する情報を含みます。
57345595但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は
57355596信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。
57365597ユーザーの暗号化されたパスワードとログインシェルである $passwd と
57375598$shell も、同様の理由で汚染されます。
57385599
57395600=begin original
57405601
57415602In scalar context, you get the name, unless the function was a
57425603lookup by name, in which case you get the other thing, whatever it is.
57435604(If the entry doesn't exist you get the undefined value.) For example:
57445605
57455606=end original
57465607
57475608スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、
57485609name を返し、NAME で検索するものは、何か別のものを返します。
57495610(エントリが存在しなければ、未定義値が返ります。)
57505611例えば:
57515612
57525613 $uid = getpwnam($name);
57535614 $name = getpwuid($num);
57545615 $name = getpwent();
57555616 $gid = getgrnam($name);
57565617 $name = getgrgid($num);
57575618 $name = getgrent();
57585619 #etc.
57595620
57605621=begin original
57615622
57625623In I<getpw*()> the fields $quota, $comment, and $expire are special
57635624in that they are unsupported on many systems. If the
57645625$quota is unsupported, it is an empty scalar. If it is supported, it
57655626usually encodes the disk quota. If the $comment field is unsupported,
57665627it is an empty scalar. If it is supported it usually encodes some
57675628administrative comment about the user. In some systems the $quota
57685629field may be $change or $age, fields that have to do with password
57695630aging. In some systems the $comment field may be $class. The $expire
57705631field, if present, encodes the expiration period of the account or the
57715632password. For the availability and the exact meaning of these fields
57725633in your system, please consult getpwnam(3) and your system's
57735634F<pwd.h> file. You can also find out from within Perl what your
57745635$quota and $comment fields mean and whether you have the $expire field
57755636by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>,
57765637C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password
57775638files are supported only if your vendor has implemented them in the
57785639intuitive fashion that calling the regular C library routines gets the
57795640shadow versions if you're running under privilege or if there exists
57805641the shadow(3) functions as found in System V (this includes Solaris
57815642and Linux). Those systems that implement a proprietary shadow password
57825643facility are unlikely to be supported.
57835644
57845645=end original
57855646
57865647I<getpw*()> では、$quota, $comment, $expire フィールドは、
57875648多くのシステムでは対応していないので特別な処理がされます。
57885649$quota が非対応の場合、空のスカラになります。
57895650対応している場合、通常はディスククォータの値が入ります。
57905651$comment フィールドが非対応の場合、空のスカラになります。
57915652対応している場合、通常はユーザーに関する管理上のコメントが入ります。
57925653$quota フィールドはパスワードの寿命を示す $change や $age である
57935654システムもあります。
57945655$comment フィールドは $class であるシステムもあります。
57955656$expire フィールドがある場合は、アカウントやパスワードが時間切れになる
57965657期間が入ります。
57975658動作させるシステムでのこれらのフィールドの有効性と正確な意味については、
57985659getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。
57995660$quota と $comment フィールドが何を意味しているかと、$expire フィールドが
58005661あるかどうかは、C<Config> モジュールを使って、C<d_pwquota>, C<d_pwage>,
58015662C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を調べることによって
58025663Perl 自身で調べることも出来ます。
58035664シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で
58045665呼び出すことでシャドウ版が取得できるか、System V にあるような
58055666(Solaris と Linux を含みます) shadow(3) 関数があるといった、
58065667直感的な方法で実装されている場合にのみ対応されます。
58075668独占的なシャドウパスワード機能を実装しているシステムでは、
58085669それに対応されることはないでしょう。
58095670
58105671=begin original
58115672
58125673The $members value returned by I<getgr*()> is a space-separated list of
58135674the login names of the members of the group.
58145675
58155676=end original
58165677
58175678I<getgr*()> によって返る値 $members は、グループのメンバの
58185679ログイン名をスペースで区切ったものです。
58195680
58205681=begin original
58215682
58225683For the I<gethost*()> functions, if the C<h_errno> variable is supported in
58235684C, it will be returned to you via C<$?> if the function call fails. The
58245685C<@addrs> value returned by a successful call is a list of raw
58255686addresses returned by the corresponding library call. In the
58265687Internet domain, each address is four bytes long; you can unpack it
58275688by saying something like:
58285689
58295690=end original
58305691
58315692I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、
58325693関数呼出が失敗したときに、C<$?> を通して、その値が返されます。
58335694成功時に返される C<@addrs> 値は、対応するシステムコールが返す、
58345695生のアドレスのリストです。
58355696インターネットドメインでは、個々のアドレスは、4 バイト長です;
58365697以下のようにして unpack することができます:
58375698
58385699 ($a,$b,$c,$d) = unpack('W4',$addr[0]);
58395700
58405701=begin original
58415702
58425703The Socket library makes this slightly easier:
58435704
58445705=end original
58455706
58465707Socket ライブラリを使うともう少し簡単になります。
58475708
58485709 use Socket;
58495710 $iaddr = inet_aton("127.1"); # or whatever address
58505711 $name = gethostbyaddr($iaddr, AF_INET);
58515712
58525713 # or going the other way
58535714 $straddr = inet_ntoa($iaddr);
58545715
58555716=begin original
58565717
58575718In the opposite way, to resolve a hostname to the IP address
58585719you can write this:
58595720
58605721=end original
58615722
58625723逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます:
58635724
58645725 use Socket;
58655726 $packed_ip = gethostbyname("www.perl.org");
58665727 if (defined $packed_ip) {
58675728 $ip_address = inet_ntoa($packed_ip);
58685729 }
58695730
58705731=begin original
58715732
58725733Make sure C<gethostbyname()> is called in SCALAR context and that
58735734its return value is checked for definedness.
58745735
58755736=end original
58765737
58775738C<gethostbyname()> はスカラコンテキストで呼び出すようにして、返り値が
58785739定義されているかを必ずチェックしてください。
58795740
58805741=begin original
58815742
58825743The C<getprotobynumber> function, even though it only takes one argument,
58835744has the precedence of a list operator, so beware:
58845745
58855746=end original
58865747
58875748C<getprotobynumber> 関数は、一つの引数しか取らないにも関わらず、リスト
58885749演算子の優先順位を持ちます; 従って注意してください:
58895750
58905751 getprotobynumber $number eq 'icmp' # WRONG
58915752 getprotobynumber($number eq 'icmp') # actually means this
58925753 getprotobynumber($number) eq 'icmp' # better this way
58935754
58945755=begin original
58955756
58965757If you get tired of remembering which element of the return list
58975758contains which return value, by-name interfaces are provided
58985759in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>,
58995760C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
59005761and C<User::grent>. These override the normal built-ins, supplying
59015762versions that return objects with the appropriate names
59025763for each field. For example:
59035764
59045765=end original
59055766
59065767返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、
59075768名前ベースのインターフェースが標準モジュールで提供されています:
59085769C<File::stat>, C<Net::hostent>, C<Net::netent>,
59095770C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
59105771C<User::grent> です。
59115772これらは通常の組み込みを上書きし、
59125773それぞれのフィールドに適切な名前をつけたオブジェクトを返します。
59135774例えば:
59145775
59155776 use File::stat;
59165777 use User::pwent;
59175778 $is_his = (stat($filename)->uid == pwent($whoever)->uid);
59185779
59195780=begin original
59205781
59215782Even though it looks as though they're the same method calls (uid),
59225783they aren't, because a C<File::stat> object is different from
59235784a C<User::pwent> object.
59245785
59255786=end original
59265787
59275788同じメソッド(uid)を呼び出しているように見えますが、違います;
59285789なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは
59295790異なるからです。
59305791
59315792=begin original
59325793
59335794Portability issues: L<perlport/getpwnam> to L<perlport/endservent>.
59345795
59355796=end original
59365797
59375798移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。
59385799
59395800=item getsockname SOCKET
59405801X<getsockname>
59415802
59425803=for Pod::Functions retrieve the sockaddr for a given socket
59435804
59445805=begin original
59455806
59465807Returns the packed sockaddr address of this end of the SOCKET connection,
59475808in case you don't know the address because you have several different
59485809IPs that the connection might have come in on.
59495810
59505811=end original
59515812
59525813SOCKET 接続のこちら側の pack された sockaddr アドレスを返します;
59535814複数の異なる IP から接続されるためにアドレスがわからない場合に使います。
59545815
59555816 use Socket;
59565817 $mysockaddr = getsockname(SOCK);
59575818 ($port, $myaddr) = sockaddr_in($mysockaddr);
59585819 printf "Connect to %s [%s]\n",
59595820 scalar gethostbyaddr($myaddr, AF_INET),
59605821 inet_ntoa($myaddr);
59615822
59625823=item getsockopt SOCKET,LEVEL,OPTNAME
59635824X<getsockopt>
59645825
59655826=for Pod::Functions get socket options on a given socket
59665827
59675828=begin original
59685829
59695830Queries the option named OPTNAME associated with SOCKET at a given LEVEL.
59705831Options may exist at multiple protocol levels depending on the socket
59715832type, but at least the uppermost socket level SOL_SOCKET (defined in the
59725833C<Socket> module) will exist. To query options at another level the
59735834protocol number of the appropriate protocol controlling the option
59745835should be supplied. For example, to indicate that an option is to be
59755836interpreted by the TCP protocol, LEVEL should be set to the protocol
59765837number of TCP, which you can get using C<getprotobyname>.
59775838
59785839=end original
59795840
59805841与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを
59815842問い合わせます。
59825843オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも
59835844ありますが、少なくとも最上位ソケットレベル SOL_SOCKET (C<Socket> モジュールで
59845845定義されています)は存在します。
59855846その他のレベルのオプションを問い合わせるには、そのオプションを制御する
59865847適切なプロトコルのプロトコル番号を指定します。
59875848例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、
59885849LEVEL は C<getprotobyname> で得られる TCP のプロトコル番号を設定します。
59895850
59905851=begin original
59915852
59925853The function returns a packed string representing the requested socket
59935854option, or C<undef> on error, with the reason for the error placed in
59945855C<$!>. Just what is in the packed string depends on LEVEL and OPTNAME;
59955856consult getsockopt(2) for details. A common case is that the option is an
59965857integer, in which case the result is a packed integer, which you can decode
59975858using C<unpack> with the C<i> (or C<I>) format.
59985859
59995860=end original
60005861
60015862この関数は、要求されたソケットオプションの pack された文字列表現か、
60025863あるいはエラーの場合は C<undef> を返し、エラーの理由は C<$!> にあります。
60035864pack された文字列の中身は LEVEL と OPTNAME に依存します;
60045865詳細については getsockopt(2) を確認してください。
60055866一般的な場合はオプションが整数の場合で、この場合結果は C<unpack> の C<i>
60065867(あるいは C<I>)フォーマットでデコードできる pack された整数です。
60075868
60085869=begin original
60095870
60105871Here's an example to test whether Nagle's algorithm is enabled on a socket:
60115872
60125873=end original
60135874
60145875あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です:
60155876
60165877 use Socket qw(:all);
60175878
60185879 defined(my $tcp = getprotobyname("tcp"))
60195880 or die "Could not determine the protocol number for tcp";
60205881 # my $tcp = IPPROTO_TCP; # Alternative
60215882 my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
60225883 or die "getsockopt TCP_NODELAY: $!";
60235884 my $nodelay = unpack("I", $packed);
6024 print "Nagle's algorithm is turned ",
5885 print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n";
6025 $nodelay ? "off\n" : "on\n";
60265886
60275887=begin original
60285888
60295889Portability issues: L<perlport/getsockopt>.
60305890
60315891=end original
60325892
60335893移植性の問題: L<perlport/getsockopt>。
60345894
60355895=item glob EXPR
60365896X<glob> X<wildcard> X<filename, expansion> X<expand>
60375897
60385898=item glob
60395899
60405900=for Pod::Functions expand filenames using wildcards
60415901
60425902=begin original
60435903
60445904In list context, returns a (possibly empty) list of filename expansions on
60455905the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
60465906scalar context, glob iterates through such filename expansions, returning
60475907undef when the list is exhausted. This is the internal function
60485908implementing the C<< <*.c> >> operator, but you can use it directly. If
60495909EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator is discussed in
60505910more detail in L<perlop/"I/O Operators">.
60515911
60525912=end original
60535913
60545914リストコンテキストでは、
60555915EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように
60565916ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。
60575917スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、
60585918リストがなくなったら undef を返します。
60595919これは、C<< <*.c> >> 演算子を実装する内部関数ですが、
60605920直接使用することもできます。
60615921EXPR が省略されると、C<$_> が使われます。
60625922C<< <*.c> >>演算子については
60635923L<perlop/"I/O Operators"> でより詳細に議論しています。
60645924
60655925=begin original
60665926
60675927Note that C<glob> splits its arguments on whitespace and treats
60685928each segment as separate pattern. As such, C<glob("*.c *.h")>
60695929matches all files with a F<.c> or F<.h> extension. The expression
60705930C<glob(".* *")> matches all files in the current working directory.
60715931If you want to glob filenames that might contain whitespace, you'll
60725932have to use extra quotes around the spacey filename to protect it.
60735933For example, to glob filenames that have an C<e> followed by a space
60745934followed by an C<f>, use either of:
60755935
60765936=end original
60775937
60785938C<glob> は引数を空白で分割して、それぞれを分割されたパターンとして扱います。
60795939従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに
60805940マッチングします。
60815941式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに
60825942マッチングします。
60835943空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために
60845944空白入りファイル名の周りに追加のクォートを使う必要があります。
60855945例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには
60865946以下のどちらかを使います:
60875947
60885948 @spacies = <"*e f*">;
60895949 @spacies = glob '"*e f*"';
60905950 @spacies = glob q("*e f*");
60915951
60925952=begin original
60935953
60945954If you had to get a variable through, you could do this:
60955955
60965956=end original
60975957
60985958変数を通す必要があった場合、以下のようにできました:
60995959
61005960 @spacies = glob "'*${var}e f*'";
61015961 @spacies = glob qq("*${var}e f*");
61025962
61035963=begin original
61045964
61055965If non-empty braces are the only wildcard characters used in the
61065966C<glob>, no filenames are matched, but potentially many strings
61075967are returned. For example, this produces nine strings, one for
61085968each pairing of fruits and colors:
61095969
61105970=end original
61115971
61125972空でない中かっこが C<glob> で使われている唯一のワイルドカード文字列の
61135973場合、ファイル名とはマッチングせず、可能性のある文字列が返されます。
61145974例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに
61155975なります:
61165976
61175977 @many = glob "{apple,tomato,cherry}={green,yellow,red}";
61185978
61195979=begin original
61205980
6121This operator is implemented using the standard
5981Beginning with v5.6.0, this operator is implemented using the standard
61225982C<File::Glob> extension. See L<File::Glob> for details, including
61235983C<bsd_glob> which does not treat whitespace as a pattern separator.
61245984
61255985=end original
61265986
61275987v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って
61285988実装されています。
61295989空白をパターンのセパレータとして扱わない C<bsd_glob> を含めた
61305990詳細は L<File::Glob> を参照してください。
61315991
61325992=begin original
61335993
61345994Portability issues: L<perlport/glob>.
61355995
61365996=end original
61375997
61385998移植性の問題: L<perlport/glob>。
61395999
61406000=item gmtime EXPR
61416001X<gmtime> X<UTC> X<Greenwich>
61426002
61436003=item gmtime
61446004
61456005=for Pod::Functions convert UNIX time into record or string using Greenwich time
61466006
61476007=begin original
61486008
61496009Works just like L</localtime> but the returned values are
61506010localized for the standard Greenwich time zone.
61516011
61526012=end original
61536013
61546014L</localtime> と同様に働きますが、返り値はグリニッジ標準時に
61556015ローカライズされています。
61566016
61576017=begin original
61586018
61596019Note: When called in list context, $isdst, the last value
61606020returned by gmtime, is always C<0>. There is no
61616021Daylight Saving Time in GMT.
61626022
61636023=end original
61646024
61656025注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である
61666026$isdst は常に C<0> です。
61676027GMT には夏時間はありません。
61686028
61696029=begin original
61706030
61716031Portability issues: L<perlport/gmtime>.
61726032
61736033=end original
61746034
61756035移植性の問題: L<perlport/gmtime>。
61766036
6177=item goto LABEL
61786037X<goto> X<jump> X<jmp>
61796038
61806039=item goto EXPR
61816040
61826041=item goto &NAME
61836042
61846043=for Pod::Functions create spaghetti code
61856044
61866045=begin original
61876046
6188The C<goto LABEL> form finds the statement labeled with LABEL and
6047The C<goto-LABEL> form finds the statement labeled with LABEL and
61896048resumes execution there. It can't be used to get out of a block or
61906049subroutine given to C<sort>. It can be used to go almost anywhere
61916050else within the dynamic scope, including out of subroutines, but it's
61926051usually better to use some other construct such as C<last> or C<die>.
61936052The author of Perl has never felt the need to use this form of C<goto>
61946053(in Perl, that is; C is another matter). (The difference is that C
61956054does not offer named loops combined with loop control. Perl does, and
61966055this replaces most structured uses of C<goto> in other languages.)
61976056
61986057=end original
61996058
6200C<goto LABEL> の形式は、LABEL というラベルの付いた文を
6059C<goto-LABEL> の形式は、LABEL というラベルの付いた文を
62016060探して、そこへ実行を移すものです。
62026061C<sort> で与えられたブロックやサブルーチンから外へ出ることはできません。
62036062これ以外は、サブルーチンの外を含む、動的スコープ内の
62046063ほとんどすべての場所へ行くために使用できますが、普通は、
62056064C<last> や C<die> といった別の構造を使った方が良いでしょう。
62066065Perl の作者はこの形式の C<goto> を使う必要を感じたことは、
620760661 度もありません (Perl では; C は別のお話です)。
62086067(違いは、C にはループ制御と結びついた名前つきのループがないことです。
62096068Perl にはあり、これが他の言語でのほとんどの構造的な C<goto> の使用法を
62106069置き換えます。)
62116070
62126071=begin original
62136072
6214The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or
6073The C<goto-EXPR> form expects a label name, whose scope will be resolved
6215a label name. If it evaluates to a code reference, it will be handled
6216like C<goto &NAME>, below. This is especially useful for implementing
6217tail recursion via C<goto __SUB__>.
6218
6219=end original
6220
6221C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名として
6222評価することを想定します。
6223コードリファレンスとして評価する場合、後述する C<goto &NAME> のように
6224扱います。
6225これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。
6226
6227=begin original
6228
6229If the expression evaluates to a label name, its scope will be resolved
62306074dynamically. This allows for computed C<goto>s per FORTRAN, but isn't
62316075necessarily recommended if you're optimizing for maintainability:
62326076
62336077=end original
62346078
6235ラベル名に評価される場合、このスコープは動的に解決されます。
6079C<goto-EXPR> の形ラベル名を予測し、このスコープは動的に解決されます。
62366080これにより FORTRAN のような算術 C<goto> が可能になりますが、
62376081保守性を重視するならお勧めしません。
62386082
62396083 goto ("FOO", "BAR", "GLARCH")[$i];
62406084
62416085=begin original
62426086
6243As shown in this example, C<goto EXPR> is exempt from the "looks like a
6087As shown in this example, C<goto-EXPR> is exempt from the "looks like a
62446088function" rule. A pair of parentheses following it does not (necessarily)
62456089delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>.
6246Also, unlike most named operators, this has the same precedence as
6247assignment.
62486090
62496091=end original
62506092
6251この例で示したように、C<goto EXPR> は「関数のように見える」ルールから
6093この例で示したように、C<goto-EXPR> は「関数のように見える」ルールから
62526094除外されます。
62536095これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。
62546096C<goto("NE")."XT"> は C<goto NEXT> と等価です。
6255また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
62566097
62576098=begin original
62586099
6259Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is
6100Use of C<goto-LABEL> or C<goto-EXPR> to jump into a construct is
62606101deprecated and will issue a warning. Even then, it may not be used to
62616102go into any construct that requires initialization, such as a
62626103subroutine or a C<foreach> loop. It also can't be used to go into a
62636104construct that is optimized away.
62646105
62656106=end original
62666107
6267構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは
6108構造の中に飛び込むために C<goto-LABEL> や C<goto-EXPR> を使うことは
62686109非推奨で、警告が発生します。
62696110それでも、サブルーチンや C<foreach> ループのような、初期化が必要な
62706111構造の中に入るために使うことは出来ません。
62716112また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。
62726113
62736114=begin original
62746115
6275The C<goto &NAME> form is quite different from the other forms of
6116The C<goto-&NAME> form is quite different from the other forms of
62766117C<goto>. In fact, it isn't a goto in the normal sense at all, and
62776118doesn't have the stigma associated with other gotos. Instead, it
62786119exits the current subroutine (losing any changes set by local()) and
62796120immediately calls in its place the named subroutine using the current
62806121value of @_. This is used by C<AUTOLOAD> subroutines that wish to
62816122load another subroutine and then pretend that the other subroutine had
62826123been called in the first place (except that any modifications to C<@_>
62836124in the current subroutine are propagated to the other subroutine.)
62846125After the C<goto>, not even C<caller> will be able to tell that this
62856126routine was called first.
62866127
62876128=end original
62886129
6289C<goto &NAME> の形式は、その他の C<goto> の形式とはかなり
6130C<goto-&NAME> の形式は、その他の C<goto> の形式とはかなり
62906131異なったものです。
62916132実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、
62926133他の goto が持つ不名誉を持っていません。
62936134現在のサブルーチンを終了し (local() による変更は失われます)、
62946135直ちに現在の @_ の値を使って指定された名前のサブルーチンを呼び出します。
62956136これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、
62966137その別のサブルーチンが最初に呼ばれたようにするために使われます
62976138(ただし、現在のサブルーチンで C<@_> を修正した場合には、
62986139その別のサブルーチンに伝えられます)。
62996140C<goto> のあとは、C<caller> でさえも、現在のサブルーチンが
63006141最初に呼び出されたと言うことができません。
63016142
63026143=begin original
63036144
63046145NAME needn't be the name of a subroutine; it can be a scalar variable
63056146containing a code reference or a block that evaluates to a code
63066147reference.
63076148
63086149=end original
63096150
63106151NAME はサブルーチンの名前である必要はありません; コードリファレンスを
63116152含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。
63126153
63136154=item grep BLOCK LIST
63146155X<grep>
63156156
63166157=item grep EXPR,LIST
63176158
63186159=for Pod::Functions locate elements in a list test true against a given criterion
63196160
63206161=begin original
63216162
63226163This is similar in spirit to, but not the same as, grep(1) and its
63236164relatives. In particular, it is not limited to using regular expressions.
63246165
63256166=end original
63266167
63276168これは grep(1) とその親類と同じようなものですが、同じではありません。
63286169特に、正規表現の使用に制限されません。
63296170
63306171=begin original
63316172
63326173Evaluates the BLOCK or EXPR for each element of LIST (locally setting
63336174C<$_> to each element) and returns the list value consisting of those
63346175elements for which the expression evaluated to true. In scalar
63356176context, returns the number of times the expression was true.
63366177
63376178=end original
63386179
63396180LIST の個々の要素に対して、BLOCK か EXPR を評価し
63406181(C<$_> は、ローカルに個々の要素が設定されます) 、
63416182その要素のうち、評価した式が真となったものからなるリスト値が返されます。
63426183スカラコンテキストでは、式が真となった回数を返します。
63436184
63446185 @foo = grep(!/^#/, @bar); # weed out comments
63456186
63466187=begin original
63476188
63486189or equivalently,
63496190
63506191=end original
63516192
63526193あるいは等価な例として:
63536194
63546195 @foo = grep {!/^#/} @bar; # weed out comments
63556196
63566197=begin original
63576198
63586199Note that C<$_> is an alias to the list value, so it can be used to
63596200modify the elements of the LIST. While this is useful and supported,
63606201it can cause bizarre results if the elements of LIST are not variables.
63616202Similarly, grep returns aliases into the original list, much as a for
63626203loop's index variable aliases the list elements. That is, modifying an
63636204element of a list returned by grep (for example, in a C<foreach>, C<map>
63646205or another C<grep>) actually modifies the element in the original list.
63656206This is usually something to be avoided when writing clear code.
63666207
63676208=end original
63686209
63696210C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
63706211変更するために使うことができます。
63716212これは、便利でサポートされていますが、
63726213LIST の要素が変数でないと、おかしな結果になります。
63736214同様に、grep は元のリストへのエイリアスを返します; for ループの
63746215インデックス変数がリスト要素のエイリアスであるのと同様です。
63756216つまり、grep で返されたリストの要素を
63766217(C<foreach>, C<map>, または他の C<grep> で)修正すると
63776218元のリストの要素が変更されます。
63786219これはきれいなコードを書くときには普通は回避されます。
63796220
63806221=begin original
63816222
63826223If C<$_> is lexical in the scope where the C<grep> appears (because it has
6383been declared with the deprecated C<my $_> construct)
6224been declared with C<my $_>) then, in addition to being locally aliased to
6384then, in addition to being locally aliased to
63856225the list elements, C<$_> keeps being lexical inside the block; i.e., it
63866226can't be seen from the outside, avoiding any potential side-effects.
63876227
63886228=end original
63896229
6390(廃止予定の C<my $_> 構文で宣言されることによって) C<$_> が C<grep> が現れる
6230(C<my $_> として宣言されることによって) C<$_> が C<grep> が現れるスコープ内で
6391スコープ内でレキシカルな場合は、ローカルではリスト要素への
6231レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加えて、
6392エイリアスであることに加えて、C<$_> はブロック内でレキシカルで
6232C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、
6393ありつづけます; つまり、外側からは見えず、起こりうる副作用を回避します。
6233起こりうる副作用を回避します。
63946234
63956235=begin original
63966236
63976237See also L</map> for a list composed of the results of the BLOCK or EXPR.
63986238
63996239=end original
64006240
64016241BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。
64026242
64036243=item hex EXPR
64046244X<hex> X<hexadecimal>
64056245
64066246=item hex
64076247
64086248=for Pod::Functions convert a string to a hexadecimal number
64096249
64106250=begin original
64116251
64126252Interprets EXPR as a hex string and returns the corresponding value.
64136253(To convert strings that might start with either C<0>, C<0x>, or C<0b>, see
64146254L</oct>.) If EXPR is omitted, uses C<$_>.
64156255
64166256=end original
64176257
64186258EXPR を 16 進数の文字列と解釈して、対応する値を返します。
64196259(C<0>, C<0x>, C<0b> で始まる文字列の変換には、L</oct> を
64206260参照してください。)
64216261EXPR が省略されると、C<$_> を使います。
64226262
64236263 print hex '0xAf'; # prints '175'
64246264 print hex 'aF'; # same
64256265
64266266=begin original
64276267
64286268Hex strings may only represent integers. Strings that would cause
64296269integer overflow trigger a warning. Leading whitespace is not stripped,
64306270unlike oct(). To present something as hex, look into L</printf>,
64316271L</sprintf>, and L</unpack>.
64326272
64336273=end original
64346274
6435627516 進文字列は整数のみを表現します。
64366276整数オーバーフローを起こすような文字列は警告を引き起こします。
64376277oct() とは違って、先頭の空白は除去されません。
64386278何かを 16 進で表現したい場合は、L</printf>, L</sprintf>, L</unpack> を
64396279参照してください。
64406280
64416281=item import LIST
64426282X<import>
64436283
64446284=for Pod::Functions patch a module's namespace into your own
64456285
64466286=begin original
64476287
64486288There is no builtin C<import> function. It is just an ordinary
64496289method (subroutine) defined (or inherited) by modules that wish to export
64506290names to another module. The C<use> function calls the C<import> method
64516291for the package used. See also L</use>, L<perlmod>, and L<Exporter>.
64526292
64536293=end original
64546294
64556295組み込みの C<import> 関数というものはありません。
64566296これは単に、別のモジュールに名前をエクスポートしたいモジュールが
64576297定義した(または継承した)、通常のメソッド(サブルーチン)です。
64586298C<use> 関数はパッケージを使う時に C<import> メソッドを呼び出します。
64596299L</use>, L<perlmod>, L<Exporter> も参照してください。
64606300
64616301=item index STR,SUBSTR,POSITION
64626302X<index> X<indexOf> X<InStr>
64636303
64646304=item index STR,SUBSTR
64656305
64666306=for Pod::Functions find a substring within a string
64676307
64686308=begin original
64696309
64706310The index function searches for one string within another, but without
64716311the wildcard-like behavior of a full regular-expression pattern match.
64726312It returns the position of the first occurrence of SUBSTR in STR at
64736313or after POSITION. If POSITION is omitted, starts searching from the
64746314beginning of the string. POSITION before the beginning of the string
64756315or after its end is treated as if it were the beginning or the end,
64766316respectively. POSITION and the return value are based at zero.
64776317If the substring is not found, C<index> returns -1.
64786318
64796319=end original
64806320
64816321index 関数は ある文字列をもうひとつの文字列から検索しますが、
64826322完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。
64836323STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。
64846324POSITION が省略された場合には、STR の最初から探し始めます。
64856325POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、
64866326それぞれ先頭と末尾を指定されたものとして扱われます。
64876327POSITION と返り値のベースは、0 です。
64886328SUBSTR が見つからなかった場合には、C<index> は -1 が返されます。
64896329
64906330=item int EXPR
64916331X<int> X<integer> X<truncate> X<trunc> X<floor>
64926332
64936333=item int
64946334
64956335=for Pod::Functions get the integer portion of a number
64966336
64976337=begin original
64986338
64996339Returns the integer portion of EXPR. If EXPR is omitted, uses C<$_>.
65006340You should not use this function for rounding: one because it truncates
65016341towards C<0>, and two because machine representations of floating-point
65026342numbers can sometimes produce counterintuitive results. For example,
65036343C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's
65046344because it's really more like -268.99999999999994315658 instead. Usually,
65056345the C<sprintf>, C<printf>, or the C<POSIX::floor> and C<POSIX::ceil>
65066346functions will serve you better than will int().
65076347
65086348=end original
65096349
65106350EXPR の整数部を返します。
65116351EXPR が省略されると、C<$_> を使います。
65126352この関数を丸めのために使うべきではありません: 第一の理由として C<0> の
65136353方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に
65146354反した結果を生み出すからです。
65156355たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を
65166356返します: これは実際には -268.99999999999994315658 というような値に
65176357なっているからです。
65186358通常、C<sprintf>, C<printf>, C<POSIX::floor>, C<POSIX::ceil> の方が
65196359int() より便利です。
65206360
65216361=item ioctl FILEHANDLE,FUNCTION,SCALAR
65226362X<ioctl>
65236363
65246364=for Pod::Functions system-dependent device control system call
65256365
65266366=begin original
65276367
65286368Implements the ioctl(2) function. You'll probably first have to say
65296369
65306370=end original
65316371
65326372ioctl(2) 関数を実装します。
65336373正しい関数の定義を得るために、おそらく最初に
65346374
6535 require "sys/ioctl.ph"; # probably in
6375 require "sys/ioctl.ph"; # probably in $Config{archlib}/sys/ioctl.ph
6536 # $Config{archlib}/sys/ioctl.ph
65376376
65386377=begin original
65396378
65406379to get the correct function definitions. If F<sys/ioctl.ph> doesn't
65416380exist or doesn't have the correct definitions you'll have to roll your
65426381own, based on your C header files such as F<< <sys/ioctl.h> >>.
65436382(There is a Perl script called B<h2ph> that comes with the Perl kit that
65446383may help you in this, but it's nontrivial.) SCALAR will be read and/or
65456384written depending on the FUNCTION; a C pointer to the string value of SCALAR
65466385will be passed as the third argument of the actual C<ioctl> call. (If SCALAR
65476386has no string value but does have a numeric value, that value will be
65486387passed rather than a pointer to the string value. To guarantee this to be
65496388true, add a C<0> to the scalar before using it.) The C<pack> and C<unpack>
65506389functions may be needed to manipulate the values of structures used by
65516390C<ioctl>.
65526391
65536392=end original
65546393
65556394としなくてはならないでしょう。
65566395F<sys/ioctl.ph> がないか、間違った定義をしている場合には、
6557F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、
6396F<< <sys/ioctl.ph> >>のような C のヘッダファイルをもとに、
65586397自分で作らなければなりません。
6559(Perl の配布キットに入っている B<h2ph> という Perl スクリプトが
6398(Perl の配布キットに入っている B<h2ph> という
6560これを手助けしてくれるでしょうが、これは自明はありません。)
6399Perl スクリプトがこれを手助けしてくれるでしょうが、これは重要。)
65616400FOUNCTION に応じて SCALAR が読み書きされます;
65626401SCALAR の文字列値へのポインタが、実際の C<ioctl> コールの
656364023 番目の引数として渡されます。
65646403(SCALAR が文字列値を持っておらず、数値を持っている場合には、
65656404文字列値へのポインタの代わりに、その値が渡されます。
65666405このことを保証するためには、使用する前に SCALAR にC<0> を足してください。)
65676406C<ioctl> で使われる構造体の値を操作するには、
65686407C<pack> 関数と C<unpack> 関数が必要となるでしょう。
65696408
65706409=begin original
65716410
65726411The return value of C<ioctl> (and C<fcntl>) is as follows:
65736412
65746413=end original
65756414
65766415C<ioctl> (と C<fcntl>) の返り値は、以下のようになります:
65776416
65786417=begin original
65796418
65806419 if OS returns: then Perl returns:
65816420 -1 undefined value
65826421 0 string "0 but true"
65836422 anything else that number
65846423
65856424=end original
65866425
65876426 OS が返した値: Perl が返す値:
65886427 -1 未定義値
65896428 0 「0 だが真」の文字列
65906429 その他 その値そのもの
65916430
65926431=begin original
65936432
65946433Thus Perl returns true on success and false on failure, yet you can
65956434still easily determine the actual value returned by the operating
65966435system:
65976436
65986437=end original
65996438
66006439つまり Perl は、成功時に「真」、失敗時に「偽」を返す
66016440ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。
66026441
66036442 $retval = ioctl(...) || -1;
66046443 printf "System returned %d\n", $retval;
66056444
66066445=begin original
66076446
66086447The special string C<"0 but true"> is exempt from B<-w> complaints
66096448about improper numeric conversions.
66106449
66116450=end original
66126451
66136452特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する
66146453B<-w> 警告を回避します。
66156454
66166455=begin original
66176456
66186457Portability issues: L<perlport/ioctl>.
66196458
66206459=end original
66216460
66226461移植性の問題: L<perlport/ioctl>。
66236462
66246463=item join EXPR,LIST
66256464X<join>
66266465
66276466=for Pod::Functions join a list into a string using a separator
66286467
66296468=begin original
66306469
66316470Joins the separate strings of LIST into a single string with fields
66326471separated by the value of EXPR, and returns that new string. Example:
66336472
66346473=end original
66356474
66366475LIST の個別の文字列を、EXPR の値で区切って
663764761 つの文字列につなげ、その文字列を返します。
66386477例:
66396478
66406479 $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
66416480
66426481=begin original
66436482
66446483Beware that unlike C<split>, C<join> doesn't take a pattern as its
66456484first argument. Compare L</split>.
66466485
66476486=end original
66486487
66496488C<split> と違って、C<join> は最初の引数にパターンは取れないことに
66506489注意してください。
66516490L</split> と比較してください。
66526491
66536492=item keys HASH
66546493X<keys> X<key>
66556494
66566495=item keys ARRAY
66576496
66586497=item keys EXPR
66596498
66606499=for Pod::Functions retrieve list of indices from a hash
66616500
66626501=begin original
66636502
66646503Called in list context, returns a list consisting of all the keys of the
66656504named hash, or in Perl 5.12 or later only, the indices of an array. Perl
66666505releases prior to 5.12 will produce a syntax error if you try to use an
66676506array argument. In scalar context, returns the number of keys or indices.
66686507
66696508=end original
66706509
66716510リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは
6672Perl 5.12 以降でのみ、配列のインデックスからなるリストを返します。
6511Perl 5.12 以降でのみ、配列のインデックスからなるリストを
6512返します。
667365135.12 より前の Perl は配列引数を使おうとすると文法エラーを出力します。
66746514スカラコンテキストでは、キーやインデックスの数を返します。
66756515
66766516=begin original
66776517
6678Hash entries are returned in an apparently random order. The actual random
6518The keys of a hash are returned in an apparently random order. The actual
6679order is specific to a given hash; the exact same series of operations
6519random order is subject to change in future versions of Perl, but it
6680on two hashes may result in a different order for each hash. Any insertion
6520is guaranteed to be the same order as either the C<values> or C<each>
6681into the hash may change the order, as will any deletion, with the exception
6521function produces (given that the hash has not been modified). Since
6682that the most recent key returned by C<each> or C<keys> may be deleted
6522Perl 5.8.1 the ordering can be different even between different runs of
6683without changing the order. So long as a given hash is unmodified you may
6523Perl for security reasons (see L<perlsec/"Algorithmic Complexity
6684rely on C<keys>, C<values> and C<each> to repeatedly return the same order
6524Attacks">).
6685as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
6686details on why hash order is randomized. Aside from the guarantees
6687provided here the exact details of Perl's hash algorithm and the hash
6688traversal order are subject to change in any release of Perl. Tied hashes
6689may behave differently to Perl's hashes with respect to changes in order on
6690insertion and deletion of items.
66916525
66926526=end original
66936527
6694ハッシュ要素は見かけ上、ランダムな順序で返されます。
6528ハッシュのキーは見たところではランダムな順番に返されます。
6695実際のランダムな順ハッシュに固有です; 二つハッシュに全く同じ一連
6529実際のランダムな順Perl 将来バージョンでは変わるかもしれませんが、
6696操作を行っも、ハッシュによっ異なった順序になります。
6530C<values> や C<each> 関数が同じ(変更されいない)ハッシュに対し
6697ハッシュへ挿入によって序が変わることがあります; 削除も同様ですが、
6531生成すると同じ番であることは保証されます
6698C<each> または C<keys> によって返されたもっとも最近のキーは順序を
6532Perl 5.8.1 以降ではセキュリティ上の理由により、
6699変えことなく削除できます
6533実行され毎に順番は変わります
6700ハッシュが変更されない限り、C<keys>, C<values>, C<each> が繰り返同じ順序で
6534(L<perlsec/"Algorithmic Complexity Attacks"> を参照てください)。
6701返すことに依存してもかまいません。
6702なぜハッシュの順序がランダム化されているかの詳細については
6703L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
6704ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
6705正確な詳細は Perl のリリースによって変更される可能性があります。
6706tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
6707異なった振る舞いをします。
67086535
67096536=begin original
67106537
6711As a side effect, calling keys() resets the internal iterator of the HASH or
6538As a side effect, calling keys() resets the internal interator of the HASH or ARRAY
6712ARRAY (see L</each>). In particular, calling keys() in void context resets
6539(see L</each>). In particular, calling keys() in void context resets
67136540the iterator with no other overhead.
67146541
67156542=end original
67166543
67176544副作用として、HASH や ARRAY の反復子を初期化します
67186545(L</each> を参照してください)。
67196546特に、無効コンテキストで keys() を呼び出すと
67206547オーバーヘッドなしで反復子を初期化します。
67216548
67226549=begin original
67236550
67246551Here is yet another way to print your environment:
67256552
67266553=end original
67276554
67286555環境変数を表示する別の例です:
67296556
67306557 @keys = keys %ENV;
67316558 @values = values %ENV;
67326559 while (@keys) {
67336560 print pop(@keys), '=', pop(@values), "\n";
67346561 }
67356562
67366563=begin original
67376564
67386565or how about sorted by key:
67396566
67406567=end original
67416568
67426569key でソートしてもいいでしょう:
67436570
67446571 foreach $key (sort(keys %ENV)) {
67456572 print $key, '=', $ENV{$key}, "\n";
67466573 }
67476574
67486575=begin original
67496576
67506577The returned values are copies of the original keys in the hash, so
67516578modifying them will not affect the original hash. Compare L</values>.
67526579
67536580=end original
67546581
67556582返される値はハッシュにある元のキーのコピーなので、
67566583これを変更しても元のハッシュには影響を与えません。
67576584L</values> と比較してください。
67586585
67596586=begin original
67606587
67616588To sort a hash by value, you'll need to use a C<sort> function.
67626589Here's a descending numeric sort of a hash by its values:
67636590
67646591=end original
67656592
67666593ハッシュを値でソートするためには、C<sort> 関数を使う必要があります。
67676594以下ではハッシュの値を数値の降順でソートしています:
67686595
67696596 foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
67706597 printf "%4d %s\n", $hash{$key}, $key;
67716598 }
67726599
67736600=begin original
67746601
67756602Used as an lvalue, C<keys> allows you to increase the number of hash buckets
67766603allocated for the given hash. This can gain you a measure of efficiency if
67776604you know the hash is going to get big. (This is similar to pre-extending
67786605an array by assigning a larger number to $#array.) If you say
67796606
67806607=end original
67816608
67826609左辺値として使うことで、C<keys> を使うことで与えられたハッシュに割り当てられた
67836610ハッシュ表の大きさを増やすことができます。
67846611これによって、ハッシュが大きくなっていくなっていくときの
67856612効率の測定ができます。
67866613(これは大きい値を $#array に代入することで配列を予め拡張することに
67876614似ています。)
67886615以下のようにすると:
67896616
67906617 keys %hash = 200;
67916618
67926619=begin original
67936620
67946621then C<%hash> will have at least 200 buckets allocated for it--256 of them,
67956622in fact, since it rounds up to the next power of two. These
67966623buckets will be retained even if you do C<%hash = ()>, use C<undef
67976624%hash> if you want to free the storage while C<%hash> is still in scope.
67986625You can't shrink the number of buckets allocated for the hash using
67996626C<keys> in this way (but you needn't worry about doing this by accident,
68006627as trying has no effect). C<keys @array> in an lvalue context is a syntax
68016628error.
68026629
68036630=end original
68046631
68056632C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
68066633実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。
68076634この表はたとえ C<%hash = ()> としても残るので、
68086635もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は
68096636C<undef %hash> を使います。
68106637この方法で C<keys> を使うことで、表の大きさを小さくすることはできません
68116638(間違えてそのようなことをしても何も起きないので気にすることはありません)。
68126639左辺値コンテキストでの C<keys @array> は文法エラーとなります。
68136640
68146641=begin original
68156642
68166643Starting with Perl 5.14, C<keys> can take a scalar EXPR, which must contain
68176644a reference to an unblessed hash or array. The argument will be
68186645dereferenced automatically. This aspect of C<keys> is considered highly
68196646experimental. The exact behaviour may change in a future version of Perl.
68206647
68216648=end original
68226649
68236650Perl 5.14 から、C<keys> はスカラの EXPR を取ることができるようになりました;
68246651これは bless されていないハッシュや配列へのリファレンスでなければなりません。
68256652引数は自動的にデリファレンスされます。
68266653C<keys> のこの動作は高度に実験的であると考えられています。
68276654正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
68286655
68296656 for (keys $hashref) { ... }
68306657 for (keys $obj->get_arrayref) { ... }
68316658
68326659=begin original
68336660
68346661To avoid confusing would-be users of your code who are running earlier
68356662versions of Perl with mysterious syntax errors, put this sort of thing at
68366663the top of your file to signal that your code will work I<only> on Perls of
68376664a recent vintage:
68386665
68396666=end original
68406667
68416668あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
68426669文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
68436670I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
68446671書いてください:
68456672
68466673 use 5.012; # so keys/values/each work on arrays
68476674 use 5.014; # so keys/values/each work on scalars (experimental)
68486675
68496676=begin original
68506677
68516678See also C<each>, C<values>, and C<sort>.
68526679
68536680=end original
68546681
68556682C<each>, C<values>, C<sort> も参照してください。
68566683
68576684=item kill SIGNAL, LIST
68586685
68596686=item kill SIGNAL
68606687X<kill> X<signal>
68616688
68626689=for Pod::Functions send a signal to a process or process group
68636690
68646691=begin original
68656692
6866Sends a signal to a list of processes. Returns the number of arguments
6693Sends a signal to a list of processes. Returns the number of
6867that were successfully used to signal (which is not necessarily the same
6694processes successfully signaled (which is not necessarily the
6868as the number of processes actually killed, e.g. where a process group is
6695same as the number actually killed).
6869killed).
68706696
68716697=end original
68726698
68736699プロセスのリストにシグナルを送ります。
6874シグナル送信に使われ引数の数を返します
6700シグナル送信に成功しプロセスの数を返します
6875(例えばプロセスグループが kill された場合のように、実際に kill され
6701(実際に kill に成功しプロセスと同じとは限りません)。
6876プロセスの数と同じとは限りません)。
68776702
6878 $cnt = kill 'HUP', $child1, $child2;
6703 $cnt = kill 1, $child1, $child2;
6879 kill 'KILL', @goners;
6704 kill 9, @goners;
68806705
68816706=begin original
68826707
6883SIGNAL may be either a signal name (a string) or a signal number. A signal
6708If SIGNAL is zero, no signal is sent to the process, but C<kill>
6884name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the
6709checks whether it's I<possible> to send a signal to it (that
6885same signal. The string form of SIGNAL is recommended for portability because
6710means, to be brief, that the process is owned by the same user, or we are
6886the same signal may have different numbers in different operating systems.
6711the super-user). This is useful to check that a child process is still
6712alive (even if only as a zombie) and hasn't changed its UID. See
6713L<perlport> for notes on the portability of this construct.
68876714
68886715=end original
68896716
6890SIGNAL シグナル名(文字列)かシグナル番号のどちかです。
6717SIGNAL がゼロの場合、プロセスにシグナルは送れませんが、
6891シグナル名は C<SIG> 接頭辞で始まることがあるので、C<FOO> と C<SIGFOO> は同じ
6718C<kill> は、シグナルを送ることが I<可能> かどうかを調べます
6892シグナルを意味します。
6719(これは、簡単に言うと、プロセスが同じユーザーに所有されているか、
6893移植性から文字列形式の SIGNAL 推奨されます; 同じシグナルが異なった
6720自分スーパーユーザーであることを意味します)。
6894オペレーティングシステムでは異なった番号になるあるからす。
6721れは子プロセス(ゾンビとしてだけも)まだ生きていて、 UID が
6722変わっていないことを調べる時に有用です。
6723この構成の移植性に関する注意については L<perlport> を参照してください。
68956724
68966725=begin original
68976726
6898A list of signal names supported by the current platform can be found in
6727Unlike in the shell, if SIGNAL is negative, it kills process groups instead
6899C<$Config{sig_name}>, which is provided by the C<Config> module. See L<Config>
6728of processes. That means you usually
6900for more details.
6729want to use positive not negative signals.
6730You may also use a signal name in quotes.
69016731
69026732=end original
69036733
6904現在のプラットフォームが対応しているシグナル一覧はC<Config>
6734ェルとは異なり、シグナルに負数を与えると
6905モジュールによって提供される C<$Config{sig_name}> にあります。
6906さらなる詳細については L<Config> を参照してください。
6907
6908=begin original
6909
6910A negative signal name is the same as a negative signal number, killing process
6911groups instead of processes. For example, C<kill '-KILL', $pgrp> and
6912C<kill -9, $pgrp> will send C<SIGKILL> to
6913the entire process group specified. That
6914means you usually want to use positive not negative signals.
6915
6916=end original
6917
6918負のシグナル名は負のシグナル番号と同じで、
69196735プロセスではなくプロセスグループに対して kill を行ないます。
6920たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された
6921プロセスグループ全体に C<SIGKILL> を送ります。
69226736すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。
6737シグナル名をクォートして使うこともできます。
69236738
69246739=begin original
69256740
6926If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>),
6927no signal is sent to
6928the process, but C<kill> checks whether it's I<possible> to send a signal to it
6929(that means, to be brief, that the process is owned by the same user, or we are
6930the super-user). This is useful to check that a child process is still
6931alive (even if only as a zombie) and hasn't changed its UID. See
6932L<perlport> for notes on the portability of this construct.
6933
6934=end original
6935
6936SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに
6937シグナルは送られませんが、C<kill> は、シグナルを送ることが I<可能> かどうかを
6938調べます (これは、簡単に言うと、プロセスが同じユーザーに所有されているか、
6939自分がスーパーユーザーであることを意味します)。
6940これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が
6941変わっていないことを調べる時に有用です。
6942この構成の移植性に関する注意については L<perlport> を参照してください。
6943
6944=begin original
6945
69466741The behavior of kill when a I<PROCESS> number is zero or negative depends on
69476742the operating system. For example, on POSIX-conforming systems, zero will
6948signal the current process group, -1 will signal all processes, and any
6743signal the current process group and -1 will signal all processes.
6949other negative PROCESS number will act as a negative signal number and
6950kill the entire process group specified.
69516744
69526745=end original
69536746
69546747I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは
69556748オペレーティングシステムに依存します。
69566749例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、
6957-1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は
6750-1 は全てのプロセスにシグナルを送ります。
6958負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。
69596751
69606752=begin original
69616753
6962If both the SIGNAL and the PROCESS are negative, the results are undefined.
6963A warning may be produced in a future version.
6964
6965=end original
6966
6967SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。
6968将来のバージョンでは警告が出るかも知れません。
6969
6970=begin original
6971
69726754See L<perlipc/"Signals"> for more details.
69736755
69746756=end original
69756757
69766758詳細は L<perlipc/"Signals"> を参照してください。
69776759
69786760=begin original
69796761
6980On some platforms such as Windows where the fork() system call is not
6762On some platforms such as Windows where the fork() system call is not available.
6981available, Perl can be built to emulate fork() at the interpreter level.
6763Perl can be built to emulate fork() at the interpreter level.
69826764This emulation has limitations related to kill that have to be considered,
69836765for code running on Windows and in code intended to be portable.
69846766
69856767=end original
69866768
69876769Windows のような fork() が利用不能なシステムでは、Perl は fork() を
69886770インタプリタレベルでエミュレートします。
69896771エミュレーションは kill に関連して、コードが Windows で実行されて
69906772しかしコードが移植性があると考えられるように制限があります。
69916773
69926774=begin original
69936775
69946776See L<perlfork> for more details.
69956777
69966778=end original
69976779
69986780さらなる詳細については L<perlfork> を参照してください。
69996781
70006782=begin original
70016783
70026784If there is no I<LIST> of processes, no signal is sent, and the return
70036785value is 0. This form is sometimes used, however, because it causes
70046786tainting checks to be run. But see
70056787L<perlsec/Laundering and Detecting Tainted Data>.
70066788
70076789=end original
70086790
70096791処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。
70106792しかし、この形式は時々使われます; 実行するために汚染チェックを
70116793引き起こすからです。
70126794しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。
70136795
70146796=begin original
70156797
70166798Portability issues: L<perlport/kill>.
70176799
70186800=end original
70196801
70206802移植性の問題: L<perlport/kill>。
70216803
70226804=item last LABEL
70236805X<last> X<break>
70246806
7025=item last EXPR
7026
70276807=item last
70286808
70296809=for Pod::Functions exit a block prematurely
70306810
70316811=begin original
70326812
70336813The C<last> command is like the C<break> statement in C (as used in
70346814loops); it immediately exits the loop in question. If the LABEL is
7035omitted, the command refers to the innermost enclosing
6815omitted, the command refers to the innermost enclosing loop. The
7036loop. The C<last EXPR> form, available starting in Perl
70375.18.0, allows a label name to be computed at run time,
7038and is otherwise identical to C<last LABEL>. The
70396816C<continue> block, if any, is not executed:
70406817
70416818=end original
70426819
70436820C<last> コマンドは、(ループ内で使った) C の C<break> 文と
70446821同じようなもので、LABEL で指定されるループを即座に抜けます。
70456822LABEL が省略されると、コマンドは一番内側のループを参照します。
7046Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算される
7047ラベル名を使えます; それ以外は C<last LABEL> と同一です。
70486823C<continue> ブロックがあっても実行されません:
70496824
70506825 LINE: while (<STDIN>) {
70516826 last LINE if /^$/; # exit when done with header
70526827 #...
70536828 }
70546829
70556830=begin original
70566831
70576832C<last> cannot be used to exit a block that returns a value such as
70586833C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
70596834a grep() or map() operation.
70606835
70616836=end original
70626837
70636838C<last> は C<eval {}>, C<sub {}>, C<do {}> といった
70646839値を返すブロックを終了するのには使えませんし、
70656840grep() や map() 操作を終了するのに使うべきではありません。
70666841
70676842=begin original
70686843
70696844Note that a block by itself is semantically identical to a loop
70706845that executes once. Thus C<last> can be used to effect an early
70716846exit out of such a block.
70726847
70736848=end original
70746849
70756850ブロック自身は一回だけ実行されるループと文法的に同一であることに
70766851注意してください。
70776852従って、C<last> でそのようなブロックを途中で抜け出すことができます。
70786853
70796854=begin original
70806855
70816856See also L</continue> for an illustration of how C<last>, C<next>, and
70826857C<redo> work.
70836858
70846859=end original
70856860
70866861C<last>, C<next>, C<redo> がどのように働くかについては
70876862L</continue> も参照してください。
70886863
7089=begin original
7090
7091Unlike most named operators, this has the same precedence as assignment.
7092It is also exempt from the looks-like-a-function rule, so
7093C<last ("foo")."bar"> will cause "bar" to be part of the argument to
7094C<last>.
7095
7096=end original
7097
7098ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
7099また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と
7100すると "bar" は C<last> への引数の一部となります。
7101
71026864=item lc EXPR
71036865X<lc> X<lowercase>
71046866
71056867=item lc
71066868
71076869=for Pod::Functions return lower-case version of a string
71086870
71096871=begin original
71106872
71116873Returns a lowercased version of EXPR. This is the internal function
71126874implementing the C<\L> escape in double-quoted strings.
71136875
71146876=end original
71156877
71166878EXPR を小文字に変換したものを返します。
71176879これは、ダブルクォート文字列における、
71186880C<\L> エスケープを実装する内部関数です。
71196881
71206882=begin original
71216883
71226884If EXPR is omitted, uses C<$_>.
71236885
71246886=end original
71256887
71266888EXPR が省略されると、C<$_> を使います。
71276889
71286890=begin original
71296891
71306892What gets returned depends on several factors:
71316893
71326894=end original
71336895
71346896返り値として得られるものは色々な要素に依存します:
71356897
71366898=over
71376899
71386900=item If C<use bytes> is in effect:
71396901
71406902(C<use bytes> が有効の場合)
71416903
6904=over
6905
6906=item On EBCDIC platforms
6907
71426908=begin original
71436909
7144The results follow ASCII rules. Only the characters C<A-Z> change,
6910The results are what the C language system call C<tolower()> returns.
7145to C<a-z> respectively.
71466911
71476912=end original
71486913
7149結果は ASCII規則に従います。
6914結果は、C 言語のシステムコール C<tolower()> が返すもす。
6915
6916=item On ASCII platforms
6917
6918=begin original
6919
6920The results follow ASCII semantics. Only characters C<A-Z> change, to C<a-z>
6921respectively.
6922
6923=end original
6924
6925結果は ASCII の意味論に従います。
71506926C<A-Z> のみが変換され、それぞれ C<a-z> になります。
71516927
6928=back
6929
71526930=item Otherwise, if C<use locale> (but not C<use locale ':not_characters'>) is in effect:
71536931
71546932(それ以外の場合で、C<use locale> が有効の(そして C<use locale 'not_characters'> が有効でない)場合)
71556933
71566934=begin original
71576935
71586936Respects current LC_CTYPE locale for code points < 256; and uses Unicode
7159rules for the remaining code points (this last can only happen if
6937semantics for the remaining code points (this last can only happen if
71606938the UTF8 flag is also set). See L<perllocale>.
71616939
71626940=end original
71636941
71646942符号位置 < 256 に対しては現在の LC_CTYPE ロケールに従います; そして
7165残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも
6943残りの符号位置に付いては Unicode の意味論を使います (これは UTF8 フラグも
71666944設定されている場合にのみ起こります)。
71676945L<perllocale> を参照してください。
71686946
71696947=begin original
71706948
7171Starting in v5.20, Perl wil use full Unicode rules if the locale is
6949A deficiency in this is that case changes that cross the 255/256
7172UTF-8. Otherwise, there is a deficiency in this scheme, which is that
7173case changes that cross the 255/256
71746950boundary are not well-defined. For example, the lower case of LATIN CAPITAL
7175LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII
6951LETTER SHARP S (U+1E9E) in Unicode semantics is U+00DF (on ASCII
7176platforms). But under C<use locale> (prior to v5.20 or not a UTF-8
6952platforms). But under C<use locale>, the lower case of U+1E9E is
7177locale), the lower case of U+1E9E is
71786953itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the
71796954current locale, and Perl has no way of knowing if that character even
71806955exists in the locale, much less what code point it is. Perl returns
71816956the input character unchanged, for all instances (and there aren't
71826957many) where the 255/256 boundary would otherwise be crossed.
71836958
71846959=end original
71856960
7186v5.20 から、ロケールが UTF-8 場合は Perl は完全な Unicode の規則使いす。
6961これの欠点は、255/266境界をまたぐ大文字小文字の変換は
7187さもなければ、の手法には、255/266 の境界をまたぐ大文字小文字の変換は
6962未定義であるとです。
7188未定義であるという欠点があります。
71896963例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は
71906964(ASCII プラットフォームでは) U+00DF です。
7191しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の
6965しかし C<use locale> が有効なら、U+1E9E の小文字は自分自身です; なぜなら
7192小文字は自分自身です; なぜなら 0xDF は現在のロケールでは
69660xDF は現在のロケールでは LATIN SMALL LETTER SHARP S ではなく、Perl
7193LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が
6967例えこのロケールに文字が存在するかどうかを知る方法がなく、まして
7194存在するかうかを知る方法がなく、ましてどの符号位置かを知る方法が
6968どの符号位置かを知る方法がないからです。
7195ないからです。
71966969Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については
71976970入力文字を変更せずに返します。
71986971
71996972=item Otherwise, If EXPR has the UTF8 flag set:
72006973
72016974(その他の場合で、EXPR に UTF8 フラグがセットされている場合)
72026975
72036976=begin original
72046977
7205Unicode rules are used for the case change.
6978Unicode semantics are used for the case change.
72066979
72076980=end original
72086981
7209大文字小文字変換には Unicode の規則が使われます。
6982大文字小文字変換には Unicode の意味論が使われます。
72106983
7211=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect:
6984=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'>) is in effect:
72126985
72136986(それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合)
72146987
72156988=begin original
72166989
7217Unicode rules are used for the case change.
6990Unicode semantics are used for the case change.
72186991
72196992=end original
72206993
7221大文字小文字変換には Unicode の規則が使われます。
6994大文字小文字変換には Unicode の意味論が使われます。
72226995
72236996=item Otherwise:
72246997
72256998(それ以外の場合)
72266999
7000=over
7001
7002=item On EBCDIC platforms
7003
72277004=begin original
72287005
7229ASCII rules are used for the case change. The lowercase of any character
7006The results are what the C language system call C<tolower()> returns.
7007
7008=end original
7009
7010結果は、C 言語のシステムコール C<tolower()> が返すものです。
7011
7012=item On ASCII platforms
7013
7014=begin original
7015
7016ASCII semantics are used for the case change. The lowercase of any character
72307017outside the ASCII range is the character itself.
72317018
72327019=end original
72337020
7234大文字小文字変換には ASCII の規則が使われます。
7021大文字小文字変換には ASCII の意味論が使われます。
72357022ASCII の範囲外の文字の「小文字」はその文字自身です。
72367023
72377024=back
72387025
7026=back
7027
72397028=item lcfirst EXPR
72407029X<lcfirst> X<lowercase>
72417030
72427031=item lcfirst
72437032
72447033=for Pod::Functions return a string with just the next letter in lower case
72457034
72467035=begin original
72477036
72487037Returns the value of EXPR with the first character lowercased. This
72497038is the internal function implementing the C<\l> escape in
72507039double-quoted strings.
72517040
72527041=end original
72537042
72547043最初の文字だけを小文字にした、EXPR を返します。
72557044これは、ダブルクォート文字列における、C<\l> エスケープを
72567045実装する内部関数です。
72577046
72587047=begin original
72597048
72607049If EXPR is omitted, uses C<$_>.
72617050
72627051=end original
72637052
72647053EXPR が省略されると、C<$_> を使います。
72657054
72667055=begin original
72677056
72687057This function behaves the same way under various pragmata, such as in a locale,
72697058as L</lc> does.
72707059
72717060=end original
72727061
72737062この関数は、ロケールのようなさまざまなプラグマの影響下では、
72747063L</lc> と同様に振る舞います。
72757064
72767065=item length EXPR
72777066X<length> X<size>
72787067
72797068=item length
72807069
7281=for Pod::Functions return the number of characters in a string
7070=for Pod::Functions return the number of bytes in a string
72827071
72837072=begin original
72847073
72857074Returns the length in I<characters> of the value of EXPR. If EXPR is
72867075omitted, returns the length of C<$_>. If EXPR is undefined, returns
72877076C<undef>.
72887077
72897078=end original
72907079
72917080EXPR の値の I<文字> の長さを返します。
72927081EXPR が省略されたときには、C<$_> の長さを返します。
72937082EXPR が未定義値の場合、C<undef> を返します。
72947083
72957084=begin original
72967085
72977086This function cannot be used on an entire array or hash to find out how
72987087many elements these have. For that, use C<scalar @array> and C<scalar keys
72997088%hash>, respectively.
73007089
73017090=end original
73027091
73037092この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを
73047093調べるためには使えません。
73057094そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を
73067095利用してください。
73077096
73087097=begin original
73097098
73107099Like all Perl character operations, length() normally deals in logical
73117100characters, not physical bytes. For how many bytes a string encoded as
73127101UTF-8 would take up, use C<length(Encode::encode_utf8(EXPR))> (you'll have
73137102to C<use Encode> first). See L<Encode> and L<perlunicode>.
73147103
73157104=end original
73167105
73177106全ての Perl の文字操作と同様、length() は通常物理的なバイトではなく
73187107論理文字を扱います。
73197108UTF-8 でエンコードされた文字列が何バイトかを知るには、
73207109C<length(Encode::encode_utf8(EXPR))> を使ってください (先に
73217110C<use Encode> する必要があります)。
73227111L<Encode> と L<perlunicode> を参照してください。
73237112
73247113=item __LINE__
73257114X<__LINE__>
73267115
73277116=for Pod::Functions the current source line number
73287117
73297118=begin original
73307119
73317120A special token that compiles to the current line number.
73327121
73337122=end original
73347123
73357124現在の行番号にコンパイルされる特殊トークン。
73367125
73377126=item link OLDFILE,NEWFILE
73387127X<link>
73397128
73407129=for Pod::Functions create a hard link in the filesystem
73417130
73427131=begin original
73437132
73447133Creates a new filename linked to the old filename. Returns true for
73457134success, false otherwise.
73467135
73477136=end original
73487137
73497138OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。
73507139成功時には真を、さもなければ偽を返します。
73517140
73527141=begin original
73537142
73547143Portability issues: L<perlport/link>.
73557144
73567145=end original
73577146
73587147移植性の問題: L<perlport/link>。
73597148
73607149=item listen SOCKET,QUEUESIZE
73617150X<listen>
73627151
73637152=for Pod::Functions register your socket as a server
73647153
73657154=begin original
73667155
73677156Does the same thing that the listen(2) system call does. Returns true if
73687157it succeeded, false otherwise. See the example in
73697158L<perlipc/"Sockets: Client/Server Communication">.
73707159
73717160=end original
73727161
73737162listen(2) システムコールと同じことをします。
73747163成功時には真を、さもなければ偽を返します。
73757164L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
73767165
73777166=item local EXPR
73787167X<local>
73797168
73807169=for Pod::Functions create a temporary value for a global variable (dynamic scoping)
73817170
73827171=begin original
73837172
73847173You really probably want to be using C<my> instead, because C<local> isn't
73857174what most people think of as "local". See
73867175L<perlsub/"Private Variables via my()"> for details.
73877176
73887177=end original
73897178
73907179あなたはが本当に望んでいるのは C<my> の方でしょう; C<local> はほとんどの
73917180人々が「ローカル」と考えるものと違うからです。
73927181詳細は L<perlsub/"Private Variables via my()"> を参照してください。
73937182
73947183=begin original
73957184
73967185A local modifies the listed variables to be local to the enclosing
73977186block, file, or eval. If more than one value is listed, the list must
73987187be placed in parentheses. See L<perlsub/"Temporary Values via local()">
73997188for details, including issues with tied arrays and hashes.
74007189
74017190=end original
74027191
74037192"local" はリストアップされた変数を、囲っているブロック、
74047193ファイル、eval の中で、ローカルなものにします。
74057194複数の値を指定する場合は、リストはかっこでくくらなければなりません。
74067195tie した配列とハッシュに関する事項を含む詳細については
74077196L<perlsub/"Temporary Values via local()"> を参照してください。
74087197
74097198=begin original
74107199
74117200The C<delete local EXPR> construct can also be used to localize the deletion
74127201of array/hash elements to the current block.
74137202See L<perlsub/"Localized deletion of elements of composite types">.
74147203
74157204=end original
74167205
74177206C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の
74187207ブロックにローカル化するためにも使われていました。
74197208L<perlsub/"Localized deletion of elements of composite types"> を
74207209参照してください。
74217210
74227211=item localtime EXPR
74237212X<localtime> X<ctime>
74247213
74257214=item localtime
74267215
74277216=for Pod::Functions convert UNIX time into record or string using local time
74287217
74297218=begin original
74307219
74317220Converts a time as returned by the time function to a 9-element list
74327221with the time analyzed for the local time zone. Typically used as
74337222follows:
74347223
74357224=end original
74367225
74377226time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、
743872279 要素の配列に変換します。
74397228普通は、以下のようにして使います:
74407229
74417230 # 0 1 2 3 4 5 6 7 8
74427231 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
74437232 localtime(time);
74447233
74457234=begin original
74467235
74477236All list elements are numeric and come straight out of the C `struct
74487237tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours
74497238of the specified time.
74507239
74517240=end original
74527241
74537242すべてのリスト要素は数値で、C の `struct tm' 構造体から
74547243直接持ってきます。
74557244C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。
74567245
74577246=begin original
74587247
74597248C<$mday> is the day of the month and C<$mon> the month in
74607249the range C<0..11>, with 0 indicating January and 11 indicating December.
74617250This makes it easy to get a month name from a list:
74627251
74637252=end original
74647253
74657254C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が
746672551 月、11 が 12 月です。
74677256これにより、リストから月の名前を得るのが簡単になります:
74687257
7469 my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
7258 my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
74707259 print "$abbr[$mon] $mday";
74717260 # $mon=9, $mday=18 gives "Oct 18"
74727261
74737262=begin original
74747263
74757264C<$year> contains the number of years since 1900. To get a 4-digit
74767265year write:
74777266
74787267=end original
74797268
74807269C<$year> は 1900 年からの年数を持ちます。
748172704 桁の年を得るには以下のようにします:
74827271
74837272 $year += 1900;
74847273
74857274=begin original
74867275
74877276To get the last two digits of the year (e.g., "01" in 2001) do:
74887277
74897278=end original
74907279
74917280西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします:
74927281
74937282 $year = sprintf("%02d", $year % 100);
74947283
74957284=begin original
74967285
74977286C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating
74987287Wednesday. C<$yday> is the day of the year, in the range C<0..364>
74997288(or C<0..365> in leap years.)
75007289
75017290=end original
75027291
75037292C<$wday> は曜日で、0 が日曜日、3 が水曜日です。
75047293C<$yday> はその年の何日目かで、C<0..364> の値を取ります
75057294(うるう年は C<0..365> です。)
75067295
75077296=begin original
75087297
75097298C<$isdst> is true if the specified time occurs during Daylight Saving
75107299Time, false otherwise.
75117300
75127301=end original
75137302
75147303C<$isdst> は指定された時刻が夏時間の場合は真、そうでなければ偽です。
75157304
75167305=begin original
75177306
75187307If EXPR is omitted, C<localtime()> uses the current time (as returned
75197308by time(3)).
75207309
75217310=end original
75227311
75237312EXPR が省略されると、C<localtime()> は(time(3) によって返される)
75247313現在時刻を使います。
75257314
75267315=begin original
75277316
75287317In scalar context, C<localtime()> returns the ctime(3) value:
75297318
75307319=end original
75317320
75327321スカラコンテキストでは、C<localtime()> は ctime(3) の値を返します:
75337322
75347323 $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
75357324
75367325=begin original
75377326
75387327The format of this scalar value is B<not> locale-dependent
75397328but built into Perl. For GMT instead of local
75407329time use the L</gmtime> builtin. See also the
75417330C<Time::Local> module (for converting seconds, minutes, hours, and such back to
75427331the integer value returned by time()), and the L<POSIX> module's strftime(3)
75437332and mktime(3) functions.
75447333
75457334=end original
75467335
75477336このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です。
75487337ローカル時刻ではなく GMT がほしい場合は L</gmtime> 組み込み関数を
75497338使ってください。
75507339また、(秒、分、時などの形から、time() が返す値である
755173401970 年 1 月 1 日の真夜中からの秒数に変換する) C<Time::Local> モジュール
75527341及び POSIX モジュールで提供される strftime(3) と mktime(3) 関数も
75537342参照してください。
75547343
75557344=begin original
75567345
75577346To get somewhat similar but locale-dependent date strings, set up your
75587347locale environment variables appropriately (please see L<perllocale>) and
75597348try for example:
75607349
75617350=end original
75627351
75637352似たような、しかしロケール依存の日付文字列がほしい場合は、
75647353ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、
75657354以下の例を試してください:
75667355
75677356 use POSIX qw(strftime);
75687357 $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
75697358 # or for GMT formatted appropriately for your locale:
75707359 $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
75717360
75727361=begin original
75737362
75747363Note that the C<%a> and C<%b>, the short forms of the day of the week
75757364and the month of the year, may not necessarily be three characters wide.
75767365
75777366=end original
75787367
75797368曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに
75807369注意してください。
75817370
75827371=begin original
75837372
75847373The L<Time::gmtime> and L<Time::localtime> modules provide a convenient,
75857374by-name access mechanism to the gmtime() and localtime() functions,
75867375respectively.
75877376
75887377=end original
75897378
75907379L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ
75917380gmtime() 関数と localtime() 関数に、名前でアクセスする機構を提供する
75927381便利なモジュールです。
75937382
75947383=begin original
75957384
75967385For a comprehensive date and time representation look at the
75977386L<DateTime> module on CPAN.
75987387
75997388=end original
76007389
76017390包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
76027391参照してください。
76037392
76047393=begin original
76057394
76067395Portability issues: L<perlport/localtime>.
76077396
76087397=end original
76097398
76107399移植性の問題: L<perlport/localtime>。
76117400
76127401=item lock THING
76137402X<lock>
76147403
76157404=for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method
76167405
76177406=begin original
76187407
76197408This function places an advisory lock on a shared variable or referenced
76207409object contained in I<THING> until the lock goes out of scope.
76217410
76227411=end original
76237412
76247413この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、
76257414スコープから出るまでアドバイサリロックを掛けます.
76267415
76277416=begin original
76287417
76297418The value returned is the scalar itself, if the argument is a scalar, or a
76307419reference, if the argument is a hash, array or subroutine.
76317420
76327421=end original
76337422
76347423返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、
76357424サブルーチンならリファレンスです。
76367425
76377426=begin original
76387427
76397428lock() is a "weak keyword" : this means that if you've defined a function
76407429by this name (before any calls to it), that function will be called
76417430instead. If you are not under C<use threads::shared> this does nothing.
76427431See L<threads::shared>.
76437432
76447433=end original
76457434
76467435lock() は「弱いキーワード」です: もしユーザーが(呼び出し前に)
76477436この名前で関数を定義すると、定義された関数の方が呼び出されます。
76487437C<use threads::shared> の影響下でない場合は、これは何もしません。
76497438L<threads::shared> を参照してください。
76507439
76517440=item log EXPR
76527441X<log> X<logarithm> X<e> X<ln> X<base>
76537442
76547443=item log
76557444
76567445=for Pod::Functions retrieve the natural logarithm for a number
76577446
76587447=begin original
76597448
76607449Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted,
76617450returns the log of C<$_>. To get the
76627451log of another base, use basic algebra:
76637452The base-N log of a number is equal to the natural log of that number
76647453divided by the natural log of N. For example:
76657454
76667455=end original
76677456
76687457EXPR の (I<e> を底とする) 自然対数を返します。
76697458EXPR が省略されると、C<$_> の対数を返します。
76707459底の異なる対数を求めるためには、基礎代数を利用してください:
76717460ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。
76727461例えば:
76737462
76747463 sub log10 {
76757464 my $n = shift;
76767465 return log($n)/log(10);
76777466 }
76787467
76797468=begin original
76807469
76817470See also L</exp> for the inverse operation.
76827471
76837472=end original
76847473
76857474逆操作については L</exp> を参照してください。
76867475
76877476=item lstat FILEHANDLE
76887477X<lstat>
76897478
76907479=item lstat EXPR
76917480
76927481=item lstat DIRHANDLE
76937482
76947483=item lstat
76957484
76967485=for Pod::Functions stat a symbolic link
76977486
76987487=begin original
76997488
77007489Does the same thing as the C<stat> function (including setting the
77017490special C<_> filehandle) but stats a symbolic link instead of the file
77027491the symbolic link points to. If symbolic links are unimplemented on
77037492your system, a normal C<stat> is done. For much more detailed
77047493information, please see the documentation for C<stat>.
77057494
77067495=end original
77077496
77087497(特別なファイルハンドルである C<_> の設定を含めて)
77097498C<stat> 関数と同じことをしますが、シンボリックリンクが
77107499指しているファイルではなく、シンボリックリンク自体の stat をとります。
7711シンボリックリンクがシステムに実装されていないと、通常の C<stat> が
7500シンボリックリンクがシステムに実装されていないと、通常の C<stat> が行なわれます。
7712行なわれます。
77137501さらにより詳細な情報については、L<stat> の文書を参照してください。
77147502
77157503=begin original
77167504
77177505If EXPR is omitted, stats C<$_>.
77187506
77197507=end original
77207508
77217509EXPR が省略されると、C<$_> の stat をとります。
77227510
77237511=begin original
77247512
77257513Portability issues: L<perlport/lstat>.
77267514
77277515=end original
77287516
77297517移植性の問題: L<perlport/lstat>。
77307518
77317519=item m//
77327520
77337521=for Pod::Functions match a string with a regular expression pattern
77347522
77357523=begin original
77367524
77377525The match operator. See L<perlop/"Regexp Quote-Like Operators">.
77387526
77397527=end original
77407528
77417529マッチ演算子です。
77427530L<perlop/"Regexp Quote-Like Operators"> を参照してください。
77437531
77447532=item map BLOCK LIST
77457533X<map>
77467534
77477535=item map EXPR,LIST
77487536
77497537=for Pod::Functions apply a change to a list to get back a new list with the changes
77507538
77517539=begin original
77527540
77537541Evaluates the BLOCK or EXPR for each element of LIST (locally setting
77547542C<$_> to each element) and returns the list value composed of the
77557543results of each such evaluation. In scalar context, returns the
77567544total number of elements so generated. Evaluates BLOCK or EXPR in
77577545list context, so each element of LIST may produce zero, one, or
77587546more elements in the returned value.
77597547
77607548=end original
77617549
77627550LIST の個々の要素に対して、BLOCK か EXPR を評価し
77637551(C<$_> は、ローカルに個々の要素が設定されます) 、
77647552それぞれの評価結果からなるリスト値が返されます。
77657553スカラコンテキストでは、生成された要素の数を返します。
77667554BLOCK や EXPR をリストコンテキストで評価しますので、LIST の
77677555個々の要素によって作られる、返り値であるリストの要素数は、
776875560 個の場合もあれば、複数の場合もあります。
77697557
77707558 @chars = map(chr, @numbers);
77717559
77727560=begin original
77737561
77747562translates a list of numbers to the corresponding characters.
77757563
77767564=end original
77777565
77787566は、数のリストを対応する文字に変換します。
77797567
77807568 my @squares = map { $_ * $_ } @numbers;
77817569
77827570=begin original
77837571
77847572translates a list of numbers to their squared values.
77857573
77867574=end original
77877575
77887576これは数値のリストを、その 2 乗に変換します。
77897577
77907578 my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers;
77917579
77927580=begin original
77937581
77947582shows that number of returned elements can differ from the number of
77957583input elements. To omit an element, return an empty list ().
77967584This could also be achieved by writing
77977585
77987586=end original
77997587
78007588のように、返された要素の数が入力要素の数と異なる場合もあります。
78017589要素を省略するには、空リスト () を返します。
78027590これは以下のように書くことでも達成できて
78037591
78047592 my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers;
78057593
78067594=begin original
78077595
78087596which makes the intention more clear.
78097597
78107598=end original
78117599
78127600この方が目的がよりはっきりします。
78137601
78147602=begin original
78157603
78167604Map always returns a list, which can be
78177605assigned to a hash such that the elements
78187606become key/value pairs. See L<perldata> for more details.
78197607
78207608=end original
78217609
78227610map は常にリストを返し、要素がキー/値の組になるようなハッシュに
78237611代入できます。
78247612さらなる詳細については L<perldata> を参照してください。
78257613
78267614 %hash = map { get_a_key_for($_) => $_ } @array;
78277615
78287616=begin original
78297617
78307618is just a funny way to write
78317619
78327620=end original
78337621
78347622は以下のものをちょっと変わった書き方で書いたものです。
78357623
78367624 %hash = ();
78377625 foreach (@array) {
78387626 $hash{get_a_key_for($_)} = $_;
78397627 }
78407628
78417629=begin original
78427630
78437631Note that C<$_> is an alias to the list value, so it can be used to
78447632modify the elements of the LIST. While this is useful and supported,
78457633it can cause bizarre results if the elements of LIST are not variables.
78467634Using a regular C<foreach> loop for this purpose would be clearer in
78477635most cases. See also L</grep> for an array composed of those items of
78487636the original list for which the BLOCK or EXPR evaluates to true.
78497637
78507638=end original
78517639
78527640C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
78537641変更するために使うことができます。
78547642これは、便利でサポートされていますが、
78557643LIST の要素が変数でないと、おかしな結果になります。
78567644この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は
78577645より明確になります。
78587646BLOCK や EXPR が真になる元のリストの要素からなる配列については、
78597647L</grep> も参照してください。
78607648
78617649=begin original
78627650
78637651If C<$_> is lexical in the scope where the C<map> appears (because it has
7864been declared with the deprecated C<my $_> construct),
7652been declared with C<my $_>), then, in addition to being locally aliased to
7865then, in addition to being locally aliased to
78667653the list elements, C<$_> keeps being lexical inside the block; that is, it
78677654can't be seen from the outside, avoiding any potential side-effects.
78687655
78697656=end original
78707657
7871(廃止予定の C<my $_> 構文で宣言されることによって) C<$_> が C<map> が現れる
7658(C<my $_> として宣言されることによって) C<$_> が C<map> が現れるスコープ内で
7872スコープ内でレキシカルな場合は、ローカルではリスト要素への
7659レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加えて、
7873エイリアスであることに加えて、C<$_> はブロック内でレキシカルでありつづけます;
7660C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、
7874つまり、外側からは見えず、起こりうる副作用を回避します。
7661起こりうる副作用を回避します。
78757662
78767663=begin original
78777664
78787665C<{> starts both hash references and blocks, so C<map { ...> could be either
78797666the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look
78807667ahead for the closing C<}> it has to take a guess at which it's dealing with
78817668based on what it finds just after the
78827669C<{>. Usually it gets it right, but if it
78837670doesn't it won't realize something is wrong until it gets to the C<}> and
78847671encounters the missing (or unexpected) comma. The syntax error will be
78857672reported close to the C<}>, but you'll need to change something near the C<{>
78867673such as using a unary C<+> to give Perl some help:
78877674
78887675=end original
78897676
78907677C<{> はハッシュリファレンスとブロックの両方の開始文字なので、
78917678C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。
78927679Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て
78937680どちらとして扱うかを推測します。
78947681通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで
78957682カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに
78967683気付きません。
78977684C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> を
78987685使うというように、C<{> の近くの何かを変更する必要があります。
78997686
7900 %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
7687 %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
7901 %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
7688 %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
7902 %hash = map { ("\L$_" => 1) } @array # this also works
7689 %hash = map { ("\L$_" => 1) } @array # this also works
7903 %hash = map { lc($_) => 1 } @array # as does this.
7690 %hash = map { lc($_) => 1 } @array # as does this.
7904 %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
7691 %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
79057692
7906 %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
7693 %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
79077694
79087695=begin original
79097696
79107697or to force an anon hash constructor use C<+{>:
79117698
79127699=end original
79137700
79147701または C<+{> を使って無名ハッシュコンストラクタを強制します:
79157702
7916 @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs
7703 @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs comma at end
7917 # comma at end
79187704
79197705=begin original
79207706
79217707to get a list of anonymous hashes each with only one entry apiece.
79227708
79237709=end original
79247710
79257711こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。
79267712
79277713=item mkdir FILENAME,MASK
79287714X<mkdir> X<md> X<directory, create>
79297715
79307716=item mkdir FILENAME
79317717
79327718=item mkdir
79337719
79347720=for Pod::Functions create a directory
79357721
79367722=begin original
79377723
79387724Creates the directory specified by FILENAME, with permissions
79397725specified by MASK (as modified by C<umask>). If it succeeds it
79407726returns true; otherwise it returns false and sets C<$!> (errno).
79417727MASK defaults to 0777 if omitted, and FILENAME defaults
79427728to C<$_> if omitted.
79437729
79447730=end original
79457731
79467732FILENAME で指定したディレクトリを、MASK で指定した許可モード(を
79477733C<umask> で修正したもの) で作成します。
79487734成功時には真を返します; さもなければ偽を返して C<$!> (errno) を設定します。
79497735MASK を省略すると、0777 とみなし、
79507736FILENAME を省略すると、C<$_> を使います。
79517737
79527738=begin original
79537739
79547740In general, it is better to create directories with a permissive MASK
79557741and let the user modify that with their C<umask> than it is to supply
79567742a restrictive MASK and give the user no way to be more permissive.
79577743The exceptions to this rule are when the file or directory should be
79587744kept private (mail files, for instance). The perlfunc(1) entry on
79597745C<umask> discusses the choice of MASK in more detail.
79607746
79617747=end original
79627748
79637749一般的に、制限された MASK を使ってユーザーがより寛容にする方法を
79647750与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の C<umask> で
79657751修正するようにした方がよいです。
79667752例外は、(例えばメールファイルのような)プライベートに保つべきファイルや
79677753ディレクトリを書く場合です。
79687754perlfunc(1) の C<umask> で、MASK の選択に関して詳細に議論しています。
79697755
79707756=begin original
79717757
79727758Note that according to the POSIX 1003.1-1996 the FILENAME may have any
79737759number of trailing slashes. Some operating and filesystems do not get
79747760this right, so Perl automatically removes all trailing slashes to keep
79757761everyone happy.
79767762
79777763=end original
79787764
79797765POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを
79807766つけることができます。
79817767このようには動かない OS やファイルシステムもあるので、Perl はみんなが
79827768幸せになれるように、自動的に末尾のスラッシュを削除します。
79837769
79847770=begin original
79857771
79867772To recursively create a directory structure, look at
7987the C<make_path> function of the L<File::Path> module.
7773the C<mkpath> function of the L<File::Path> module.
79887774
79897775=end original
79907776
79917777ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの
7992C<make_path> 関数を参照してください。
7778C<makepath> 関数を参照してください。
79937779
79947780=item msgctl ID,CMD,ARG
79957781X<msgctl>
79967782
79977783=for Pod::Functions SysV IPC message control operations
79987784
79997785=begin original
80007786
80017787Calls the System V IPC function msgctl(2). You'll probably have to say
80027788
80037789=end original
80047790
80057791System V IPC 関数 msgctl を呼び出します。
80067792正しい定数定義を得るために、まず
80077793
80087794 use IPC::SysV;
80097795
80107796=begin original
80117797
80127798first to get the correct constant definitions. If CMD is C<IPC_STAT>,
80137799then ARG must be a variable that will hold the returned C<msqid_ds>
80147800structure. Returns like C<ioctl>: the undefined value for error,
80157801C<"0 but true"> for zero, or the actual return value otherwise. See also
80167802L<perlipc/"SysV IPC"> and the documentation for C<IPC::SysV> and
80177803C<IPC::Semaphore>.
80187804
80197805=end original
80207806
80217807と書くことが必要でしょう。
80227808CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を
80237809納める変数でなければなりません。
80247810C<ioctl> と同じように、エラー時には未定義値、
80257811ゼロのときは C<"0 but true">、それ以外なら、その値そのものを返します。
80267812L<perlipc/"SysV IPC"> および、C<IPC::SysV>, C<IPC::Semaphore> の文書も
80277813参照してください。
80287814
80297815=begin original
80307816
80317817Portability issues: L<perlport/msgctl>.
80327818
80337819=end original
80347820
80357821移植性の問題: L<perlport/msgctl>。
80367822
80377823=item msgget KEY,FLAGS
80387824X<msgget>
80397825
80407826=for Pod::Functions get SysV IPC message queue
80417827
80427828=begin original
80437829
80447830Calls the System V IPC function msgget(2). Returns the message queue
80457831id, or C<undef> on error. See also
80467832L<perlipc/"SysV IPC"> and the documentation for C<IPC::SysV> and
80477833C<IPC::Msg>.
80487834
80497835=end original
80507836
80517837System V IPC 関数 msgget を呼び出します。
80527838メッセージキューの ID か、エラー時には C<undef> を返します。
80537839L<perlipc/"SysV IPC"> よよび、C<IPC::SysV>, C<IPC::Msg> の文書も
80547840参照してください。
80557841
80567842=begin original
80577843
80587844Portability issues: L<perlport/msgget>.
80597845
80607846=end original
80617847
80627848移植性の問題: L<perlport/msgget>。
80637849
80647850=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
80657851X<msgrcv>
80667852
80677853=for Pod::Functions receive a SysV IPC message from a message queue
80687854
80697855=begin original
80707856
80717857Calls the System V IPC function msgrcv to receive a message from
80727858message queue ID into variable VAR with a maximum message size of
80737859SIZE. Note that when a message is received, the message type as a
80747860native long integer will be the first thing in VAR, followed by the
80757861actual message. This packing may be opened with C<unpack("l! a*")>.
80767862Taints the variable. Returns true if successful, false
80777863on error. See also L<perlipc/"SysV IPC"> and the documentation for
80787864C<IPC::SysV> and C<IPC::SysV::Msg>.
80797865
80807866=end original
80817867
80827868System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、
80837869変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。
80847870メッセージが受信された時、ネイティブな long 整数のメッセージタイプが
80857871VAR の先頭となり、実際のメッセージが続きます。
80867872このパッキングは C<unpack("l! a*")> で展開できます。
80877873変数は汚染されます。
80887874成功時には真を、エラー時には偽を返します。
80897875L<perlipc/"SysV IPC"> および、C<IPC::SysV>, C<IPC::SysV::Msg> の文書も
80907876参照してください。
80917877
80927878=begin original
80937879
80947880Portability issues: L<perlport/msgrcv>.
80957881
80967882=end original
80977883
80987884移植性の問題: L<perlport/msgrcv>。
80997885
81007886=item msgsnd ID,MSG,FLAGS
81017887X<msgsnd>
81027888
81037889=for Pod::Functions send a SysV IPC message to a message queue
81047890
81057891=begin original
81067892
81077893Calls the System V IPC function msgsnd to send the message MSG to the
81087894message queue ID. MSG must begin with the native long integer message
81097895type, be followed by the length of the actual message, and then finally
81107896the message itself. This kind of packing can be achieved with
81117897C<pack("l! a*", $type, $message)>. Returns true if successful,
81127898false on error. See also the C<IPC::SysV>
81137899and C<IPC::SysV::Msg> documentation.
81147900
81157901=end original
81167902
81177903System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に
81187904メッセージ MSG を送信します。
8119MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、
7905MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、
81207906メッセージの長さ、メッセージ本体と続きます。
81217907これは、C<pack("l! a*", $type, $message)> として生成できます。
81227908成功時には真を、エラー時には偽を返します。
81237909C<IPC::SysV> と C<IPC::SysV::Msg> の文書も参照してください。
81247910
81257911=begin original
81267912
81277913Portability issues: L<perlport/msgsnd>.
81287914
81297915=end original
81307916
81317917移植性の問題: L<perlport/msgsnd>。
81327918
8133=item my VARLIST
7919=item my EXPR
81347920X<my>
81357921
8136=item my TYPE VARLIST
7922=item my TYPE EXPR
81377923
8138=item my VARLIST : ATTRS
7924=item my EXPR : ATTRS
81397925
8140=item my TYPE VARLIST : ATTRS
7926=item my TYPE EXPR : ATTRS
81417927
81427928=for Pod::Functions declare and assign a local variable (lexical scoping)
81437929
81447930=begin original
81457931
81467932A C<my> declares the listed variables to be local (lexically) to the
8147enclosing block, file, or C<eval>. If more than one variable is listed,
7933enclosing block, file, or C<eval>. If more than one value is listed,
81487934the list must be placed in parentheses.
81497935
81507936=end original
81517937
81527938C<my> はリストアップされた変数を、囲っているブロック、ファイル、
81537939C<eval> の中でローカルな (レキシカルな) ものにします。
8154複数の変数を指定する場合は、リストはかっこでくくらなければなりません。
7940複数のを指定する場合は、リストはかっこでくくらなければなりません。
81557941
81567942=begin original
81577943
81587944The exact semantics and interface of TYPE and ATTRS are still
8159evolving. TYPE may be a bareword, a constant declared
7945evolving. TYPE is currently bound to the use of the C<fields> pragma,
8160with C<use constant>, or C<__PACKAGE__>. It is
8161currently bound to the use of the C<fields> pragma,
81627946and attributes are handled using the C<attributes> pragma, or starting
81637947from Perl 5.8.0 also via the C<Attribute::Handlers> module. See
81647948L<perlsub/"Private Variables via my()"> for details, and L<fields>,
81657949L<attributes>, and L<Attribute::Handlers>.
81667950
81677951=end original
81687952
81697953TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
8170TYPE は、裸の単語、C<use constant> で宣言された定数、C<__PACKAGE__> の
8171いずれかです。
81727954現在のところ、TYPE は C<fields> プラグマの使用と結び付けられていて、
81737955属性は C<attributes> プラグマか、Perl 5.8.0 からは
81747956C<Attribute::Handlers> モジュールと結び付けられています。
8175詳しくは L<perlsub/"Private Variables via my()">, L<fields>,
7957詳しくはL<perlsub/"Private Variables via my()">, L<fields>,
81767958L<attributes>, L<Attribute::Handlers> を参照してください。
81777959
8178=begin original
8179
8180Note that with a parenthesised list, C<undef> can be used as a dummy
8181placeholder, for example to skip assignment of initial values:
8182
8183=end original
8184
8185かっこで囲まれたリストでは、C<undef> は、例えば初期値の代入を飛ばすために、
8186ダミーのプレースホルダとして使えることに注意してください:
8187
8188 my ( undef, $min, $hour ) = localtime;
8189
81907960=item next LABEL
81917961X<next> X<continue>
81927962
8193=item next EXPR
8194
81957963=item next
81967964
81977965=for Pod::Functions iterate a block prematurely
81987966
81997967=begin original
82007968
82017969The C<next> command is like the C<continue> statement in C; it starts
82027970the next iteration of the loop:
82037971
82047972=end original
82057973
82067974C<next> コマンドは、C での C<continue> 文のようなもので、
82077975ループの次の繰り返しを開始します:
82087976
82097977 LINE: while (<STDIN>) {
82107978 next LINE if /^#/; # discard comments
82117979 #...
82127980 }
82137981
82147982=begin original
82157983
82167984Note that if there were a C<continue> block on the above, it would get
82177985executed even on discarded lines. If LABEL is omitted, the command
8218refers to the innermost enclosing loop. The C<next EXPR> form, available
7986refers to the innermost enclosing loop.
8219as of Perl 5.18.0, allows a label name to be computed at run time, being
8220otherwise identical to C<next LABEL>.
82217987
82227988=end original
82237989
82247990C<continue> ブロックが存在すれば、たとえ捨てられる行に
82257991あっても、それが実行されます。
82267992LABEL が省略されると、コマンドは一番内側のループを参照します。
8227Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される
8228ラベル名が使えます; それ以外は C<next LABEL> と同一です。
82297993
82307994=begin original
82317995
82327996C<next> cannot be used to exit a block which returns a value such as
82337997C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
82347998a grep() or map() operation.
82357999
82368000=end original
82378001
82388002C<next> は C<eval {}>, C<sub {}>, C<do {}> のように値を返すブロックから
82398003抜けるのには使えません; また、grep() や map() 操作から抜けるのに
82408004使うべきではありません。
82418005
82428006=begin original
82438007
82448008Note that a block by itself is semantically identical to a loop
82458009that executes once. Thus C<next> will exit such a block early.
82468010
82478011=end original
82488012
82498013ブロック自身は一回だけ実行されるループと文法的に同一であることに
82508014注意してください。
82518015従って、C<next> はそのようなブロックから早く抜けるのに使えます。
82528016
82538017=begin original
82548018
82558019See also L</continue> for an illustration of how C<last>, C<next>, and
82568020C<redo> work.
82578021
82588022=end original
82598023
82608024C<last>, C<next>, C<redo> がどのように働くかについては
82618025L</continue> も参照してください。
82628026
8263=begin original
8264
8265Unlike most named operators, this has the same precedence as assignment.
8266It is also exempt from the looks-like-a-function rule, so
8267C<next ("foo")."bar"> will cause "bar" to be part of the argument to
8268C<next>.
8269
8270=end original
8271
8272ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
8273また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と
8274すると "bar" は C<next> への引数の一部となります。
8275
82768027=item no MODULE VERSION LIST
82778028X<no declarations>
82788029X<unimporting>
82798030
82808031=item no MODULE VERSION
82818032
82828033=item no MODULE LIST
82838034
82848035=item no MODULE
82858036
82868037=item no VERSION
82878038
82888039=for Pod::Functions unimport some module symbols or semantics at compile time
82898040
82908041=begin original
82918042
82928043See the C<use> function, of which C<no> is the opposite.
82938044
82948045=end original
82958046
82968047L<use> 関数を参照してください; C<no> は、その逆を行なうものです。
82978048
82988049=item oct EXPR
82998050X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin>
83008051
83018052=item oct
83028053
83038054=for Pod::Functions convert a string to an octal number
83048055
83058056=begin original
83068057
83078058Interprets EXPR as an octal string and returns the corresponding
83088059value. (If EXPR happens to start off with C<0x>, interprets it as a
83098060hex string. If EXPR starts off with C<0b>, it is interpreted as a
83108061binary string. Leading whitespace is ignored in all three cases.)
83118062The following will handle decimal, binary, octal, and hex in standard
83128063Perl notation:
83138064
83148065=end original
83158066
83168067EXPR を 8 進数文字列と解釈して、対応する値を返します。
83178068(EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。
83188069EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。
83198070どの場合でも、先頭の空白は無視されます。)
83208071以下の例は、標準的な Perl の記法での
8321807210 進数、2 進数、8 進数、16 進数を扱います:
83228073
83238074 $val = oct($val) if $val =~ /^0/;
83248075
83258076=begin original
83268077
83278078If EXPR is omitted, uses C<$_>. To go the other way (produce a number
83288079in octal), use sprintf() or printf():
83298080
83308081=end original
83318082
83328083EXPR が省略されると、C<$_> を使います。
83338084(8 進数を扱う)その他の方法としては sprintf() または printf()があります。
83348085
83358086 $dec_perms = (stat("filename"))[2] & 07777;
83368087 $oct_perm_str = sprintf "%o", $perms;
83378088
83388089=begin original
83398090
83408091The oct() function is commonly used when a string such as C<644> needs
83418092to be converted into a file mode, for example. Although Perl
83428093automatically converts strings into numbers as needed, this automatic
83438094conversion assumes base 10.
83448095
83458096=end original
83468097
83478098oct() 関数は例えば、 C<644> といった文字列をファイルモードに変換する時に
83488099よく使います。
83498100Perl は必要に応じて自動的に文字列を数値に変換しますが、
83508101この自動変換は十進数を仮定します。
83518102
83528103=begin original
83538104
83548105Leading white space is ignored without warning, as too are any trailing
83558106non-digits, such as a decimal point (C<oct> only handles non-negative
83568107integers, not negative integers or floating point).
83578108
83588109=end original
83598110
83608111先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます
83618112(C<oct> は非負整数のみを扱えます; 負の整数や小数は扱えません)。
83628113
83638114=item open FILEHANDLE,EXPR
83648115X<open> X<pipe> X<file, open> X<fopen>
83658116
83668117=item open FILEHANDLE,MODE,EXPR
83678118
83688119=item open FILEHANDLE,MODE,EXPR,LIST
83698120
83708121=item open FILEHANDLE,MODE,REFERENCE
83718122
83728123=item open FILEHANDLE
83738124
83748125=for Pod::Functions open a file, pipe, or descriptor
83758126
83768127=begin original
83778128
83788129Opens the file whose filename is given by EXPR, and associates it with
83798130FILEHANDLE.
83808131
83818132=end original
83828133
83838134EXPR で与えられたファイル名のファイルを開き、FILEHANDLE と結び付けます。
83848135
83858136=begin original
83868137
83878138Simple examples to open a file for reading:
83888139
83898140=end original
83908141
83918142読み込みのためにファイルを開くための簡単な例は以下のもので:
83928143
83938144 open(my $fh, "<", "input.txt")
83948145 or die "cannot open < input.txt: $!";
83958146
83968147=begin original
83978148
83988149and for writing:
83998150
84008151=end original
84018152
84028153書き込み用は以下のものです:
84038154
84048155 open(my $fh, ">", "output.txt")
84058156 or die "cannot open > output.txt: $!";
84068157
84078158=begin original
84088159
84098160(The following is a comprehensive reference to open(): for a gentler
84108161introduction you may consider L<perlopentut>.)
84118162
84128163=end original
84138164
84148165(以下は総合的な open() のリファレンスです: より親切な説明については
84158166L<perlopentut> を参照してください。)
84168167
84178168=begin original
84188169
84198170If FILEHANDLE is an undefined scalar variable (or array or hash element), a
84208171new filehandle is autovivified, meaning that the variable is assigned a
84218172reference to a newly allocated anonymous filehandle. Otherwise if
84228173FILEHANDLE is an expression, its value is the real filehandle. (This is
84238174considered a symbolic reference, so C<use strict "refs"> should I<not> be
84248175in effect.)
84258176
84268177=end original
84278178
84288179FILEHANDLE が未定義のスカラ変数(または配列かハッシュの要素)の場合、
84298180新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた
84308181無名ファイルハンドルへのリファレンスが代入されます。
84318182さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の
84328183ファイルハンドルの名前として使います。
84338184(これはシンボリックリファレンスとして扱われるので、
84348185C<use strict "refs"> の影響を I<受けません>。)
84358186
84368187=begin original
84378188
8189If EXPR is omitted, the global (package) scalar variable of the same
8190name as the FILEHANDLE contains the filename. (Note that lexical
8191variables--those declared with C<my> or C<state>--will not work for this
8192purpose; so if you're using C<my> or C<state>, specify EXPR in your
8193call to open.)
8194
8195=end original
8196
8197EXPR が省略された場合、FILEHANDLE と同じ名前のグローバル(パッケージ)
8198スカラ変数にファイル名が入っています。
8199(レキシカル変数 -- C<my> や C<state> で宣言されたもの -- はこの用途には
8200使えないことに注意してください; 従って、C<my> や C<state> を使っている場合は、
8201open を呼び出すときに EXPR を指定してください。)
8202
8203=begin original
8204
84388205If three (or more) arguments are specified, the open mode (including
84398206optional encoding) in the second argument are distinct from the filename in
84408207the third. If MODE is C<< < >> or nothing, the file is opened for input.
84418208If MODE is C<< > >>, the file is opened for output, with existing files
84428209first being truncated ("clobbered") and nonexisting files newly created.
84438210If MODE is C<<< >> >>>, the file is opened for appending, again being
84448211created if necessary.
84458212
84468213=end original
84478214
844882153 (またはそれ以上)の引数が指定された場合、2 番目の引数の(オプションの
84498216エンコーディングを含む)開く時のモードは、3 番目のファイル名と分離されます。
84508217MODE が C<< < >> か空の場合、ファイルは入力用に開かれます。
84518218MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが
84528219ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。
84538220MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら
84548221作成されます。
84558222
84568223=begin original
84578224
84588225You can put a C<+> in front of the C<< > >> or C<< < >> to
84598226indicate that you want both read and write access to the file; thus
84608227C<< +< >> is almost always preferred for read/write updates--the
84618228C<< +> >> mode would clobber the file first. You can't usually use
84628229either read-write mode for updating textfiles, since they have
84638230variable-length records. See the B<-i> switch in L<perlrun> for a
84648231better approach. The file is created with permissions of C<0666>
84658232modified by the process's C<umask> value.
84668233
84678234=end original
84688235
84698236ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、
84708237C<< > >> や C<< < >> の前に C<+> を付けることができます:
84718238従って、ほとんど常に C<< +< >> が読み書き更新のために使われます --
84728239C<< +> >> モードはまずファイルを上書きします。
84738240普通はこれらの読み書きモードをテキストファイルの更新のためには使えません;
84748241なぜなら可変長のレコードで構成されているからです。
84758242よりよい手法については L<perlrun> の B<-i> オプションを参照してください。
84768243ファイルは C<0666> をプロセスの C<umask> 値で修正したパーミッションで
84778244作成されます。
84788245
84798246=begin original
84808247
84818248These various prefixes correspond to the fopen(3) modes of C<r>,
84828249C<r+>, C<w>, C<w+>, C<a>, and C<a+>.
84838250
84848251=end original
84858252
84868253これらの様々な前置詞は fopen(3) の C<r>, C<r+>,
84878254C<w>, C<w+>, C<a>, C<a+> のモードに対応します。
84888255
84898256=begin original
84908257
84918258In the one- and two-argument forms of the call, the mode and filename
84928259should be concatenated (in that order), preferably separated by white
84938260space. You can--but shouldn't--omit the mode in these forms when that mode
84948261is C<< < >>. It is always safe to use the two-argument form of C<open> if
84958262the filename argument is a known literal.
84968263
84978264=end original
84988265
849982661 引数 と 2 引数の形式ではモードとファイル名は(この順番で)
85008267結合されます(空白によって分割されているかもしれません)。
85018268この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、
85028269するべきではありません)。
85038270ファイル引数が既知のリテラルの場合、2 引数形式の C<open> は常に安全です。
85048271
85058272=begin original
85068273
85078274For three or more arguments if MODE is C<|->, the filename is
85088275interpreted as a command to which output is to be piped, and if MODE
85098276is C<-|>, the filename is interpreted as a command that pipes
85108277output to us. In the two-argument (and one-argument) form, one should
85118278replace dash (C<->) with the command.
85128279See L<perlipc/"Using open() for IPC"> for more examples of this.
85138280(You are not allowed to C<open> to a command that pipes both in I<and>
85148281out, but see L<IPC::Open2>, L<IPC::Open3>, and
85158282L<perlipc/"Bidirectional Communication with Another Process"> for
85168283alternatives.)
85178284
85188285=end original
85198286
852082873 引数以上の形式で
85218288MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして
85228289解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに
85238290パイプされるコマンドとして解釈されます。
85242 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。
82912 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに
8292使えます。
85258293これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
85268294参照してください。
85278295(C<open> を入出力 I<両用> にパイプすることは出来ませんが
85288296代替案としては L<IPC::Open2>, L<IPC::Open3>,
85298297L<perlipc/"Bidirectional Communication with Another Process"> を
85308298参照してください。)
85318299
85328300=begin original
85338301
85348302In the form of pipe opens taking three or more arguments, if LIST is specified
85358303(extra arguments after the command name) then LIST becomes arguments
85368304to the command invoked if the platform supports it. The meaning of
85378305C<open> with more than three arguments for non-pipe modes is not yet
85388306defined, but experimental "layers" may give extra LIST arguments
85398307meaning.
85408308
85418309=end original
85428310
85438311パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が
85448312指定されると、プラットフォームが対応していれば、LIST は起動される
85458313コマンドへの引数となります。
85468314パイプモードではない C<open> での三つ以上の引数の意味はまだ未定義ですが、
85478315実験的な「層」は追加の LIST 引数の意味を与えます。
85488316
85498317=begin original
85508318
85518319In the two-argument (and one-argument) form, opening C<< <- >>
85528320or C<-> opens STDIN and opening C<< >- >> opens STDOUT.
85538321
85548322=end original
85558323
855683242 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が
85578325オープンされ、C<< >- >> を open すると STDOUT がオープンされます。
85588326
85598327=begin original
85608328
85618329You may (and usually should) use the three-argument form of open to specify
85628330I/O layers (sometimes referred to as "disciplines") to apply to the handle
85638331that affect how the input and output are processed (see L<open> and
85648332L<PerlIO> for more details). For example:
85658333
85668334=end original
85678335
85688336open の 3 引数形式では、どのように入出力が処理されるかに影響を与える
85698337I/O 層(「ディシプリン」とも呼ばれます)を指定できます
85708338(そして普通はそうするべきです)
85718339(詳細については L<open> と L<PerlIO> を参照してください)。
85728340例えば:
85738341
85748342 open(my $fh, "<:encoding(UTF-8)", "filename")
85758343 || die "can't open UTF-8 encoded filename: $!";
85768344
85778345=begin original
85788346
85798347opens the UTF8-encoded file containing Unicode characters;
85808348see L<perluniintro>. Note that if layers are specified in the
85818349three-argument form, then default layers stored in ${^OPEN} (see L<perlvar>;
85828350usually set by the B<open> pragma or the switch B<-CioD>) are ignored.
85838351Those layers will also be ignored if you specifying a colon with no name
85848352following it. In that case the default layer for the operating system
85858353(:raw on Unix, :crlf on Windows) is used.
85868354
85878355=end original
85888356
85898357は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます;
85908358L<perluniintro> を参照してください。
859183593 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください;
8592通常は C<open> プラグマか B<-CioD> オプションでセットされます) に保存された
8360通常はC<open> プラグマか B<-CioD> オプションでセットされます)
8593デフォルト層は無視されることに注意してください。
8361に保存されたデフォルト層は無視されることに注意してください。
85948362これらの層は、名前なしでコロンを指定した場合にも無視されます。
85958363この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が
85968364使われます。
85978365
85988366=begin original
85998367
86008368Open returns nonzero on success, the undefined value otherwise. If
86018369the C<open> involved a pipe, the return value happens to be the pid of
86028370the subprocess.
86038371
86048372=end original
86058373
86068374open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。
86078375パイプに関る C<open> のときには、返り値はサブプロセスの pid となります。
86088376
86098377=begin original
86108378
86118379If you're running Perl on a system that distinguishes between text
86128380files and binary files, then you should check out L</binmode> for tips
86138381for dealing with this. The key distinction between systems that need
86148382C<binmode> and those that don't is their text file formats. Systems
86158383like Unix, Mac OS, and Plan 9, that end lines with a single
86168384character and encode that character in C as C<"\n"> do not
86178385need C<binmode>. The rest need it.
86188386
86198387=end original
86208388
86218389テキストファイルとバイナリファイルを区別するシステムで Perl を実行している
86228390場合、これを扱うための小技のために L</binmode> をチェックするべきです。
86238391動作させているシステムで C<binmode> が必要か不要化を区別する鍵は、テキスト
86248392ファイルの形式です。
86258393Unix, Mac OS, Plan 9 といった、行の境界を 1 文字で表現し、それが C では
86268394C<"\n"> でエンコードされる場合、C<binmode> は不要です。
86278395それ以外では必要です。
86288396
86298397=begin original
86308398
86318399When opening a file, it's seldom a good idea to continue
86328400if the request failed, so C<open> is frequently used with
86338401C<die>. Even if C<die> won't do what you want (say, in a CGI script,
86348402where you want to format a suitable error message (but there are
86358403modules that can help with that problem)) always check
86368404the return value from opening a file.
86378405
86388406=end original
86398407
8640ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは普通は悪い
8408ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは
8641考えので、C<open> はしばしば C<die> と結び付けられて使われます。
8409普通は悪い考えですので、C<open> はしばしば C<die> と結び付けられて
8642望むものが C<die> でない場合(例えば、CGI スクリプト のようにきいに
8410使わます。
8643フォーマットされたエラーメッセージを作りたい場合
8411望むものが C<die> でない場合(例えば、CGI スクリプト のように
8412きれいにフォーマットされたエラーメッセージを作りたい場合
86448413(但しこの問題を助けるモジュールがあります))でも、
8645ファイルを開いた時の返り値を常にチェックするべきです。
8414ファイルを開いた時の返り値を常にチェックするべきです。
86468415
86478416=begin original
86488417
8649The filehandle will be closed when its reference count reaches zero.
8650If it is a lexically scoped variable declared with C<my>, that usually
8651means the end of the enclosing scope. However, this automatic close
8652does not check for errors, so it is better to explicitly close
8653filehandles, especially those used for writing:
8654
8655=end original
8656
8657ファイルハンドルは、参照カウントが 0 になったときに閉じられます。
8658これが C<my> で宣言されたレキシカルスコープを持つ変数の場合、普通は
8659囲まれたスコープの終わりを意味します。
8660しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、
8661明示的にファイルハンドルを閉じる方がよいです。
8662
8663 close($handle)
8664 || warn "close failed: $!";
8665
8666=begin original
8667
8668An older style is to use a bareword as the filehandle, as
8669
8670=end original
8671
8672より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います
8673
8674 open(FH, "<", "input.txt")
8675 or die "cannot open < input.txt: $!";
8676
8677=begin original
8678
8679Then you can use C<FH> as the filehandle, in C<< close FH >> and C<<
8680<FH> >> and so on. Note that it's a global variable, so this form is
8681not recommended in new code.
8682
8683=end original
8684
8685それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、
8686ファイルハンドルとして使えます。
8687これはグローバル変数なので、新しいコードでは非推奨であることに
8688注意してください。
8689
8690=begin original
8691
8692As a shortcut a one-argument call takes the filename from the global
8693scalar variable of the same name as the filehandle:
8694
8695=end original
8696
8697短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の
8698グローバルなスカラ変数から取ります:
8699
8700 $ARTICLE = 100;
8701 open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
8702
8703=begin original
8704
8705Here C<$ARTICLE> must be a global (package) scalar variable - not one
8706declared with C<my> or C<state>.
8707
8708=end original
8709
8710ここで C<$ARTICLE> はグローバル(パッケージ)スカラ変数でなければなりません -
8711C<my> や C<state> で宣言された変数ではありません。
8712
8713=begin original
8714
87158418As a special case the three-argument form with a read/write mode and the third
87168419argument being C<undef>:
87178420
87188421=end original
87198422
8720特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が C<undef> の場合:
8423特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が
8424C<undef> の場合:
87218425
87228426 open(my $tmp, "+>", undef) or die ...
87238427
87248428=begin original
87258429
87268430opens a filehandle to an anonymous temporary file. Also using C<< +< >>
87278431works for symmetry, but you really should consider writing something
87288432to the temporary file first. You will need to seek() to do the
87298433reading.
87308434
87318435=end original
87328436
87338437無名一時ファイルとしてファイルハンドルを開きます。
87348438また C<< +< >> も対称性のために動作しますが、
87358439一時ファイルにはまず何かを書き込みたいはずです。
87368440読み込みを行うためには seek() が必要です。
87378441
87388442=begin original
87398443
8740Perl is built using PerlIO by default; Unless you've
8444Since v5.8.0, Perl has built using PerlIO by default. Unless you've
87418445changed this (such as building Perl with C<Configure -Uuseperlio>), you can
87428446open filehandles directly to Perl scalars via:
87438447
87448448=end original
87458449
8746Perl はデフォルトで PerlIO を使ってビルドされています;
8450v5.8.0 から、Perl はデフォルトで PerlIO を使ってビルドされています
87478451(C<Configure -Uuseperlio> して Perl をビルドするなどして)これを
87488452変更していない限り、以下のようにして、Perl スカラを直接ファイルハンドルで
87498453開くことができます:
87508454
87518455 open($fh, ">", \$variable) || ..
87528456
87538457=begin original
87548458
87558459To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
87568460
87578461=end original
87588462
87598463C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして
87608464再び開きたい場合は、先にそれを閉じます:
87618465
87628466 close STDOUT;
87638467 open(STDOUT, ">", \$variable)
87648468 or die "Can't open STDOUT: $!";
87658469
87668470=begin original
87678471
87688472General examples:
87698473
87708474=end original
87718475
87728476一般的な例:
87738477
8478 $ARTICLE = 100;
8479 open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
8480 while (<ARTICLE>) {...
8481
87748482 open(LOG, ">>/usr/spool/news/twitlog"); # (log is reserved)
87758483 # if the open fails, output is discarded
87768484
87778485 open(my $dbase, "+<", "dbase.mine") # open for update
87788486 or die "Can't open 'dbase.mine' for update: $!";
87798487
87808488 open(my $dbase, "+<dbase.mine") # ditto
87818489 or die "Can't open 'dbase.mine' for update: $!";
87828490
87838491 open(ARTICLE, "-|", "caesar <$article") # decrypt article
87848492 or die "Can't start caesar: $!";
87858493
87868494 open(ARTICLE, "caesar <$article |") # ditto
87878495 or die "Can't start caesar: $!";
87888496
87898497 open(EXTRACT, "|sort >Tmp$$") # $$ is our process id
87908498 or die "Can't start sort: $!";
87918499
87928500 # in-memory files
87938501 open(MEMORY, ">", \$var)
87948502 or die "Can't open memory file: $!";
8795 print MEMORY "foo!\n"; # output will appear in $var
8503 print MEMORY "foo!\n"; # output will appear in $var
87968504
87978505 # process argument list of files along with any includes
87988506
87998507 foreach $file (@ARGV) {
88008508 process($file, "fh00");
88018509 }
88028510
88038511 sub process {
88048512 my($filename, $input) = @_;
88058513 $input++; # this is a string increment
88068514 unless (open($input, "<", $filename)) {
88078515 print STDERR "Can't open $filename: $!\n";
88088516 return;
88098517 }
88108518
88118519 local $_;
88128520 while (<$input>) { # note use of indirection
88138521 if (/^#include "(.*)"/) {
88148522 process($1, $input);
88158523 next;
88168524 }
88178525 #... # whatever
88188526 }
88198527 }
88208528
88218529=begin original
88228530
88238531See L<perliol> for detailed info on PerlIO.
88248532
88258533=end original
88268534
88278535PerlIO に関する詳しい情報については L<perliol> を参照してください。
88288536
88298537=begin original
88308538
88318539You may also, in the Bourne shell tradition, specify an EXPR beginning
88328540with C<< >& >>, in which case the rest of the string is interpreted
88338541as the name of a filehandle (or file descriptor, if numeric) to be
88348542duped (as C<dup(2)>) and opened. You may use C<&> after C<< > >>,
88358543C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>.
88368544The mode you specify should match the mode of the original filehandle.
88378545(Duping a filehandle does not take into account any existing contents
88388546of IO buffers.) If you use the three-argument
88398547form, then you can pass either a
88408548number, the name of a filehandle, or the normal "reference to a glob".
88418549
88428550=end original
88438551
88448552Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >>
88458553を付けると、EXPR の残りの文字列をファイルハンドル名
88468554(数字であれば、ファイル記述子) と解釈して、それを (C<dup(2)> によって)
88478555複製してオープンします。
88488556C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>,
88498557C<< +< >>というモード指定に付けることができます。
88508558指定するモード指定は、もとのファイルハンドルのモードと
88518559合っていないといけません。
88528560(ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。)
885385613 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、
88548562通常の「グロブへのリファレンス」を渡します。
88558563
88568564=begin original
88578565
88588566Here is a script that saves, redirects, and restores C<STDOUT> and
88598567C<STDERR> using various methods:
88608568
88618569=end original
88628570
88638571C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します:
88648572
88658573 #!/usr/bin/perl
88668574 open(my $oldout, ">&STDOUT") or die "Can't dup STDOUT: $!";
88678575 open(OLDERR, ">&", \*STDERR) or die "Can't dup STDERR: $!";
88688576
88698577 open(STDOUT, '>', "foo.out") or die "Can't redirect STDOUT: $!";
88708578 open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!";
88718579
88728580 select STDERR; $| = 1; # make unbuffered
88738581 select STDOUT; $| = 1; # make unbuffered
88748582
88758583 print STDOUT "stdout 1\n"; # this works for
88768584 print STDERR "stderr 1\n"; # subprocesses too
88778585
88788586 open(STDOUT, ">&", $oldout) or die "Can't dup \$oldout: $!";
88798587 open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!";
88808588
88818589 print STDOUT "stdout 2\n";
88828590 print STDERR "stderr 2\n";
88838591
88848592=begin original
88858593
88868594If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
88878595or a filehandle, then Perl will do an equivalent of C's C<fdopen> of
88888596that file descriptor (and not call C<dup(2)>); this is more
88898597parsimonious of file descriptors. For example:
88908598
88918599=end original
88928600
88938601C<X> をファイル記述子の番号かファイルハンドルとして、
88948602C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する
88958603C の C<fdopen> と同じことを行ないます(そして C<dup(2)> は呼び出しません);
88968604これはファイル記述子をより節約します。
88978605例えば:
88988606
88998607 # open for input, reusing the fileno of $fd
89008608 open(FILEHANDLE, "<&=$fd")
89018609
89028610=begin original
89038611
89048612or
89058613
89068614=end original
89078615
89088616または
89098617
89108618 open(FILEHANDLE, "<&=", $fd)
89118619
89128620=begin original
89138621
89148622or
89158623
89168624=end original
89178625
89188626または
89198627
89208628 # open for append, using the fileno of OLDFH
89218629 open(FH, ">>&=", OLDFH)
89228630
89238631=begin original
89248632
89258633or
89268634
89278635=end original
89288636
89298637または
89308638
89318639 open(FH, ">>&=OLDFH")
89328640
89338641=begin original
89348642
89358643Being parsimonious on filehandles is also useful (besides being
89368644parsimonious) for example when something is dependent on file
89378645descriptors, like for example locking using flock(). If you do just
89388646C<< open(A, ">>&B") >>, the filehandle A will not have the same file
89398647descriptor as B, and therefore flock(A) will not flock(B) nor vice
89408648versa. But with C<< open(A, ">>&=B") >>, the filehandles will share
89418649the same underlying system file descriptor.
89428650
89438651=end original
89448652
8945ファイルハンドルを倹約することは、(倹約できること以外に)何かが
8653ファイルハンドルを倹約することは、何かがファイル記述子に依存している場合、
8946ファイル記述子に依存している場合、例えば flock() を使った
8654例えば flock() を使ったファイルロックといった場合に有用です
8947ファイルロックといった場合に有用です。
8655(しかも倹約きま)
89488656C<< open(A, ">>&B") >> とすると、ファイルハンドル A は B と同じ
89498657ファイル記述子にはならないので、flock(A) と flock(B) は別々になります。
89508658しかし C<< open(A, ">>&=B") >> ではファイルハンドルは基礎となるシステムの
89518659同じファイル記述子を共有します。
89528660
89538661=begin original
89548662
89558663Note that under Perls older than 5.8.0, Perl uses the standard C library's'
89568664fdopen() to implement the C<=> functionality. On many Unix systems,
89578665fdopen() fails when file descriptors exceed a certain value, typically 255.
89588666For Perls 5.8.0 and later, PerlIO is (most often) the default.
89598667
89608668=end original
89618669
896286705.8.0 より前の Perl の場合、C<=> 機能の実装は
89638671標準 C ライブラリの fdopen() を使っています。
89648672多くの Unix システムでは、fdopen() はファイル記述子がある値
89658673(典型的には 255)を超えた場合に失敗することが知られています。
896686745.8.0 以降の Perl では、(ほとんどの場合) PerlIO がデフォルトです。
89678675
89688676=begin original
89698677
89708678You can see whether your Perl was built with PerlIO by running C<perl -V>
89718679and looking for the C<useperlio=> line. If C<useperlio> is C<define>, you
89728680have PerlIO; otherwise you don't.
89738681
89748682=end original
89758683
89768684Perl が PerlIO つきでビルドされているかどうかを確認するには、
89778685C<perl -V> として C<useperlio=> の行を見ます。
89788686C<useperlio> が C<define> なら PerlIO を使っています;
89798687そうでなければ使っていません。
89808688
89818689=begin original
89828690
89838691If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|>
89848692with the one- or two-argument forms of C<open>),
89858693an implicit C<fork> is done, so C<open> returns twice: in the parent
89868694process it returns the pid
89878695of the child process, and in the child process it returns (a defined) C<0>.
89888696Use C<defined($pid)> or C<//> to determine whether the open was successful.
89898697
89908698=end original
89918699
899287001 引数 または 2 引数の形の C<open()> で (C<-|> や C<|-> というふうに)
89938701C<-> というコマンドにパイプを開くと、暗黙の C<fork> が行なわれるので、
89948702C<open> は 2 回返ります;
89958703親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が
89968704返されます。
89978705open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を
89988706使います。
89998707
90008708=begin original
90018709
90028710For example, use either
90038711
90048712=end original
90058713
90068714例えば、以下の二つ
90078715
90088716 $child_pid = open(FROM_KID, "-|") // die "can't fork: $!";
90098717
90108718=begin original
90118719
90128720or
90138721
90148722=end original
90158723
90168724または
90178725
90188726 $child_pid = open(TO_KID, "|-") // die "can't fork: $!";
90198727
90208728=begin original
90218729
90228730followed by
90238731
90248732=end original
90258733
90268734を使って、後で以下のようにします。
90278735
90288736 if ($child_pid) {
90298737 # am the parent:
90308738 # either write TO_KID or else read FROM_KID
90318739 ...
9032 waitpid $child_pid, 0;
8740 wait $child_pid;
90338741 } else {
90348742 # am the child; use STDIN/STDOUT normally
90358743 ...
90368744 exit;
90378745 }
90388746
90398747=begin original
90408748
90418749The filehandle behaves normally for the parent, but I/O to that
90428750filehandle is piped from/to the STDOUT/STDIN of the child process.
90438751In the child process, the filehandle isn't opened--I/O happens from/to
90448752the new STDOUT/STDIN. Typically this is used like the normal
90458753piped open when you want to exercise more control over just how the
90468754pipe command gets executed, such as when running setuid and
90478755you don't want to have to scan shell commands for metacharacters.
90488756
90498757=end original
90508758
9051親プロセスでは、このファイルハンドルは通常通りに動作しますが、行なわれる
8759親プロセスでは、このファイルハンドルは
9052入出力は、子プロセスの STDIN/STDOUT にパイプされます。
8760通常通りに動作しますが、行なわれる入出力は、
9053プロセス側では、そファイルハンドルは開かれず、入出力は新しい STDOUT
8761チャイルドプロセスの STDIN/STDOUT にパイプされます。
9054STDIN に対して行なわれます。
8762チャイルドプロセス側では、そのファイルハンドルは
8763オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。
90558764これは、setuid で実行して、シェルコマンドのメタ文字を
90568765検索させたくないような場合に、パイプコマンドの起動の仕方を
90578766制御したいとき、普通のパイプの open と同じように使います。
90588767
90598768=begin original
90608769
90618770The following blocks are more or less equivalent:
90628771
90638772=end original
90648773
90658774以下の組み合わせは、だいたい同じものです:
90668775
90678776 open(FOO, "|tr '[a-z]' '[A-Z]'");
90688777 open(FOO, "|-", "tr '[a-z]' '[A-Z]'");
90698778 open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]';
90708779 open(FOO, "|-", "tr", '[a-z]', '[A-Z]');
90718780
90728781 open(FOO, "cat -n '$file'|");
90738782 open(FOO, "-|", "cat -n '$file'");
90748783 open(FOO, "-|") || exec "cat", "-n", $file;
90758784 open(FOO, "-|", "cat", "-n", $file);
90768785
90778786=begin original
90788787
90798788The last two examples in each block show the pipe as "list form", which is
90808789not yet supported on all platforms. A good rule of thumb is that if
90818790your platform has a real C<fork()> (in other words, if your platform is
90828791Unix, including Linux and MacOS X), you can use the list form. You would
90838792want to use the list form of the pipe so you can pass literal arguments
90848793to the command without risk of the shell interpreting any shell metacharacters
90858794in them. However, this also bars you from opening pipes to commands
90868795that intentionally contain shell metacharacters, such as:
90878796
90888797=end original
90898798
90908799それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、
90918800これはまだ全てのプラットフォームで対応しているわけではなりません。
90928801よい経験則としては、もし実行しているプラットフォームで本当の C<fork()> が
90938802あれば(言い換えると、プラットフォームが Linux や MacOS X を含む Unix なら)
90948803リスト形式が使えます。
90958804パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、
90968805シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。
90978806しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして
90988807開くことを妨げます:
90998808
91008809 open(FOO, "|cat -n | expand -4 | lpr")
91018810 // die "Can't open pipeline to lpr: $!";
91028811
91038812=begin original
91048813
91058814See L<perlipc/"Safe Pipe Opens"> for more examples of this.
91068815
91078816=end original
91088817
91098818これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を
91108819参照してください。
91118820
91128821=begin original
91138822
9114Perl will attempt to flush all files opened for
8823Beginning with v5.6.0, Perl will attempt to flush all files opened for
91158824output before any operation that may do a fork, but this may not be
91168825supported on some platforms (see L<perlport>). To be safe, you may need
91178826to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
91188827of C<IO::Handle> on any open handles.
91198828
91208829=end original
91218830
91228831v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
91238832fork を行う前にフラッシュしようとしますが、これに対応していない
91248833プラットフォームもあります(L<perlport> を参照してください)。
91258834安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、
91268835全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
91278836呼び出す必要があるかもしれません。
91288837
91298838=begin original
91308839
91318840On systems that support a close-on-exec flag on files, the flag will
91328841be set for the newly opened file descriptor as determined by the value
91338842of C<$^F>. See L<perlvar/$^F>.
91348843
91358844=end original
91368845
91378846ファイルに対する close-on-exec フラグをサポートしているシステムでは、
91388847フラグは C<$^F> の値で決定される、新しくオープンされたファイル記述子に対して
91398848セットされます。
91408849L<perlvar/$^F> を参照してください。
91418850
91428851=begin original
91438852
91448853Closing any piped filehandle causes the parent process to wait for the
91458854child to finish, then returns the status value in C<$?> and
91468855C<${^CHILD_ERROR_NATIVE}>.
91478856
91488857=end original
91498858
9150パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を
8859パイプのファイルハンドルを close することで、
9151待ち、それから C<$?> と C<${^CHILD_ERROR_NATIVE}> にステータス値を返します。
8860親プロセスは、チャイルドプロセスの終了を待ち、それから C<$?> と
8861C<${^CHILD_ERROR_NATIVE}> にステータス値を返します。
91528862
91538863=begin original
91548864
91558865The filename passed to the one- and two-argument forms of open() will
91568866have leading and trailing whitespace deleted and normal
91578867redirection characters honored. This property, known as "magic open",
91588868can often be used to good effect. A user could specify a filename of
91598869F<"rsh cat file |">, or you could change certain filenames as needed:
91608870
91618871=end original
91628872
91631 引数 と 2 引数の形の open() に渡されたファイル名は、はじめと終わりの空白が
88731 引数 と 2 引数の形の open() に渡されたファイル名は、
9164取り除かれ、通常のリダイレクト文字列を受け付けます。
8874はじめと終わりの空白が取り除かれ、
9165この機能は "magic open" として知られていますが、普いい効果もたらします。
8875常のリダイレクト文字列受け付けます。
8876この機能は "magic open" として知られていますが、
8877普通いい効果をもたらします。
91668878ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、
91678879特定のファイル名を必要に応じて変更できます。
91688880
91698881 $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
91708882 open(FH, $filename) or die "Can't open $filename: $!";
91718883
91728884=begin original
91738885
91748886Use the three-argument form to open a file with arbitrary weird characters in it,
91758887
91768888=end original
91778889
91788890妙な文字が含まれているようなファイル名をオープンするには、
917988913 引数の形を使います。
91808892
91818893 open(FOO, "<", $file)
91828894 || die "can't open < $file: $!";
91838895
91848896=begin original
91858897
91868898otherwise it's necessary to protect any leading and trailing whitespace:
91878899
91888900=end original
91898901
91908902あるいは、次のようにして、最初と最後の空白を保護します:
91918903
91928904 $file =~ s#^(\s)#./$1#;
91938905 open(FOO, "< $file\0")
91948906 || die "open failed: $!";
91958907
91968908=begin original
91978909
91988910(this may not work on some bizarre filesystems). One should
91998911conscientiously choose between the I<magic> and I<three-argument> form
92008912of open():
92018913
92028914=end original
92038915
92048916(これは奇妙なファイルシステムでは動作しないかもしれません)。
92058917open() の I<magic> と I<3 引数> 形式を誠実に選択するべきです。
92068918
92078919 open(IN, $ARGV[0]) || die "can't open $ARGV[0]: $!";
92088920
92098921=begin original
92108922
92118923will allow the user to specify an argument of the form C<"rsh cat file |">,
92128924but will not work on a filename that happens to have a trailing space, while
92138925
92148926=end original
92158927
92168928とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、
92178929末尾にスペースがついてしまったファイル名では動作しません; 一方:
92188930
92198931 open(IN, "<", $ARGV[0])
92208932 || die "can't open < $ARGV[0]: $!";
92218933
92228934=begin original
92238935
92248936will have exactly the opposite restrictions.
92258937
92268938=end original
92278939
92288940はまったく逆の制限があります。
92298941
92308942=begin original
92318943
92328944If you want a "real" C C<open> (see L<open(2)> on your system), then you
92338945should use the C<sysopen> function, which involves no such magic (but may
92348946use subtly different filemodes than Perl open(), which is mapped to C
92358947fopen()). This is another way to protect your filenames from
92368948interpretation. For example:
92378949
92388950=end original
92398951
92408952もし「本当の」C 言語の C<open> (システムの C<open(2)> を参照してください)が
92418953必要なら、このような副作用のない C<sysopen> 関数を使うべきです
92428954(ただし、C の fopen() に割り付けられる Perl の open() とは
92438955かすかに違うファイルモードを持ちます)。
92448956これはファイル名を解釈から守るもう一つの方法です。
92458957例えば:
92468958
92478959 use IO::Handle;
92488960 sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL)
92498961 or die "sysopen $path: $!";
92508962 $oldfh = select(HANDLE); $| = 1; select($oldfh);
92518963 print HANDLE "stuff $$\n";
92528964 seek(HANDLE, 0, 0);
92538965 print "File contains: ", <HANDLE>;
92548966
92558967=begin original
92568968
8969Using the constructor from the C<IO::Handle> package (or one of its
8970subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous
8971filehandles that have the scope of the variables used to hold them, then
8972automatically (but silently) close once their reference counts become
8973zero, typically at scope exit:
8974
8975=end original
8976
8977C<IO::Handle> パッケージ(または C<IO::File> や C<IO::Socket> といった
8978サブパッケージ)のコンストラクタを使うことで、
8979これらへのリファレンスを保持している変数のスコープを持ち、それから
8980参照カウントが 0 になると自動的に (しかし暗黙に) 閉じる
8981無名ファイルハンドルを作成できます:
8982
8983 use IO::File;
8984 #...
8985 sub read_myfile_munged {
8986 my $ALL = shift;
8987 # or just leave it undef to autoviv
8988 my $handle = IO::File->new;
8989 open($handle, "<", "myfile") or die "myfile: $!";
8990 $first = <$handle>
8991 or return (); # Automatically closed here.
8992 mung($first) or die "mung failed"; # Or here.
8993 return (first, <$handle>) if $ALL; # Or here.
8994 return $first; # Or here.
8995 }
8996
8997=begin original
8998
8999B<WARNING:> The previous example has a bug because the automatic
9000close that happens when the refcount on C<handle> does not
9001properly detect and report failures. I<Always> close the handle
9002yourself and inspect the return value.
9003
9004=end original
9005
9006B<警告:> 自動的に閉じると、C<handle> の参照カウントが適切に検出できない
9007ときに失敗が報告されるのでバグがあります。
9008I<常に> ハンドルを自分自身で閉じて、返り値を調べてください。
9009
9010 close($handle)
9011 || warn "close failed: $!";
9012
9013=begin original
9014
92579015See L</seek> for some details about mixing reading and writing.
92589016
92599017=end original
92609018
92619019読み書きを混ぜる場合の詳細については L</seek> を参照してください。
92629020
92639021=begin original
92649022
92659023Portability issues: L<perlport/open>.
92669024
92679025=end original
92689026
92699027移植性の問題: L<perlport/open>。
92709028
92719029=item opendir DIRHANDLE,EXPR
92729030X<opendir>
92739031
92749032=for Pod::Functions open a directory
92759033
92769034=begin original
92779035
92789036Opens a directory named EXPR for processing by C<readdir>, C<telldir>,
92799037C<seekdir>, C<rewinddir>, and C<closedir>. Returns true if successful.
92809038DIRHANDLE may be an expression whose value can be used as an indirect
92819039dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined
92829040scalar variable (or array or hash element), the variable is assigned a
92839041reference to a new anonymous dirhandle; that is, it's autovivified.
92849042DIRHANDLEs have their own namespace separate from FILEHANDLEs.
92859043
92869044=end original
92879045
92889046C<readdir>、C<telldir>、C<seekdir>、C<rewinddir>、C<closedir> で
92899047処理するために、EXPR で指定された名前のディレクトリをオープンします。
92909048成功時には真を返します。
92919049DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ
92929050ハンドルの名前)となる式でも構いません。
92939051DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は
92949052新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、
92959053自動有効化されます。
92969054DIRHANDLE は、FILEHANDLE とは別に名前空間を持っています。
92979055
92989056=begin original
92999057
93009058See the example at C<readdir>.
93019059
93029060=end original
93039061
93049062C<readdir> の例を参照してください。
93059063
93069064=item ord EXPR
93079065X<ord> X<encoding>
93089066
93099067=item ord
93109068
93119069=for Pod::Functions find a character's numeric representation
93129070
93139071=begin original
93149072
93159073Returns the numeric value of the first character of EXPR.
93169074If EXPR is an empty string, returns 0. If EXPR is omitted, uses C<$_>.
93179075(Note I<character>, not byte.)
93189076
93199077=end original
93209078
93219079EXPR の最初の文字の数値としての値を返します。
93229080EXPR が空文字列の場合は、0 を返します。
93239081EXPR が省略されると、C<$_> を使います。
93249082(バイトではなく I<文字> であることに注意してください。)
93259083
93269084=begin original
93279085
93289086For the reverse, see L</chr>.
93299087See L<perlunicode> for more about Unicode.
93309088
93319089=end original
93329090
93339091逆のことをするには L</chr> を参照してください。
93349092Unicode については L<perlunicode> を参照してください。
93359093
9336=item our VARLIST
9094=item our EXPR
93379095X<our> X<global>
93389096
9339=item our TYPE VARLIST
9097=item our TYPE EXPR
93409098
9341=item our VARLIST : ATTRS
9099=item our EXPR : ATTRS
93429100
9343=item our TYPE VARLIST : ATTRS
9101=item our TYPE EXPR : ATTRS
93449102
93459103=for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping)
93469104
93479105=begin original
93489106
9349C<our> makes a lexical alias to a package (i.e. global) variable of the
9107C<our> associates a simple name with a package variable in the current
9350same name in the current package for use within the current lexical scope.
9108package for use within the current scope. When C<use strict 'vars'> is in
9109effect, C<our> lets you use declared global variables without qualifying
9110them with package names, within the lexical scope of the C<our> declaration.
9111In this way C<our> differs from C<use vars>, which is package-scoped.
93519112
93529113=end original
93539114
9354C<our> は単純名を、現在のレキシカルスコープ内で使うために、現在のパッケージの
9115C<our> は単純名を、現在のスコープ内で使うために、現在のパッケージの
9355同じ名前のパッケージ(つまりグローバルな)変数へのレキシカルな別名を作ります。
9116パッケージ変数と結び付けます。
9117C<use strict 'vars'> が有効の場合は、C<our> を使うことで、C<our> 宣言の
9118レキシカルスコープ内で、宣言されたグローバル変数をパッケージ名で
9119修飾することなく使うことができます。
9120この意味では、C<use vars> はパッケージスコープなので、C<our> とは異なります。
93569121
93579122=begin original
93589123
9359C<our> has the same scoping rules as C<my> or C<state>, meaning that it is
9124Unlike C<my> or C<state>, which allocates storage for a variable and
9360only valid within a lexical scope. Unlike C<my> and C<state>, which both
9125associates a simple name with that storage for use within the current
9361declare new (lexical) variables, C<our> only creates an alias to an
9126scope, C<our> associates a simple name with a package (read: global)
9362existing variable: a package variable of the same name.
9127variable in the current package, for use within the current lexical scope.
9128In other words, C<our> has the same scoping rules as C<my> or C<state>, but
9129does not necessarily create a variable.
93639130
93649131=end original
93659132
9366C<our> は C<my> や C<state> と同じスコープルールを持ちます; つまり
9133記憶領域を変数に割り当て、単純名を現在のスコープ内で使うためにその記憶領域に
9367レキシカルスコープの中でだけ有効です。
9134割り当てる C<my> や C<state> と違って、C<our> は単純名を、現在のレキシカル
9368新しい(レキシカル)変数を宣言する C<my> や C<state> と異なり、C<our> は既に
9135スコープ内で使うために、現在のパッケージの(読み込み: グローバル) パッケージ
9369存在する変数への別名を作るだです: 同じ名前のパッケージ変数です。
9136変数と結び付す。
9137言い換えると、C<our> は C<my> や C<state> と同じスコープルールを持ちますが、
9138変数を作る必要はありません。
93709139
93719140=begin original
93729141
9373This means that when C<use strict 'vars'> is in effect, C<our> lets you use
9142If more than one value is listed, the list must be placed
9374a package variable without qualifying it with the package name, but only within
9375the lexical scope of the C<our> declaration.
9376
9377=end original
9378
9379つまり、C<use strict 'vars'> が有効の場合は、C<our> を使うことで、
9380パッケージ変数をパッケージ名で修飾することなく使うことができますが、
9381C<our> 宣言のレキシカルスコープ内だけということです。
9382
9383 package Foo;
9384 use strict;
9385
9386 $Foo::foo = 23;
9387
9388 {
9389 our $foo; # alias to $Foo::foo
9390 print $foo; # prints 23
9391 }
9392
9393 print $Foo::foo; # prints 23
9394
9395 print $foo; # ERROR: requires explicit package name
9396
9397=begin original
9398
9399This works even if the package variable has not been used before, as
9400package variables spring into existence when first used.
9401
9402=end original
9403
9404これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、
9405最初に使われた時にひょっこり現れるからです。
9406
9407 package Foo;
9408 use strict;
9409
9410 our $foo = 23; # just like $Foo::foo = 23
9411
9412 print $Foo::foo; # prints 23
9413
9414=begin original
9415
9416If more than one variable is listed, the list must be placed
94179143in parentheses.
94189144
94199145=end original
94209146
9421複数の変数を指定する場合は、リストはかっこでくくらなければなりません。
9147複数のを指定する場合は、リストはかっこでくくらなければなりません。
94229148
9149 our $foo;
94239150 our($bar, $baz);
94249151
94259152=begin original
94269153
9427An C<our> declaration declares an alias for a package variable that will be visible
9154An C<our> declaration declares a global variable that will be visible
94289155across its entire lexical scope, even across package boundaries. The
94299156package in which the variable is entered is determined at the point
94309157of the declaration, not at the point of use. This means the following
94319158behavior holds:
94329159
94339160=end original
94349161
94359162C<our> 宣言はレキシカルスコープ全体に対して(たとえパッケージ境界を
9436越えていても)見える、パッケ変数への別名を宣言します。
9163越えていても)見えるグロバル変数を宣言します。
94379164この変数が入るパッケージは宣言した時点で定義され、
94389165使用した時点ではありません。
94399166これにより、以下のような振る舞いになります:
94409167
94419168 package Foo;
94429169 our $bar; # declares $Foo::bar for rest of lexical scope
94439170 $bar = 20;
94449171
94459172 package Bar;
94469173 print $bar; # prints 20, as it refers to $Foo::bar
94479174
94489175=begin original
94499176
94509177Multiple C<our> declarations with the same name in the same lexical
94519178scope are allowed if they are in different packages. If they happen
94529179to be in the same package, Perl will emit warnings if you have asked
94539180for them, just like multiple C<my> declarations. Unlike a second
94549181C<my> declaration, which will bind the name to a fresh variable, a
94559182second C<our> declaration in the same package, in the same scope, is
94569183merely redundant.
94579184
94589185=end original
94599186
94609187同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の
94619188C<our> 宣言ができます。
94629189同じパッケージになっていると、警告が出力されるようになっていれば
94639190複数の C<my> 宣言がある場合と同じように警告が出力されます。
94649191新しい変数を名前に割り当てることになる 2 回目の C<my> 宣言と違って、
94659192同じパッケージの同じスコープで 2 回 C<our> 宣言するのは単に冗長です。
94669193
94679194 use warnings;
94689195 package Foo;
94699196 our $bar; # declares $Foo::bar for rest of lexical scope
94709197 $bar = 20;
94719198
94729199 package Bar;
94739200 our $bar = 30; # declares $Bar::bar for rest of lexical scope
94749201 print $bar; # prints 30
94759202
94769203 our $bar; # emits warning but has no other effect
94779204 print $bar; # still prints 30
94789205
94799206=begin original
94809207
94819208An C<our> declaration may also have a list of attributes associated
94829209with it.
94839210
94849211=end original
94859212
94869213C<our> 宣言には、それと結び付けられる属性のリストを持つこともあります。
94879214
94889215=begin original
94899216
94909217The exact semantics and interface of TYPE and ATTRS are still
94919218evolving. TYPE is currently bound to the use of the C<fields> pragma,
94929219and attributes are handled using the C<attributes> pragma, or, starting
94939220from Perl 5.8.0, also via the C<Attribute::Handlers> module. See
94949221L<perlsub/"Private Variables via my()"> for details, and L<fields>,
94959222L<attributes>, and L<Attribute::Handlers>.
94969223
94979224=end original
94989225
94999226TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
95009227現在のところ、TYPE は C<fields> プラグマの使用と結び付けられていて、
95019228属性は C<attributes> プラグマか、Perl 5.8.0 からは
95029229C<Attribute::Handlers> モジュールと結び付けられています。
95039230詳しくはL<perlsub/"Private Variables via my()">, L<fields>,
95049231L<attributes>, L<Attribute::Handlers> を参照してください。
95059232
9506=begin original
9507
9508Note that with a parenthesised list, C<undef> can be used as a dummy
9509placeholder, for example to skip assignment of initial values:
9510
9511=end original
9512
9513かっこで囲まれたリストでは、C<undef> は、例えば初期値の代入を飛ばすために、
9514ダミーのプレースホルダとして使えることに注意してください:
9515
9516 our ( undef, $min, $hour ) = localtime;
9517
9518=begin original
9519
9520C<our> differs from C<use vars>, which allows use of an unqualified name
9521I<only> within the affected package, but across scopes.
9522
9523=end original
9524
9525C<our> は C<use vars> と異なります; スコープをまたぐのではなく、影響する
9526パッケージの内側 I<のみ> で完全修飾されていない名前を使えるようにします。
9527
95289233=item pack TEMPLATE,LIST
95299234X<pack>
95309235
95319236=for Pod::Functions convert a list into a binary representation
95329237
95339238=begin original
95349239
95359240Takes a LIST of values and converts it into a string using the rules
95369241given by the TEMPLATE. The resulting string is the concatenation of
95379242the converted values. Typically, each converted value looks
95389243like its machine-level representation. For example, on 32-bit machines
95399244an integer may be represented by a sequence of 4 bytes, which will in
95409245Perl be presented as a string that's 4 characters long.
95419246
95429247=end original
95439248
95449249LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。
95459250結果の文字列は変換した値を連結したものです。
95469251典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。
95479252例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、
95489253Perl では 4 文字の文字列で表現されます。
95499254
95509255=begin original
95519256
95529257See L<perlpacktut> for an introduction to this function.
95539258
95549259=end original
95559260
95569261この関数の説明については L<perlpacktut> を参照してください。
95579262
95589263=begin original
95599264
95609265The TEMPLATE is a sequence of characters that give the order and type
95619266of values, as follows:
95629267
95639268=end original
95649269
95659270TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです:
95669271
95679272=begin original
95689273
95699274 a A string with arbitrary binary data, will be null padded.
95709275 A A text (ASCII) string, will be space padded.
95719276 Z A null-terminated (ASCIZ) string, will be null padded.
95729277
95739278=end original
95749279
95759280 a 任意のバイナリデータを含む文字列、ヌル文字で埋める。
95769281 A テキスト (ASCII) 文字列、スペース文字で埋める。
95779282 Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。
95789283
95799284=begin original
95809285
95819286 b A bit string (ascending bit order inside each byte,
95829287 like vec()).
95839288 B A bit string (descending bit order inside each byte).
95849289 h A hex string (low nybble first).
95859290 H A hex string (high nybble first).
95869291
95879292=end original
95889293
95899294 b ビット列 (バイトごとに昇ビット順、vec() と同じ)。
95909295 B ビット列 (バイトごとに降ビット順)。
95919296 h 16 進数文字列 (低位ニブルが先)。
95929297 H 16 進数文字列 (高位ニブルが先)。
95939298
95949299=begin original
95959300
95969301 c A signed char (8-bit) value.
95979302 C An unsigned char (octet) value.
95989303 W An unsigned char value (can be greater than 255).
95999304
96009305=end original
96019306
96029307 c signed char (8 ビット) 値。
96039308 C unsigned char (オクテット) 値。
96049309 W unsigned char 値 (255 より大きいかもしれません)。
96059310
96069311=begin original
96079312
96089313 s A signed short (16-bit) value.
96099314 S An unsigned short value.
96109315
96119316=end original
96129317
96139318 s signed short (16 ビット) 値。
96149319 S unsigned short 値。
96159320
96169321=begin original
96179322
96189323 l A signed long (32-bit) value.
96199324 L An unsigned long value.
96209325
96219326=end original
96229327
96239328 l signed long (32 ビット) 値。
96249329 L unsigned long 値。
96259330
96269331=begin original
96279332
96289333 q A signed quad (64-bit) value.
96299334 Q An unsigned quad value.
96309335 (Quads are available only if your system supports 64-bit
96319336 integer values _and_ if Perl has been compiled to support
96329337 those. Raises an exception otherwise.)
96339338
96349339=end original
96359340
96369341 q 符号付き 64 ビット整数。
96379342 Q 符号なし 64 ビット整数。
96389343 (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が
96399344 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。
96409345 それ以外の場合は例外が発生します。)
96419346
96429347=begin original
96439348
96449349 i A signed integer value.
96459350 I A unsigned integer value.
96469351 (This 'integer' is _at_least_ 32 bits wide. Its exact
96479352 size depends on what a local C compiler calls 'int'.)
96489353
96499354=end original
96509355
96519356 i signed int 値。
96529357 I unsigned int 値。
9653 (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは
9358 (ここでの 'integer' は 「最低」 32 bits 幅です。正確なサイズは
9654 ローカルの C コンパイラの 'int' のサイズに依存します。)
9359 ローカルの C コンパイラの'int'のサイズに依存します。)
96559360
96569361=begin original
96579362
96589363 n An unsigned short (16-bit) in "network" (big-endian) order.
96599364 N An unsigned long (32-bit) in "network" (big-endian) order.
96609365 v An unsigned short (16-bit) in "VAX" (little-endian) order.
96619366 V An unsigned long (32-bit) in "VAX" (little-endian) order.
96629367
96639368=end original
96649369
96659370 n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。
96669371 N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。
96679372 v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。
96689373 V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。
96699374
96709375=begin original
96719376
96729377 j A Perl internal signed integer value (IV).
96739378 J A Perl internal unsigned integer value (UV).
96749379
96759380=end original
96769381
96779382 j Perl 内部符号付き整数 (IV)。
96789383 J Perl 内部符号なし整数 (UV)。
96799384
96809385=begin original
96819386
96829387 f A single-precision float in native format.
96839388 d A double-precision float in native format.
96849389
96859390=end original
96869391
96879392 f 機種依存の単精度浮動小数点数。
96889393 d 機種依存の倍精度浮動小数点数。
96899394
96909395=begin original
96919396
96929397 F A Perl internal floating-point value (NV) in native format
96939398 D A float of long-double precision in native format.
96949399 (Long doubles are available only if your system supports
96959400 long double values _and_ if Perl has been compiled to
96969401 support those. Raises an exception otherwise.)
96979402
96989403=end original
96999404
97009405 F ネイティブフォーマットの Perl 内部浮動小数点数 (NV)
97019406 D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。
97029407 (long double は、システムが long double に対応していて、かつ Perl が
97039408 long double 対応としてコンパイルされている場合にのみ使用可能です。
97049409 それ以外の場合は例外が発生します。)
97059410
97069411=begin original
97079412
97089413 p A pointer to a null-terminated string.
97099414 P A pointer to a structure (fixed-length string).
97109415
97119416=end original
97129417
97139418 p ヌル文字で終端する文字列へのポインタ。
97149419 P 構造体 (固定長文字列) へのポインタ。
97159420
97169421=begin original
97179422
97189423 u A uuencoded string.
97199424 U A Unicode character number. Encodes to a character in char-
97209425 acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in
97219426 byte mode.
97229427
97239428=end original
97249429
97259430 u uuencode 文字列。
97269431 U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に
97279432 (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。
97289433
97299434=begin original
97309435
97319436 w A BER compressed integer (not an ASN.1 BER, see perlpacktut
97329437 for details). Its bytes represent an unsigned integer in
97339438 base 128, most significant digit first, with as few digits
97349439 as possible. Bit eight (the high bit) is set on each byte
97359440 except the last.
97369441
97379442=end original
97389443
97399444 w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を
97409445 参照してください)。このバイト列はできるだけ少ない桁数で表現された
97419446 128 を基とした符号なし整数で、最上位ビットから順に並びます。
97429447 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。
97439448
97449449=begin original
97459450
97469451 x A null byte (a.k.a ASCII NUL, "\000", chr(0))
97479452 X Back up a byte.
97489453 @ Null-fill or truncate to absolute position, counted from the
97499454 start of the innermost ()-group.
97509455 . Null-fill or truncate to absolute position specified by
97519456 the value.
97529457 ( Start of a ()-group.
97539458
97549459=end original
97559460
97569461 x ヌル文字 (つまり ASCII NUL, "\000", chr(0))
97579462 X 1 文字後退。
97589463 @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で
97599464 埋めるか切り詰める。
97609465 . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。
97619466 ( () の組の開始。
97629467
97639468=begin original
97649469
97659470One or more modifiers below may optionally follow certain letters in the
97669471TEMPLATE (the second column lists letters for which the modifier is valid):
97679472
97689473=end original
97699474
97709475以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで
97719476付けることができます(表の 2 列目は、その修飾子が有効な文字です):
97729477
97739478=begin original
97749479
97759480 ! sSlLiI Forces native (short, long, int) sizes instead
97769481 of fixed (16-/32-bit) sizes.
97779482
97789483=end original
97799484
97809485 ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな
97819486 (short, long, int)サイズを強制する。
97829487
97839488=begin original
97849489
9785 ! xX Make x and X act as alignment commands.
9490 xX Make x and X act as alignment commands.
97869491
97879492=end original
97889493
9789 ! xX x と X をアライメントコマンドとして振舞わせる。
9494 xX x と X をアライメントコマンドとして振舞わせる。
97909495
97919496=begin original
97929497
9793 ! nNvV Treat integers as signed instead of unsigned.
9498 nNvV Treat integers as signed instead of unsigned.
97949499
97959500=end original
97969501
9797 ! nNvV 整数を符号なしではなく符号付きとして扱わせる。
9502 nNvV 整数を符号なしではなく符号付きとして扱わせる。
97989503
97999504=begin original
98009505
9801 ! @. Specify position as byte offset in the internal
9506 @. Specify position as byte offset in the internal
98029507 representation of the packed string. Efficient
98039508 but dangerous.
98049509
98059510=end original
98069511
9807 ! @. pack された内部表現のバイトオフセットとして位置を指定する。
9512 @. pack された内部表現のバイトオフセットとして位置を指定する。
98089513 効率的ですが危険です。
98099514
98109515=begin original
98119516
98129517 > sSiIlLqQ Force big-endian byte-order on the type.
98139518 jJfFdDpP (The "big end" touches the construct.)
98149519
98159520=end original
98169521
98179522 > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。
98189523 jJfFdDpP (「大きい端」が構造に触れています。)
98199524
98209525=begin original
98219526
98229527 < sSiIlLqQ Force little-endian byte-order on the type.
98239528 jJfFdDpP (The "little end" touches the construct.)
98249529
98259530=end original
98269531
98279532 < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。
98289533 jJfFdDpP (「小さい端」が構造に触れています。)
98299534
98309535=begin original
98319536
98329537The C<< > >> and C<< < >> modifiers can also be used on C<()> groups
98339538to force a particular byte-order on all components in that group,
98349539including all its subgroups.
98359540
98369541=end original
98379542
98389543C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます;
98399544この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に
98409545強制します。
98419546
9842=begin comment
9843
9844Larry recalls that the hex and bit string formats (H, h, B, b) were added to
9845pack for processing data from NASA's Magellan probe. Magellan was in an
9846elliptical orbit, using the antenna for the radar mapping when close to
9847Venus and for communicating data back to Earth for the rest of the orbit.
9848There were two transmission units, but one of these failed, and then the
9849other developed a fault whereby it would randomly flip the sense of all the
9850bits. It was easy to automatically detect complete records with the correct
9851sense, and complete records with all the bits flipped. However, this didn't
9852recover the records where the sense flipped midway. A colleague of Larry's
9853was able to pretty much eyeball where the records flipped, so they wrote an
9854editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to
9855manually correct the records and recover the data. For this purpose pack
9856gained the hex and bit string format specifiers.
9857
9858git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit
985927e2fb84680b9cc1), but the patch description makes no mention of their
9860addition, let alone the story behind them.
9861
9862=end comment
9863
98649547=begin original
98659548
98669549The following rules apply:
98679550
98689551=end original
98699552
98709553以下の条件が適用されます:
98719554
98729555=over
98739556
98749557=item *
98759558
98769559=begin original
98779560
98789561Each letter may optionally be followed by a number indicating the repeat
98799562count. A numeric repeat count may optionally be enclosed in brackets, as
98809563in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from
98819564the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>,
98829565C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means
98839566something else, described below. Supplying a C<*> for the repeat count
98849567instead of a number means to use however many items are left, except for:
98859568
98869569=end original
98879570
98889571これらの文字の後には、繰り返し数を示す数字を付けることができます。
98899572数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで
98909573囲むこともできます。
98919574C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P>
98929575以外の全ての型では、LIST から繰り返し数の値を取り出して使います。
98939576繰り返し数に C<*> を指定すると、以下の例外を除いて、
98949577その時点で残っているすべての要素を意味します。
98959578
98969579=over
98979580
98989581=item *
98999582
99009583=begin original
99019584
99029585C<@>, C<x>, and C<X>, where it is equivalent to C<0>.
99039586
99049587=end original
99059588
99069589C<@>, C<x>, C<X> では C<0> と等価です。
99079590
99089591=item *
99099592
99109593=begin original
99119594
99129595<.>, where it means relative to the start of the string.
99139596
99149597=end original
99159598
99169599C<.> では文字列の先頭からの相対位置を意味します。
99179600
99189601=item *
99199602
99209603=begin original
99219604
99229605C<u>, where it is equivalent to 1 (or 45, which here is equivalent).
99239606
99249607=end original
99259608
99269609C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。
99279610
99289611=back
99299612
99309613=begin original
99319614
99329615One can replace a numeric repeat count with a template letter enclosed in
99339616brackets to use the packed byte length of the bracketed template for the
99349617repeat count.
99359618
99369619=end original
99379620
99389621このテンプレートでパックされたバイト長を繰り返し数として使うために、
99399622大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが
99409623できます。
99419624
99429625=begin original
99439626
99449627For example, the template C<x[L]> skips as many bytes as in a packed long,
99459628and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when
99469629variable-expanded) unpacks. If the template in brackets contains alignment
99479630commands (such as C<x![d]>), its packed length is calculated as if the
99489631start of the template had the maximal possible alignment.
99499632
99509633=end original
99519634
99529635例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、
99539636テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を
99549637unpack したものの 2 倍を unpack します。
99559638(C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、
99569639パックされた長さは、テンプレートの先頭で最大限可能なアライメントを
99579640持っているものとして計算されます。
99589641
99599642=begin original
99609643
99619644When used with C<Z>, a C<*> as the repeat count is guaranteed to add a
99629645trailing null byte, so the resulting string is always one byte longer than
99639646the byte length of the item itself.
99649647
99659648=end original
99669649
99679650C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが
99689651保証されるので、パックされた結果は常に要素の C<length> の値より
996996521 大きくなります。
99709653
99719654=begin original
99729655
99739656When used with C<@>, the repeat count represents an offset from the start
99749657of the innermost C<()> group.
99759658
99769659=end original
99779660
99789661C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを
99799662表現します。
99809663
99819664=begin original
99829665
99839666When used with C<.>, the repeat count determines the starting position to
99849667calculate the value offset as follows:
99859668
99869669=end original
99879670
99889671C<.> で使われると、繰り返し数は以下のようにして、
99899672値のオフセットを計算するための開始位置を決定するために使われます。
99909673
99919674=over
99929675
99939676=item *
99949677
99959678=begin original
99969679
99979680If the repeat count is C<0>, it's relative to the current position.
99989681
99999682=end original
100009683
100019684繰り返し数が C<0> なら、現在位置からの相対位置となります。
100029685
100039686=item *
100049687
100059688=begin original
100069689
100079690If the repeat count is C<*>, the offset is relative to the start of the
100089691packed string.
100099692
100109693=end original
100119694
10012繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの
9695繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの相対位置です。
10013相対位置です。
100149696
100159697=item *
100169698
100179699=begin original
100189700
100199701And if it's an integer I<n>, the offset is relative to the start of the
100209702I<n>th innermost C<( )> group, or to the start of the string if I<n> is
100219703bigger then the group level.
100229704
100239705=end original
100249706
100259707そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの
100269708先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの
100279709相対位置です。
100289710
100299711=back
100309712
100319713=begin original
100329714
100339715The repeat count for C<u> is interpreted as the maximal number of bytes
100349716to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
100359717count should not be more than 65.
100369718
100379719=end original
100389720
100399721C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを
100409722示します; 0, 1, 2 は 45 として扱われます。
100419723繰り返し数は 65 を超えてはなりません。
100429724
100439725=item *
100449726
100459727=begin original
100469728
100479729The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a
100489730string of length count, padding with nulls or spaces as needed. When
100499731unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything
100509732after the first null, and C<a> returns data with no stripping at all.
100519733
100529734=end original
100539735
100549736C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、
100559737繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か
100569738スペース文字を付け足します。
100579739unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の
100589740ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく
100599741そのまま返します。
100609742
100619743=begin original
100629744
100639745If the value to pack is too long, the result is truncated. If it's too
100649746long and an explicit count is provided, C<Z> packs only C<$count-1> bytes,
100659747followed by a null byte. Thus C<Z> always packs a trailing null, except
100669748when the count is 0.
100679749
100689750=end original
100699751
100709752pack する値が長すぎる場合、結果は切り詰められます。
100719753長すぎてかつ明示的に個数が指定されている場合、
100729754C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。
100739755従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが
100749756つきます。
100759757
100769758=item *
100779759
100789760=begin original
100799761
100809762Likewise, the C<b> and C<B> formats pack a string that's that many bits long.
100819763Each such format generates 1 bit of the result. These are typically followed
100829764by a repeat count like C<B8> or C<B64>.
100839765
100849766=end original
100859767
100869768同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。
100879769これらの各文字は結果の 1 ビットを生成します。
100889770これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。
100899771
100909772=begin original
100919773
100929774Each result bit is based on the least-significant bit of the corresponding
100939775input character, i.e., on C<ord($char)%2>. In particular, characters C<"0">
100949776and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">.
100959777
100969778=end original
100979779
100989780結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします
100999781(つまり C<ord($char)%2>)。
101009782特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、
101019783ビット 0 と 1 を生成します。
101029784
101039785=begin original
101049786
101059787Starting from the beginning of the input string, each 8-tuple
101069788of characters is converted to 1 character of output. With format C<b>,
101079789the first character of the 8-tuple determines the least-significant bit of a
101089790character; with format C<B>, it determines the most-significant bit of
101099791a character.
101109792
101119793=end original
101129794
10113pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。
9795pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に
9796変換されます。
101149797C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります;
101159798C<B> フォーマットでは出力の最上位ビットとなります。
101169799
101179800=begin original
101189801
101199802If the length of the input string is not evenly divisible by 8, the
101209803remainder is packed as if the input string were padded by null characters
101219804at the end. Similarly during unpacking, "extra" bits are ignored.
101229805
101239806=end original
101249807
101259808もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の
101269809最後にヌル文字がパッディングされているものとしてパックされます。
101279810同様に、unpack 中は「余分な」ビットは無視されます。
101289811
101299812=begin original
101309813
101319814If the input string is longer than needed, remaining characters are ignored.
101329815
101339816=end original
101349817
101359818入力文字列が必要な分よりも長い場合、余分な文字は無視されます。
101369819
101379820=begin original
101389821
101399822A C<*> for the repeat count uses all characters of the input field.
101409823On unpacking, bits are converted to a string of C<0>s and C<1>s.
101419824
101429825=end original
101439826
101449827繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が
101459828使われます。
101469829unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。
101479830
101489831=item *
101499832
101509833=begin original
101519834
101529835The C<h> and C<H> formats pack a string that many nybbles (4-bit groups,
101539836representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long.
101549837
101559838=end original
101569839
101579840C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で
101589841表現可能な 4 ビットグループ)のニブル列に pack します。
101599842
101609843=begin original
101619844
101629845For each such format, pack() generates 4 bits of result.
101639846With non-alphabetical characters, the result is based on the 4 least-significant
101649847bits of the input character, i.e., on C<ord($char)%16>. In particular,
101659848characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
101669849C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result
101679850is compatible with the usual hexadecimal digits, so that C<"a"> and
101689851C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex
101699852characters with this format.
101709853
101719854=end original
101729855
101739856このようなフォーマット文字のそれぞれについて、pack() は
101749857結果の 4 ビットを生成します。
101759858英字でない文字の場合、結果は入力文字の下位 4 ビットを
101769859基にします(つまり C<ord($char)%16>)。
101779860特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に
101789861ニブル 0 と 1 を生成します。
10179文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に
9862文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の
10180ので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。
986316 進数と同じ結果にりますので、C<"a"> と C<"A"> はどちらも
9864ニブル C<0xa==10> を生成します。
101819865これらの 16 進文字はこの特定のフォーマットでだけ使ってください。
101829866
101839867=begin original
101849868
101859869Starting from the beginning of the template to pack(), each pair
101869870of characters is converted to 1 character of output. With format C<h>, the
101879871first character of the pair determines the least-significant nybble of the
101889872output character; with format C<H>, it determines the most-significant
101899873nybble.
101909874
101919875=end original
101929876
101939877pack() のテンプレートの先頭から始めて、2 文字毎に 1 文字の出力に
101949878変換されます。
101959879C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、
101969880C<H> フォーマットでは出力の最上位ニブルとなります。
101979881
101989882=begin original
101999883
102009884If the length of the input string is not even, it behaves as if padded by
102019885a null character at the end. Similarly, "extra" nybbles are ignored during
102029886unpacking.
102039887
102049888=end original
102059889
102069890入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて
102079891いるかのように振る舞います。
102089892同様に、unpack 中は「余分な」ニブルは無視されます。
102099893
102109894=begin original
102119895
102129896If the input string is longer than needed, extra characters are ignored.
102139897
102149898=end original
102159899
102169900入力文字列が必要な分より長い場合、余分な部分は無視されます。
102179901
102189902=begin original
102199903
102209904A C<*> for the repeat count uses all characters of the input field. For
102219905unpack(), nybbles are converted to a string of hexadecimal digits.
102229906
102239907=end original
102249908
10225繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
9909繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が
9910使われます。
102269911unpack() 時にはニブルは 16 進数の文字列に変換されます。
102279912
102289913=item *
102299914
102309915=begin original
102319916
102329917The C<p> format packs a pointer to a null-terminated string. You are
102339918responsible for ensuring that the string is not a temporary value, as that
102349919could potentially get deallocated before you got around to using the packed
102359920result. The C<P> format packs a pointer to a structure of the size indicated
102369921by the length. A null pointer is created if the corresponding value for
102379922C<p> or C<P> is C<undef>; similarly with unpack(), where a null pointer
102389923unpacks into C<undef>.
102399924
102409925=end original
102419926
102429927C<p> は、ヌル文字終端文字列へのポインタを pack します。
102439928文字列が一時的な値でない(つまり pack された結果を使う前に文字列が
102449929解放されない) ことに責任を持つ必要があります。
102459930C<P> は、指定した長さの構造体へのポインタを pack します。
102469931C<p> または C<P> に対応する値が C<undef> だった場合、
102479932ヌルポインタが作成されます; ヌルポインタが C<undef> に unpack される
102489933unpack() と同様です。
102499934
102509935=begin original
102519936
102529937If your system has a strange pointer size--meaning a pointer is neither as
102539938big as an int nor as big as a long--it may not be possible to pack or
102549939unpack pointers in big- or little-endian byte order. Attempting to do
102559940so raises an exception.
102569941
102579942=end original
102589943
102599944システムのポインタが変わったサイズの場合--つまり、int の大きさでも
102609945long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの
102619946バイト順で pack や unpack することはできません。
102629947そうしようとすると例外が発生します。
102639948
102649949=item *
102659950
102669951=begin original
102679952
102689953The C</> template character allows packing and unpacking of a sequence of
102699954items where the packed structure contains a packed item count followed by
102709955the packed items themselves. This is useful when the structure you're
102719956unpacking has encoded the sizes or repeat counts for some of its fields
102729957within the structure itself as separate fields.
102739958
102749959=end original
102759960
102769961C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の
102779962アイテム列を pack 及び unpack します。
102789963これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に
102799964独立したフィールドとしてエンコードされている場合に有効です。
102809965
102819966=begin original
102829967
102839968For C<pack>, you write I<length-item>C</>I<sequence-item>, and the
102849969I<length-item> describes how the length value is packed. Formats likely
102859970to be of most use are integer-packing ones like C<n> for Java strings,
102869971C<w> for ASN.1 or SNMP, and C<N> for Sun XDR.
102879972
102889973=end original
102899974
102909975C<pack> では I<length-item>C</>I<string-item> の形になり、
102919976I<length-item> は長さの値がどのように pack されているかを指定します。
102929977もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための
102939978C<w>、Sun XDR のための C<N> といった整数型です。
102949979
102959980=begin original
102969981
102979982For C<pack>, I<sequence-item> may have a repeat count, in which case
102989983the minimum of that and the number of available items is used as the argument
102999984for I<length-item>. If it has no repeat count or uses a '*', the number
103009985of available items is used.
103019986
103029987=end original
103039988
103049989C<pack> では、I<sequence-item> は繰り返し数を持つことがあり、その場合は
103059990その最小値と利用可能なアイテムの数は I<length-item> のための引数として
103069991使われます。
103079992繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。
103089993
103099994=begin original
103109995
103119996For C<unpack>, an internal stack of integer arguments unpacked so far is
103129997used. You write C</>I<sequence-item> and the repeat count is obtained by
103139998popping off the last element from the stack. The I<sequence-item> must not
103149999have a repeat count.
1031510000
1031610001=end original
1031710002
1031810003C<unpack> では、今まで unpack した数値引数の内部スタックが使われます。
1031910004C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を
1032010005取り出すことで得ます。
1032110006I<sequence-item> は繰り返し数を持っていてはいけません。
1032210007
1032310008=begin original
1032410009
1032510010If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">),
1032610011the I<length-item> is the string length, not the number of strings. With
1032710012an explicit repeat count for pack, the packed string is adjusted to that
1032810013length. For example:
1032910014
1033010015=end original
1033110016
1033210017I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、
1033310018I<length-item> は文字列の数ではなく、文字列の長さです。
1033410019pack で明示的な繰り返し数があると、pack された文字列は与えられた
1033510020長さに調整されます。
1033610021例えば:
1033710022
10338 This code: gives this result:
10023 This code: gives this result:
10024
10025 unpack("W/a", "\004Gurusamy") ("Guru")
10026 unpack("a3/A A*", "007 Bond J ") (" Bond", "J")
10027 unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".")
1033910028
10340 unpack("W/a", "\004Gurusamy") ("Guru")
10029 pack("n/a* w/a","hello,","world") "\000\006hello,\005world"
10341 unpack("a3/A A*", "007 Bond J ") (" Bond", "J")
10030 pack("a/W2", ord("a") .. ord("z")) "2ab"
10342 unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".")
1034310031
10344 pack("n/a* w/a","hello,","world") "\000\006hello,\005world"
10345 pack("a/W2", ord("a") .. ord("z")) "2ab"
10346
1034710032=begin original
1034810033
1034910034The I<length-item> is not returned explicitly from C<unpack>.
1035010035
1035110036=end original
1035210037
1035310038I<length-item> は C<unpack> から明示的には返されません。
1035410039
1035510040=begin original
1035610041
1035710042Supplying a count to the I<length-item> format letter is only useful with
1035810043C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may
1035910044introduce C<"\000"> characters, which Perl does not regard as legal in
1036010045numeric strings.
1036110046
1036210047=end original
1036310048
1036410049I<length-item> 文字に繰り返し数をつけるのは、
1036510050文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。
1036610051C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が
1036710052出力されることがあり、Perl はこれを有効な数値文字列として認識しません。
1036810053
1036910054=item *
1037010055
1037110056=begin original
1037210057
1037310058The integer types C<s>, C<S>, C<l>, and C<L> may be
1037410059followed by a C<!> modifier to specify native shorts or
1037510060longs. As shown in the example above, a bare C<l> means
1037610061exactly 32 bits, although the native C<long> as seen by the local C compiler
1037710062may be larger. This is mainly an issue on 64-bit platforms. You can
1037810063see whether using C<!> makes any difference this way:
1037910064
1038010065=end original
1038110066
1038210067C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を
1038310068つけることで、ネイティブの short や long を指定できます。
1038410069上述のように、C<l> は正確に 32 ビットですが、ネイティブな
1038510070(ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。
1038610071これは主に 64 ビットプラットフォームで意味があります。
1038710072C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます:
1038810073
1038910074 printf "format s is %d, s! is %d\n",
1039010075 length pack("s"), length pack("s!");
1039110076
1039210077 printf "format l is %d, l! is %d\n",
1039310078 length pack("l"), length pack("l!");
1039410079
1039510080=begin original
1039610081
1039710082C<i!> and C<I!> are also allowed, but only for completeness' sake:
1039810083they are identical to C<i> and C<I>.
1039910084
1040010085=end original
1040110086
1040210087C<i!> と C<I!> も動作しますが、単に完全性のためだけです;
1040310088これは C<i> 及び C<I> と同じです。
1040410089
1040510090=begin original
1040610091
1040710092The actual sizes (in bytes) of native shorts, ints, longs, and long
1040810093longs on the platform where Perl was built are also available from
1040910094the command line:
1041010095
1041110096=end original
1041210097
1041310098Perl がビルドされたプラットフォームでの short, int, long, long long の
1041410099実際の(バイト数での)サイズはコマンドラインから:
1041510100
1041610101 $ perl -V:{short,int,long{,long}}size
1041710102 shortsize='2';
1041810103 intsize='4';
1041910104 longsize='4';
1042010105 longlongsize='8';
1042110106
1042210107=begin original
1042310108
1042410109or programmatically via the C<Config> module:
1042510110
1042610111=end original
1042710112
1042810113あるいは C<Config> モジュールからプログラムで:
1042910114
1043010115 use Config;
1043110116 print $Config{shortsize}, "\n";
1043210117 print $Config{intsize}, "\n";
1043310118 print $Config{longsize}, "\n";
1043410119 print $Config{longlongsize}, "\n";
1043510120
1043610121=begin original
1043710122
1043810123C<$Config{longlongsize}> is undefined on systems without
1043910124long long support.
1044010125
1044110126=end original
1044210127
1044310128システムが long long に対応していない場合は C<$Config{longlongsize}> は
1044410129未定義値になります。
1044510130
1044610131=item *
1044710132
1044810133=begin original
1044910134
1045010135The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are
1045110136inherently non-portable between processors and operating systems because
1045210137they obey native byteorder and endianness. For example, a 4-byte integer
10453101380x12345678 (305419896 decimal) would be ordered natively (arranged in and
1045410139handled by the CPU registers) into bytes as
1045510140
1045610141=end original
1045710142
1045810143整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は
1045910144ネイティブなバイト順序とエンディアンに従っているため、
1046010145本質的にプロセッサ間や OS 間で移植性がありません。
1046110146例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は
1046210147内部では(CPU レジスタによって変換され扱われる形では)
1046310148以下のようなバイト列に並べられます:
1046410149
1046510150 0x12 0x34 0x56 0x78 # big-endian
1046610151 0x78 0x56 0x34 0x12 # little-endian
1046710152
1046810153=begin original
1046910154
1047010155Basically, Intel and VAX CPUs are little-endian, while everybody else,
1047110156including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are
1047210157big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used)
1047310158them in little-endian mode, but SGI/Cray uses them in big-endian mode.
1047410159
1047510160=end original
1047610161
1047710162基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、
1047810163Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては
1047910164ビッグエンディアンです。
1048010165Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで
1048110166使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで
1048210167使っています。
1048310168
1048410169=begin original
1048510170
1048610171The names I<big-endian> and I<little-endian> are comic references to the
1048710172egg-eating habits of the little-endian Lilliputians and the big-endian
1048810173Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>.
1048910174This entered computer lingo via the paper "On Holy Wars and a Plea for
1049010175Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980.
1049110176
1049210177=end original
1049310178
10494I<ビッグエンディアン> と I<リトルエンディアン> の名前は
10179I<ビッグエンディアン> と I<リトルエンディアン> の名前は
10495ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> で卵を
10180古典である「ガリバー旅行記」とリリパット族の卵を食べる習慣から
10496小さい方からむくリリパット国と大きい方からむくブレフスキュ国から
1049710181取られています。
1049810182"On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137,
1049910183April 1, 1980 の文書からコンピュータ用語として取り入れられました。
1050010184
1050110185=begin original
1050210186
1050310187Some systems may have even weirder byte orders such as
1050410188
1050510189=end original
1050610190
1050710191以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません:
1050810192
1050910193 0x56 0x78 0x12 0x34
1051010194 0x34 0x12 0x78 0x56
1051110195
1051210196=begin original
1051310197
1051410198You can determine your system endianness with this incantation:
1051510199
1051610200=end original
1051710201
1051810202システムの設定は以下のようにして調べられます:
1051910203
1052010204 printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
1052110205
1052210206=begin original
1052310207
1052410208The byteorder on the platform where Perl was built is also available
1052510209via L<Config>:
1052610210
1052710211=end original
1052810212
1052910213Perl がビルドされたプラットフォームでのバイト順序は
1053010214L<Config> 経由か:
1053110215
1053210216 use Config;
1053310217 print "$Config{byteorder}\n";
1053410218
1053510219=begin original
1053610220
1053710221or from the command line:
1053810222
1053910223=end original
1054010224
1054110225あるいはコマンドラインで:
1054210226
1054310227 $ perl -V:byteorder
1054410228
1054510229=begin original
1054610230
1054710231Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321">
1054810232and C<"87654321"> are big-endian.
1054910233
1055010234=end original
1055110235
1055210236C<"1234"> と C<"12345678"> はリトルエンディアンです;
1055310237C<"4321"> と C<"87654321"> はビッグエンディアンです。
1055410238
1055510239=begin original
1055610240
1055710241For portably packed integers, either use the formats C<n>, C<N>, C<v>,
1055810242and C<V> or else use the C<< > >> and C<< < >> modifiers described
1055910243immediately below. See also L<perlport>.
1056010244
1056110245=end original
1056210246
1056310247移植性のあるパック化された整数がほしい場合は、
1056410248C<n>, C<N>, C<v>, C<V> フォーマットを使うか、
1056510249直後で説明する C<< > >> と C<< < >> の修飾子が使えます。
1056610250L<perlport> も参照してください。
1056710251
1056810252=item *
1056910253
1057010254=begin original
1057110255
10572Starting with Perl 5.10.0, integer and floating-point formats, along with
10256Starting with Perl 5.9.2, integer and floating-point formats, along with
1057310257the C<p> and C<P> formats and C<()> groups, may all be followed by the
1057410258C<< > >> or C<< < >> endianness modifiers to respectively enforce big-
1057510259or little-endian byte-order. These modifiers are especially useful
1057610260given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers,
105771026164-bit integers, or floating-point values.
1057810262
1057910263=end original
1058010264
10581Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、
10265Perl 5.9.2 から、C<p> と C<P> フォーマットや C<()> グループと同様、
1058210266全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の
1058310267エンディアン修飾子をつけることで、それぞれ
1058410268ビッグエンディアンとリトルエンディアンに強制させることができます。
1058510269C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に
1058610270対応していないので、これは特に有用です。
1058710271
1058810272=begin original
1058910273
1059010274Here are some concerns to keep in mind when using an endianness modifier:
1059110275
1059210276=end original
1059310277
1059410278エンディアン修飾子を使うときに心に留めておくべきことを記します:
1059510279
1059610280=over
1059710281
1059810282=item *
1059910283
1060010284=begin original
1060110285
1060210286Exchanging signed integers between different platforms works only
1060310287when all platforms store them in the same format. Most platforms store
1060410288signed integers in two's-complement notation, so usually this is not an issue.
1060510289
1060610290=end original
1060710291
1060810292異なったプラットフォームで符号付き整数を交換することは、全ての
1060910293プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。
1061010294ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、
1061110295普通はこれは問題になりません。
1061210296
1061310297=item *
1061410298
1061510299=begin original
1061610300
1061710301The C<< > >> or C<< < >> modifiers can only be used on floating-point
1061810302formats on big- or little-endian machines. Otherwise, attempting to
1061910303use them raises an exception.
1062010304
1062110305=end original
1062210306
1062310307C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの
1062410308マシンでの浮動小数点フォーマットでのみ使えます。
1062510309それ以外では、そのようなことをすると例外が発生します。
1062610310
1062710311=item *
1062810312
1062910313=begin original
1063010314
1063110315Forcing big- or little-endian byte-order on floating-point values for
1063210316data exchange can work only if all platforms use the same
1063310317binary representation such as IEEE floating-point. Even if all
1063410318platforms are using IEEE, there may still be subtle differences. Being able
1063510319to use C<< > >> or C<< < >> on floating-point values can be useful,
1063610320but also dangerous if you don't know exactly what you're doing.
1063710321It is not a general way to portably store floating-point values.
1063810322
1063910323=end original
1064010324
1064110325データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル
1064210326エンディアンに強制することは、全てのプラットフォームが
1064310327IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ
1064410328うまくいきます。
1064510329たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが
1064610330あるかもしれません。
10647浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、
10331浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合が
10648もし自分が何をしているかを正確に理解していなければ、危険です。
10332ありますが、もし自分が何をしているかを正確に理解していなければ、
10333危険です。
1064910334移植性のある浮動小数点数の保存のための一般的な方法はありません。
1065010335
1065110336=item *
1065210337
1065310338=begin original
1065410339
1065510340When using C<< > >> or C<< < >> on a C<()> group, this affects
1065610341all types inside the group that accept byte-order modifiers,
1065710342including all subgroups. It is silently ignored for all other
1065810343types. You are not allowed to override the byte-order within a group
1065910344that already has a byte-order modifier suffix.
1066010345
1066110346=end original
1066210347
1066310348C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを
1066410349含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。
1066510350その他の型については沈黙のうちに無視されます。
1066610351既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは
1066710352できません。
1066810353
1066910354=back
1067010355
1067110356=item *
1067210357
1067310358=begin original
1067410359
1067510360Real numbers (floats and doubles) are in native machine format only.
1067610361Due to the multiplicity of floating-point formats and the lack of a
1067710362standard "network" representation for them, no facility for interchange has been
1067810363made. This means that packed floating-point data written on one machine
1067910364may not be readable on another, even if both use IEEE floating-point
1068010365arithmetic (because the endianness of the memory representation is not part
1068110366of the IEEE spec). See also L<perlport>.
1068210367
1068310368=end original
1068410369
1068510370実数 (float と double) は、機種依存のフォーマットしかありません。
10686いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが
10371いろんな浮動小数点数のフォーマットが在り、標準的な
10687ないため、データ交換のための機能は用意してありません。
10372"network" 表現といったものがないため、データ交換のための機能は
10373用意してありません。
1068810374つまり、あるマシンで pack した浮動小数点数は、別のマシンでは
1068910375読めないかもしれないということです; たとえ双方で IEEE フォーマットの
1069010376浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の
1069110377バイト順序までは、規定されていないからです)。
1069210378L<perlport> も参照してください。
1069310379
1069410380=begin original
1069510381
1069610382If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >>
1069710383modifiers to force big- or little-endian byte-order on floating-point values.
1069810384
1069910385=end original
1070010386
1070110387もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の
1070210388バイト順をビッグエンディアンやリトルエンディアンに強制するために、
1070310389C<< > >> と C<< < >> の修飾子が使えます。
1070410390
1070510391=begin original
1070610392
1070710393Because Perl uses doubles (or long doubles, if configured) internally for
1070810394all numeric calculation, converting from double into float and thence
1070910395to double again loses precision, so C<unpack("f", pack("f", $foo)>)
1071010396will not in general equal $foo.
1071110397
1071210398=end original
1071310399
10714Perl では、すべての数値演算のために、内部的に double (または設定によっては
10400Perl では、すべての数値演算のために、内部的に double (または
10715long double) を使用しているので、double から float へ変換し、それから再び
10401設定によっては long double) を使用しているので、
10716double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>)
10402double から float へ変換しそれから再び double に戻すと
10403精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、
1071710404一般には $foo と同じではありません。
1071810405
1071910406=item *
1072010407
1072110408=begin original
1072210409
1072310410Pack and unpack can operate in two modes: character mode (C<C0> mode) where
1072410411the packed string is processed per character, and UTF-8 mode (C<U0> mode)
1072510412where the packed string is processed in its UTF-8-encoded Unicode form on
1072610413a byte-by-byte basis. Character mode is the default
1072710414unless the format string starts with C<U>. You
1072810415can always switch mode mid-format with an explicit
1072910416C<C0> or C<U0> in the format. This mode remains in effect until the next
1073010417mode change, or until the end of the C<()> group it (directly) applies to.
1073110418
1073210419=end original
1073310420
1073410421pack と unpack は二つのモードで操作します: pack された文字列を文字単位で
1073510422処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、
1073610423その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。
1073710424文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。
1073810425モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも
1073910426切り替えられます。
1074010427モードは次のモードに切り替えられるか、(直接)適用された () グループが
1074110428終了するまで有効です。
1074210429
1074310430=begin original
1074410431
1074510432Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode
1074610433bytes is not necessarily obvious. Probably only the first of these
1074710434is what you want:
1074810435
1074910436=end original
1075010437
1075110438Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに
1075210439C<U0> を使うというのは必ずしも明白ではありません。
1075310440おそらく、これらのうち最初のものだけが望みのものでしょう:
1075410441
1075510442 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1075610443 perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)'
1075710444 03B1.03C9
1075810445 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1075910446 perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
1076010447 CE.B1.CF.89
1076110448 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1076210449 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)'
1076310450 CE.B1.CF.89
1076410451 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1076510452 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
1076610453 C3.8E.C2.B1.C3.8F.C2.89
1076710454
1076810455=begin original
1076910456
1077010457Those examples also illustrate that you should not try to use
1077110458C<pack>/C<unpack> as a substitute for the L<Encode> module.
1077210459
1077310460=end original
1077410461
1077510462これらの例は、C<pack>/C<unpack> を L<Encode> モジュールの代わりとして
1077610463使おうとするべきではないということも示しています。
1077710464
1077810465=item *
1077910466
1078010467=begin original
1078110468
1078210469You must yourself do any alignment or padding by inserting, for example,
1078310470enough C<"x">es while packing. There is no way for pack() and unpack()
1078410471to know where characters are going to or coming from, so they
1078510472handle their output and input as flat sequences of characters.
1078610473
1078710474=end original
1078810475
1078910476pack するときに、例えば十分な数の C<"x"> を挿入することによって
1079010477アライメントやパッディングを行うのは全て自分でしなければなりません。
1079110478文字列がどこへ行くかやどこから来たかを pack() や unpack() が
1079210479知る方法はないので、C<pack> (と C<unpack>) は出力と入力をフラットな
1079310480文字列として扱います。
1079410481
1079510482=item *
1079610483
1079710484=begin original
1079810485
1079910486A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may
1080010487take a repeat count either as postfix, or for unpack(), also via the C</>
1080110488template character. Within each repetition of a group, positioning with
1080210489C<@> starts over at 0. Therefore, the result of
1080310490
1080410491=end original
1080510492
1080610493C<()> のグループはかっこで囲われた副テンプレートです。
1080710494グループは繰り返し数を取ることができます; 接尾辞によるか、unpack() の場合は
1080810495C</> テンプレート文字によります。
1080910496グループの繰り返し毎に、C<@> の位置は 0 になります。
1081010497従って、以下の結果は:
1081110498
1081210499 pack("@1A((@2A)@3A)", qw[X Y Z])
1081310500
1081410501=begin original
1081510502
1081610503is the string C<"\0X\0\0YZ">.
1081710504
1081810505=end original
1081910506
1082010507文字列 C<"\0X\0\0YZ"> です。
1082110508
1082210509=item *
1082310510
1082410511=begin original
1082510512
1082610513C<x> and C<X> accept the C<!> modifier to act as alignment commands: they
1082710514jump forward or back to the closest position aligned at a multiple of C<count>
1082810515characters. For example, to pack() or unpack() a C structure like
1082910516
1083010517=end original
1083110518
1083210519C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます:
1083310520これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。
1083410521例えば、以下のような構造体を pack() または unpack() するためには
1083510522
1083610523 struct {
1083710524 char c; /* one signed, 8-bit character */
1083810525 double d;
1083910526 char cc[2];
1084010527 }
1084110528
1084210529=begin original
1084310530
1084410531one may need to use the template C<c x![d] d c[2]>. This assumes that
1084510532doubles must be aligned to the size of double.
1084610533
1084710534=end original
1084810535
1084910536C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。
1085010537これは double が double のサイズでアライメントされていることを
1085110538仮定しています。
1085210539
1085310540=begin original
1085410541
1085510542For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1;
1085610543both are no-ops.
1085710544
1085810545=end original
1085910546
1086010547アライメントコマンドに対しては、C<count> に 0 を指定するのは 1 を
1086110548指定するのと等価です; どちらも何もしません。
1086210549
1086310550=item *
1086410551
1086510552=begin original
1086610553
1086710554C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to
1086810555represent signed 16-/32-bit integers in big-/little-endian order.
1086910556This is portable only when all platforms sharing packed data use the
1087010557same binary representation for signed integers; for example, when all
1087110558platforms use two's-complement representation.
1087210559
1087310560=end original
1087410561
10875C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または
10562C<n>, C<N>, C<v>, C<V> は
10563ビッグ/リトルエンディアンの順序で符号付き 16 または
108761056432 ビット整数で表現するための C<!> 修飾子を受け入れます。
1087710565これは pack されたデータを共有する全てのプラットフォームが
1087810566符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります;
1087910567例えば、全てのプラットフォームで 2 の補数表現を使う場合です。
1088010568
1088110569=item *
1088210570
1088310571=begin original
1088410572
1088510573Comments can be embedded in a TEMPLATE using C<#> through the end of line.
1088610574White space can separate pack codes from each other, but modifiers and
1088710575repeat counts must follow immediately. Breaking complex templates into
1088810576individual line-by-line components, suitably annotated, can do as much to
1088910577improve legibility and maintainability of pack/unpack formats as C</x> can
1089010578for complicated pattern matches.
1089110579
1089210580=end original
1089310581
1089410582TEMPLATE の中の C<#> から行末まではコメントです。
1089510583空白は pack コードをそれぞれ分けるために使えますが、修飾子と
1089610584繰り返し数は直後に置かなければなりません。
1089710585複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、
1089810586複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack
1089910587フォーマットの読みやすさと保守性が向上します。
1090010588
1090110589=item *
1090210590
1090310591=begin original
1090410592
1090510593If TEMPLATE requires more arguments than pack() is given, pack()
1090610594assumes additional C<""> arguments. If TEMPLATE requires fewer arguments
1090710595than given, extra arguments are ignored.
1090810596
1090910597=end original
1091010598
1091110599TEMPLATE が要求する引数の数が pack() が実際に与えている数より多い場合、
1091210600pack() は追加の C<""> 引数があるものと仮定します。
1091310601TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。
1091410602
1091510603=back
1091610604
1091710605=begin original
1091810606
1091910607Examples:
1092010608
1092110609=end original
1092210610
1092310611例:
1092410612
1092510613 $foo = pack("WWWW",65,66,67,68);
1092610614 # foo eq "ABCD"
1092710615 $foo = pack("W4",65,66,67,68);
1092810616 # same thing
1092910617 $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9);
1093010618 # same thing with Unicode circled letters.
1093110619 $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9);
1093210620 # same thing with Unicode circled letters. You don't get the
1093310621 # UTF-8 bytes because the U at the start of the format caused
1093410622 # a switch to U0-mode, so the UTF-8 bytes get joined into
1093510623 # characters
1093610624 $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9);
1093710625 # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9"
1093810626 # This is the UTF-8 encoding of the string in the
1093910627 # previous example
1094010628
1094110629 $foo = pack("ccxxcc",65,66,67,68);
1094210630 # foo eq "AB\0\0CD"
1094310631
1094410632 # NOTE: The examples above featuring "W" and "c" are true
1094510633 # only on ASCII and ASCII-derived systems such as ISO Latin 1
1094610634 # and UTF-8. On EBCDIC systems, the first example would be
1094710635 # $foo = pack("WWWW",193,194,195,196);
1094810636
1094910637 $foo = pack("s2",1,2);
1095010638 # "\001\000\002\000" on little-endian
1095110639 # "\000\001\000\002" on big-endian
1095210640
1095310641 $foo = pack("a4","abcd","x","y","z");
1095410642 # "abcd"
1095510643
1095610644 $foo = pack("aaaa","abcd","x","y","z");
1095710645 # "axyz"
1095810646
1095910647 $foo = pack("a14","abcdefg");
1096010648 # "abcdefg\0\0\0\0\0\0\0"
1096110649
1096210650 $foo = pack("i9pl", gmtime);
1096310651 # a real struct tm (on my system anyway)
1096410652
1096510653 $utmp_template = "Z8 Z8 Z16 L";
1096610654 $utmp = pack($utmp_template, @utmp1);
1096710655 # a struct utmp (BSDish)
1096810656
1096910657 @utmp2 = unpack($utmp_template, $utmp);
1097010658 # "@utmp1" eq "@utmp2"
1097110659
1097210660 sub bintodec {
1097310661 unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
1097410662 }
1097510663
1097610664 $foo = pack('sx2l', 12, 34);
1097710665 # short 12, two zero bytes padding, long 34
1097810666 $bar = pack('s@4l', 12, 34);
1097910667 # short 12, zero fill to position 4, long 34
1098010668 # $foo eq $bar
1098110669 $baz = pack('s.l', 12, 4, 34);
1098210670 # short 12, zero fill to position 4, long 34
1098310671
1098410672 $foo = pack('nN', 42, 4711);
1098510673 # pack big-endian 16- and 32-bit unsigned integers
1098610674 $foo = pack('S>L>', 42, 4711);
1098710675 # exactly the same
1098810676 $foo = pack('s<l<', -42, 4711);
1098910677 # pack little-endian 16- and 32-bit signed integers
1099010678 $foo = pack('(sl)<', -42, 4711);
1099110679 # exactly the same
1099210680
1099310681=begin original
1099410682
1099510683The same template may generally also be used in unpack().
1099610684
1099710685=end original
1099810686
1099910687一般には、pack で使用したものと同じテンプレートが、
1100010688unpack() 関数でも使用できます。
1100110689
1100210690=item package NAMESPACE
1100310691
1100410692=item package NAMESPACE VERSION
1100510693X<package> X<module> X<namespace> X<version>
1100610694
1100710695=item package NAMESPACE BLOCK
1100810696
1100910697=item package NAMESPACE VERSION BLOCK
1101010698X<package> X<module> X<namespace> X<version>
1101110699
1101210700=for Pod::Functions declare a separate global namespace
1101310701
1101410702=begin original
1101510703
1101610704Declares the BLOCK or the rest of the compilation unit as being in the
1101710705given namespace. The scope of the package declaration is either the
1101810706supplied code BLOCK or, in the absence of a BLOCK, from the declaration
1101910707itself through the end of current scope (the enclosing block, file, or
1102010708C<eval>). That is, the forms without a BLOCK are operative through the end
1102110709of the current scope, just like the C<my>, C<state>, and C<our> operators.
1102210710All unqualified dynamic identifiers in this scope will be in the given
1102310711namespace, except where overridden by another C<package> declaration or
1102410712when they're one of the special identifiers that qualify into C<main::>,
1102510713like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables.
1102610714
1102710715=end original
1102810716
1102910717BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。
1103010718パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から
1103110719現在のスコープの末尾 (閉じたブロック、ファイル、C<eval>) です。
1103210720つまり、BLOCK なしの形式は、C<my>, C<state>, C<our> 演算子と同様に
1103310721現在のスコープの末尾にまで作用します。
1103410722このスコープ内の、全ての完全修飾されていない動的識別子は、他の
1103510723C<package> 宣言によって上書きされるか、
1103610724C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に
1103710725割り当てられる特殊変数でない限り、指定された
1103810726名前空間になります。
1103910727
1104010728=begin original
1104110729
1104210730A package statement affects dynamic variables only, including those
11043you've used C<local> on, but I<not> lexically-scoped variables, which are created
10731you've used C<local> on, but I<not> lexical variables, which are created
1104410732with C<my>, C<state>, or C<our>. Typically it would be the first
1104510733declaration in a file included by C<require> or C<use>. You can switch into a
1104610734package in more than one place, since this only determines which default
1104710735symbol table the compiler uses for the rest of that block. You can refer to
1104810736identifiers in other packages than the current one by prefixing the identifier
1104910737with the package name and a double colon, as in C<$SomePack::var>
1105010738or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main>
1105110739package as assumed. That is, C<$::sail> is equivalent to
1105210740C<$main::sail> (as well as to C<$main'sail>, still seen in ancient
1105310741code, mostly from Perl 4).
1105410742
1105510743=end original
1105610744
1105710745package 文は動的変数にのみ影響します(C<local> で使ったものも
1105810746含みます)が、C<my>, C<state>, C<our> のいずれかで作成された
11059レキシカルなスコープの変数には I<影響しません>。
10747レキシカル変数には I<影響しません>。
1106010748典型的にはこれは C<require> や C<use> 演算子でインクルードされるファイルの
1106110749最初に宣言されます。
1106210750パッケージを複数の場所で切り替えることができます;
1106310751なぜならこれは単にコンパイラがこのブロックの残りに対してどの
1106410752シンボルテーブルを使うかにのみ影響するからです。
1106510753他のパッケージの識別子は、C<$SomePack::var> や
1106610754C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と
1106710755コロン二つをつけることで参照できます。
1106810756パッケージ名が省略された場合、C<main> パッケージが仮定されます。
1106910757つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、
1107010758古いコードでは C<$main'sail> もまだ見られます)。
1107110759
1107210760=begin original
1107310761
1107410762If VERSION is provided, C<package> sets the C<$VERSION> variable in the given
1107510763namespace to a L<version> object with the VERSION provided. VERSION must be a
1107610764"strict" style version number as defined by the L<version> module: a positive
1107710765decimal number (integer or decimal-fraction) without exponentiation or else a
1107810766dotted-decimal v-string with a leading 'v' character and at least three
1107910767components. You should set C<$VERSION> only once per package.
1108010768
1108110769=end original
1108210770
1108310771VERSION が指定されると、C<package> は与えられた名前空間の C<$VERSION> 変数に、
1108410772指定された VERSION の L<version> オブジェクトをセットします。
1108510773VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で
1108610774なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、
1108710775さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から
1108810776構成されるドット付き 10 進v-文字列です。
1108910777C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。
1109010778
1109110779=begin original
1109210780
1109310781See L<perlmod/"Packages"> for more information about packages, modules,
1109410782and classes. See L<perlsub> for other scoping issues.
1109510783
1109610784=end original
1109710785
1109810786パッケージ、モジュール、クラスに関するさらなる情報については
1109910787L<perlmod/"Packages"> を参照してください。
1110010788その他のスコープに関する話題については L<perlsub> を参照してください。
1110110789
1110210790=item __PACKAGE__
1110310791X<__PACKAGE__>
1110410792
1110510793=for Pod::Functions +5.004 the current package
1110610794
1110710795=begin original
1110810796
1110910797A special token that returns the name of the package in which it occurs.
1111010798
1111110799=end original
1111210800
1111310801これが書いてあるパッケージの名前を返す特殊トークン。
1111410802
1111510803=item pipe READHANDLE,WRITEHANDLE
1111610804X<pipe>
1111710805
1111810806=for Pod::Functions open a pair of connected filehandles
1111910807
1112010808=begin original
1112110809
1112210810Opens a pair of connected pipes like the corresponding system call.
1112310811Note that if you set up a loop of piped processes, deadlock can occur
1112410812unless you are very careful. In addition, note that Perl's pipes use
1112510813IO buffering, so you may need to set C<$|> to flush your WRITEHANDLE
1112610814after each command, depending on the application.
1112710815
1112810816=end original
1112910817
11130対応するシステムコールと同じように、接続されたパイプのペアを開きます。
10818対応するシステムコールと同じように、
10819接続されたパイプのペアをオープンします。
1113110820パイプでプロセスをループにするときには、よほど気を付けないと、
1113210821デッドロックが起こり得ます。
11133さらに、Perl のパイプでは、IO のバッファリングを使ので
10822さらに、Perl のパイプでは、IO のバッファリングを使いますから
1113410823アプリケーションによっては、コマンドごとに WRITEHANDLE を
1113510824フラッシュするように、C<$|> を設定することが必要になるかもしれません。
1113610825
1113710826=begin original
1113810827
11139Returns true on success.
11140
11141=end original
11142
11143成功時には真を返します。
11144
11145=begin original
11146
1114710828See L<IPC::Open2>, L<IPC::Open3>, and
1114810829L<perlipc/"Bidirectional Communication with Another Process">
1114910830for examples of such things.
1115010831
1115110832=end original
1115210833
1115310834これらに関する例については、L<IPC::Open2>, L<IPC::Open3>,
1115410835L<perlipc/"Bidirectional Communication with Another Process"> を
1115510836参照してください。
1115610837
1115710838=begin original
1115810839
1115910840On systems that support a close-on-exec flag on files, that flag is set
1116010841on all newly opened file descriptors whose C<fileno>s are I<higher> than
1116110842the current value of $^F (by default 2 for C<STDERR>). See L<perlvar/$^F>.
1116210843
1116310844=end original
1116410845
1116510846ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1116610847新しくオープンされたファイル記述子のうち、
1116710848C<fileno> が現在の $^F の値(デフォルトでは C<STDERR> の 2)
1116810849I<よりも大きい> ものに対してフラグがセットされます。
1116910850L<perlvar/$^F> を参照してください。
1117010851
1117110852=item pop ARRAY
1117210853X<pop> X<stack>
1117310854
1117410855=item pop EXPR
1117510856
1117610857=item pop
1117710858
1117810859=for Pod::Functions remove the last element from an array and return it
1117910860
1118010861=begin original
1118110862
1118210863Pops and returns the last value of the array, shortening the array by
1118310864one element.
1118410865
1118510866=end original
1118610867
1118710868配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。
1118810869
1118910870=begin original
1119010871
1119110872Returns the undefined value if the array is empty, although this may also
1119210873happen at other times. If ARRAY is omitted, pops the C<@ARGV> array in the
1119310874main program, but the C<@_> array in subroutines, just like C<shift>.
1119410875
1119510876=end original
1119610877
1119710878指定された配列に要素がなければ未定義値が返されますが、
1119810879しかしこれは他の場合にも起こり得ます。
1119910880ARRAY が省略されると、C<shift> と同様に、メインプログラムでは C<@ARGV> が
1120010881使われますが、サブルーチンでは C<@_> が使われます。
1120110882
1120210883=begin original
1120310884
1120410885Starting with Perl 5.14, C<pop> can take a scalar EXPR, which must hold a
1120510886reference to an unblessed array. The argument will be dereferenced
1120610887automatically. This aspect of C<pop> is considered highly experimental.
1120710888The exact behaviour may change in a future version of Perl.
1120810889
1120910890=end original
1121010891
1121110892Perl 5.14 から、C<pop> はスカラの EXPR を取ることができるようになりました;
1121210893これは bless されていない配列へのリファレンスでなければなりません。
1121310894引数は自動的にデリファレンスされます。
1121410895C<pop> のこの動作は高度に実験的であると考えられています。
1121510896正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1121610897
1121710898=begin original
1121810899
1121910900To avoid confusing would-be users of your code who are running earlier
1122010901versions of Perl with mysterious syntax errors, put this sort of thing at
1122110902the top of your file to signal that your code will work I<only> on Perls of
1122210903a recent vintage:
1122310904
1122410905=end original
1122510906
1122610907あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1122710908文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
1122810909I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1122910910書いてください:
1123010911
1123110912 use 5.014; # so push/pop/etc work on scalars (experimental)
1123210913
1123310914=item pos SCALAR
1123410915X<pos> X<match, position>
1123510916
1123610917=item pos
1123710918
1123810919=for Pod::Functions find or set the offset for the last/next m//g search
1123910920
1124010921=begin original
1124110922
1124210923Returns the offset of where the last C<m//g> search left off for the
1124310924variable in question (C<$_> is used when the variable is not
1124410925specified). Note that 0 is a valid match offset. C<undef> indicates
1124510926that the search position is reset (usually due to match failure, but
1124610927can also be because no match has yet been run on the scalar).
1124710928
1124810929=end original
1124910930
1125010931対象の変数に対して、前回の C<m//g> が終了した場所の
1125110932オフセットを返します(変数が指定されなかった場合は C<$_> が使われます)。
11252109330 は有効なマッチオフセットであることに注意してください。
1125310934C<undef> は検索位置がリセットされることを意味します (通常はマッチ失敗が
1125410935原因ですが、このスカラ値にまだマッチングが行われていないためかもしれません)。
1125510936
1125610937=begin original
1125710938
1125810939C<pos> directly accesses the location used by the regexp engine to
1125910940store the offset, so assigning to C<pos> will change that offset, and
1126010941so will also influence the C<\G> zero-width assertion in regular
1126110942expressions. Both of these effects take place for the next match, so
1126210943you can't affect the position with C<pos> during the current match,
1126310944such as in C<(?{pos() = 5})> or C<s//pos() = 5/e>.
1126410945
1126510946=end original
1126610947
1126710948C<pos> は正規表現エンジンがオフセットを保存するために使う場所を直接
1126810949アクセスするので、C<pos> への代入はオフセットを変更し、そのような変更は
1126910950正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
1127010951これらの効果の両方は次のマッチングのために行われるので、
1127110952C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の
1127210953C<pos> の位置には影響を与えません。
1127310954
1127410955=begin original
1127510956
1127610957Setting C<pos> also resets the I<matched with zero-length> flag, described
1127710958under L<perlre/"Repeated Patterns Matching a Zero-length Substring">.
1127810959
1127910960=end original
1128010961
1128110962C<pos> を設定すると、
1128210963L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に
1128310964記述されている、I<長さ 0 でマッチング> フラグもリセットされます。
1128410965
1128510966=begin original
1128610967
1128710968Because a failed C<m//gc> match doesn't reset the offset, the return
1128810969from C<pos> won't change either in this case. See L<perlre> and
1128910970L<perlop>.
1129010971
1129110972=end original
1129210973
1129310974C<m//gc> マッチに失敗してもオフセットはリセットしないので、
1129410975C<pos> からの返り値はどちらの場合も変更されません。
1129510976L<perlre> と L<perlop> を参照してください。
1129610977
1129710978=item print FILEHANDLE LIST
1129810979X<print>
1129910980
1130010981=item print FILEHANDLE
1130110982
1130210983=item print LIST
1130310984
1130410985=item print
1130510986
1130610987=for Pod::Functions output a list to a filehandle
1130710988
1130810989=begin original
1130910990
1131010991Prints a string or a list of strings. Returns true if successful.
1131110992FILEHANDLE may be a scalar variable containing the name of or a reference
1131210993to the filehandle, thus introducing one level of indirection. (NOTE: If
1131310994FILEHANDLE is a variable and the next token is a term, it may be
1131410995misinterpreted as an operator unless you interpose a C<+> or put
1131510996parentheses around the arguments.) If FILEHANDLE is omitted, prints to the
1131610997last selected (see L</select>) output handle. If LIST is omitted, prints
1131710998C<$_> to the currently selected output handle. To use FILEHANDLE alone to
1131810999print the content of C<$_> to it, you must use a real filehandle like
1131911000C<FH>, not an indirect one like C<$fh>. To set the default output handle
1132011001to something other than STDOUT, use the select operation.
1132111002
1132211003=end original
1132311004
1132411005文字列か文字列のリストを出力します。
1132511006成功時には真を返します。
1132611007FILEHANDLE は、ファイルハンドル名またはそのリファレンスが
1132711008入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。
1132811009(注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、
1132911010間に C<+> を置くか、引数の前後を括弧で括らなければ、
1133011011誤って解釈されることがあります。)
1133111012FILEHANDLE を省略した場合には、最後に選択された (L</select> 参照) 出力
1133211013チャネルに出力します。
1133311014LIST を省略すると、C<$_> が現在選択されている出力ハンドルに出力されます。
1133411015C<$_> の内容を表示するために FILEHANDLE のみを使用するには、
1133511016C<$fh> のような間接ファイルハンドルではなく、C<FH> のような実際の
1133611017ファイルハンドルを使わなければなりません。
1133711018デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を
1133811019使ってください。
1133911020
1134011021=begin original
1134111022
1134211023The current value of C<$,> (if any) is printed between each LIST item. The
1134311024current value of C<$\> (if any) is printed after the entire LIST has been
1134411025printed. Because print takes a LIST, anything in the LIST is evaluated in
1134511026list context, including any subroutines whose return lists you pass to
1134611027C<print>. Be careful not to follow the print keyword with a left
1134711028parenthesis unless you want the corresponding right parenthesis to
1134811029terminate the arguments to the print; put parentheses around all arguments
1134911030(or interpose a C<+>, but that doesn't look as good).
1135011031
1135111032=end original
1135211033
1135311034C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
1135411035LIST 全体が出力された後、(もしあれば) C<$\> の現在の値が出力されます。
1135511036print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで
1135611037評価されます; C<print> に渡した、リストを返すサブルーチンも含みます。
1135711038また、すべての引数を括弧で括るのでなければ、print というキーワードの
1135811039次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください
1135911040(あるいは "print" と引数の間に C<+> を書きますが、これはあまり
1136011041よくありません)。
1136111042
1136211043=begin original
1136311044
1136411045If you're storing handles in an array or hash, or in general whenever
1136511046you're using any expression more complex than a bareword handle or a plain,
1136611047unsubscripted scalar variable to retrieve it, you will have to use a block
1136711048returning the filehandle value instead, in which case the LIST may not be
1136811049omitted:
1136911050
1137011051=end original
1137111052
1137211053もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや
1137311054普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す
1137411055ブロックを使う必要があります; この場合 LIST は省略できません:
1137511056
1137611057 print { $files[$i] } "stuff\n";
1137711058 print { $OK ? STDOUT : STDERR } "stuff\n";
1137811059
1137911060=begin original
1138011061
1138111062Printing to a closed pipe or socket will generate a SIGPIPE signal. See
1138211063L<perlipc> for more on signal handling.
1138311064
1138411065=end original
1138511066
1138611067閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。
1138711068さらなるシグナル操作については L<perlipc> を参照してください。
1138811069
1138911070=item printf FILEHANDLE FORMAT, LIST
1139011071X<printf>
1139111072
1139211073=item printf FILEHANDLE
1139311074
1139411075=item printf FORMAT, LIST
1139511076
1139611077=item printf
1139711078
1139811079=for Pod::Functions output a formatted list to a filehandle
1139911080
1140011081=begin original
1140111082
1140211083Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that C<$\>
11403(the output record separator) is not appended. The FORMAT and the
11084(the output record separator) is not appended. The first argument of the
11404LIST are actually parsed as a single list. The first argument
11085list will be interpreted as the C<printf> format. See
11405of the list will be interpreted as the C<printf> format. This
11406means that C<printf(@_)> will use C<$_[0]> as the format. See
1140711086L<sprintf|/sprintf FORMAT, LIST> for an
11408explanation of the format argument. If C<use locale> (including
11087explanation of the format argument. If you omit the LIST, C<$_> is used;
11088to use FILEHANDLE without a LIST, you must use a real filehandle like
11089C<FH>, not an indirect one like C<$fh>. If C<use locale> (including
1140911090C<use locale ':not_characters'>) is in effect and
1141011091POSIX::setlocale() has been called, the character used for the decimal
1141111092separator in formatted floating-point numbers is affected by the LC_NUMERIC
1141211093locale setting. See L<perllocale> and L<POSIX>.
1141311094
1141411095=end original
1141511096
1141611097C<$\>(出力レコードセパレータ)を追加しないことを除けば、
1141711098C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。
11418FORMAT と LIST は実際には単一のリストとしてパースされます。
1141911099リストの最初の要素は、C<printf> フォーマットと解釈されます。
11420これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うということです。
1142111100フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を
1142211101参照してください。
11102LIST を省略すると、C<$_> が使われます;
11103LIST なしで FILEHANDLE を使用するには、
11104C<$fh> のような間接ファイルハンドルではなく、C<FH> のような実際の
11105ファイルハンドルを使わなければなりません。
1142311106(C<use locale ':not_characters'> を含む) C<use locale> が効力をもっていて、
1142411107POSIX::setlocale() が呼び出されていれば、
1142511108小数点に使われる文字は LC_NUMERIC ロケール設定の影響を受けます。
1142611109L<perllocale> と L<POSIX> を参照してください。
1142711110
1142811111=begin original
1142911112
11430For historical reasons, if you omit the list, C<$_> is used as the format;
11431to use FILEHANDLE without a list, you must use a real filehandle like
11432C<FH>, not an indirect one like C<$fh>. However, this will rarely do what
11433you want; if $_ contains formatting codes, they will be replaced with the
11434empty string and a warning will be emitted if warnings are enabled. Just
11435use C<print> if you want to print the contents of $_.
11436
11437=end original
11438
11439歴史的な理由により、リストを省略すると、フォーマットとして C<$_> が使われます;
11440リストなしで FILEHANDLE を使用するには、C<$fh> のような
11441間接ファイルハンドルではなく、C<FH> のような実際の
11442ファイルハンドルを使わなければなりません。
11443しかし、これがあなたが求めていることをすることはまれです; $_ が
11444フォーマッティングコードの場合、空文字列に置き換えられ、警告が有効なら
11445警告が出力されます。
11446$_ の内容を表示したい場合は、単に C<print> を使ってください。
11447
11448=begin original
11449
1145011113Don't fall into the trap of using a C<printf> when a simple
1145111114C<print> would do. The C<print> is more efficient and less
1145211115error prone.
1145311116
1145411117=end original
1145511118
1145611119単純な C<print> を使うべきところで C<printf> を使ってしまう
1145711120罠にかからないようにしてください。
1145811121C<print> はより効率的で、間違いが起こりにくいです。
1145911122
1146011123=item prototype FUNCTION
1146111124X<prototype>
1146211125
1146311126=for Pod::Functions +5.002 get the prototype (if any) of a subroutine
1146411127
1146511128=begin original
1146611129
1146711130Returns the prototype of a function as a string (or C<undef> if the
1146811131function has no prototype). FUNCTION is a reference to, or the name of,
1146911132the function whose prototype you want to retrieve.
1147011133
1147111134=end original
1147211135
1147311136関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は
1147411137C<undef> を返します)。
1147511138FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。
1147611139
1147711140=begin original
1147811141
1147911142If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
11480name for a Perl builtin. If the builtin's arguments
11143name for a Perl builtin. If the builtin is not I<overridable> (such as
11481cannot be adequately expressed by a prototype
11144C<qw//>) or if its arguments cannot be adequately expressed by a prototype
1148211145(such as C<system>), prototype() returns C<undef>, because the builtin
1148311146does not really behave like a Perl function. Otherwise, the string
1148411147describing the equivalent prototype is returned.
1148511148
1148611149=end original
1148711150
1148811151FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として
1148911152扱われます。
11490このビルドインの引数が(C<system> のように)プロトタプとして適切に
11153このビルドインが(C<qw//> のように) I<オーバーラド可能> でない、
11491記述できない場合、prototype() は C<undef> を返します;
11154またはこの引数が(C<system> のように)プロトタイプとして適切に記述できない場合、
11155prototype() は C<undef> を返します;
1149211156なぜならビルドインは実際に Perl 関数のように振舞わないからです。
1149311157それ以外では、等価なプロトタイプを表現した文字列が返されます。
1149411158
1149511159=item push ARRAY,LIST
1149611160X<push> X<stack>
1149711161
1149811162=item push EXPR,LIST
1149911163
1150011164=for Pod::Functions append one or more elements to an array
1150111165
1150211166=begin original
1150311167
1150411168Treats ARRAY as a stack by appending the values of LIST to the end of
1150511169ARRAY. The length of ARRAY increases by the length of LIST. Has the same
1150611170effect as
1150711171
1150811172=end original
1150911173
1151011174ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。
1151111175ARRAY の大きさは、LIST の長さ分だけ大きくなります。
1151211176これは、
1151311177
1151411178 for $value (LIST) {
1151511179 $ARRAY[++$#ARRAY] = $value;
1151611180 }
1151711181
1151811182=begin original
1151911183
1152011184but is more efficient. Returns the number of elements in the array following
1152111185the completed C<push>.
1152211186
1152311187=end original
1152411188
1152511189とするのと同じ効果がありますが、より効率的です。
1152611190C<push> の処理終了後の配列の要素数を返します。
1152711191
1152811192=begin original
1152911193
1153011194Starting with Perl 5.14, C<push> can take a scalar EXPR, which must hold a
1153111195reference to an unblessed array. The argument will be dereferenced
1153211196automatically. This aspect of C<push> is considered highly experimental.
1153311197The exact behaviour may change in a future version of Perl.
1153411198
1153511199=end original
1153611200
1153711201Perl 5.14 から、C<push> はスカラの EXPR を取ることができるようになりました;
1153811202これは bless されていない配列へのリファレンスでなければなりません。
1153911203引数は自動的にデリファレンスされます。
1154011204C<push> のこの動作は高度に実験的であると考えられています。
1154111205正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1154211206
1154311207=begin original
1154411208
1154511209To avoid confusing would-be users of your code who are running earlier
1154611210versions of Perl with mysterious syntax errors, put this sort of thing at
1154711211the top of your file to signal that your code will work I<only> on Perls of
1154811212a recent vintage:
1154911213
1155011214=end original
1155111215
1155211216あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1155311217文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
1155411218I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1155511219書いてください:
1155611220
1155711221 use 5.014; # so push/pop/etc work on scalars (experimental)
1155811222
1155911223=item q/STRING/
1156011224
1156111225=for Pod::Functions singly quote a string
1156211226
1156311227=item qq/STRING/
1156411228
1156511229=for Pod::Functions doubly quote a string
1156611230
1156711231=item qw/STRING/
1156811232
1156911233=for Pod::Functions quote a list of words
1157011234
1157111235=item qx/STRING/
1157211236
1157311237=for Pod::Functions backquote quote a string
1157411238
1157511239=begin original
1157611240
1157711241Generalized quotes. See L<perlop/"Quote-Like Operators">.
1157811242
1157911243=end original
1158011244
1158111245汎用のクォートです。
1158211246L<perlop/"Quote-Like Operators"> を参照してください。
1158311247
1158411248=item qr/STRING/
1158511249
1158611250=for Pod::Functions +5.005 compile pattern
1158711251
1158811252=begin original
1158911253
1159011254Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">.
1159111255
1159211256=end original
1159311257
1159411258正規表現風のクォートです。
1159511259L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1159611260
1159711261=item quotemeta EXPR
1159811262X<quotemeta> X<metacharacter>
1159911263
1160011264=item quotemeta
1160111265
1160211266=for Pod::Functions quote regular expression magic characters
1160311267
1160411268=begin original
1160511269
1160611270Returns the value of EXPR with all the ASCII non-"word"
1160711271characters backslashed. (That is, all ASCII characters not matching
1160811272C</[A-Za-z_0-9]/> will be preceded by a backslash in the
1160911273returned string, regardless of any locale settings.)
1161011274This is the internal function implementing
1161111275the C<\Q> escape in double-quoted strings.
1161211276(See below for the behavior on non-ASCII code points.)
1161311277
1161411278=end original
1161511279
1161611280EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで
1161711281エスケープしたものを返します。
1161811282(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には
1161911283ロケールに関わらずバックスラッシュが前置されます。)
1162011284これは、ダブルクォート文字列での C<\Q> エスケープを実装するための
1162111285内部関数です。
1162211286(非 ASCII 符号位置での振る舞いについては以下を参照してください。)
1162311287
1162411288=begin original
1162511289
1162611290If EXPR is omitted, uses C<$_>.
1162711291
1162811292=end original
1162911293
1163011294EXPR が省略されると、C<$_> を使います。
1163111295
1163211296=begin original
1163311297
1163411298quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into
1163511299regular expressions, because by default an interpolated variable will be
1163611300considered a mini-regular expression. For example:
1163711301
1163811302=end original
1163911303
1164011304クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに
1164111305便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として
1164211306扱われるからです。
1164311307例えば:
1164411308
1164511309 my $sentence = 'The quick brown fox jumped over the lazy dog';
1164611310 my $substring = 'quick.*?fox';
1164711311 $sentence =~ s{$substring}{big bad wolf};
1164811312
1164911313=begin original
1165011314
1165111315Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>.
1165211316
1165311317=end original
1165411318
1165511319とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。
1165611320
1165711321=begin original
1165811322
1165911323On the other hand:
1166011324
1166111325=end original
1166211326
1166311327一方:
1166411328
1166511329 my $sentence = 'The quick brown fox jumped over the lazy dog';
1166611330 my $substring = 'quick.*?fox';
1166711331 $sentence =~ s{\Q$substring\E}{big bad wolf};
1166811332
1166911333=begin original
1167011334
1167111335Or:
1167211336
1167311337=end original
1167411338
1167511339あるいは:
1167611340
1167711341 my $sentence = 'The quick brown fox jumped over the lazy dog';
1167811342 my $substring = 'quick.*?fox';
1167911343 my $quoted_substring = quotemeta($substring);
1168011344 $sentence =~ s{$quoted_substring}{big bad wolf};
1168111345
1168211346=begin original
1168311347
1168411348Will both leave the sentence as is.
1168511349Normally, when accepting literal string
1168611350input from the user, quotemeta() or C<\Q> must be used.
1168711351
1168811352=end original
1168911353
1169011354とすると、両方ともそのままです。
1169111355普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、
1169211356必ず quotemeta() か C<\Q> を使わなければなりません。
1169311357
1169411358=begin original
1169511359
1169611360In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded
1169711361strings, but not quoted in UTF-8 strings.
1169811362
1169911363=end original
1170011364
1170111365Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた
1170211366文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。
1170311367
1170411368=begin original
1170511369
1170611370Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for
1170711371quoting non-ASCII characters; the quoting of ASCII characters is
1170811372unchanged.
1170911373
1171011374=end original
1171111375
1171211376Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で
1171311377定義された戦略を採用しました; ASCII 文字のクォートは変わりません。
1171411378
1171511379=begin original
1171611380
1171711381Also unchanged is the quoting of non-UTF-8 strings when outside the
1171811382scope of a C<use feature 'unicode_strings'>, which is to quote all
1171911383characters in the upper Latin1 range. This provides complete backwards
1172011384compatibility for old programs which do not use Unicode. (Note that
1172111385C<unicode_strings> is automatically enabled within the scope of a
1172211386S<C<use v5.12>> or greater.)
1172311387
1172411388=end original
1172511389
1172611390また、C<use feature 'unicode_strings'> の範囲外で非 UTF-8 文字列を
1172711391クォートするのも変わりません; 上位の Latin1 の範囲の全ての文字を
1172811392クォートします。
11729これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。
11393これは Unicode を使わない古いプログラムに対して完全な後方互換性を
11394提供します。
1173011395(C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは
1173111396自動的に有効になることに注意してください。)
1173211397
1173311398=begin original
1173411399
1173511400Within the scope of C<use locale>, all non-ASCII Latin1 code points
1173611401are quoted whether the string is encoded as UTF-8 or not. As mentioned
1173711402above, locale does not affect the quoting of ASCII-range characters.
1173811403This protects against those locales where characters such as C<"|"> are
1173911404considered to be word characters.
1174011405
1174111406=end original
1174211407
1174311408C<use locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は
1174411409文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。
1174511410上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。
1174611411これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。
1174711412
1174811413=begin original
1174911414
1175011415Otherwise, Perl quotes non-ASCII characters using an adaptation from
11751Unicode (see L<http://www.unicode.org/reports/tr31/>).
11416Unicode (see L<http://www.unicode.org/reports/tr31/>.)
1175211417The only code points that are quoted are those that have any of the
1175311418Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space,
1175411419Default_Ignorable_Code_Point, or General_Category=Control.
1175511420
1175611421=end original
1175711422
1175811423さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします
1175911424(L<http://www.unicode.org/reports/tr31/> 参照)。
1176011425クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです:
1176111426Pattern_Syntax, Pattern_White_Space, White_Space,
1176211427Default_Ignorable_Code_Point, or General_Category=Control。
1176311428
1176411429=begin original
1176511430
1176611431Of these properties, the two important ones are Pattern_Syntax and
1176711432Pattern_White_Space. They have been set up by Unicode for exactly this
1176811433purpose of deciding which characters in a regular expression pattern
1176911434should be quoted. No character that can be in an identifier has these
1177011435properties.
1177111436
1177211437=end original
1177311438
1177411439これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。
1177511440これらはまさに正規表現中パターン中のどの文字をクォートするべきかを
1177611441決定するという目的のために Unicode によって設定されています。
1177711442識別子になる文字はこれらの特性はありません。
1177811443
1177911444=begin original
1178011445
1178111446Perl promises, that if we ever add regular expression pattern
1178211447metacharacters to the dozen already defined
1178311448(C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the
1178411449Pattern_Syntax property. Perl also promises, that if we ever add
1178511450characters that are considered to be white space in regular expressions
1178611451(currently mostly affected by C</x>), they will all have the
1178711452Pattern_White_Space property.
1178811453
1178911454=end original
1179011455
1179111456Perl は、正規表現メタ文字として既に定義されている
1179211457(C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、
1179311458Pattern_Syntax 特性を持つものだけを使うことを約束します。
1179411459Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と
1179511460考えられる文字に追加するときは、Pattern_White_Space 特性を
1179611461持つものであることを約束します。
1179711462
1179811463=begin original
1179911464
1180011465Unicode promises that the set of code points that have these two
1180111466properties will never change, so something that is not quoted in v5.16
1180211467will never need to be quoted in any future Perl release. (Not all the
1180311468code points that match Pattern_Syntax have actually had characters
1180411469assigned to them; so there is room to grow, but they are quoted
1180511470whether assigned or not. Perl, of course, would never use an
1180611471unassigned code point as an actual metacharacter.)
1180711472
1180811473=end original
1180911474
1181011475Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを
1181111476約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも
1181211477クォートする必要はありません。
1181311478(Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている
1181411479文字を持っているわけではありません; したがって拡張する余地がありますが、
1181511480割り当てられているかどうかに関わらずクォートされます。
1181611481Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは
1181711482ありません。)
1181811483
1181911484=begin original
1182011485
1182111486Quoting characters that have the other 3 properties is done to enhance
1182211487the readability of the regular expression and not because they actually
1182311488need to be quoted for regular expression purposes (characters with the
1182411489White_Space property are likely to be indistinguishable on the page or
1182511490screen from those with the Pattern_White_Space property; and the other
1182611491two properties contain non-printing characters).
1182711492
1182811493=end original
1182911494
1183011495その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために
1183111496行われ、実際には正規表現の目的でクォートする必要があるからではありません
1183211497(White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と
1183311498おそらく区別が付かないでしょう; そして残りの
1183411499二つの特性は非表示文字を含んでいます).
1183511500
1183611501=item rand EXPR
1183711502X<rand> X<random>
1183811503
1183911504=item rand
1184011505
1184111506=for Pod::Functions retrieve the next pseudorandom number
1184211507
1184311508=begin original
1184411509
1184511510Returns a random fractional number greater than or equal to C<0> and less
1184611511than the value of EXPR. (EXPR should be positive.) If EXPR is
1184711512omitted, the value C<1> is used. Currently EXPR with the value C<0> is
1184811513also special-cased as C<1> (this was undocumented before Perl 5.8.0
1184911514and is subject to change in future versions of Perl). Automatically calls
1185011515C<srand> unless C<srand> has already been called. See also C<srand>.
1185111516
1185211517=end original
1185311518
1185411519C<0> 以上 EXPR の値未満の小数の乱数値を返します。
1185511520(EXPR は正の数である必要があります。)
1185611521EXPR が省略されると、C<1> が使われます。
1185711522現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます
1185811523(これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では
1185911524変更される可能性があります)。
11860C<srand> が既に呼ばれている場合以外は、自動的に C<srand> 関数を呼び出します。
11525C<srand> が既に呼ばれている場合以外は、自動的に C<srand> 関数を
11526呼び出します。
1186111527C<srand> も参照してください。
1186211528
1186311529=begin original
1186411530
1186511531Apply C<int()> to the value returned by C<rand()> if you want random
1186611532integers instead of random fractional numbers. For example,
1186711533
1186811534=end original
1186911535
1187011536ランダムな小数ではなく、ランダムな整数がほしい場合は、C<rand()> から
1187111537返された値に C<int()> を適用してください。
1187211538例えば:
1187311539
1187411540 int(rand(10))
1187511541
1187611542=begin original
1187711543
1187811544returns a random integer between C<0> and C<9>, inclusive.
1187911545
1188011546=end original
1188111547
1188211548これは C<0> から C<9> の値をランダムに返します。
1188311549
1188411550=begin original
1188511551
1188611552(Note: If your rand function consistently returns numbers that are too
1188711553large or too small, then your version of Perl was probably compiled
1188811554with the wrong number of RANDBITS.)
1188911555
1189011556=end original
1189111557
1189211558(注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを
1189311559返すようなら、お使いになっている Perl が、
1189411560良くない RANDBITS を使ってコンパイルされている可能性があります。)
1189511561
1189611562=begin original
1189711563
1189811564B<C<rand()> is not cryptographically secure. You should not rely
1189911565on it in security-sensitive situations.> As of this writing, a
1190011566number of third-party CPAN modules offer random number generators
1190111567intended by their authors to be cryptographically secure,
1190211568including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1190311569and L<Math::TrulyRandom>.
1190411570
1190511571=end original
1190611572
1190711573B<C<rand()> は暗号学的に安全ではありません。
1190811574セキュリティ的に重要な状況でこれに頼るべきではありません。>
1190911575これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
11910作者によって暗号学的に安全であることを目的とした乱数生成器を提供しています:
11576作者によって暗号学的に安全であることを目的とした乱数生成器を
11911L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
11577提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1191211578L<Math::TrulyRandom> などです。
1191311579
1191411580=item read FILEHANDLE,SCALAR,LENGTH,OFFSET
1191511581X<read> X<file, read>
1191611582
1191711583=item read FILEHANDLE,SCALAR,LENGTH
1191811584
1191911585=for Pod::Functions fixed-length buffered input from a filehandle
1192011586
1192111587=begin original
1192211588
1192311589Attempts to read LENGTH I<characters> of data into variable SCALAR
1192411590from the specified FILEHANDLE. Returns the number of characters
1192511591actually read, C<0> at end of file, or undef if there was an error (in
1192611592the latter case C<$!> is also set). SCALAR will be grown or shrunk
1192711593so that the last character actually read is the last character of the
1192811594scalar after the read.
1192911595
1193011596=end original
1193111597
11932指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> のデータを
11598指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> の
11933読み込みます。
11599データを読み込みます。
11934実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の
11600実際に読み込まれた文字数、
11935いずれかを返します (後者の場合C<$!> もセットされます)。
11601ファイル終端の場合C<0>、エラーの場合は undef のいずかを返します
11936SCALAR は伸び縮みるので、読み込み後は、実際に読み込んだ最後の文字がスカラの
11602(後者の場合、C<$!> もセットされま)。
11937最後の文字になりま
11603SCALAR は伸び縮みるので、
11604読み込み後は、実際に読み込んだ最後の文字がスカラの最後の文字になります。
1193811605
1193911606=begin original
1194011607
1194111608An OFFSET may be specified to place the read data at some place in the
1194211609string other than the beginning. A negative OFFSET specifies
1194311610placement at that many characters counting backwards from the end of
1194411611the string. A positive OFFSET greater than the length of SCALAR
1194511612results in the string being padded to the required size with C<"\0">
1194611613bytes before the result of the read is appended.
1194711614
1194811615=end original
1194911616
1195011617OFFSET を指定すると、文字列の先頭以外の場所から、読み込みを行なうことが
1195111618できます。
1195211619OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1195311620位置を指定します。
11954OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
11621OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は
11955追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
11622読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで
11623パッディングされます。
1195611624
1195711625=begin original
1195811626
1195911627The call is implemented in terms of either Perl's or your system's native
1196011628fread(3) library function. To get a true read(2) system call, see
1196111629L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>.
1196211630
1196311631=end original
1196411632
1196511633この関数は、Perl か システムの fread(3) ライブラリ関数を使って実装しています。
1196611634本当の read(2) システムコールを利用するには、
1196711635L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。
1196811636
1196911637=begin original
1197011638
1197111639Note the I<characters>: depending on the status of the filehandle,
1197211640either (8-bit) bytes or characters are read. By default, all
1197311641filehandles operate on bytes, but for example if the filehandle has
1197411642been opened with the C<:utf8> I/O layer (see L</open>, and the C<open>
1197511643pragma, L<open>), the I/O will operate on UTF8-encoded Unicode
1197611644characters, not bytes. Similarly for the C<:encoding> pragma:
1197711645in that case pretty much any characters can be read.
1197811646
1197911647=end original
1198011648
1198111649I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか
1198211650文字が読み込まれます。
1198311651デフォルトでは全てのファイルハンドルはバイトを処理しますが、
1198411652例えばファイルハンドルが C<:utf8> I/O 層(L</open>, C<open> プラグマ、
1198511653L<open> を参照してください) で開かれた場合、I/O はバイトではなく、
1198611654UTF8 エンコードされた Unicode 文字を操作します。
1198711655C<:encoding> プラグマも同様です:
1198811656この場合、ほとんど大体全ての文字が読み込めます。
1198911657
1199011658=item readdir DIRHANDLE
1199111659X<readdir>
1199211660
1199311661=for Pod::Functions get a directory from a directory handle
1199411662
1199511663=begin original
1199611664
1199711665Returns the next directory entry for a directory opened by C<opendir>.
1199811666If used in list context, returns all the rest of the entries in the
1199911667directory. If there are no more entries, returns the undefined value in
1200011668scalar context and the empty list in list context.
1200111669
1200211670=end original
1200311671
12004C<opendir> でオープンしたディレクトリで、次のディレクトリエントリを返します。
11672C<opendir> でオープンしたディレクトリで、
12005リストコンテキストで用いると、そのディレクトリの残りのエントリをべて
11673のディレクトリエントリを返しま
12006返します。
11674リストコンテキストで用いると、
11675そのディレクトリの残りのエントリを、すべて返します。
1200711676エントリが残っていない場合には、スカラコンテキストでは未定義値を、
1200811677リストコンテキストでは空リストを返します。
1200911678
1201011679=begin original
1201111680
1201211681If you're planning to filetest the return values out of a C<readdir>, you'd
1201311682better prepend the directory in question. Otherwise, because we didn't
1201411683C<chdir> there, it would have been testing the wrong file.
1201511684
1201611685=end original
1201711686
1201811687C<readdir> の返り値をファイルテストに使おうと計画しているなら、
1201911688頭にディレクトリをつける必要があります。
1202011689さもなければ、ここでは C<chdir> はしないので、
1202111690間違ったファイルをテストしてしまうことになるでしょう。
1202211691
1202311692 opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!";
1202411693 @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
1202511694 closedir $dh;
1202611695
1202711696=begin original
1202811697
12029As of Perl 5.12 you can use a bare C<readdir> in a C<while> loop,
11698As of Perl 5.11.2 you can use a bare C<readdir> in a C<while> loop,
1203011699which will set C<$_> on every iteration.
1203111700
1203211701=end original
1203311702
12034Perl 5.12 から裸の C<readdir> を C<while> で使うことができ、
11703Perl 5.11.2 から裸の C<readdir> を C<while> で使うことができ、
1203511704この場合繰り返し毎に C<$_> にセットされます。
1203611705
1203711706 opendir(my $dh, $some_dir) || die;
1203811707 while(readdir $dh) {
1203911708 print "$some_dir/$_\n";
1204011709 }
1204111710 closedir $dh;
1204211711
1204311712=begin original
1204411713
1204511714To avoid confusing would-be users of your code who are running earlier
1204611715versions of Perl with mysterious failures, put this sort of thing at the
1204711716top of your file to signal that your code will work I<only> on Perls of a
1204811717recent vintage:
1204911718
1205011719=end original
1205111720
1205211721あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1205311722失敗で混乱することを避けるために、コードが最近のバージョンの Perl で
1205411723I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1205511724書いてください:
1205611725
1205711726 use 5.012; # so readdir assigns to $_ in a lone while test
1205811727
1205911728=item readline EXPR
1206011729
1206111730=item readline
1206211731X<readline> X<gets> X<fgets>
1206311732
1206411733=for Pod::Functions fetch a record from a file
1206511734
1206611735=begin original
1206711736
1206811737Reads from the filehandle whose typeglob is contained in EXPR (or from
1206911738C<*ARGV> if EXPR is not provided). In scalar context, each call reads and
1207011739returns the next line until end-of-file is reached, whereupon the
1207111740subsequent call returns C<undef>. In list context, reads until end-of-file
1207211741is reached and returns a list of lines. Note that the notion of "line"
1207311742used here is whatever you may have defined with C<$/> or
1207411743C<$INPUT_RECORD_SEPARATOR>). See L<perlvar/"$/">.
1207511744
1207611745=end original
1207711746
1207811747型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている
1207911748ファイルハンドルから読み込みます。
1208011749スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの
1208111750最後まで読み込んだら、以後の呼び出しでは C<undef> を返します。
1208211751リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。
1208311752ここでの「行」とは、C<$/> または C<$INPUT_RECORD_SEPARATOR> で
1208411753定義されることに注意してください。
1208511754L<perlvar/"$/"> を参照してください。
1208611755
1208711756=begin original
1208811757
1208911758When C<$/> is set to C<undef>, when C<readline> is in scalar
1209011759context (i.e., file slurp mode), and when an empty file is read, it
1209111760returns C<''> the first time, followed by C<undef> subsequently.
1209211761
1209311762=end original
1209411763
1209511764C<$/> に C<undef> を設定した場合は、C<readline> はスカラコンテキスト
1209611765(つまりファイル吸い込みモード)となり、
1209711766空のファイルを読み込んだ場合は、最初は C<''> を返し、
1209811767それ以降は C<undef> を返します。
1209911768
1210011769=begin original
1210111770
1210211771This is the internal function implementing the C<< <EXPR> >>
1210311772operator, but you can use it directly. The C<< <EXPR> >>
1210411773operator is discussed in more detail in L<perlop/"I/O Operators">.
1210511774
1210611775=end original
1210711776
1210811777これは C<< <EXPR> >> 演算子を実装している内部関数ですが、
1210911778直接使うこともできます。
1211011779C<< <EXPR> >> 演算子についてのさらなる詳細については
1211111780L<perlop/"I/O Operators"> で議論されています。
1211211781
1211311782 $line = <STDIN>;
1211411783 $line = readline(*STDIN); # same thing
1211511784
1211611785=begin original
1211711786
1211811787If C<readline> encounters an operating system error, C<$!> will be set
1211911788with the corresponding error message. It can be helpful to check
1212011789C<$!> when you are reading from filehandles you don't trust, such as a
1212111790tty or a socket. The following example uses the operator form of
1212211791C<readline> and dies if the result is not defined.
1212311792
1212411793=end original
1212511794
1212611795C<readline> が OS のシステムエラーになると、C<$!> に対応するエラーメッセージが
1212711796セットされます。
1212811797tty やソケットといった、信頼できないファイルハンドルから読み込む時には
1212911798C<$!> をチェックするのが助けになります。
1213011799以下の例は演算子の形の C<readline> を使っており、結果が
1213111800未定義の場合は die します。
1213211801
1213311802 while ( ! eof($fh) ) {
1213411803 defined( $_ = <$fh> ) or die "readline failed: $!";
1213511804 ...
1213611805 }
1213711806
1213811807=begin original
1213911808
1214011809Note that you have can't handle C<readline> errors that way with the
1214111810C<ARGV> filehandle. In that case, you have to open each element of
1214211811C<@ARGV> yourself since C<eof> handles C<ARGV> differently.
1214311812
1214411813=end original
1214511814
1214611815C<readline> のエラーは C<ARGV> ファイルハンドルの方法では扱えないことに
1214711816注意してください。
1214811817この場合、C<eof> は C<ARGV> を異なった方法で扱うので、
1214911818C<@ARGV> のそれぞれの要素を自分でオープンする必要があります。
1215011819
1215111820 foreach my $arg (@ARGV) {
1215211821 open(my $fh, $arg) or warn "Can't open $arg: $!";
1215311822
1215411823 while ( ! eof($fh) ) {
1215511824 defined( $_ = <$fh> )
1215611825 or die "readline failed for $arg: $!";
1215711826 ...
1215811827 }
1215911828 }
1216011829
1216111830=item readlink EXPR
1216211831X<readlink>
1216311832
1216411833=item readlink
1216511834
1216611835=for Pod::Functions determine where a symbolic link is pointing
1216711836
1216811837=begin original
1216911838
1217011839Returns the value of a symbolic link, if symbolic links are
1217111840implemented. If not, raises an exception. If there is a system
1217211841error, returns the undefined value and sets C<$!> (errno). If EXPR is
1217311842omitted, uses C<$_>.
1217411843
1217511844=end original
1217611845
12177シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。
11846シンボリックリンクが実装されていれば、
11847シンボリックリンクの値を返します。
1217811848実装されていないときには、例外が発生します。
1217911849何らかのシステムエラーが検出されると、未定義値を返し、
1218011850C<$!> (errno) を設定します。
1218111851EXPR が省略されると、C<$_> を使います。
1218211852
1218311853=begin original
1218411854
1218511855Portability issues: L<perlport/readlink>.
1218611856
1218711857=end original
1218811858
1218911859移植性の問題: L<perlport/readlink>。
1219011860
1219111861=item readpipe EXPR
1219211862
1219311863=item readpipe
1219411864X<readpipe>
1219511865
1219611866=for Pod::Functions execute a system command and collect standard output
1219711867
1219811868=begin original
1219911869
1220011870EXPR is executed as a system command.
1220111871The collected standard output of the command is returned.
1220211872In scalar context, it comes back as a single (potentially
1220311873multi-line) string. In list context, returns a list of lines
1220411874(however you've defined lines with C<$/> or C<$INPUT_RECORD_SEPARATOR>).
1220511875This is the internal function implementing the C<qx/EXPR/>
1220611876operator, but you can use it directly. The C<qx/EXPR/>
1220711877operator is discussed in more detail in L<perlop/"I/O Operators">.
1220811878If EXPR is omitted, uses C<$_>.
1220911879
1221011880=end original
1221111881
1221211882EXPR がシステムコマンドとして実行されます。
1221311883コマンドの標準出力の内容が返されます。
1221411884スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。
1221511885リストコンテキストでは、行のリストを返します
1221611886(但し、行は C<$/> または C<$INPUT_RECORD_SEPARATOR> で定義されます)。
12217これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。
11887これは C<qx/EXPR/> 演算子を実装する内部関数ですが、
12218C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に述べられています。
11888直接使うことも出来ます。
11889C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に
11890述べられています。
1221911891EXPR が省略されると、C<$_> を使います。
1222011892
1222111893=item recv SOCKET,SCALAR,LENGTH,FLAGS
1222211894X<recv>
1222311895
1222411896=for Pod::Functions receive a message over a Socket
1222511897
1222611898=begin original
1222711899
1222811900Receives a message on a socket. Attempts to receive LENGTH characters
1222911901of data into variable SCALAR from the specified SOCKET filehandle.
1223011902SCALAR will be grown or shrunk to the length actually read. Takes the
1223111903same flags as the system call of the same name. Returns the address
1223211904of the sender if SOCKET's protocol supports this; returns an empty
1223311905string otherwise. If there's an error, returns the undefined value.
1223411906This call is actually implemented in terms of recvfrom(2) system call.
1223511907See L<perlipc/"UDP: Message Passing"> for examples.
1223611908
1223711909=end original
1223811910
1223911911ソケット上のメッセージを受信します。
12240指定されたファイルハンドル SOCKET から、変数 SCALAR に
11912指定されたファイルハンドル SOCKET から、変数 SCALAR に
1224111913LENGTH 文字のデータを読み込もうとします。
12242SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。
11914SCALAR は、実際に読まれた長さによって、大きくなったり、
11915小さくなったりします。
1224311916同名のシステムコールと同じフラグが指定できます。
1224411917SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。
1224511918エラー発生時には、未定義値を返します。
1224611919実際には、C のrecvfrom(2) を呼びます。
1224711920例については L<perlipc/"UDP: Message Passing"> を参照してください。
1224811921
1224911922=begin original
1225011923
1225111924Note the I<characters>: depending on the status of the socket, either
1225211925(8-bit) bytes or characters are received. By default all sockets
1225311926operate on bytes, but for example if the socket has been changed using
1225411927binmode() to operate with the C<:encoding(utf8)> I/O layer (see the
1225511928C<open> pragma, L<open>), the I/O will operate on UTF8-encoded Unicode
1225611929characters, not bytes. Similarly for the C<:encoding> pragma: in that
1225711930case pretty much any characters can be read.
1225811931
1225911932=end original
1226011933
1226111934I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
1226211935文字を受信します。
1226311936デフォルトでは全てのソケットはバイトを処理しますが、
1226411937例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(C<open> プラグマ、
1226511938L<open> を参照してください) を使うように指定された場合、I/O はバイトではなく、
1226611939UTF8 エンコードされた Unicode 文字を操作します。
1226711940C<:encoding> プラグマも同様です:
1226811941この場合、ほとんど大体全ての文字が読み込めます。
1226911942
1227011943=item redo LABEL
1227111944X<redo>
1227211945
12273=item redo EXPR
12274
1227511946=item redo
1227611947
1227711948=for Pod::Functions start this loop iteration over again
1227811949
1227911950=begin original
1228011951
1228111952The C<redo> command restarts the loop block without evaluating the
1228211953conditional again. The C<continue> block, if any, is not executed. If
1228311954the LABEL is omitted, the command refers to the innermost enclosing
12284loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a
11955loop. Programs that want to lie to themselves about what was just input
12285label name to be computed at run time, and is otherwise identical to C<redo
12286LABEL>. Programs that want to lie to themselves about what was just input
1228711956normally use this command:
1228811957
1228911958=end original
1229011959
1229111960C<redo> コマンドは、条件を再評価しないで、ループブロックの始めからもう一度
1229211961実行を開始します。
1229311962C<continue> ブロックがあっても、実行されません。
1229411963LABEL が省略されると、コマンドは一番内側のループを参照します。
12295Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が
12296使えます; それ以外は C<redo LABEL> と同一です。
1229711964このコマンドは通常、自分への入力を欺くために使用します:
1229811965
1229911966 # a simpleminded Pascal comment stripper
1230011967 # (warning: assumes no { or } in strings)
1230111968 LINE: while (<STDIN>) {
1230211969 while (s|({.*}.*){.*}|$1 |) {}
1230311970 s|{.*}| |;
1230411971 if (s|{.*| |) {
1230511972 $front = $_;
1230611973 while (<STDIN>) {
1230711974 if (/}/) { # end of comment?
1230811975 s|^|$front\{|;
1230911976 redo LINE;
1231011977 }
1231111978 }
1231211979 }
1231311980 print;
1231411981 }
1231511982
1231611983=begin original
1231711984
1231811985C<redo> cannot be used to retry a block that returns a value such as
1231911986C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
1232011987a grep() or map() operation.
1232111988
1232211989=end original
1232311990
12324C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返すブロックを
11991C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
12325繰り返すのには使えません; また、grep() や map() 操作から抜けるのに
11992ブロックを繰り返すのには使えません; また、grep() や map() 操作から抜けるのに
1232611993使うべきではありません。
1232711994
1232811995=begin original
1232911996
1233011997Note that a block by itself is semantically identical to a loop
1233111998that executes once. Thus C<redo> inside such a block will effectively
1233211999turn it into a looping construct.
1233312000
1233412001=end original
1233512002
1233612003ブロック自身は一回だけ実行されるループと文法的に同一であることに
1233712004注意してください。
1233812005従って、ブロックの中で C<redo> を使うことで効果的に
1233912006ループ構造に変換します。
1234012007
1234112008=begin original
1234212009
1234312010See also L</continue> for an illustration of how C<last>, C<next>, and
1234412011C<redo> work.
1234512012
1234612013=end original
1234712014
1234812015C<last>, C<next>, C<redo> がどのように働くかについては
1234912016L</continue> も参照してください。
1235012017
12351=begin original
12352
12353Unlike most named operators, this has the same precedence as assignment.
12354It is also exempt from the looks-like-a-function rule, so
12355C<redo ("foo")."bar"> will cause "bar" to be part of the argument to
12356C<redo>.
12357
12358=end original
12359
12360ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
12361また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と
12362すると "bar" は C<redo> への引数の一部となります。
12363
1236412018=item ref EXPR
1236512019X<ref> X<reference>
1236612020
1236712021=item ref
1236812022
1236912023=for Pod::Functions find out the type of thing being referenced
1237012024
1237112025=begin original
1237212026
1237312027Returns a non-empty string if EXPR is a reference, the empty
12374string otherwise. If EXPR is not specified, C<$_> will be used. The
12028string otherwise. If EXPR
12375value returned depends on the type of thing the reference is a reference to.
12029is not specified, C<$_> will be used. The value returned depends on the
12030type of thing the reference is a reference to.
12031Builtin types include:
1237612032
1237712033=end original
1237812034
1237912035EXPR がリファレンスであれば、空でない文字列を返し、さもなくば、
1238012036空文字列を返します。
1238112037EXPR が指定されなければ、C<$_> が使われます。
1238212038返される値は、リファレンスが参照するものの型に依存します。
12383
12384=begin original
12385
12386Builtin types include:
12387
12388=end original
12389
1239012039組み込みの型には、以下のものがあります。
1239112040
1239212041 SCALAR
1239312042 ARRAY
1239412043 HASH
1239512044 CODE
1239612045 REF
1239712046 GLOB
1239812047 LVALUE
1239912048 FORMAT
1240012049 IO
1240112050 VSTRING
1240212051 Regexp
1240312052
1240412053=begin original
1240512054
12406You can think of C<ref> as a C<typeof> operator.
12055If the referenced object has been blessed into a package, then that package
12056name is returned instead. You can think of C<ref> as a C<typeof> operator.
1240712057
1240812058=end original
1240912059
12060参照されるオブジェクトが、何らかのパッケージに
12061bless されたものであれば、これらの代わりに、
12062そのパッケージ名が返されます。
1241012063C<ref> は、C<typeof> 演算子のように考えることができます。
1241112064
1241212065 if (ref($r) eq "HASH") {
1241312066 print "r is a reference to a hash.\n";
1241412067 }
1241512068 unless (ref($r)) {
1241612069 print "r is not a reference at all.\n";
1241712070 }
1241812071
1241912072=begin original
1242012073
1242112074The return value C<LVALUE> indicates a reference to an lvalue that is not
1242212075a variable. You get this from taking the reference of function calls like
1242312076C<pos()> or C<substr()>. C<VSTRING> is returned if the reference points
1242412077to a L<version string|perldata/"Version Strings">.
1242512078
1242612079=end original
1242712080
1242812081返り値 C<LVALUE> は、変数ではない左辺値へのリファレンスを示します。
1242912082これは、C<pos()> や C<substr()> のようの関数呼び出しのリファレンスから
1243012083得られます。
1243112084C<VSTRING> は、リファレンスが L<version string|perldata/"Version Strings"> を
1243212085指している場合に返されます。
1243312086
1243412087=begin original
1243512088
1243612089The result C<Regexp> indicates that the argument is a regular expression
1243712090resulting from C<qr//>.
1243812091
1243912092=end original
1244012093
1244112094C<Regexp> という結果は、引数が C<qr//> からの結果である
1244212095正規表現であることを意味します。
1244312096
1244412097=begin original
1244512098
12446If the referenced object has been blessed into a package, then that package
12447name is returned instead. But don't use that, as it's now considered
12448"bad practice". For one reason, an object could be using a class called
12449C<Regexp> or C<IO>, or even C<HASH>. Also, C<ref> doesn't take into account
12450subclasses, like C<isa> does.
12451
12452=end original
12453
12454参照されるオブジェクトが、何らかのパッケージに bless されたものであれば、
12455これらの代わりに、そのパッケージ名が返されます。
12456しかし、これは今では「悪い習慣」と考えられているので、しないでください。
12457理由の一つは、オブジェクトは C<Regexp>, C<IO> や C<HASH> などと呼ばれる
12458クラスを使うかも知れないからです。
12459また、C<ref> は C<isa> のようにサブクラスを考慮したりはしません。
12460
12461=begin original
12462
12463Instead, use C<blessed> (in the L<Scalar::Util> module) for boolean
12464checks, C<isa> for specific class checks and C<reftype> (also from
12465L<Scalar::Util>) for type checks. (See L<perlobj> for details and a
12466C<blessed/isa> example.)
12467
12468=end original
12469
12470代わりに、真偽値チェックには (L<Scalar::Util> モジュールにある)
12471C<blessed> を、特定のクラスのチェックには C<isa> を、型のチェックには
12472(これも L<Scalar::Util> にある) C<reftype> を使ってください。
12473(詳細と C<blessed/isa> の例については L<perlobj> を参照してください。)
12474
12475=begin original
12476
1247712099See also L<perlref>.
1247812100
1247912101=end original
1248012102
1248112103L<perlref> も参照してください。
1248212104
1248312105=item rename OLDNAME,NEWNAME
1248412106X<rename> X<move> X<mv> X<ren>
1248512107
1248612108=for Pod::Functions change a filename
1248712109
1248812110=begin original
1248912111
1249012112Changes the name of a file; an existing file NEWNAME will be
1249112113clobbered. Returns true for success, false otherwise.
1249212114
1249312115=end original
1249412116
1249512117ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、
1249612118上書きされるかもしれません。
1249712119成功時には真を、さもなければ偽を返します。
1249812120
1249912121=begin original
1250012122
1250112123Behavior of this function varies wildly depending on your system
1250212124implementation. For example, it will usually not work across file system
1250312125boundaries, even though the system I<mv> command sometimes compensates
1250412126for this. Other restrictions include whether it works on directories,
1250512127open files, or pre-existing files. Check L<perlport> and either the
1250612128rename(2) manpage or equivalent system documentation for details.
1250712129
1250812130=end original
1250912131
1251012132この関数の振る舞いはシステムの実装に大きく依存して異なります。
1251112133例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません;
1251212134システムの I<mv> がこれを補完している場合でもそうです。
1251312135その他の制限には、ディレクトリ、オープンしているファイル、既に存在している
1251412136ファイルに対して使えるか、といったことを含みます。
1251512137詳しくは、L<perlport> および rename(2) man ページあるいは同様の
1251612138システムドキュメントを参照してください。
1251712139
1251812140=begin original
1251912141
1252012142For a platform independent C<move> function look at the L<File::Copy>
1252112143module.
1252212144
1252312145=end original
1252412146
1252512147プラットフォームに依存しない C<move> 関数については L<File::Copy> モジュールを
1252612148参照してください。
1252712149
1252812150=begin original
1252912151
1253012152Portability issues: L<perlport/rename>.
1253112153
1253212154=end original
1253312155
1253412156移植性の問題: L<perlport/rename>。
1253512157
1253612158=item require VERSION
1253712159X<require>
1253812160
1253912161=item require EXPR
1254012162
1254112163=item require
1254212164
1254312165=for Pod::Functions load in external functions from a library at runtime
1254412166
1254512167=begin original
1254612168
1254712169Demands a version of Perl specified by VERSION, or demands some semantics
1254812170specified by EXPR or by C<$_> if EXPR is not supplied.
1254912171
1255012172=end original
1255112173
1255212174VERSION で指定される Perl のバージョンを要求するか、
1255312175EXPR (省略時には C<$_>) によって指定されるいくつかの動作を要求します。
1255412176
1255512177=begin original
1255612178
1255712179VERSION may be either a numeric argument such as 5.006, which will be
1255812180compared to C<$]>, or a literal of the form v5.6.1, which will be compared
1255912181to C<$^V> (aka $PERL_VERSION). An exception is raised if
1256012182VERSION is greater than the version of the current Perl interpreter.
1256112183Compare with L</use>, which can do a similar check at compile time.
1256212184
1256312185=end original
1256412186
1256512187VERSION は 5.006 のような数値(C<$]> と比較されます)か、v5.6.1 の形
1256612188(C<$^V> (またの名を $PERL_VERSION) と比較されます)で指定します。
1256712189VERSION が Perl の現在のバージョンより大きいと、例外が発生します。
1256812190L</use> と似ていますが、これはコンパイル時にチェックされます。
1256912191
1257012192=begin original
1257112193
1257212194Specifying VERSION as a literal of the form v5.6.1 should generally be
1257312195avoided, because it leads to misleading error messages under earlier
1257412196versions of Perl that do not support this syntax. The equivalent numeric
1257512197version should be used instead.
1257612198
1257712199=end original
1257812200
1257912201VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
1258012202なぜなら、この文法に対応していない Perl の初期のバージョンでは
1258112203誤解させるようなエラーメッセージが出るからです。
1258212204代わりに等価な数値表現を使うべきです。
1258312205
1258412206=begin original
1258512207
1258612208 require v5.6.1; # run time version check
1258712209 require 5.6.1; # ditto
12588 require 5.006_001; # ditto; preferred for backwards
12210 require 5.006_001; # ditto; preferred for backwards compatibility
12589 compatibility
1259012211
1259112212=end original
1259212213
1259312214 require v5.6.1; # 実行時バージョンチェック
1259412215 require 5.6.1; # 同様
1259512216 require 5.006_001; # 同様; 後方互換性のためには望ましい
1259612217
1259712218=begin original
1259812219
1259912220Otherwise, C<require> demands that a library file be included if it
1260012221hasn't already been included. The file is included via the do-FILE
1260112222mechanism, which is essentially just a variety of C<eval> with the
1260212223caveat that lexical variables in the invoking script will be invisible
12603to the included code. If it were implemented in pure Perl, it
12224to the included code. Has semantics similar to the following subroutine:
12604would have semantics similar to the following:
1260512225
1260612226=end original
1260712227
1260812228それ以外の場合には、C<require> は、既に読み込まれていないときに読み込む
1260912229ライブラリファイルを要求するものとなります。
1261012230そのファイルは、基本的には C<eval> の一種である、do-FILE によって
1261112231読み込まれますが、起動したスクリプトのレキシカル変数は読み込まれたコードから
1261212232見えないという欠点があります。
12613ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと
12233意味的には、次のようなサブルーチンと同じようなものです:
12614同じようなものです:
1261512234
12616 use Carp 'croak';
12617 use version;
12618
1261912235 sub require {
12620 my ($filename) = @_;
12236 my ($filename) = @_;
12621 if ( my $version = eval { version->parse($filename) } ) {
12237 if (exists $INC{$filename}) {
12622 if ( $version > $^V ) {
12238 return 1 if $INC{$filename};
12623 my $vn = $version->normal;
12239 die "Compilation failed in require";
12624 croak "Perl $vn required--this is only $^V, stopped";
12240 }
12625 }
12241 my ($realfilename,$result);
12626 return 1;
12242 ITER: {
12627 }
12243 foreach $prefix (@INC) {
12244 $realfilename = "$prefix/$filename";
12629 if (exists $INC{$filename}) {
12245 if (-f $realfilename) {
12630 return 1 if $INC{$filename};
12246 $INC{$filename} = $realfilename;
12631 croak "Compilation failed in require";
12247 $result = do $realfilename;
12632 }
12248 last ITER;
12249 }
12634 foreach $prefix (@INC) {
12250 }
12635 if (ref($prefix)) {
12251 die "Can't find $filename in \@INC";
12636 #... do other stuff - see text below ....
12252 }
12637 }
12253 if ($@) {
12638 # (see text below about possible appending of .pmc
12254 $INC{$filename} = undef;
12639 # suffix to $filename)
12255 die $@;
12640 my $realfilename = "$prefix/$filename";
12256 } elsif (!$result) {
12641 next if ! -e $realfilename || -d _ || -b _;
12257 delete $INC{$filename};
12642 $INC{$filename} = $realfilename;
12258 die "$filename did not return true value";
12643 my $result = do($realfilename);
12259 } else {
12644 # but run in caller's namespace
12260 return $result;
12261 }
12646 if (!defined $result) {
12647 $INC{$filename} = undef;
12648 croak $@ ? "$@Compilation failed in require"
12649 : "Can't locate $filename: $!\n";
12650 }
12651 if (!$result) {
12652 delete $INC{$filename};
12653 croak "$filename did not return true value";
12654 }
12655 $! = 0;
12656 return $result;
12657 }
12658 croak "Can't locate $filename in \@INC ...";
1265912262 }
1266012263
1266112264=begin original
1266212265
1266312266Note that the file will not be included twice under the same specified
1266412267name.
1266512268
1266612269=end original
1266712270
1266812271ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。
1266912272
1267012273=begin original
1267112274
1267212275The file must return true as the last statement to indicate
1267312276successful execution of any initialization code, so it's customary to
1267412277end such a file with C<1;> unless you're sure it'll return true
1267512278otherwise. But it's better just to put the C<1;>, in case you add more
1267612279statements.
1267712280
1267812281=end original
1267912282
12680初期化コードの実行がうまくいったことを示すために、ファイルは真を
12283初期化コードの実行がうまくいったことを示すために、
12681返さなければならないので、真を返すようになっている自信がある場合を除いては
12284ファイルは真を返さなければなりませんから、
12285真を返すようになっている自信がある場合を除いては、
1268212286ファイルの最後に C<1;> と書くのが習慣です。
12683しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。
12287実行文を追加するような場合に備えて、C<1;> と書いておいた方が
12288良いでしょう。
1268412289
1268512290=begin original
1268612291
1268712292If EXPR is a bareword, the require assumes a "F<.pm>" extension and
1268812293replaces "F<::>" with "F</>" in the filename for you,
1268912294to make it easy to load standard modules. This form of loading of
1269012295modules does not risk altering your namespace.
1269112296
1269212297=end original
1269312298
12694EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、
12299EXPR が裸の単語であるときには、標準モジュールのロードを
12695require は拡張子が "F<.pm>" であり、"F<::>" を "F</>" に変えたものが
12300簡単にするように、require は拡張子が "F<.pm>" であり、
12696ファイル名であると仮定します。
12301"F<::>" を "F</>" に変えたものがファイル名であると仮定します。
12697この形式のモジュールロードは、名前空間を変更してしまう危険はありません。
12302この形式のモジュールロードは、
12303名前空間を変更してしまう危険はありません。
1269812304
1269912305=begin original
1270012306
1270112307In other words, if you try this:
1270212308
1270312309=end original
1270412310
1270512311言い換えると、以下のようにすると:
1270612312
1270712313 require Foo::Bar; # a splendid bareword
1270812314
1270912315=begin original
1271012316
1271112317The require function will actually look for the "F<Foo/Bar.pm>" file in the
1271212318directories specified in the C<@INC> array.
1271312319
1271412320=end original
1271512321
1271612322require 関数は C<@INC> 配列で指定されたディレクトリにある
1271712323"F<Foo/Bar.pm>" ファイルを探します。
1271812324
1271912325=begin original
1272012326
1272112327But if you try this:
1272212328
1272312329=end original
1272412330
1272512331しかし、以下のようにすると:
1272612332
1272712333 $class = 'Foo::Bar';
1272812334 require $class; # $class is not a bareword
1272912335 #or
1273012336 require "Foo::Bar"; # not a bareword because of the ""
1273112337
1273212338=begin original
1273312339
1273412340The require function will look for the "F<Foo::Bar>" file in the @INC array and
1273512341will complain about not finding "F<Foo::Bar>" there. In this case you can do:
1273612342
1273712343=end original
1273812344
1273912345require 関数は @INC 配列の "F<Foo::Bar>" ファイルを探し、
1274012346おそらくそこに "F<Foo::Bar>" がないと文句をいうことになるでしょう。
1274112347このような場合には、以下のようにします:
1274212348
1274312349 eval "require $class";
1274412350
1274512351=begin original
1274612352
1274712353Now that you understand how C<require> looks for files with a
1274812354bareword argument, there is a little extra functionality going on behind
1274912355the scenes. Before C<require> looks for a "F<.pm>" extension, it will
1275012356first look for a similar filename with a "F<.pmc>" extension. If this file
1275112357is found, it will be loaded in place of any file ending in a "F<.pm>"
1275212358extension.
1275312359
1275412360=end original
1275512361
1275612362引数が裸の単語の場合、C<require> がどのようにファイルを探すかを
1275712363理解してください; 水面下でちょっとした追加の機能があります。
1275812364C<require> が拡張子 "F<.pm>" のファイルを探す前に、まず拡張子 "F<.pmc>" を
1275912365持つファイルを探します。
1276012366このファイルが見つかると、このファイルが拡張子 "F<.pm>" の代わりに
1276112367読み込まれます。
1276212368
1276312369=begin original
1276412370
1276512371You can also insert hooks into the import facility by putting Perl code
1276612372directly into the @INC array. There are three forms of hooks: subroutine
1276712373references, array references, and blessed objects.
1276812374
1276912375=end original
1277012376
1277112377@INC 配列に直接 Perl コードを入れることで、インポート機能にフックを
1277212378挿入できます。
12773123793 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、
1277412380bless されたオブジェクトです。
1277512381
1277612382=begin original
1277712383
1277812384Subroutine references are the simplest case. When the inclusion system
1277912385walks through @INC and encounters a subroutine, this subroutine gets
1278012386called with two parameters, the first a reference to itself, and the
1278112387second the name of the file to be included (e.g., "F<Foo/Bar.pm>"). The
12782subroutine should return either nothing or else a list of up to four
12388subroutine should return either nothing or else a list of up to three
1278312389values in the following order:
1278412390
1278512391=end original
1278612392
1278712393サブルーチンへのリファレンスは一番単純な場合です。
1278812394インクルード機能が @INC を走査してサブルーチンに出会った場合、この
1278912395サブルーチンは二つの引数と共に呼び出されます;
1279012396一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名
1279112397("F<Foo/Bar.pm>" など)です。
12792サブルーチンは何も返さないか、以下の順で最大つの値のリストを返します。
12398サブルーチンは何も返さないか、以下の順で最大つの値のリストを
12399返します。
1279312400
1279412401=over
1279512402
1279612403=item 1
1279712404
1279812405=begin original
1279912406
12800A reference to a scalar, containing any initial source code to prepend to
12801the file or generator output.
12802
12803=end original
12804
12805ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む
12806スカラへのリファレンス。
12807
12808=item 2
12809
12810=begin original
12811
1281212407A filehandle, from which the file will be read.
1281312408
1281412409=end original
1281512410
1281612411ファイルが読み込まれるファイルハンドル。
1281712412
12818=item 3
12413=item 2
1281912414
1282012415=begin original
1282112416
1282212417A reference to a subroutine. If there is no filehandle (previous item),
1282312418then this subroutine is expected to generate one line of source code per
1282412419call, writing the line into C<$_> and returning 1, then finally at end of
1282512420file returning 0. If there is a filehandle, then the subroutine will be
1282612421called to act as a simple source filter, with the line as read in C<$_>.
1282712422Again, return 1 for each valid line, and 0 after all lines have been
1282812423returned.
1282912424
1283012425=end original
1283112426
1283212427サブルーチンへのリファレンス。
12833(一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に
12428(一つ前のアイテムである)ファイルハンドルがない場合、
12834一行のソースコードを生成し、その行を C<$_> に書き込んで 1 を返し、それから
12429サブルーチンは呼び出し毎に一行のソースコードを生成し、その行を C<$_> に
12835最終的にファイル終端で 0 を返すものと想定されます。
12430書き込んで 1 を返し、それから最終的にファイル終端で 0 を返すものと
12431想定されます。
1283612432ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして
1283712433振舞うように呼び出され、行は C<$_> から読み込まれます。
1283812434再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。
1283912435
12840=item 4
12436=item 3
1284112437
1284212438=begin original
1284312439
1284412440Optional state for the subroutine. The state is passed in as C<$_[1]>. A
1284512441reference to the subroutine itself is passed in as C<$_[0]>.
1284612442
1284712443=end original
1284812444
1284912445サブルーチンのための状態(オプション)。
1285012446状態は C<$_[1]> として渡されます。
1285112447サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。
1285212448
1285312449=back
1285412450
1285512451=begin original
1285612452
1285712453If an empty list, C<undef>, or nothing that matches the first 3 values above
1285812454is returned, then C<require> looks at the remaining elements of @INC.
1285912455Note that this filehandle must be a real filehandle (strictly a typeglob
1286012456or reference to a typeglob, whether blessed or unblessed); tied filehandles
1286112457will be ignored and processing will stop there.
1286212458
1286312459=end original
1286412460
1286512461空リスト、C<undef>、または上記の最初の三つの値のどれとも一致しないものが
1286612462返されると、C<require> は @INC の残りの要素を見ます。
1286712463このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの
1286812464リファレンス、bless されているかに関わらず)でなければなりません;
1286912465tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。
1287012466
1287112467=begin original
1287212468
1287312469If the hook is an array reference, its first element must be a subroutine
1287412470reference. This subroutine is called as above, but the first parameter is
1287512471the array reference. This lets you indirectly pass arguments to
1287612472the subroutine.
1287712473
1287812474=end original
1287912475
1288012476フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの
1288112477リファレンスでなければなりません。
1288212478このサブルーチンは上述のように呼び出されますが、その最初の引数は
1288312479配列のリファレンスです。
1288412480これによって、間接的にサブルーチンに引数を渡すことが出来ます。
1288512481
1288612482=begin original
1288712483
1288812484In other words, you can write:
1288912485
1289012486=end original
1289112487
1289212488言い換えると、以下のように書いたり:
1289312489
1289412490 push @INC, \&my_sub;
1289512491 sub my_sub {
1289612492 my ($coderef, $filename) = @_; # $coderef is \&my_sub
1289712493 ...
1289812494 }
1289912495
1290012496=begin original
1290112497
1290212498or:
1290312499
1290412500=end original
1290512501
1290612502または以下のように書けます:
1290712503
1290812504 push @INC, [ \&my_sub, $x, $y, ... ];
1290912505 sub my_sub {
1291012506 my ($arrayref, $filename) = @_;
1291112507 # Retrieve $x, $y, ...
1291212508 my @parameters = @$arrayref[1..$#$arrayref];
1291312509 ...
1291412510 }
1291512511
1291612512=begin original
1291712513
1291812514If the hook is an object, it must provide an INC method that will be
1291912515called as above, the first parameter being the object itself. (Note that
1292012516you must fully qualify the sub's name, as unqualified C<INC> is always forced
1292112517into package C<main>.) Here is a typical code layout:
1292212518
1292312519=end original
1292412520
1292512521フックがオブジェクトの場合、INC メソッドを提供している必要があります;
1292612522それが、最初の引数をオブジェクト自身として上述のように呼び出されます。
1292712523(修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、
1292812524サブルーチン名は完全修飾する必要があることに注意してください。)
1292912525以下は典型的なコードレイアウトです:
1293012526
1293112527 # In Foo.pm
1293212528 package Foo;
1293312529 sub new { ... }
1293412530 sub Foo::INC {
1293512531 my ($self, $filename) = @_;
1293612532 ...
1293712533 }
1293812534
1293912535 # In the main program
1294012536 push @INC, Foo->new(...);
1294112537
1294212538=begin original
1294312539
1294412540These hooks are also permitted to set the %INC entry
1294512541corresponding to the files they have loaded. See L<perlvar/%INC>.
1294612542
1294712543=end original
1294812544
1294912545これらのフックは、読み込まれるファイルに対応する %INC エントリを
1295012546セットすることも許可します。
1295112547L<perlvar/%INC> を参照してください。
1295212548
1295312549=begin original
1295412550
1295512551For a yet-more-powerful import facility, see L</use> and L<perlmod>.
1295612552
1295712553=end original
1295812554
1295912555より強力な import 機能については、このドキュメントの
1296012556L</use> の項と、L<perlmod> を参照してください。
1296112557
1296212558=item reset EXPR
1296312559X<reset>
1296412560
1296512561=item reset
1296612562
1296712563=for Pod::Functions clear all variables of a given name
1296812564
1296912565=begin original
1297012566
1297112567Generally used in a C<continue> block at the end of a loop to clear
1297212568variables and reset C<??> searches so that they work again. The
1297312569expression is interpreted as a list of single characters (hyphens
1297412570allowed for ranges). All variables and arrays beginning with one of
1297512571those letters are reset to their pristine state. If the expression is
1297612572omitted, one-match searches (C<?pattern?>) are reset to match again.
1297712573Only resets variables or searches in the current package. Always returns
12978125741. Examples:
1297912575
1298012576=end original
1298112577
12982通常、ループの最後に、変数をクリアし、C<??> 検索を再び動作するように
12578通常、ループの最後に、変数をクリアし、C<??> 検索を再び
12983リセットするため、C<continue> ブロックで使われます。
12579動作するようにリセットするため、C<continue> ブロックで使われます。
1298412580EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と
1298512581解釈されます。
1298612582名前がその文字のいずれかで始まる変数や配列は、
1298712583最初の状態にリセットされます。
1298812584EXPR を省略すると、1 回検索 (C<?PATTERN?>) を再びマッチするように
1298912585リセットできます。
1299012586カレントパッケージの変数もしくは検索だけがリセットされます。
1299112587常に 1 を返します。
1299212588例:
1299312589
1299412590 reset 'X'; # reset all X variables
1299512591 reset 'a-z'; # reset lower case variables
1299612592 reset; # just reset ?one-time? searches
1299712593
1299812594=begin original
1299912595
1300012596Resetting C<"A-Z"> is not recommended because you'll wipe out your
1300112597C<@ARGV> and C<@INC> arrays and your C<%ENV> hash. Resets only package
1300212598variables; lexical variables are unaffected, but they clean themselves
1300312599up on scope exit anyway, so you'll probably want to use them instead.
1300412600See L</my>.
1300512601
1300612602=end original
1300712603
1300812604reset C<"A-Z"> とすると、C<@ARGV>, C<@INC> 配列や C<%ENV> ハッシュも
13009なくなってしまうので、止めた方が良いでしょう。
12605なくなってしまいますから、止めた方が良いでしょう。
13010パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、
12606パッケージ変数だけがリセットされます;
13011スコープから外れれば自動的に綺麗になるのでこれからはこちらを
12607レキシカル変数は、影響を受けませんが、スコープから外れれば、
13012使うようにした方がよいでしょう。
12608自動的に綺麗になりますので、これからは、こちらを使うようにした方が
12609よいでしょう。
1301312610L</my> を参照してください。
1301412611
1301512612=item return EXPR
1301612613X<return>
1301712614
1301812615=item return
1301912616
1302012617=for Pod::Functions get out of a function early
1302112618
1302212619=begin original
1302312620
1302412621Returns from a subroutine, C<eval>, or C<do FILE> with the value
1302512622given in EXPR. Evaluation of EXPR may be in list, scalar, or void
1302612623context, depending on how the return value will be used, and the context
1302712624may vary from one execution to the next (see L</wantarray>). If no EXPR
1302812625is given, returns an empty list in list context, the undefined value in
1302912626scalar context, and (of course) nothing at all in void context.
1303012627
1303112628=end original
1303212629
1303312630サブルーチン, C<eval>, C<do FILE> から EXPR で与えられた値をもって、
1303412631リターンします。
1303512632EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、
1303612633無効コンテキストになります; またコンテキストは実行毎に変わります
1303712634(C<wantarray> を参照してください)。
1303812635EXPR が指定されなかった場合は、リストコンテキストでは空リストを、
1303912636スカラコンテキストでは未定義値を返します; そして(もちろん)
1304012637無効コンテキストでは何も返しません。
1304112638
1304212639=begin original
1304312640
1304412641(In the absence of an explicit C<return>, a subroutine, eval,
1304512642or do FILE automatically returns the value of the last expression
1304612643evaluated.)
1304712644
1304812645=end original
1304912646
13050(サブルーチン, eval, do FILE に明示的に C<return> がなければ、最後に
12647(サブルーチン, eval, do FILE に明示的に C<return> が
13051評価された値で、自動的にリターンします。)
12648なければ、最後に評価された値で、自動的にリターンします。)
1305212649
13053=begin original
13054
13055Unlike most named operators, this is also exempt from the
13056looks-like-a-function rule, so C<return ("foo")."bar"> will
13057cause "bar" to be part of the argument to C<return>.
13058
13059=end original
13060
13061ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも
13062免れるので、C<return ("foo")."bar"> とすると "bar" は C<return> への引数の
13063一部となります。
13064
1306512650=item reverse LIST
1306612651X<reverse> X<rev> X<invert>
1306712652
1306812653=for Pod::Functions flip a string or a list
1306912654
1307012655=begin original
1307112656
1307212657In list context, returns a list value consisting of the elements
1307312658of LIST in the opposite order. In scalar context, concatenates the
1307412659elements of LIST and returns a string value with all characters
1307512660in the opposite order.
1307612661
1307712662=end original
1307812663
1307912664リストコンテキストでは、LIST を構成する要素を逆順に並べた
1308012665リスト値を返します。
1308112666スカラコンテキストでは、LIST の要素を連結して、
1308212667全ての文字を逆順にした文字列を返します。
1308312668
1308412669 print join(", ", reverse "world", "Hello"); # Hello, world
1308512670
1308612671 print scalar reverse "dlrow ,", "olleH"; # Hello, world
1308712672
1308812673=begin original
1308912674
1309012675Used without arguments in scalar context, reverse() reverses C<$_>.
1309112676
1309212677=end original
1309312678
1309412679スカラコンテキストで引数なしで使うと、reverse() は C<$_> を逆順にします。
1309512680
1309612681 $_ = "dlrow ,olleH";
13097 print reverse; # No output, list context
12682 print reverse; # No output, list context
13098 print scalar reverse; # Hello, world
12683 print scalar reverse; # Hello, world
1309912684
1310012685=begin original
1310112686
1310212687Note that reversing an array to itself (as in C<@a = reverse @a>) will
13103preserve non-existent elements whenever possible; i.e., for non-magical
12688preserve non-existent elements whenever possible, i.e., for non magical
13104arrays or for tied arrays with C<EXISTS> and C<DELETE> methods.
12689arrays or tied arrays with C<EXISTS> and C<DELETE> methods.
1310512690
1310612691=end original
1310712692
1310812693(C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、
1310912694存在しない要素は可能なら(つまりマジカルでない配列や
1311012695C<EXISTS> と C<DELETE> メソッドがある tie された配列)
1311112696いつでも保存されることに注意してください。
1311212697
1311312698=begin original
1311412699
1311512700This operator is also handy for inverting a hash, although there are some
1311612701caveats. If a value is duplicated in the original hash, only one of those
1311712702can be represented as a key in the inverted hash. Also, this has to
1311812703unwind one hash and build a whole new one, which may take some time
1311912704on a large hash, such as from a DBM file.
1312012705
1312112706=end original
1312212707
1312312708この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。
1312412709元のハッシュで値が重複していると、それらのうち一つだけが
1312512710逆順になったハッシュのキーとして表現されます。
1312612711また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、
1312712712DBM ファイルからのような大きなハッシュでは少し時間がかかります。
1312812713
1312912714 %by_name = reverse %by_address; # Invert the hash
1313012715
1313112716=item rewinddir DIRHANDLE
1313212717X<rewinddir>
1313312718
1313412719=for Pod::Functions reset directory handle
1313512720
1313612721=begin original
1313712722
1313812723Sets the current position to the beginning of the directory for the
1313912724C<readdir> routine on DIRHANDLE.
1314012725
1314112726=end original
1314212727
1314312728DIRHANDLE に対する C<readdir> ルーチンの現在位置を
1314412729ディレクトリの最初に設定します。
1314512730
1314612731=begin original
1314712732
1314812733Portability issues: L<perlport/rewinddir>.
1314912734
1315012735=end original
1315112736
1315212737移植性の問題: L<perlport/rewinddir>。
1315312738
1315412739=item rindex STR,SUBSTR,POSITION
1315512740X<rindex>
1315612741
1315712742=item rindex STR,SUBSTR
1315812743
1315912744=for Pod::Functions right-to-left substring search
1316012745
1316112746=begin original
1316212747
1316312748Works just like index() except that it returns the position of the I<last>
1316412749occurrence of SUBSTR in STR. If POSITION is specified, returns the
1316512750last occurrence beginning at or before that position.
1316612751
1316712752=end original
1316812753
1316912754STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、
1317012755index() と同じように動作します。
1317112756POSITION を指定すると、その位置から始まるか、その位置より前の、
1317212757最後の位置を返します。
1317312758
1317412759=item rmdir FILENAME
1317512760X<rmdir> X<rd> X<directory, remove>
1317612761
1317712762=item rmdir
1317812763
1317912764=for Pod::Functions remove a directory
1318012765
1318112766=begin original
1318212767
1318312768Deletes the directory specified by FILENAME if that directory is
1318412769empty. If it succeeds it returns true; otherwise it returns false and
1318512770sets C<$!> (errno). If FILENAME is omitted, uses C<$_>.
1318612771
1318712772=end original
1318812773
1318912774FILENAME で指定したディレクトリが空であれば、
1319012775そのディレクトリを削除します。
1319112776成功時には真を返します; さもなければ偽を返して C<$!> (errno) を設定します。
1319212777FILENAME を省略した場合には、C<$_> を使用します。
1319312778
1319412779=begin original
1319512780
1319612781To remove a directory tree recursively (C<rm -rf> on Unix) look at
1319712782the C<rmtree> function of the L<File::Path> module.
1319812783
1319912784=end original
1320012785
1320112786ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、
1320212787L<File::Path> モジュールの C<rmtree> 関数を参照してください。
1320312788
1320412789=item s///
1320512790
1320612791=for Pod::Functions replace a pattern with a string
1320712792
1320812793=begin original
1320912794
1321012795The substitution operator. See L<perlop/"Regexp Quote-Like Operators">.
1321112796
1321212797=end original
1321312798
1321412799置換演算子。
1321512800L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1321612801
1321712802=item say FILEHANDLE LIST
1321812803X<say>
1321912804
1322012805=item say FILEHANDLE
1322112806
1322212807=item say LIST
1322312808
1322412809=item say
1322512810
1322612811=for Pod::Functions +say output a list to a filehandle, appending a newline
1322712812
1322812813=begin original
1322912814
1323012815Just like C<print>, but implicitly appends a newline. C<say LIST> is
1323112816simply an abbreviation for C<{ local $\ = "\n"; print LIST }>. To use
1323212817FILEHANDLE without a LIST to print the contents of C<$_> to it, you must
1323312818use a real filehandle like C<FH>, not an indirect one like C<$fh>.
1323412819
1323512820=end original
1323612821
1323712822C<print> と同様ですが、暗黙に改行が追加されます。
1323812823C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> の省略形です。
1323912824C<$_> の内容を表示するために LIST なしで FILEHANDLE を使用するには、
1324012825C<$fh> のような間接ファイルハンドルではなく、C<FH> のような実際の
1324112826ファイルハンドルを使わなければなりません。
1324212827
1324312828=begin original
1324412829
1324512830This keyword is available only when the C<"say"> feature
1324612831is enabled, or when prefixed with C<CORE::>; see
1324712832L<feature>. Alternately, include a C<use v5.10> or later to the current
1324812833scope.
1324912834
1325012835=end original
1325112836
1325212837このキーワードは、C<"say"> 機能が有効か、C<CORE::> が前置された場合にのみ
1325312838利用可能です; L<feature> を参照してください。
1325412839または、現在のスコープに C<use v5.10> 以降を含めてください。
1325512840
1325612841=item scalar EXPR
1325712842X<scalar> X<context>
1325812843
1325912844=for Pod::Functions force a scalar context
1326012845
1326112846=begin original
1326212847
1326312848Forces EXPR to be interpreted in scalar context and returns the value
1326412849of EXPR.
1326512850
1326612851=end original
1326712852
1326812853EXPR を強制的にスカラコンテキストで解釈されるようにして、
1326912854EXPR の値を返します。
1327012855
1327112856 @counts = ( scalar @a, scalar @b, scalar @c );
1327212857
1327312858=begin original
1327412859
1327512860There is no equivalent operator to force an expression to
1327612861be interpolated in list context because in practice, this is never
1327712862needed. If you really wanted to do so, however, you could use
1327812863the construction C<@{[ (some expression) ]}>, but usually a simple
1327912864C<(some expression)> suffices.
1328012865
1328112866=end original
1328212867
1328312868式を強制的にリストコンテキストで解釈させるようにする演算子はありません;
1328412869理論的には不要だからです。
1328512870それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を
1328612871使えます; しかし、普通は単に C<(some expression)> とすれば十分です。
1328712872
1328812873=begin original
1328912874
1329012875Because C<scalar> is a unary operator, if you accidentally use a
1329112876parenthesized list for the EXPR, this behaves as a scalar comma expression,
1329212877evaluating all but the last element in void context and returning the final
1329312878element evaluated in scalar context. This is seldom what you want.
1329412879
1329512880=end original
1329612881
1329712882C<scalar> は単項演算子なので、EXPR として括弧でくくったリストを使った場合、
1329812883これはスカラカンマ表現として振舞い、最後以外の全ては無効コンテキストとして
1329912884扱われ、最後の要素をスカラコンテキストとして扱った結果が返されます。
1330012885これがあなたの望むものであることはめったにないでしょう。
1330112886
1330212887=begin original
1330312888
1330412889The following single statement:
1330512890
1330612891=end original
1330712892
1330812893以下の一つの文は:
1330912894
1331012895 print uc(scalar(&foo,$bar)),$baz;
1331112896
1331212897=begin original
1331312898
1331412899is the moral equivalent of these two:
1331512900
1331612901=end original
1331712902
1331812903以下の二つの文と等価です。
1331912904
1332012905 &foo;
1332112906 print(uc($bar),$baz);
1332212907
1332312908=begin original
1332412909
1332512910See L<perlop> for more details on unary operators and the comma operator.
1332612911
1332712912=end original
1332812913
1332912914単項演算子とカンマ演算子に関する詳細については L<perlop> を参照してください。
1333012915
1333112916=item seek FILEHANDLE,POSITION,WHENCE
1333212917X<seek> X<fseek> X<filehandle, position>
1333312918
1333412919=for Pod::Functions reposition file pointer for random-access I/O
1333512920
1333612921=begin original
1333712922
1333812923Sets FILEHANDLE's position, just like the C<fseek> call of C<stdio>.
1333912924FILEHANDLE may be an expression whose value gives the name of the
1334012925filehandle. The values for WHENCE are C<0> to set the new position
1334112926I<in bytes> to POSITION; C<1> to set it to the current position plus
1334212927POSITION; and C<2> to set it to EOF plus POSITION, typically
1334312928negative. For WHENCE you may use the constants C<SEEK_SET>,
1334412929C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end
1334512930of the file) from the L<Fcntl> module. Returns C<1> on success, false
1334612931otherwise.
1334712932
1334812933=end original
1334912934
1335012935C<stdio> ライブラリの C<fseek> 関数のように、FILEHANDLE の
1335112936ファイルポインタを任意の位置に設定します。
1335212937FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1335312938WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ
1335412939設定します; C<1> ならば、現在位置から I<バイト数で> POSITION 加えた位置へ
1335512940設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を
1335612941設定します。
1335712942この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、
1335812943C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1335912944使うこともできます。
1336012945成功時には、C<1> を、失敗時には C<0> を返します。
1336112946
1336212947=begin original
1336312948
1336412949Note the I<in bytes>: even if the filehandle has been set to
1336512950operate on characters (for example by using the C<:encoding(utf8)> open
1336612951layer), tell() will return byte offsets, not character offsets
1336712952(because implementing that would render seek() and tell() rather slow).
1336812953
1336912954=end original
1337012955
1337112956I<バイト単位> に関する注意: ファイルハンドルが (例えば C<:encoding(utf8)> 層を
1337212957使って)文字を操作するように設定されていたとしても、tell() は文字の
1337312958オフセットではなくバイトのオフセットを返すことに注意してください
1337412959(なぜならこれを実装すると seek() と tell() が遅くなってしまうからです)。
1337512960
1337612961=begin original
1337712962
1337812963If you want to position the file for C<sysread> or C<syswrite>, don't use
1337912964C<seek>, because buffering makes its effect on the file's read-write position
1338012965unpredictable and non-portable. Use C<sysseek> instead.
1338112966
1338212967=end original
1338312968
1338412969C<sysread> や C<syswrite> のためにファイルの位置を指定したい場合は、
1338512970C<seek> は使えません; なぜならバッファリングのためにファイルの読み込み位置は
1338612971動作は予測不能で移植性のないものになってしまいます。
1338712972代わりに C<sysseek> を使ってください。
1338812973
1338912974=begin original
1339012975
1339112976Due to the rules and rigors of ANSI C, on some systems you have to do a
1339212977seek whenever you switch between reading and writing. Amongst other
1339312978things, this may have the effect of calling stdio's clearerr(3).
1339412979A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position:
1339512980
1339612981=end original
1339712982
1339812983ANSI C の規則と困難により、システムによっては読み込みと書き込みを
1339912984切り替える度にシークしなければならない場合があります。
1340012985その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。
1340112986WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です:
1340212987
1340312988 seek(TEST,0,1);
1340412989
1340512990=begin original
1340612991
1340712992This is also useful for applications emulating C<tail -f>. Once you hit
1340812993EOF on your read and then sleep for a while, you (probably) have to stick in a
1340912994dummy seek() to reset things. The C<seek> doesn't change the position,
1341012995but it I<does> clear the end-of-file condition on the handle, so that the
1341112996next C<< <FILE> >> makes Perl try again to read something. (We hope.)
1341212997
1341312998=end original
1341412999
1341513000これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。
1341613001一度読み込み時に EOF に到達すると、しばらくスリープし、
1341713002(おそらく) ダミーの seek() をすることでリセットする必要があります。
1341813003C<seek> は現在の位置を変更しませんが、ハンドルの EOF 状態を
1341913004I<クリアします> ので、次の C<< <FILE> >> で Perl は再び何かを
1342013005読み込もうとします。(そのはずです。)
1342113006
1342213007=begin original
1342313008
1342413009If that doesn't work (some I/O implementations are particularly
1342513010cantankerous), you might need something like this:
1342613011
1342713012=end original
1342813013
1342913014これが動かない場合(特に意地の悪い I/O 実装もあります)、
1343013015以下のようなことをする必要があります:
1343113016
1343213017 for (;;) {
1343313018 for ($curpos = tell(FILE); $_ = <FILE>;
1343413019 $curpos = tell(FILE)) {
1343513020 # search for some stuff and put it into files
1343613021 }
1343713022 sleep($for_a_while);
1343813023 seek(FILE, $curpos, 0);
1343913024 }
1344013025
1344113026=item seekdir DIRHANDLE,POS
1344213027X<seekdir>
1344313028
1344413029=for Pod::Functions reposition directory pointer
1344513030
1344613031=begin original
1344713032
1344813033Sets the current position for the C<readdir> routine on DIRHANDLE. POS
1344913034must be a value returned by C<telldir>. C<seekdir> also has the same caveats
1345013035about possible directory compaction as the corresponding system library
1345113036routine.
1345213037
1345313038=end original
1345413039
1345513040DIRHANDLE での C<readdir> ルーチンの現在位置を設定します。
1345613041POS は、C<telldir> が返す値でなければなりません。
1345713042C<seekdir> は同名のシステムライブラリルーチンと同じく、
1345813043ディレクトリ縮小時の問題が考えられます。
1345913044
1346013045=item select FILEHANDLE
1346113046X<select> X<filehandle, default>
1346213047
1346313048=item select
1346413049
1346513050=for Pod::Functions reset default output or do I/O multiplexing
1346613051
1346713052=begin original
1346813053
1346913054Returns the currently selected filehandle. If FILEHANDLE is supplied,
1347013055sets the new current default filehandle for output. This has two
1347113056effects: first, a C<write> or a C<print> without a filehandle
1347213057default to this FILEHANDLE. Second, references to variables related to
1347313058output will refer to this output channel.
1347413059
1347513060=end original
1347613061
1347713062その時点で、選択されていたファイルハンドルを返します。
1347813063FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに
1347913064設定します。
1348013065これには、2 つの効果があります: まず、ファイルハンドルを指定しないで
1348113066C<write> や C<print> を行なった場合のデフォルトが、この FILEHANDLE に
1348213067なります。
1348313068もう一つは、出力関連の変数への参照は、この出力チャネルを
1348413069参照するようになります。
1348513070
1348613071=begin original
1348713072
1348813073For example, to set the top-of-form format for more than one
1348913074output channel, you might do the following:
1349013075
1349113076=end original
1349213077
1349313078例えば、複数の出力チャネルに対して、ページ先頭フォーマットを
1349413079設定するには:
1349513080
1349613081 select(REPORT1);
1349713082 $^ = 'report1_top';
1349813083 select(REPORT2);
1349913084 $^ = 'report2_top';
1350013085
1350113086=begin original
1350213087
1350313088FILEHANDLE may be an expression whose value gives the name of the
1350413089actual filehandle. Thus:
1350513090
1350613091=end original
1350713092
1350813093FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
1350913094つまり、以下のようなものです:
1351013095
1351113096 $oldfh = select(STDERR); $| = 1; select($oldfh);
1351213097
1351313098=begin original
1351413099
1351513100Some programmers may prefer to think of filehandles as objects with
1351613101methods, preferring to write the last example as:
1351713102
1351813103=end original
1351913104
1352013105ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む
1352113106プログラマもいるかもしれません; そのような場合のための最後の例は
1352213107以下のようなものです:
1352313108
1352413109 use IO::Handle;
1352513110 STDERR->autoflush(1);
1352613111
1352713112=begin original
1352813113
1352913114Portability issues: L<perlport/select>.
1353013115
1353113116=end original
1353213117
1353313118移植性の問題: L<perlport/select>。
1353413119
1353513120=item select RBITS,WBITS,EBITS,TIMEOUT
1353613121X<select>
1353713122
1353813123=begin original
1353913124
1354013125This calls the select(2) syscall with the bit masks specified, which
1354113126can be constructed using C<fileno> and C<vec>, along these lines:
1354213127
1354313128=end original
1354413129
1354513130これは、select(2) システムコールを、指定したビットマスクで呼び出します;
1354613131ビットマスクは、C<fileno> と C<vec> を使って、以下のようにして
1354713132作成できます:
1354813133
1354913134 $rin = $win = $ein = '';
1355013135 vec($rin, fileno(STDIN), 1) = 1;
1355113136 vec($win, fileno(STDOUT), 1) = 1;
1355213137 $ein = $rin | $win;
1355313138
1355413139=begin original
1355513140
1355613141If you want to select on many filehandles, you may wish to write a
1355713142subroutine like this:
1355813143
1355913144=end original
1356013145
1356113146複数のファイルハンドルに select を行ないたいのであれば、
1356213147以下のようにします:
1356313148
1356413149 sub fhbits {
1356513150 my @fhlist = @_;
1356613151 my $bits = "";
1356713152 for my $fh (@fhlist) {
1356813153 vec($bits, fileno($fh), 1) = 1;
1356913154 }
1357013155 return $bits;
1357113156 }
1357213157 $rin = fhbits(*STDIN, *TTY, *MYSOCK);
1357313158
1357413159=begin original
1357513160
1357613161The usual idiom is:
1357713162
1357813163=end original
1357913164
1358013165通常は、
1358113166
1358213167 ($nfound,$timeleft) =
1358313168 select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
1358413169
1358513170=begin original
1358613171
1358713172or to block until something becomes ready just do this
1358813173
1358913174=end original
1359013175
1359113176のように使い、いずれかの準備が整うまでブロックするには、
1359213177以下のようにします。
1359313178
1359413179 $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
1359513180
1359613181=begin original
1359713182
1359813183Most systems do not bother to return anything useful in $timeleft, so
1359913184calling select() in scalar context just returns $nfound.
1360013185
1360113186=end original
1360213187
1360313188ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、
1360413189select() をスカラコンテキストで呼び出すと、単に $nfound を返します。
1360513190
1360613191=begin original
1360713192
1360813193Any of the bit masks can also be undef. The timeout, if specified, is
1360913194in seconds, which may be fractional. Note: not all implementations are
1361013195capable of returning the $timeleft. If not, they always return
1361113196$timeleft equal to the supplied $timeout.
1361213197
1361313198=end original
1361413199
1361513200どのビットマスクにも undef を設定することができます。
1361613201TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。
1361713202注: すべての実装で、$timeleft が返せるものではありません。
1361813203その場合、$timeleft には、常に指定した TIMEOUT と同じ値が返されます。
1361913204
1362013205=begin original
1362113206
1362213207You can effect a sleep of 250 milliseconds this way:
1362313208
1362413209=end original
1362513210
1362613211250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。
1362713212
1362813213 select(undef, undef, undef, 0.25);
1362913214
1363013215=begin original
1363113216
1363213217Note that whether C<select> gets restarted after signals (say, SIGALRM)
1363313218is implementation-dependent. See also L<perlport> for notes on the
1363413219portability of C<select>.
1363513220
1363613221=end original
1363713222
1363813223C<select> がシグナル (例えば、SIGALRM) の後に再起動するかどうかは
1363913224実装依存であることに注意してください。
1364013225C<select> の移植性に関する注意については L<perlport> も参照してください。
1364113226
1364213227=begin original
1364313228
1364413229On error, C<select> behaves just like select(2): it returns
1364513230-1 and sets C<$!>.
1364613231
1364713232=end original
1364813233
1364913234エラー時は、C<select> は select(2) のように振舞います:
1365013235-1 を返し、C<$!> をセットします。
1365113236
1365213237=begin original
1365313238
1365413239On some Unixes, select(2) may report a socket file descriptor as "ready for
1365513240reading" even when no data is available, and thus any subsequent C<read>
1365613241would block. This can be avoided if you always use O_NONBLOCK on the
1365713242socket. See select(2) and fcntl(2) for further details.
1365813243
1365913244=end original
1366013245
1366113246Unix の中には、実際に利用可能なデータがないために引き続く C<read> が
1366213247ブロックされる場合でも、select(2) が、ソケットファイル記述子が
1366313248「読み込み準備中」であると報告するものもあります。
1366413249これは、ソケットに対して常に O_NONBLOCK フラグを使うことで回避できます。
1366513250さらなる詳細については select(2) と fcntl(2) を参照してください。
1366613251
1366713252=begin original
1366813253
1366913254The standard C<IO::Select> module provides a user-friendlier interface
1367013255to C<select>, mostly because it does all the bit-mask work for you.
1367113256
1367213257=end original
1367313258
1367413259標準の C<IO::Select> モジュールは C<select> へのよりユーザーフレンドリーな
1367513260インターフェースを提供します; 主な理由はビットマスクの仕事を
1367613261してくれることです。
1367713262
1367813263=begin original
1367913264
1368013265B<WARNING>: One should not attempt to mix buffered I/O (like C<read>
1368113266or <FH>) with C<select>, except as permitted by POSIX, and even
1368213267then only on POSIX systems. You have to use C<sysread> instead.
1368313268
1368413269=end original
1368513270
1368613271B<警告>: バッファ付き I/O (C<read> や <FH>) と C<select> を
1368713272混ぜて使ってはいけません(例外: POSIX で認められている形で使い、
1368813273POSIX システムでだけ動かす場合を除きます)。
1368913274代わりに C<sysread> を使わなければなりません。
1369013275
1369113276=begin original
1369213277
1369313278Portability issues: L<perlport/select>.
1369413279
1369513280=end original
1369613281
1369713282移植性の問題: L<perlport/select>。
1369813283
1369913284=item semctl ID,SEMNUM,CMD,ARG
1370013285X<semctl>
1370113286
1370213287=for Pod::Functions SysV semaphore control operations
1370313288
1370413289=begin original
1370513290
1370613291Calls the System V IPC function semctl(2). You'll probably have to say
1370713292
1370813293=end original
1370913294
1371013295System V IPC 関数 semctl(2) を呼び出します。
1371113296正しい定数定義を得るために、まず
1371213297
1371313298 use IPC::SysV;
1371413299
1371513300=begin original
1371613301
1371713302first to get the correct constant definitions. If CMD is IPC_STAT or
1371813303GETALL, then ARG must be a variable that will hold the returned
1371913304semid_ds structure or semaphore value array. Returns like C<ioctl>:
1372013305the undefined value for error, "C<0 but true>" for zero, or the actual
1372113306return value otherwise. The ARG must consist of a vector of native
1372213307short integers, which may be created with C<pack("s!",(0)x$nsem)>.
1372313308See also L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore>
1372413309documentation.
1372513310
1372613311=end original
1372713312
1372813313と書くことが必要でしょう。
1372913314CMD が、IPC_STAT か GETALL のときには、ARG は、返される
1373013315semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。
1373113316C<ioctl> と同じように、エラー時には未定義値、
1373213317ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
1373313318ARG はネイティブな short int のベクターから成っていなければなりません; これは
1373413319C<pack("s!",(0)x$nsem)> で作成できます。
1373513320L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。
1373613321
1373713322=begin original
1373813323
1373913324Portability issues: L<perlport/semctl>.
1374013325
1374113326=end original
1374213327
1374313328移植性の問題: L<perlport/semctl>。
1374413329
1374513330=item semget KEY,NSEMS,FLAGS
1374613331X<semget>
1374713332
1374813333=for Pod::Functions get set of SysV semaphores
1374913334
1375013335=begin original
1375113336
1375213337Calls the System V IPC function semget(2). Returns the semaphore id, or
1375313338the undefined value on error. See also
1375413339L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
1375513340documentation.
1375613341
1375713342=end original
1375813343
1375913344System V IPC 関数 semget(2) を呼び出します。
1376013345セマフォ ID か、エラー時には未定義値を返します。
1376113346L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> も
1376213347参照してください。
1376313348
1376413349=begin original
1376513350
1376613351Portability issues: L<perlport/semget>.
1376713352
1376813353=end original
1376913354
1377013355移植性の問題: L<perlport/semget>。
1377113356
1377213357=item semop KEY,OPSTRING
1377313358X<semop>
1377413359
1377513360=for Pod::Functions SysV semaphore operations
1377613361
1377713362=begin original
1377813363
1377913364Calls the System V IPC function semop(2) for semaphore operations
1378013365such as signalling and waiting. OPSTRING must be a packed array of
1378113366semop structures. Each semop structure can be generated with
1378213367C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
1378313368implies the number of semaphore operations. Returns true if
1378413369successful, false on error. As an example, the
1378513370following code waits on semaphore $semnum of semaphore id $semid:
1378613371
1378713372=end original
1378813373
1378913374シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、
1379013375System V IPC 関数 semop(2) を呼び出します。
1379113376OPSTRING は、semop 構造体の pack された配列でなければなりません。
13792semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように
13377semop 構造体は、それぞれ、
13793作ることができます。
13378C<pack("s!3", $semnum, $semop, $semflag)> のように作ることができます。
1379413379セマフォ操作の数は、OPSTRING の長さからわかります。
1379513380成功時には真を、エラー時には偽を返します。
1379613381以下の例は、セマフォ ID $semid のセマフォ $semnum で
1379713382待ち合わせを行ないます。
1379813383
1379913384 $semop = pack("s!3", $semnum, -1, 0);
1380013385 die "Semaphore trouble: $!\n" unless semop($semid, $semop);
1380113386
1380213387=begin original
1380313388
1380413389To signal the semaphore, replace C<-1> with C<1>. See also
1380513390L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::SysV::Semaphore>
1380613391documentation.
1380713392
1380813393=end original
1380913394
1381013395セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。
1381113396L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> も
1381213397参照してください。
1381313398
1381413399=begin original
1381513400
1381613401Portability issues: L<perlport/semop>.
1381713402
1381813403=end original
1381913404
1382013405移植性の問題: L<perlport/semop>。
1382113406
1382213407=item send SOCKET,MSG,FLAGS,TO
1382313408X<send>
1382413409
1382513410=item send SOCKET,MSG,FLAGS
1382613411
1382713412=for Pod::Functions send a message over a socket
1382813413
1382913414=begin original
1383013415
1383113416Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET
1383213417filehandle. Takes the same flags as the system call of the same name. On
1383313418unconnected sockets, you must specify a destination to I<send to>, in which
1383413419case it does a sendto(2) syscall. Returns the number of characters sent,
1383513420or the undefined value on error. The sendmsg(2) syscall is currently
1383613421unimplemented. See L<perlipc/"UDP: Message Passing"> for examples.
1383713422
1383813423=end original
1383913424
1384013425ソケットにメッセージを送ります。
1384113426スカラ MSG を ファイルハンドル SOCKET に送ろうとします。
1384213427同名のシステムコールと同じフラグが指定できます。
1384313428接続していないソケットには、I<send to> に接続先を指定しなければならず、
1384413429この場合、sendto(2) を実行します。
1384513430送信した文字数か、エラー時には、未定義値を返します。
1384613431システムコール sendmsg(2) は現在実装されていません。
1384713432例については L<perlipc/"UDP: Message Passing"> を参照してください。
1384813433
1384913434=begin original
1385013435
1385113436Note the I<characters>: depending on the status of the socket, either
1385213437(8-bit) bytes or characters are sent. By default all sockets operate
1385313438on bytes, but for example if the socket has been changed using
1385413439binmode() to operate with the C<:encoding(utf8)> I/O layer (see
1385513440L</open>, or the C<open> pragma, L<open>), the I/O will operate on UTF-8
1385613441encoded Unicode characters, not bytes. Similarly for the C<:encoding>
1385713442pragma: in that case pretty much any characters can be sent.
1385813443
1385913444=end original
1386013445
1386113446I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
1386213447文字を送信します。
1386313448デフォルトでは全てのソケットはバイトを処理しますが、
1386413449例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(L</open>、
1386513450C<open> プラグマ、L<open> を参照してください) を使うように指定された場合、
1386613451I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。
1386713452C<:encoding> プラグマも同様です:
1386813453この場合、ほとんど大体全ての文字が書き込めます。
1386913454
1387013455=item setpgrp PID,PGRP
1387113456X<setpgrp> X<group>
1387213457
1387313458=for Pod::Functions set the process group of a process
1387413459
1387513460=begin original
1387613461
1387713462Sets the current process group for the specified PID, C<0> for the current
1387813463process. Raises an exception when used on a machine that doesn't
1387913464implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments are omitted,
1388013465it defaults to C<0,0>. Note that the BSD 4.2 version of C<setpgrp> does not
1388113466accept any arguments, so only C<setpgrp(0,0)> is portable. See also
1388213467C<POSIX::setsid()>.
1388313468
1388413469=end original
1388513470
1388613471指定した PID (C<0> を指定するとカレントプロセス) に
1388713472対するプロセスグループを設定します。
1388813473POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、
1388913474例外が発生します。
1389013475引数が省略された場合は、C<0,0>が使われます。
1389113476BSD 4.2 版の C<setpgrp> は引数を取ることができないので、
1389213477C<setpgrp(0,0)> のみが移植性があることに注意してください。
1389313478C<POSIX::setsid()> も参照してください。
1389413479
1389513480=begin original
1389613481
1389713482Portability issues: L<perlport/setpgrp>.
1389813483
1389913484=end original
1390013485
1390113486移植性の問題: L<perlport/setpgrp>。
1390213487
1390313488=item setpriority WHICH,WHO,PRIORITY
1390413489X<setpriority> X<priority> X<nice> X<renice>
1390513490
1390613491=for Pod::Functions set a process's nice value
1390713492
1390813493=begin original
1390913494
1391013495Sets the current priority for a process, a process group, or a user.
1391113496(See setpriority(2).) Raises an exception when used on a machine
1391213497that doesn't implement setpriority(2).
1391313498
1391413499=end original
1391513500
1391613501プロセス、プロセスグループ、ユーザに対する優先順位を設定します。
1391713502(setpriority(2) を参照してください。)
13918setpriority(2) が実装されていないマシンでは、例外が発生します。
13503setpriority(2) が実装されていないマシンでは、
13504例外が発生します。
1391913505
1392013506=begin original
1392113507
1392213508Portability issues: L<perlport/setpriority>.
1392313509
1392413510=end original
1392513511
1392613512移植性の問題: L<perlport/setpriority>。
1392713513
1392813514=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1392913515X<setsockopt>
1393013516
1393113517=for Pod::Functions set some socket options
1393213518
1393313519=begin original
1393413520
1393513521Sets the socket option requested. Returns C<undef> on error.
1393613522Use integer constants provided by the C<Socket> module for
1393713523LEVEL and OPNAME. Values for LEVEL can also be obtained from
1393813524getprotobyname. OPTVAL might either be a packed string or an integer.
1393913525An integer OPTVAL is shorthand for pack("i", OPTVAL).
1394013526
1394113527=end original
1394213528
1394313529要求したソケットオプションを設定します。
1394413530エラー時には、C<undef> を返します。
1394513531LEVEL と OPNAME には C<Socket> モジュールが提供する整数定数を使います。
1394613532LEVEL の値は getprotobyname から得ることもできます。
1394713533OPTVAL は pack された文字列か整数です。
1394813534整数の OPTVAL は pack("i", OPTVAL) の省略表現です。
1394913535
1395013536=begin original
1395113537
1395213538An example disabling Nagle's algorithm on a socket:
1395313539
1395413540=end original
1395513541
1395613542ソケットに対する Nagle のアルゴリズムを無効にする例です:
1395713543
1395813544 use Socket qw(IPPROTO_TCP TCP_NODELAY);
1395913545 setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1);
1396013546
1396113547=begin original
1396213548
1396313549Portability issues: L<perlport/setsockopt>.
1396413550
1396513551=end original
1396613552
1396713553移植性の問題: L<perlport/setsockopt>。
1396813554
1396913555=item shift ARRAY
1397013556X<shift>
1397113557
1397213558=item shift EXPR
1397313559
1397413560=item shift
1397513561
1397613562=for Pod::Functions remove the first element of an array, and return it
1397713563
1397813564=begin original
1397913565
1398013566Shifts the first value of the array off and returns it, shortening the
1398113567array by 1 and moving everything down. If there are no elements in the
1398213568array, returns the undefined value. If ARRAY is omitted, shifts the
1398313569C<@_> array within the lexical scope of subroutines and formats, and the
1398413570C<@ARGV> array outside a subroutine and also within the lexical scopes
1398513571established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
1398613572C<UNITCHECK {}>, and C<END {}> constructs.
1398713573
1398813574=end original
1398913575
13990配列の最初の値を取り出して、その値を返し、配列を一つ短くして、すべての要素を
13576配列の最初の値を取り出して、その値を返し、配列を一つ
13991前へずらします。
13577短くして、すべての要素を前へずらします。
1399213578配列に要素がなければ、未定義値を返します。
13993ARRAY を省略すると、サブルーチンやフォーマットのレキシカルスコープでは
13579ARRAY を省略すると、
13994C<@_> を、サブルーチンの外側、C<eval STRING>, C<BEGIN {}>, C<INIT {}>,
13580サブルーチンやフォーマットレキシカルスコープ C<@_> を、
13995C<CHECK {}>, C<UNITCHECK {}>, C<END {}> で作成されたレキシカルスコープでは
13581サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
13582C<UNITCHECK {}>, C<END {}> で作成されたレキシカルスコープでは
1399613583C<@ARGV> が用いられます。
1399713584
1399813585=begin original
1399913586
1400013587Starting with Perl 5.14, C<shift> can take a scalar EXPR, which must hold a
1400113588reference to an unblessed array. The argument will be dereferenced
1400213589automatically. This aspect of C<shift> is considered highly experimental.
1400313590The exact behaviour may change in a future version of Perl.
1400413591
1400513592=end original
1400613593
1400713594Perl 5.14 から、C<shift> はスカラの EXPR を取ることができるようになりました;
1400813595これは bless されていない配列へのリファレンスでなければなりません。
1400913596引数は自動的にデリファレンスされます。
1401013597C<shift> のこの動作は高度に実験的であると考えられています。
1401113598正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1401213599
1401313600=begin original
1401413601
1401513602To avoid confusing would-be users of your code who are running earlier
1401613603versions of Perl with mysterious syntax errors, put this sort of thing at
1401713604the top of your file to signal that your code will work I<only> on Perls of
1401813605a recent vintage:
1401913606
1402013607=end original
1402113608
1402213609あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1402313610文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
1402413611I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1402513612書いてください:
1402613613
1402713614 use 5.014; # so push/pop/etc work on scalars (experimental)
1402813615
1402913616=begin original
1403013617
1403113618See also C<unshift>, C<push>, and C<pop>. C<shift> and C<unshift> do the
1403213619same thing to the left end of an array that C<pop> and C<push> do to the
1403313620right end.
1403413621
1403513622=end original
1403613623
1403713624C<unshift>、C<push>、C<pop> も参照してください。
14038C<shift> と C<unshift> は、C<pop> と C<push> が配列の右端で行なうことを、
13625C<shift> と C<unshift> は、C<pop> と
14039左端で行ないます。
13626C<push> が配列の右端で行なうことを、左端で行ないます。
1404013627
1404113628=item shmctl ID,CMD,ARG
1404213629X<shmctl>
1404313630
1404413631=for Pod::Functions SysV shared memory operations
1404513632
1404613633=begin original
1404713634
1404813635Calls the System V IPC function shmctl. You'll probably have to say
1404913636
1405013637=end original
1405113638
1405213639System V IPC 関数 shmctl を呼び出します。
1405313640正しい定数定義を得るために、まず
1405413641
1405513642 use IPC::SysV;
1405613643
1405713644=begin original
1405813645
1405913646first to get the correct constant definitions. If CMD is C<IPC_STAT>,
1406013647then ARG must be a variable that will hold the returned C<shmid_ds>
1406113648structure. Returns like ioctl: C<undef> for error; "C<0> but
1406213649true" for zero; and the actual return value otherwise.
1406313650See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
1406413651
1406513652=end original
1406613653
1406713654と書くことが必要でしょう。
1406813655CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を
1406913656納める変数でなければなりません。
1407013657ioctl と同様です: エラー時には C<undef>; ゼロのときは "C<0> だが真";
1407113658それ以外なら、その値そのものを返します。
1407213659L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。
1407313660
1407413661=begin original
1407513662
1407613663Portability issues: L<perlport/shmctl>.
1407713664
1407813665=end original
1407913666
1408013667移植性の問題: L<perlport/shmctl>。
1408113668
1408213669=item shmget KEY,SIZE,FLAGS
1408313670X<shmget>
1408413671
1408513672=for Pod::Functions get SysV shared memory segment identifier
1408613673
1408713674=begin original
1408813675
1408913676Calls the System V IPC function shmget. Returns the shared memory
1409013677segment id, or C<undef> on error.
1409113678See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
1409213679
1409313680=end original
1409413681
1409513682System V IPC 関数 shmget を呼び出します。
1409613683共有メモリのセグメント ID か、エラー時には C<undef> を返します。
1409713684L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。
1409813685
1409913686=begin original
1410013687
1410113688Portability issues: L<perlport/shmget>.
1410213689
1410313690=end original
1410413691
1410513692移植性の問題: L<perlport/shmget>。
1410613693
1410713694=item shmread ID,VAR,POS,SIZE
1410813695X<shmread>
1410913696X<shmwrite>
1411013697
1411113698=for Pod::Functions read SysV shared memory
1411213699
1411313700=item shmwrite ID,STRING,POS,SIZE
1411413701
1411513702=for Pod::Functions write SysV shared memory
1411613703
1411713704=begin original
1411813705
1411913706Reads or writes the System V shared memory segment ID starting at
1412013707position POS for size SIZE by attaching to it, copying in/out, and
1412113708detaching from it. When reading, VAR must be a variable that will
1412213709hold the data read. When writing, if STRING is too long, only SIZE
1412313710bytes are used; if STRING is too short, nulls are written to fill out
1412413711SIZE bytes. Return true if successful, false on error.
1412513712shmread() taints the variable. See also L<perlipc/"SysV IPC">,
1412613713C<IPC::SysV>, and the C<IPC::Shareable> module from CPAN.
1412713714
1412813715=end original
1412913716
14130System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、
13717System V 共有メモリセグメント ID に対し、アタッチして、
14131デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを
13718コピーを行ない、デタッチするという形で、位置 POS から、
14132行ないます。
13719サイズ SIZE だけ、読み込みか書き込みを行ないます。
14133読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。
13720読み込み時には、VAR は読み込んだデータを納める
13721変数でなければなりません。
1413413722書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます; STRING が
1413513723短すぎる場合には、SIZE バイトを埋めるために、ヌル文字が書き込まれます。
1413613724成功時には真を、エラー時には偽を返します。
1413713725shmread() は変数を汚染します。
14138L<perlipc/"SysV IPC"> および C<IPC::SysV> と、CPAN の C<IPC::Shareable> も
13726L<perlipc/"SysV IPC"> および C<IPC::SysV> と、
14139参照してください。
13727CPAN の C<IPC::Shareable> も参照してください。
1414013728
1414113729=begin original
1414213730
1414313731Portability issues: L<perlport/shmread> and L<perlport/shmwrite>.
1414413732
1414513733=end original
1414613734
1414713735移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。
1414813736
1414913737=item shutdown SOCKET,HOW
1415013738X<shutdown>
1415113739
1415213740=for Pod::Functions close down just half of a socket connection
1415313741
1415413742=begin original
1415513743
1415613744Shuts down a socket connection in the manner indicated by HOW, which
1415713745has the same interpretation as in the syscall of the same name.
1415813746
1415913747=end original
1416013748
1416113749同名のシステムコールと同じように解釈される HOW によって、
1416213750指定された方法でソケット接続のシャットダウンを行ないます。
1416313751
1416413752 shutdown(SOCKET, 0); # I/we have stopped reading data
1416513753 shutdown(SOCKET, 1); # I/we have stopped writing data
1416613754 shutdown(SOCKET, 2); # I/we have stopped using this socket
1416713755
1416813756=begin original
1416913757
1417013758This is useful with sockets when you want to tell the other
1417113759side you're done writing but not done reading, or vice versa.
1417213760It's also a more insistent form of close because it also
1417313761disables the file descriptor in any forked copies in other
1417413762processes.
1417513763
1417613764=end original
1417713765
1417813766これは、こちらがソケットを書き終わったが読み終わっていない、
1417913767またはその逆を相手側に伝えたいときに便利です。
1418013768これはその他のプロセスでフォークしたファイル記述子のコピーも
1418113769無効にするので、よりしつこい閉じ方です。
1418213770
1418313771=begin original
1418413772
1418513773Returns C<1> for success; on error, returns C<undef> if
1418613774the first argument is not a valid filehandle, or returns C<0> and sets
1418713775C<$!> for any other failure.
1418813776
1418913777=end original
1419013778
1419113779成功時には C<1> を返します;
1419213780エラーの場合、最初の引数が有効なファイルハンドルでない場合は C<undef> を
1419313781返し、その他のエラーの場合は C<0> を返してC<$!> をセットします。
1419413782
1419513783=item sin EXPR
1419613784X<sin> X<sine> X<asin> X<arcsine>
1419713785
1419813786=item sin
1419913787
1420013788=for Pod::Functions return the sine of a number
1420113789
1420213790=begin original
1420313791
1420413792Returns the sine of EXPR (expressed in radians). If EXPR is omitted,
1420513793returns sine of C<$_>.
1420613794
1420713795=end original
1420813796
1420913797(ラジアンで示した) EXPR の正弦を返します。
1421013798EXPR が省略されたときには、C<$_> の正弦を返します。
1421113799
1421213800=begin original
1421313801
1421413802For the inverse sine operation, you may use the C<Math::Trig::asin>
1421513803function, or use this relation:
1421613804
1421713805=end original
1421813806
1421913807逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、
1422013808以下の関係を使ってください:
1422113809
1422213810 sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
1422313811
1422413812=item sleep EXPR
1422513813X<sleep> X<pause>
1422613814
1422713815=item sleep
1422813816
1422913817=for Pod::Functions block for some number of seconds
1423013818
1423113819=begin original
1423213820
1423313821Causes the script to sleep for (integer) EXPR seconds, or forever if no
1423413822argument is given. Returns the integer number of seconds actually slept.
1423513823
1423613824=end original
1423713825
1423813826スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に)
1423913827スリープさせます。
1424013828実際にスリープした秒数を返します。
1424113829
1424213830=begin original
1424313831
1424413832May be interrupted if the process receives a signal such as C<SIGALRM>.
1424513833
1424613834=end original
1424713835
1424813836そのプロセスが C<SIGALRM>のようなシグナルを受信すると、
1424913837割り込みがかかります。
1425013838
1425113839 eval {
1425213840 local $SIG{ALARM} = sub { die "Alarm!\n" };
1425313841 sleep;
1425413842 };
1425513843 die $@ unless $@ eq "Alarm!\n";
1425613844
1425713845=begin original
1425813846
1425913847You probably cannot mix C<alarm> and C<sleep> calls, because C<sleep>
1426013848is often implemented using C<alarm>.
1426113849
1426213850=end original
1426313851
1426413852C<sleep> は、C<alarm> を使って実装されることが多いので、C<alarm> と
1426513853C<sleep> は、混ぜて使用することはおそらくできません。
1426613854
1426713855=begin original
1426813856
1426913857On some older systems, it may sleep up to a full second less than what
1427013858you requested, depending on how it counts seconds. Most modern systems
1427113859always sleep the full amount. They may appear to sleep longer than that,
1427213860however, because your process might not be scheduled right away in a
1427313861busy multitasking system.
1427413862
1427513863=end original
1427613864
1427713865古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に
1427813866満たないうちに、スリープから抜ける場合があります。
1427913867最近のシステムでは、常に完全にスリープします。
1428013868しかし、負荷の高いマルチタスクシステムでは
1428113869正しくスケジューリングされないがために
1428213870より長い時間スリープすることがあります。
1428313871
1428413872=begin original
1428513873
1428613874For delays of finer granularity than one second, the Time::HiRes module
1428713875(from CPAN, and starting from Perl 5.8 part of the standard
1428813876distribution) provides usleep(). You may also use Perl's four-argument
1428913877version of select() leaving the first three arguments undefined, or you
1429013878might be able to use the C<syscall> interface to access setitimer(2) if
1429113879your system supports it. See L<perlfaq8> for details.
1429213880
1429313881=end original
1429413882
142951 秒より精度の高いスリープを行なうには、Time::HiRes モジュール(CPAN から、
138831 秒より精度の高いスリープを行なうには、
14296また Perl 5.8 からは標準配布されています) が usleep() を提供します。
13884Time::HiRes モジュール(CPAN から、また Perl 5.8 からは
13885標準配布されています) が usleep() を提供します。
1429713886Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、
1429813887setitimer(2) をサポートしているシステムでは、Perl の
1429913888C<syscall> インタフェースを使ってアクセスすることもできます。
1430013889詳しくは L<perlfaq8> を参照してください。
1430113890
1430213891=begin original
1430313892
1430413893See also the POSIX module's C<pause> function.
1430513894
1430613895=end original
1430713896
1430813897POSIX モジュールの C<pause> 関数も参照してください。
1430913898
1431013899=item socket SOCKET,DOMAIN,TYPE,PROTOCOL
1431113900X<socket>
1431213901
1431313902=for Pod::Functions create a socket
1431413903
1431513904=begin original
1431613905
1431713906Opens a socket of the specified kind and attaches it to filehandle
1431813907SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for
1431913908the syscall of the same name. You should C<use Socket> first
1432013909to get the proper definitions imported. See the examples in
1432113910L<perlipc/"Sockets: Client/Server Communication">.
1432213911
1432313912=end original
1432413913
14325指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。
13914指定した種類のソケットをオープンし、ファイルハンドル
13915SOCKET にアタッチします。
1432613916DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
14327適切な定義を import するために、まず、C<use Socket> とするとよいでしょう。
13917適切な定義を import するために、まず、C<use Socket> と
13918するとよいでしょう。
1432813919L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
1432913920
1433013921=begin original
1433113922
1433213923On systems that support a close-on-exec flag on files, the flag will
1433313924be set for the newly opened file descriptor, as determined by the
1433413925value of $^F. See L<perlvar/$^F>.
1433513926
1433613927=end original
1433713928
1433813929ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1433913930フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
1434013931セットされます。
1434113932L<perlvar/$^F> を参照してください。
1434213933
1434313934=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1434413935X<socketpair>
1434513936
1434613937=for Pod::Functions create a pair of sockets
1434713938
1434813939=begin original
1434913940
1435013941Creates an unnamed pair of sockets in the specified domain, of the
1435113942specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as
1435213943for the syscall of the same name. If unimplemented, raises an exception.
1435313944Returns true if successful.
1435413945
1435513946=end original
1435613947
1435713948指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。
1435813949DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
1435913950実装されていない場合には、例外が発生します。
1436013951成功時には真を返します。
1436113952
1436213953=begin original
1436313954
1436413955On systems that support a close-on-exec flag on files, the flag will
1436513956be set for the newly opened file descriptors, as determined by the value
1436613957of $^F. See L<perlvar/$^F>.
1436713958
1436813959=end original
1436913960
1437013961ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1437113962フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
1437213963セットされます。
1437313964L<perlvar/$^F> を参照してください。
1437413965
1437513966=begin original
1437613967
1437713968Some systems defined C<pipe> in terms of C<socketpair>, in which a call
1437813969to C<pipe(Rdr, Wtr)> is essentially:
1437913970
1438013971=end original
1438113972
1438213973C<pipe> を C<socketpair> を使って定義しているシステムもあります;
1438313974C<pipe(Rdr, Wtr)> は本質的には以下のようになります:
1438413975
1438513976 use Socket;
1438613977 socketpair(Rdr, Wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
1438713978 shutdown(Rdr, 1); # no more writing for reader
1438813979 shutdown(Wtr, 0); # no more reading for writer
1438913980
1439013981=begin original
1439113982
1439213983See L<perlipc> for an example of socketpair use. Perl 5.8 and later will
1439313984emulate socketpair using IP sockets to localhost if your system implements
1439413985sockets but not socketpair.
1439513986
1439613987=end original
1439713988
1439813989socketpair の使用例については L<perlipc> を参照してください。
1439913990Perl 5.8 以降では、システムがソケットを実装しているが socketpair を
1440013991実装していない場合、localhost に対して IP ソケットを使うことで
1440113992socketpair をエミュレートします。
1440213993
1440313994=begin original
1440413995
1440513996Portability issues: L<perlport/socketpair>.
1440613997
1440713998=end original
1440813999
1440914000移植性の問題: L<perlport/socketpair>。
1441014001
1441114002=item sort SUBNAME LIST
1441214003X<sort> X<qsort> X<quicksort> X<mergesort>
1441314004
1441414005=item sort BLOCK LIST
1441514006
1441614007=item sort LIST
1441714008
1441814009=for Pod::Functions sort a list of values
1441914010
1442014011=begin original
1442114012
1442214013In list context, this sorts the LIST and returns the sorted list value.
1442314014In scalar context, the behaviour of C<sort()> is undefined.
1442414015
1442514016=end original
1442614017
1442714018リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。
1442814019スカラコンテキストでは、C<sort()> の振る舞いは未定義です。
1442914020
1443014021=begin original
1443114022
1443214023If SUBNAME or BLOCK is omitted, C<sort>s in standard string comparison
1443314024order. If SUBNAME is specified, it gives the name of a subroutine
1443414025that returns an integer less than, equal to, or greater than C<0>,
1443514026depending on how the elements of the list are to be ordered. (The
1443614027C<< <=> >> and C<cmp> operators are extremely useful in such routines.)
1443714028SUBNAME may be a scalar variable name (unsubscripted), in which case
1443814029the value provides the name of (or a reference to) the actual
1443914030subroutine to use. In place of a SUBNAME, you can provide a BLOCK as
1444014031an anonymous, in-line sort subroutine.
1444114032
1444214033=end original
1444314034
14444SUBNAME や BLOCK を省略すると、標準の文字列比較の順番でソートが行なわれます。
14035SUBNAME や BLOCK を省略すると、標準の文字列比較の順番でソートが
14036行なわれます。
1444514037SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに
1444614038応じて、負、ゼロ、正の整数を返すサブルーチンの名前であると解釈されます。
1444714039(このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、
1444814040たいへん便利です。)
14449SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する
14041SUBNAME は、スカラ変数名(添字なし)でもよく、
14450実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。
14042その場合には、その値が使用する実際のサブルーチンの
14451SUBNAME の代わりに、無名のラインソートルーチンして、BLOCK を
14043前(またはそリファレス)解釈されます。
14452書くことができます。
14044SUBNAME の代わりに、無名のインライン
14045ソートルーチンとして、BLOCK を書くことができます。
1445314046
1445414047=begin original
1445514048
1445614049If the subroutine's prototype is C<($$)>, the elements to be compared are
1445714050passed by reference in C<@_>, as for a normal subroutine. This is slower
1445814051than unprototyped subroutines, where the elements to be compared are passed
1445914052into the subroutine as the package global variables $a and $b (see example
1446014053below). Note that in the latter case, it is usually highly counter-productive
1446114054to declare $a and $b as lexicals.
1446214055
1446314056=end original
1446414057
1446514058サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常の
1446614059サブルーチンと同じように C<@_> の中にリファレンスとして渡されます。
1446714060これはプロトタイプなしのサブルーチンより遅いです; この場合は比較のため
1446814061サブルーチンに渡される二つの要素は、パッケージのグローバル変数 $a と $b で
1446914062渡されます(次の例を参照してください)。
1447014063後者の場合、レキシカルに $a と $b を宣言するのは普通とても逆効果になります。
1447114064
1447214065=begin original
1447314066
1447414067If the subroutine is an XSUB, the elements to be compared are pushed on to
1447514068the stack, the way arguments are usually passed to XSUBs. $a and $b are
1447614069not set.
1447714070
1447814071=end original
1447914072
1448014073サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、
1448114074スタックにプッシュされます。
1448214075$a と $b は設定されません。
1448314076
1448414077=begin original
1448514078
1448614079The values to be compared are always passed by reference and should not
1448714080be modified.
1448814081
1448914082=end original
1449014083
1449114084$a や $b はリファレンスによって渡されるので、変更するべきではありません。
1449214085
1449314086=begin original
1449414087
1449514088You also cannot exit out of the sort block or subroutine using any of the
1449614089loop control operators described in L<perlsyn> or with C<goto>.
1449714090
1449814091=end original
1449914092
1450014093また、ソートブロックやサブルーチンから L<perlsyn> で説明されている
1450114094ループ制御子や C<goto> を使って抜けてはいけません。
1450214095
1450314096=begin original
1450414097
1450514098When C<use locale> (but not C<use locale 'not_characters'>) is in
1450614099effect, C<sort LIST> sorts LIST according to the
1450714100current collation locale. See L<perllocale>.
1450814101
1450914102=end original
1451014103
1451114104C<use locale> が有効(そして C<use locale 'not_characters'> が有効でない)の
1451214105場合、C<sort LIST> は LIST を現在の比較ロケールに従ってソートします。
1451314106L<perllocale> を参照してください。
1451414107
1451514108=begin original
1451614109
1451714110sort() returns aliases into the original list, much as a for loop's index
1451814111variable aliases the list elements. That is, modifying an element of a
1451914112list returned by sort() (for example, in a C<foreach>, C<map> or C<grep>)
1452014113actually modifies the element in the original list. This is usually
1452114114something to be avoided when writing clear code.
1452214115
1452314116=end original
1452414117
1452514118sort() は元のリストへのエイリアスを返します; for ループのインデックス変数が
1452614119リスト要素へのエイリアスと同様です。
1452714120つまり、sort() で返されるリストの要素を(例えば、C<foreach> や C<map> や
1452814121C<grep> で)変更すると、実際に元のリストの要素が変更されます。
1452914122これはきれいなコードを書くときには普通は回避されます。
1453014123
1453114124=begin original
1453214125
1453314126Perl 5.6 and earlier used a quicksort algorithm to implement sort.
1453414127That algorithm was not stable, so I<could> go quadratic. (A I<stable> sort
1453514128preserves the input order of elements that compare equal. Although
1453614129quicksort's run time is O(NlogN) when averaged over all arrays of
1453714130length N, the time can be O(N**2), I<quadratic> behavior, for some
1453814131inputs.) In 5.7, the quicksort implementation was replaced with
1453914132a stable mergesort algorithm whose worst-case behavior is O(NlogN).
1454014133But benchmarks indicated that for some inputs, on some platforms,
1454114134the original quicksort was faster. 5.8 has a sort pragma for
1454214135limited control of the sort. Its rather blunt control of the
1454314136underlying algorithm may not persist into future Perls, but the
1454414137ability to characterize the input or output in implementation
1454514138independent ways quite probably will. See L<the sort pragma|sort>.
1454614139
1454714140=end original
1454814141
1454914142Perl 5.6 以前ではソートの実装にクイックソートアルゴリズムを使っていました。
14550このアルゴリズムは安定していないので、2 乗の時間が掛かる I<可能性があります>。
14143このアルゴリズムは安定していないので、2 乗の時間が掛かる
14144I<可能性があります>。
1455114145(I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。
14552クイックソートの実行時間は、長さ N の全ての配列の平均では O(NlogN) ですが、
14146クイックソートの実行時間は、長さ N の全ての配列の平均では
14553入力によっては O(N**2) という I<2 乗の> 振る舞いをすることがあります。)
14147O(NlogN) ですが、入力によっては O(N**2) という I<2 乗の> 振る舞いを
145545.7 では、クイックソートによ実装は、最悪の場合の振る舞いも O(NlogN) でる、
14148ことがります。)
14555安定したマージソートアルゴリズム置き換えられました。
141495.7 では、クイックソートによる実装は、最悪の場合の振る舞いも
14556しかし入力とプラットフォームによっては、ベンチマークはクイックソートの方が
14150O(NlogN) である安定したマーソートアルゴリズムに置き換えられました。
14557速くなります。
14151しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの
14152方が速くなります。
14558141535.8 ではソートを限定的に制御できる sort プラグマがあります。
1455914154この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも
1456014155しれませんが、実装に依存しない形で入力や出力を性格付ける機能は
1456114156おそらくあります。
1456214157L<the sort pragma|sort> を参照してください。
1456314158
1456414159=begin original
1456514160
1456614161Examples:
1456714162
1456814163=end original
1456914164
1457014165例:
1457114166
1457214167 # sort lexically
1457314168 @articles = sort @files;
14169
1457514170 # same thing, but with explicit sort routine
1457614171 @articles = sort {$a cmp $b} @files;
14172
1457814173 # now case-insensitively
1457914174 @articles = sort {fc($a) cmp fc($b)} @files;
14175
1458114176 # same thing in reversed order
1458214177 @articles = sort {$b cmp $a} @files;
14178
1458414179 # sort numerically ascending
1458514180 @articles = sort {$a <=> $b} @files;
14181
1458714182 # sort numerically descending
1458814183 @articles = sort {$b <=> $a} @files;
14184
1459014185 # this sorts the %age hash by value instead of key
1459114186 # using an in-line function
1459214187 @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
14188
1459414189 # sort using explicit subroutine name
1459514190 sub byage {
1459614191 $age{$a} <=> $age{$b}; # presuming numeric
1459714192 }
1459814193 @sortedclass = sort byage @class;
14194
1460014195 sub backwards { $b cmp $a }
1460114196 @harry = qw(dog cat x Cain Abel);
1460214197 @george = qw(gone chased yz Punished Axed);
1460314198 print sort @harry;
1460414199 # prints AbelCaincatdogx
1460514200 print sort backwards @harry;
1460614201 # prints xdogcatCainAbel
1460714202 print sort @george, 'to', @harry;
1460814203 # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
1460914204
1461014205 # inefficiently sort by descending numeric compare using
1461114206 # the first integer after the first = sign, or the
1461214207 # whole record case-insensitively otherwise
1461314208
1461414209 my @new = sort {
1461514210 ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
1461614211 ||
1461714212 fc($a) cmp fc($b)
1461814213 } @old;
1461914214
1462014215 # same thing, but much more efficiently;
1462114216 # we'll build auxiliary indices instead
1462214217 # for speed
1462314218 my @nums = @caps = ();
1462414219 for (@old) {
1462514220 push @nums, ( /=(\d+)/ ? $1 : undef );
1462614221 push @caps, fc($_);
1462714222 }
1462814223
1462914224 my @new = @old[ sort {
1463014225 $nums[$b] <=> $nums[$a]
1463114226 ||
1463214227 $caps[$a] cmp $caps[$b]
1463314228 } 0..$#old
1463414229 ];
1463514230
1463614231 # same thing, but without any temps
1463714232 @new = map { $_->[0] }
1463814233 sort { $b->[1] <=> $a->[1]
1463914234 ||
1464014235 $a->[2] cmp $b->[2]
1464114236 } map { [$_, /=(\d+)/, fc($_)] } @old;
1464214237
1464314238 # using a prototype allows you to use any comparison subroutine
1464414239 # as a sort subroutine (including other package's subroutines)
1464514240 package other;
14646 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are
14241 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are not set here
14647 # not set here
14242
1464814243 package main;
1464914244 @new = sort other::backwards @old;
14245
1465114246 # guarantee stability, regardless of algorithm
1465214247 use sort 'stable';
1465314248 @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
14249
1465514250 # force use of mergesort (not portable outside Perl 5.8)
1465614251 use sort '_mergesort'; # note discouraging _
1465714252 @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
1465814253
1465914254=begin original
1466014255
1466114256Warning: syntactical care is required when sorting the list returned from
1466214257a function. If you want to sort the list returned by the function call
1466314258C<find_records(@key)>, you can use:
1466414259
1466514260=end original
1466614261
1466714262警告: 関数からかえされたリストをソートするときには文法上の注意が必要です。
1466814263関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、
1466914264以下のように出来ます:
1467014265
1467114266 @contact = sort { $a cmp $b } find_records @key;
1467214267 @contact = sort +find_records(@key);
1467314268 @contact = sort &find_records(@key);
1467414269 @contact = sort(find_records(@key));
1467514270
1467614271=begin original
1467714272
1467814273If instead you want to sort the array @key with the comparison routine
1467914274C<find_records()> then you can use:
1468014275
1468114276=end original
1468214277
1468314278一方、配列 @key を比較ルーチン C<find_records()> でソートしたい場合は、
1468414279以下のように出来ます:
1468514280
1468614281 @contact = sort { find_records() } @key;
1468714282 @contact = sort find_records(@key);
1468814283 @contact = sort(find_records @key);
1468914284 @contact = sort(find_records (@key));
1469014285
1469114286=begin original
1469214287
1469314288If you're using strict, you I<must not> declare $a
1469414289and $b as lexicals. They are package globals. That means
1469514290that if you're in the C<main> package and type
1469614291
1469714292=end original
1469814293
14699use strict している場合、$a と $b をレキシカルとして宣言しては I<いけません>。
14294use strict している場合、$a と $b をレキシカルとして
14295宣言しては I<いけません>。
1470014296これはパッケージグローバルです。
1470114297つまり、C<main> パッケージで以下のように書いた場合:
1470214298
1470314299 @articles = sort {$b <=> $a} @files;
1470414300
1470514301=begin original
1470614302
1470714303then C<$a> and C<$b> are C<$main::a> and C<$main::b> (or C<$::a> and C<$::b>),
1470814304but if you're in the C<FooPack> package, it's the same as typing
1470914305
1471014306=end original
1471114307
1471214308C<$a> と C<$b> は C<$main::a> と C<$main::b> (または C<$::a> と C<$::b>) を
1471314309意味しますが、C<FooPack> パッケージ内の場合、これは以下と同じになります:
1471414310
1471514311 @articles = sort {$FooPack::b <=> $FooPack::a} @files;
1471614312
1471714313=begin original
1471814314
1471914315The comparison function is required to behave. If it returns
1472014316inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and
1472114317sometimes saying the opposite, for example) the results are not
1472214318well-defined.
1472314319
1472414320=end original
1472514321
1472614322比較関数は一貫した振る舞いをすることが求められます。
1472714323一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より
1472814324小さいと返し、またあるときは逆を返す)場合、結果は未定義です。
1472914325
1473014326=begin original
1473114327
1473214328Because C<< <=> >> returns C<undef> when either operand is C<NaN>
1473314329(not-a-number), be careful when sorting with a
1473414330comparison function like C<< $a <=> $b >> any lists that might contain a
1473514331C<NaN>. The following example takes advantage that C<NaN != NaN> to
1473614332eliminate any C<NaN>s from the input list.
1473714333
1473814334=end original
1473914335
14740C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに C<undef> を
14336C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに
14741返すので、C<< $a <=> $b >> といった比較関数でソートる場合はリストに
14337C<undef> を返ので、
14742C<NaN> が含まれないように注意してください。
14338C<< $a <=> $b >> といった比較関数でソートする場合はリストに C<NaN> が
14339含まれないように注意してください。
1474314340以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を
1474414341利用しています。
1474514342
1474614343 @result = sort { $a <=> $b } grep { $_ == $_ } @input;
1474714344
1474814345=item splice ARRAY or EXPR,OFFSET,LENGTH,LIST
1474914346X<splice>
1475014347
1475114348=item splice ARRAY or EXPR,OFFSET,LENGTH
1475214349
1475314350=item splice ARRAY or EXPR,OFFSET
1475414351
1475514352=item splice ARRAY or EXPR
1475614353
1475714354=for Pod::Functions add or remove elements anywhere in an array
1475814355
1475914356=begin original
1476014357
1476114358Removes the elements designated by OFFSET and LENGTH from an array, and
1476214359replaces them with the elements of LIST, if any. In list context,
1476314360returns the elements removed from the array. In scalar context,
1476414361returns the last element removed, or C<undef> if no elements are
1476514362removed. The array grows or shrinks as necessary.
1476614363If OFFSET is negative then it starts that far from the end of the array.
1476714364If LENGTH is omitted, removes everything from OFFSET onward.
1476814365If LENGTH is negative, removes the elements from OFFSET onward
1476914366except for -LENGTH elements at the end of the array.
1477014367If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
14771past the end of the array and a LENGTH was provided, Perl issues a warning,
14368past the end of the array, Perl issues a warning, and splices at the
14772and splices at the end of the array.
14369end of the array.
1477314370
1477414371=end original
1477514372
1477614373ARRAY から OFFSET、LENGTH で指定される要素を取り除き、
1477714374LIST があれば、それを代わりに挿入します。
1477814375リストコンテキストでは、配列から取り除かれた要素を返します。
1477914376スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が
1478014377取り除かれなかった場合は C<undef> を返します。
1478114378配列は、必要に応じて、大きくなったり、小さくなったりします。
1478214379OFFSET が負の数の場合は、配列の最後からの距離を示します。
1478314380LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。
1478414381LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を
1478514382除いて取り除きます。
1478614383OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。
14787OFFSET が配列の最後より後ろ LENGTH が指定されていると、Perl は警告を出し、
14384OFFSET が配列の最後より後ろの場合、Perl は警告を出し、配列の最後に対して
14788配列の最後に対して処理します。
14385処理します。
1478914386
1479014387=begin original
1479114388
1479214389The following equivalences hold (assuming C<< $#a >= $i >> )
1479314390
1479414391=end original
1479514392
1479614393以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。
1479714394
1479814395 push(@a,$x,$y) splice(@a,@a,0,$x,$y)
1479914396 pop(@a) splice(@a,-1)
1480014397 shift(@a) splice(@a,0,1)
1480114398 unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
1480214399 $a[$i] = $y splice(@a,$i,1,$y)
1480314400
1480414401=begin original
1480514402
14806C<splice> can be used, for example, to implement n-ary queue processing:
14403Example, assuming array lengths are passed before arrays:
1480714404
1480814405=end original
1480914406
14810C<splice> は、例えば、n-ary キュー処理実装使えます:
14407次の例では、配列、それぞれの配列の大きさが渡されるものとしています:
1481114408
14812 sub nary_print {
14409 sub aeq { # compare two list values
14813 my $n = shift;
14410 my(@a) = splice(@_,0,shift);
14814 while (my @next_n = splice @_, 0, $n) {
14411 my(@b) = splice(@_,0,shift);
14815 say join q{ -- }, @next_n;
14412 return 0 unless @a == @b; # same len?
14816 }
14413 while (@a) {
14414 return 0 if pop(@a) ne pop(@b);
14415 }
14416 return 1;
1481714417 }
14418 if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
1481814419
14819 nary_print(3, qw(a b c d e f g h));
14820 # prints:
14821 # a -- b -- c
14822 # d -- e -- f
14823 # g -- h
14824
1482514420=begin original
1482614421
1482714422Starting with Perl 5.14, C<splice> can take scalar EXPR, which must hold a
1482814423reference to an unblessed array. The argument will be dereferenced
1482914424automatically. This aspect of C<splice> is considered highly experimental.
1483014425The exact behaviour may change in a future version of Perl.
1483114426
1483214427=end original
1483314428
1483414429Perl 5.14 から、C<splice> はスカラの EXPR を取ることができるようになりました;
1483514430これは bless されていない配列へのリファレンスでなければなりません。
1483614431引数は自動的にデリファレンスされます。
1483714432C<splice> のこの動作は高度に実験的であると考えられています。
1483814433正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1483914434
1484014435=begin original
1484114436
1484214437To avoid confusing would-be users of your code who are running earlier
1484314438versions of Perl with mysterious syntax errors, put this sort of thing at
1484414439the top of your file to signal that your code will work I<only> on Perls of
1484514440a recent vintage:
1484614441
1484714442=end original
1484814443
1484914444あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1485014445文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
1485114446I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1485214447書いてください:
1485314448
1485414449 use 5.014; # so push/pop/etc work on scalars (experimental)
1485514450
1485614451=item split /PATTERN/,EXPR,LIMIT
1485714452X<split>
1485814453
1485914454=item split /PATTERN/,EXPR
1486014455
1486114456=item split /PATTERN/
1486214457
1486314458=item split
1486414459
1486514460=for Pod::Functions split up a string using a regexp delimiter
1486614461
1486714462=begin original
1486814463
1486914464Splits the string EXPR into a list of strings and returns the
1487014465list in list context, or the size of the list in scalar context.
1487114466
1487214467=end original
1487314468
1487414469文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリストを
1487514470返し、スカラコンテキストではリストの大きさを返します。
1487614471
1487714472=begin original
1487814473
1487914474If only PATTERN is given, EXPR defaults to C<$_>.
1488014475
1488114476=end original
1488214477
1488314478PATTERN のみが与えられた場合、EXPR のデフォルトは C<$_> です。
1488414479
1488514480=begin original
1488614481
1488714482Anything in EXPR that matches PATTERN is taken to be a separator
1488814483that separates the EXPR into substrings (called "I<fields>") that
1488914484do B<not> include the separator. Note that a separator may be
1489014485longer than one character or even have no characters at all (the
1489114486empty string, which is a zero-width match).
1489214487
1489314488=end original
1489414489
1489514490EXPR の中で PATTERN にマッチングするものは何でも EXPR を("I<fields>" と
1489614491呼ばれる)セパレータを B<含まない> 部分文字列に分割するための
1489714492セパレータとなります。
1489814493セパレータは一文字より長くてもよく、全く文字がなくてもよい(空文字列は
1489914494ゼロ幅マッチングです)ということに注意してください。
1490014495
1490114496=begin original
1490214497
1490314498The PATTERN need not be constant; an expression may be used
1490414499to specify a pattern that varies at runtime.
1490514500
1490614501=end original
1490714502
1490814503PATTERN は定数である必要はありません; 実行時に変更されるパターンを
1490914504指定するために式を使えます。
1491014505
1491114506=begin original
1491214507
1491314508If PATTERN matches the empty string, the EXPR is split at the match
1491414509position (between characters). As an example, the following:
1491514510
1491614511=end original
1491714512
1491814513PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置
1491914514(文字の間)で分割されます。
1492014515例えば、以下のものは:
1492114516
1492214517 print join(':', split('b', 'abc')), "\n";
1492314518
1492414519=begin original
1492514520
1492614521uses the 'b' in 'abc' as a separator to produce the output 'a:c'.
1492714522However, this:
1492814523
1492914524=end original
1493014525
1493114526'abc' の 'b' をセパレータとして使って出力 'a:c' を生成します。
1493214527しかし、これは:
1493314528
1493414529 print join(':', split('', 'abc')), "\n";
1493514530
1493614531=begin original
1493714532
1493814533uses empty string matches as separators to produce the output
1493914534'a:b:c'; thus, the empty string may be used to split EXPR into a
1494014535list of its component characters.
1494114536
1494214537=end original
1494314538
1494414539空文字列マッチングをセパレータとして使って出力 'a:b:c' を生成します; 従って、
1494514540空文字列は EXPR を構成する文字のリストに分割するために使われます。
1494614541
1494714542=begin original
1494814543
1494914544As a special case for C<split>, the empty pattern given in
1495014545L<match operator|perlop/"m/PATTERN/msixpodualgc"> syntax (C<//>) specifically matches the empty string, which is contrary to its usual
1495114546interpretation as the last successful match.
1495214547
1495314548=end original
1495414549
1495514550C<split> の特殊な場合として、
1495614551L<マッチング演算子|perlop/"m/PATTERN/msixpodualgc"> 文法で与えられた
1495714552空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した
1495814553マッチングという普通の解釈と異なります。
1495914554
1496014555=begin original
1496114556
1496214557If PATTERN is C</^/>, then it is treated as if it used the
1496314558L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it
1496414559isn't much use otherwise.
1496514560
1496614561=end original
1496714562
1496814563PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS>
1496914564(C</^/m>) が使われたかのように扱われます; そうでなければほとんど
1497014565使えないからです。
1497114566
1497214567=begin original
1497314568
1497414569As another special case, C<split> emulates the default behavior of the
1497514570command line tool B<awk> when the PATTERN is either omitted or a I<literal
1497614571string> composed of a single space character (such as S<C<' '>> or
1497714572S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading
1497814573whitespace in EXPR is removed before splitting occurs, and the PATTERN is
1497914574instead treated as if it were C</\s+/>; in particular, this means that
1498014575I<any> contiguous whitespace (not just a single space character) is used as
1498114576a separator. However, this special treatment can be avoided by specifying
1498214577the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
14983only a single space character to be a separator. In earlier Perls this
14578only a single space character to be a separator.
14984special case was restricted to the use of a plain S<C<" ">> as the
14985pattern argument to split, in Perl 5.18.0 and later this special case is
14986triggered by any expression which evaluates as the simple string S<C<" ">>.
1498714579
1498814580=end original
1498914581
1499014582もう一つの特別な場合として、C<split> は PATTERN が省略されるか
1499114583単一のスペース文字からなる I<リテラル文字列> (つまり例えば
1499214584S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール
1499314585B<awk> のデフォルトの振る舞いをエミュレートします。
1499414586この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は
1499514587C</\s+/> であったかのように扱われます; 特に、これは (単に単一の
1499614588スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして
1499714589使われるということです。
1499814590しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を
14999指定することで回避でき、それによってセパレータとして単一の
14591指定することで回避でき、それによってセパレータとして単一の
1500014592スペース文字のみが使われます。
15001以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を
15002使った場合に制限されていましたが、Perl 5.18.0 以降では、この特別な場合は
15003単純な文字列 S<C<" ">> に評価される任意の式によって引き起こされます。
1500414593
1500514594=begin original
1500614595
1500714596If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering
1500814597the previously described I<awk> emulation.
1500914598
1501014599=end original
1501114600
1501214601省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、
1501314602先に記述した I<awk> エミュレーションを起動します。
1501414603
1501514604=begin original
1501614605
1501714606If LIMIT is specified and positive, it represents the maximum number
1501814607of fields into which the EXPR may be split; in other words, LIMIT is
1501914608one greater than the maximum number of times EXPR may be split. Thus,
1502014609the LIMIT value C<1> means that EXPR may be split a maximum of zero
1502114610times, producing a maximum of one field (namely, the entire value of
1502214611EXPR). For instance:
1502314612
1502414613=end original
1502514614
1502614615LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を
15027表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。
14616表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい
14617数です。
1502814618従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、
1502914619最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。
1503014620例えば:
1503114621
1503214622 print join(':', split(//, 'abc', 1)), "\n";
1503314623
1503414624=begin original
1503514625
1503614626produces the output 'abc', and this:
1503714627
1503814628=end original
1503914629
1504014630これは 'abc' を出力し、次のものは:
1504114631
1504214632 print join(':', split(//, 'abc', 2)), "\n";
1504314633
1504414634=begin original
1504514635
1504614636produces the output 'a:bc', and each of these:
1504714637
1504814638=end original
1504914639
1505014640'a:bc' を出力し、以下のものそれぞれは:
1505114641
1505214642 print join(':', split(//, 'abc', 3)), "\n";
1505314643 print join(':', split(//, 'abc', 4)), "\n";
1505414644
1505514645=begin original
1505614646
1505714647produces the output 'a:b:c'.
1505814648
1505914649=end original
1506014650
1506114651'a:b:c' を出力します。
1506214652
1506314653=begin original
1506414654
1506514655If LIMIT is negative, it is treated as if it were instead arbitrarily
1506614656large; as many fields as possible are produced.
1506714657
1506814658=end original
1506914659
1507014660LIMIT が負数なら、非常に大きい数であるかのように扱われます; できるだけ多くの
1507114661フィールドが生成されます。
1507214662
1507314663=begin original
1507414664
1507514665If LIMIT is omitted (or, equivalently, zero), then it is usually
1507614666treated as if it were instead negative but with the exception that
1507714667trailing empty fields are stripped (empty leading fields are always
1507814668preserved); if all fields are empty, then all fields are considered to
1507914669be trailing (and are thus stripped in this case). Thus, the following:
1508014670
1508114671=end original
1508214672
1508314673LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように
1508414674動作しますが、末尾の空フィールドは取り除かれるという例外があります
1508514675(先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、
1508614676全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。
1508714677従って、以下のようにすると:
1508814678
1508914679 print join(':', split(',', 'a,b,c,,,')), "\n";
1509014680
1509114681=begin original
1509214682
1509314683produces the output 'a:b:c', but the following:
1509414684
1509514685=end original
1509614686
1509714687出力 'a:b:c' を生成しますが、以下のようにすると:
1509814688
1509914689 print join(':', split(',', 'a,b,c,,,', -1)), "\n";
1510014690
1510114691=begin original
1510214692
1510314693produces the output 'a:b:c:::'.
1510414694
1510514695=end original
1510614696
1510714697出力 'a:b:c:::' を生成します。
1510814698
1510914699=begin original
1511014700
1511114701In time-critical applications, it is worthwhile to avoid splitting
1511214702into more fields than necessary. Thus, when assigning to a list,
1511314703if LIMIT is omitted (or zero), then LIMIT is treated as though it
1511414704were one larger than the number of variables in the list; for the
15115following, LIMIT is implicitly 3:
14705following, LIMIT is implicitly 4:
1511614706
1511714707=end original
1511814708
1511914709時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは
1512014710価値があります。
1512114711従って、リストに代入される場合に、LIMIT が省略される(または 0)と、
1512214712LIMIT は リストにある変数の数より一つ大きい数のように扱われます;
15123次の場合、LIMIT は暗黙に 3 になります:
14713次の場合、LIMIT は暗黙に 4 になります:
1512414714
15125 ($login, $passwd) = split(/:/);
14715 ($login, $passwd, $remainder) = split(/:/);
1512614716
1512714717=begin original
1512814718
1512914719Note that splitting an EXPR that evaluates to the empty string always
1513014720produces zero fields, regardless of the LIMIT specified.
1513114721
1513214722=end original
1513314723
1513414724LIMIT の指定に関わらず、空文字列に評価される EXPR を分割すると常に 0 個の
1513514725フィールドを生成することに注意してください。
1513614726
1513714727=begin original
1513814728
1513914729An empty leading field is produced when there is a positive-width
1514014730match at the beginning of EXPR. For instance:
1514114731
1514214732=end original
1514314733
1514414734EXPR の先頭で正数幅でマッチングしたときには先頭に空のフィールドが
1514514735生成されます。
1514614736例えば:
1514714737
1514814738 print join(':', split(/ /, ' abc')), "\n";
1514914739
1515014740=begin original
1515114741
1515214742produces the output ':abc'. However, a zero-width match at the
1515314743beginning of EXPR never produces an empty field, so that:
1515414744
1515514745=end original
1515614746
1515714747これは出力 ':abc' を生成します。
1515814748しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので:
1515914749
1516014750 print join(':', split(//, ' abc'));
1516114751
1516214752=begin original
1516314753
1516414754produces the output S<' :a:b:c'> (rather than S<': :a:b:c'>).
1516514755
1516614756=end original
1516714757
1516814758これは(S<': :a:b:c'> ではなく)出力 S<' :a:b:c'> を生成します。
1516914759
1517014760=begin original
1517114761
1517214762An empty trailing field, on the other hand, is produced when there is a
1517314763match at the end of EXPR, regardless of the length of the match
1517414764(of course, unless a non-zero LIMIT is given explicitly, such fields are
1517514765removed, as in the last example). Thus:
1517614766
1517714767=end original
1517814768
1517914769一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で
1518014770マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に
1518114771指定されていない場合です; このようなフィールドは前の例のように
1518214772取り除かれます)。
1518314773従って:
1518414774
1518514775 print join(':', split(//, ' abc', -1)), "\n";
1518614776
1518714777=begin original
1518814778
1518914779produces the output S<' :a:b:c:'>.
1519014780
1519114781=end original
1519214782
1519314783これは出力 S<' :a:b:c:'> を生成します。
1519414784
1519514785=begin original
1519614786
1519714787If the PATTERN contains
1519814788L<capturing groups|perlretut/Grouping things and hierarchical matching>,
1519914789then for each separator, an additional field is produced for each substring
1520014790captured by a group (in the order in which the groups are specified,
1520114791as per L<backreferences|perlretut/Backreferences>); if any group does not
1520214792match, then it captures the C<undef> value instead of a substring. Also,
1520314793note that any such additional field is produced whenever there is a
1520414794separator (that is, whenever a split occurs), and such an additional field
1520514795does B<not> count towards the LIMIT. Consider the following expressions
1520614796evaluated in list context (each returned list is provided in the associated
1520714797comment):
1520814798
1520914799=end original
1521014800
1521114801PATTERN が
1521214802L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を
1521314803含んでいる場合、それぞれのセパレータについて、
1521414804(L<後方参照|perlretut/Backreferences> のようにグループが指定された)
1521514805グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが
1521614806生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに
1521714807C<undef> 値を捕捉します。
1521814808また、このような追加のフィールドはセパレータがあるとき(つまり、分割が
1521914809行われるとき)はいつでも生成され、このような追加のフィールドは
1522014810LIMIT に関してはカウント B<されない> ことに注意してください。
1522114811リストコンテキストで評価される以下のような式を考えます
1522214812(それぞれの返されるリストは関連づけられたコメントで提供されます):
1522314813
1522414814 split(/-|,/, "1-10,20", 3)
1522514815 # ('1', '10', '20')
1522614816
1522714817 split(/(-|,)/, "1-10,20", 3)
1522814818 # ('1', '-', '10', ',', '20')
1522914819
1523014820 split(/-|(,)/, "1-10,20", 3)
1523114821 # ('1', undef, '10', ',', '20')
1523214822
1523314823 split(/(-)|,/, "1-10,20", 3)
1523414824 # ('1', '-', '10', undef, '20')
1523514825
1523614826 split(/(-)|(,)/, "1-10,20", 3)
1523714827 # ('1', '-', undef, '10', undef, ',', '20')
1523814828
1523914829=item sprintf FORMAT, LIST
1524014830X<sprintf>
1524114831
1524214832=for Pod::Functions formatted print into a string
1524314833
1524414834=begin original
1524514835
1524614836Returns a string formatted by the usual C<printf> conventions of the C
1524714837library function C<sprintf>. See below for more details
1524814838and see L<sprintf(3)> or L<printf(3)> on your system for an explanation of
1524914839the general principles.
1525014840
1525114841=end original
1525214842
1525314843普通の C 言語の C<printf> 記法のフォーマットで、整形された文字列を返します。
1525414844一般的な原則の説明については以下の説明と、システムの
1525514845L<sprintf(3)> または L<printf(3)> の説明を参照してください。
1525614846
1525714847=begin original
1525814848
1525914849For example:
1526014850
1526114851=end original
1526214852
1526314853例えば:
1526414854
1526514855 # Format number with up to 8 leading zeroes
1526614856 $result = sprintf("%08d", $number);
1526714857
1526814858 # Round number to 3 digits after decimal point
1526914859 $rounded = sprintf("%.3f", $number);
1527014860
1527114861=begin original
1527214862
1527314863Perl does its own C<sprintf> formatting: it emulates the C
1527414864function sprintf(3), but doesn't use it except for floating-point
1527514865numbers, and even then only standard modifiers are allowed.
1527614866Non-standard extensions in your local sprintf(3) are
1527714867therefore unavailable from Perl.
1527814868
1527914869=end original
1528014870
15281Perl は C<sprintf> フォーマット処理を自力で行います: これは C の
14871Perl は C<sprintf> フォーマット処理を自力で行います:
15282sprintf(3) 関数をエミュレートしますが、C の関数は使いません(浮動小数点を
14872これは C の sprintf(3) 関数をエミュレートしますが、
15283除きますが、それでも標準の記述子のみが利用できます)。
14873C の関数は使いません(浮動小数点を除きますが、それでも標準の
14874記述子のみが利用できます)。
1528414875従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。
1528514876
1528614877=begin original
1528714878
1528814879Unlike C<printf>, C<sprintf> does not do what you probably mean when you
1528914880pass it an array as your first argument.
1529014881The array is given scalar context,
1529114882and instead of using the 0th element of the array as the format, Perl will
1529214883use the count of elements in the array as the format, which is almost never
1529314884useful.
1529414885
1529514886=end original
1529614887
1529714888C<printf> と違って、 C<sprintf> の最初の引数に配列を渡しても
1529814889あなたが多分望むとおりには動作しません。
1529914890配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、
1530014891配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません。
1530114892
1530214893=begin original
1530314894
1530414895Perl's C<sprintf> permits the following universally-known conversions:
1530514896
1530614897=end original
1530714898
1530814899Perl の C<sprintf> は以下の一般に知られている変換に対応しています:
1530914900
1531014901=begin original
1531114902
1531214903 %% a percent sign
1531314904 %c a character with the given number
1531414905 %s a string
1531514906 %d a signed integer, in decimal
1531614907 %u an unsigned integer, in decimal
1531714908 %o an unsigned integer, in octal
1531814909 %x an unsigned integer, in hexadecimal
1531914910 %e a floating-point number, in scientific notation
1532014911 %f a floating-point number, in fixed decimal notation
1532114912 %g a floating-point number, in %e or %f notation
1532214913
1532314914=end original
1532414915
1532514916 %% パーセントマーク
1532614917 %c 与えられた番号の文字
1532714918 %s 文字列
1532814919 %d 符号付き 10 進数
1532914920 %u 符号なし 10 進数
1533014921 %o 符号なし 8 進数
1533114922 %x 符号なし 16 進数
1533214923 %e 科学的表記の浮動小数点数
1533314924 %f 固定 10 進数表記の浮動小数点数
1533414925 %g %e か %f の表記の浮動小数点数
1533514926
1533614927=begin original
1533714928
1533814929In addition, Perl permits the following widely-supported conversions:
1533914930
1534014931=end original
1534114932
1534214933さらに、Perl では以下のよく使われている変換に対応しています:
1534314934
1534414935=begin original
1534514936
1534614937 %X like %x, but using upper-case letters
1534714938 %E like %e, but using an upper-case "E"
1534814939 %G like %g, but with an upper-case "E" (if applicable)
1534914940 %b an unsigned integer, in binary
1535014941 %B like %b, but using an upper-case "B" with the # flag
1535114942 %p a pointer (outputs the Perl value's address in hexadecimal)
1535214943 %n special: *stores* the number of characters output so far
1535314944 into the next argument in the parameter list
1535414945
1535514946=end original
1535614947
1535714948 %X %x と同様だが大文字を使う
1535814949 %E %e と同様だが大文字の "E" を使う
1535914950 %G %g と同様だが(適切なら)大文字の "E" を使う
1536014951 %b 符号なし 2 進数
1536114952 %B %b と同様だが、# フラグで大文字の "B" を使う
1536214953 %p ポインタ (Perl の値のアドレスを 16 進数で出力する)
1536314954 %n 特殊: 出力文字数を引数リストの次の変数に「格納」する
1536414955
1536514956=begin original
1536614957
1536714958Finally, for backward (and we do mean "backward") compatibility, Perl
1536814959permits these unnecessary but widely-supported conversions:
1536914960
1537014961=end original
1537114962
1537214963最後に、過去との互換性(これは「過去」だと考えています)のために、
1537314964Perl は以下の不要ではあるけれども広く使われている変換に対応しています。
1537414965
1537514966=begin original
1537614967
1537714968 %i a synonym for %d
1537814969 %D a synonym for %ld
1537914970 %U a synonym for %lu
1538014971 %O a synonym for %lo
1538114972 %F a synonym for %f
1538214973
1538314974=end original
1538414975
1538514976 %i %d の同義語
1538614977 %D %ld の同義語
1538714978 %U %lu の同義語
1538814979 %O %lo の同義語
1538914980 %F %f の同義語
1539014981
1539114982=begin original
1539214983
1539314984Note that the number of exponent digits in the scientific notation produced
1539414985by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
1539514986exponent less than 100 is system-dependent: it may be three or less
1539614987(zero-padded as necessary). In other words, 1.23 times ten to the
153971498899th may be either "1.23e99" or "1.23e099".
1539814989
1539914990=end original
1540014991
1540114992C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の
1540214993指数部の科学的な表記法はシステム依存であることに注意してください:
15403149943 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で
1540414995パッディングされます)。
1540514996言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし
1540614997"1.23e099" かもしれません。
1540714998
1540814999=begin original
1540915000
1541015001Between the C<%> and the format letter, you may specify several
1541115002additional attributes controlling the interpretation of the format.
1541215003In order, these are:
1541315004
1541415005=end original
1541515006
1541615007C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、
1541715008いくつかの追加の属性を指定できます。
1541815009順番に、以下のものがあります:
1541915010
1542015011=over 4
1542115012
1542215013=item format parameter index
1542315014
1542415015(フォーマットパラメータインデックス)
1542515016
1542615017=begin original
1542715018
1542815019An explicit format parameter index, such as C<2$>. By default sprintf
1542915020will format the next unused argument in the list, but this allows you
1543015021to take the arguments out of order:
1543115022
1543215023=end original
1543315024
1543415025C<2$> のような明示的なフォーマットパラメータインデックス。
1543515026デフォルトでは sprintf はリストの次の使われていない引数を
1543615027フォーマットしますが、これによって異なった順番の引数を使えるようにします:
1543715028
1543815029 printf '%2$d %1$d', 12, 34; # prints "34 12"
1543915030 printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1"
1544015031
1544115032=item flags
1544215033
1544315034(フラグ)
1544415035
1544515036=begin original
1544615037
1544715038one or more of:
1544815039
1544915040=end original
1545015041
1545115042以下のうちの一つまたは複数指定できます:
1545215043
1545315044=begin original
1545415045
1545515046 space prefix non-negative number with a space
1545615047 + prefix non-negative number with a plus sign
1545715048 - left-justify within the field
1545815049 0 use zeros, not spaces, to right-justify
1545915050 # ensure the leading "0" for any octal,
1546015051 prefix non-zero hexadecimal with "0x" or "0X",
1546115052 prefix non-zero binary with "0b" or "0B"
1546215053
1546315054=end original
1546415055
1546515056 space 非負数の前に空白をつける
1546615057 + 非負数の前にプラス記号をつける
1546715058 - フィールド内で左詰めする
1546815059 0 右詰めに空白ではなくゼロを使う
1546915060 # 8 進数では確実に先頭に "0" をつける;
1547015061 非 0 の 16 進数では "0x" か "0X" をつける;
1547115062 非 0 の 2 進数では "0b" か "0B" をつける
1547215063
1547315064=begin original
1547415065
1547515066For example:
1547615067
1547715068=end original
1547815069
1547915070例えば:
1548015071
1548115072 printf '<% d>', 12; # prints "< 12>"
1548215073 printf '<%+d>', 12; # prints "<+12>"
1548315074 printf '<%6s>', 12; # prints "< 12>"
1548415075 printf '<%-6s>', 12; # prints "<12 >"
1548515076 printf '<%06s>', 12; # prints "<000012>"
1548615077 printf '<%#o>', 12; # prints "<014>"
1548715078 printf '<%#x>', 12; # prints "<0xc>"
1548815079 printf '<%#X>', 12; # prints "<0XC>"
1548915080 printf '<%#b>', 12; # prints "<0b1100>"
1549015081 printf '<%#B>', 12; # prints "<0B1100>"
1549115082
1549215083=begin original
1549315084
1549415085When a space and a plus sign are given as the flags at once,
1549515086a plus sign is used to prefix a positive number.
1549615087
1549715088=end original
1549815089
1549915090空白とプラス記号がフラグとして同時に与えられると、プラス記号は正の数に
1550015091前置するために使われます。
1550115092
1550215093 printf '<%+ d>', 12; # prints "<+12>"
1550315094 printf '<% +d>', 12; # prints "<+12>"
1550415095
1550515096=begin original
1550615097
1550715098When the # flag and a precision are given in the %o conversion,
1550815099the precision is incremented if it's necessary for the leading "0".
1550915100
1551015101=end original
1551115102
1551215103%o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は
1551315104精度に 1 が加えられます。
1551415105
1551515106 printf '<%#.5o>', 012; # prints "<00012>"
1551615107 printf '<%#.5o>', 012345; # prints "<012345>"
1551715108 printf '<%#.0o>', 0; # prints "<0>"
1551815109
1551915110=item vector flag
1552015111
1552115112(ベクタフラグ)
1552215113
1552315114=begin original
1552415115
1552515116This flag tells Perl to interpret the supplied string as a vector of
1552615117integers, one for each character in the string. Perl applies the format to
1552715118each integer in turn, then joins the resulting strings with a separator (a
1552815119dot C<.> by default). This can be useful for displaying ordinal values of
1552915120characters in arbitrary strings:
1553015121
1553115122=end original
1553215123
1553315124このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして
1553415125解釈させます。
1553515126Perl は各数値をフォーマットし、それから結果の文字列をセパレータ
1553615127(デフォルトでは C<.>)で連結します。
1553715128これは任意の文字列の文字を順序付きの値として表示するのに便利です:
1553815129
1553915130 printf "%vd", "AB\x{100}"; # prints "65.66.256"
1554015131 printf "version is v%vd\n", $^V; # Perl's version
1554115132
1554215133=begin original
1554315134
1554415135Put an asterisk C<*> before the C<v> to override the string to
1554515136use to separate the numbers:
1554615137
1554715138=end original
1554815139
1554915140アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を
1555015141上書きします:
1555115142
1555215143 printf "address is %*vX\n", ":", $addr; # IPv6 address
1555315144 printf "bits are %0*v8b\n", " ", $bits; # random bitstring
1555415145
1555515146=begin original
1555615147
1555715148You can also explicitly specify the argument number to use for
1555815149the join string using something like C<*2$v>; for example:
1555915150
1556015151=end original
1556115152
1556215153また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に
1556315154指定できます; 例えば:
1556415155
15565 printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses
15156 printf '%*4$vX %*4$vX %*4$vX', @addr[1..3], ":"; # 3 IPv6 addresses
15566 @addr[1..3], ":";
1556715157
1556815158=item (minimum) width
1556915159
1557015160((最小)幅)
1557115161
1557215162=begin original
1557315163
1557415164Arguments are usually formatted to be only as wide as required to
1557515165display the given value. You can override the width by putting
1557615166a number here, or get the width from the next argument (with C<*>)
1557715167or from a specified argument (e.g., with C<*2$>):
1557815168
1557915169=end original
1558015170
1558115171引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。
1558215172ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で
1558315173幅を上書きできます。
1558415174
15585 printf "<%s>", "a"; # prints "<a>"
15175 printf "<%s>", "a"; # prints "<a>"
15586 printf "<%6s>", "a"; # prints "< a>"
15176 printf "<%6s>", "a"; # prints "< a>"
15587 printf "<%*s>", 6, "a"; # prints "< a>"
15177 printf "<%*s>", 6, "a"; # prints "< a>"
15588 printf '<%*2$s>', "a", 6; # prints "< a>"
15178 printf "<%*2$s>", "a", 6; # prints "< a>"
15589 printf "<%2s>", "long"; # prints "<long>" (does not truncate)
15179 printf "<%2s>", "long"; # prints "<long>" (does not truncate)
1559015180
1559115181=begin original
1559215182
1559315183If a field width obtained through C<*> is negative, it has the same
1559415184effect as the C<-> flag: left-justification.
1559515185
1559615186=end original
1559715187
1559815188C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと
1559915189同様の効果 (左詰め) があります。
1560015190
1560115191=item precision, or maximum width
1560215192X<precision>
1560315193
1560415194(精度あるいは最大幅)
1560515195
1560615196=begin original
1560715197
1560815198You can specify a precision (for numeric conversions) or a maximum
1560915199width (for string conversions) by specifying a C<.> followed by a number.
1561015200For floating-point formats except C<g> and C<G>, this specifies
1561115201how many places right of the decimal point to show (the default being 6).
1561215202For example:
1561315203
1561415204=end original
1561515205
1561615206C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合)
1561715207最大幅を指定できます。
1561815208小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の
1561915209桁数を指定します(デフォルトは 6 です)。
1562015210例えば:
1562115211
1562215212 # these examples are subject to system-specific variation
1562315213 printf '<%f>', 1; # prints "<1.000000>"
1562415214 printf '<%.1f>', 1; # prints "<1.0>"
1562515215 printf '<%.0f>', 1; # prints "<1>"
1562615216 printf '<%e>', 10; # prints "<1.000000e+01>"
1562715217 printf '<%.1e>', 10; # prints "<1.0e+01>"
1562815218
1562915219=begin original
1563015220
1563115221For "g" and "G", this specifies the maximum number of digits to show,
1563215222including those prior to the decimal point and those after it; for
1563315223example:
1563415224
1563515225=end original
1563615226
1563715227"g" と "G" の場合、これは表示する数値の数を指定します;
1563815228これには小数点の前の数値と後の数値を含みます; 例えば:
1563915229
1564015230 # These examples are subject to system-specific variation.
1564115231 printf '<%g>', 1; # prints "<1>"
1564215232 printf '<%.10g>', 1; # prints "<1>"
1564315233 printf '<%g>', 100; # prints "<100>"
1564415234 printf '<%.1g>', 100; # prints "<1e+02>"
1564515235 printf '<%.2g>', 100.01; # prints "<1e+02>"
1564615236 printf '<%.5g>', 100.01; # prints "<100.01>"
1564715237 printf '<%.4g>', 100.01; # prints "<100>"
1564815238
1564915239=begin original
1565015240
1565115241For integer conversions, specifying a precision implies that the
1565215242output of the number itself should be zero-padded to this width,
1565315243where the 0 flag is ignored:
1565415244
1565515245=end original
1565615246
1565715247整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で
1565815248パッディングするべきであることを暗に示すことになり、0 フラグは
1565915249無視されます:
1566015250
1566115251 printf '<%.6d>', 1; # prints "<000001>"
1566215252 printf '<%+.6d>', 1; # prints "<+000001>"
1566315253 printf '<%-10.6d>', 1; # prints "<000001 >"
1566415254 printf '<%10.6d>', 1; # prints "< 000001>"
1566515255 printf '<%010.6d>', 1; # prints "< 000001>"
1566615256 printf '<%+10.6d>', 1; # prints "< +000001>"
1566715257
1566815258 printf '<%.6x>', 1; # prints "<000001>"
1566915259 printf '<%#.6x>', 1; # prints "<0x000001>"
1567015260 printf '<%-10.6x>', 1; # prints "<000001 >"
1567115261 printf '<%10.6x>', 1; # prints "< 000001>"
1567215262 printf '<%010.6x>', 1; # prints "< 000001>"
1567315263 printf '<%#10.6x>', 1; # prints "< 0x000001>"
1567415264
1567515265=begin original
1567615266
1567715267For string conversions, specifying a precision truncates the string
1567815268to fit the specified width:
1567915269
1568015270=end original
1568115271
1568215272文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を
1568315273切り詰めます:
1568415274
1568515275 printf '<%.5s>', "truncated"; # prints "<trunc>"
1568615276 printf '<%10.5s>', "truncated"; # prints "< trunc>"
1568715277
1568815278=begin original
1568915279
1569015280You can also get the precision from the next argument using C<.*>:
1569115281
1569215282=end original
1569315283
1569415284C<.*> を使って精度を次の引数から取ることも出来ます:
1569515285
1569615286 printf '<%.6x>', 1; # prints "<000001>"
1569715287 printf '<%.*x>', 6, 1; # prints "<000001>"
1569815288
1569915289=begin original
1570015290
1570115291If a precision obtained through C<*> is negative, it counts
1570215292as having no precision at all.
1570315293
1570415294=end original
1570515295
1570615296C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と
1570715297同じ効果となります。
1570815298
1570915299 printf '<%.*s>', 7, "string"; # prints "<string>"
1571015300 printf '<%.*s>', 3, "string"; # prints "<str>"
1571115301 printf '<%.*s>', 0, "string"; # prints "<>"
1571215302 printf '<%.*s>', -1, "string"; # prints "<string>"
1571315303
1571415304 printf '<%.*d>', 1, 0; # prints "<0>"
1571515305 printf '<%.*d>', 0, 0; # prints "<>"
1571615306 printf '<%.*d>', -1, 0; # prints "<0>"
1571715307
1571815308=begin original
1571915309
1572015310You cannot currently get the precision from a specified number,
1572115311but it is intended that this will be possible in the future, for
1572215312example using C<.*2$>:
1572315313
1572415314=end original
1572515315
1572615316現在のところ精度を指定した数値から得ることはできませんが、
1572715317将来は 例えば C<.*2$> のようにして可能にしようとしています:
1572815318
15729 printf '<%.*2$x>', 1, 6; # INVALID, but in future will print
15319 printf "<%.*2$x>", 1, 6; # INVALID, but in future will print "<000001>"
15730 # "<000001>"
1573115320
1573215321=item size
1573315322
1573415323(サイズ)
1573515324
1573615325=begin original
1573715326
1573815327For numeric conversions, you can specify the size to interpret the
1573915328number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer
1574015329conversions (C<d u o x X b i D U O>), numbers are usually assumed to be
1574115330whatever the default integer size is on your platform (usually 32 or 64
1574215331bits), but you can override this to use instead one of the standard C types,
1574315332as supported by the compiler used to build Perl:
1574415333
1574515334=end original
1574615335
1574715336数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の
1574815337大きさを指定できます。
1574915338整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの
1575015339デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、
1575115340これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで
1575215341上書きできます:
1575315342
1575415343=begin original
1575515344
15756 hh interpret integer as C type "char" or "unsigned
15345 hh interpret integer as C type "char" or "unsigned char"
15757 char" on Perl 5.14 or later
15346 on Perl 5.14 or later
15758 h interpret integer as C type "short" or
15347 h interpret integer as C type "short" or "unsigned short"
15759 "unsigned short"
15348 j interpret integer as C type "intmax_t" on Perl 5.14
15760 j interpret integer as C type "intmax_t" on Perl
15349 or later, and only with a C99 compiler (unportable)
15761 5.14 or later, and only with a C99 compiler
15350 l interpret integer as C type "long" or "unsigned long"
15762 (unportable)
15351 q, L, or ll interpret integer as C type "long long", "unsigned long long",
15763 l interpret integer as C type "long" or
15352 or "quad" (typically 64-bit integers)
15764 "unsigned long"
15353 t interpret integer as C type "ptrdiff_t" on Perl 5.14 or later
15765 q, L, or ll interpret integer as C type "long long",
15354 z interpret integer as C type "size_t" on Perl 5.14 or later
15766 "unsigned long long", or "quad" (typically
15767 64-bit integers)
15768 t interpret integer as C type "ptrdiff_t" on Perl
15769 5.14 or later
15770 z interpret integer as C type "size_t" on Perl 5.14
15771 or later
1577215355
1577315356=end original
1577415357
1577515358 hh Perl 5.14 以降で整数を C の "char" または "unsigned char"
15776 型として解釈する
15359 型として解釈する
1577715360 h 整数を C の "char" または "unsigned char" 型として解釈する
15778 j Perl 5.14 以降 C99 コンパイラのみで整数を C の "intmax_t"
15361 j Perl 5.14 以降 C99 コンパイラのみで整数を C の "intmax_t"
15779 型として解釈する (移植性なし)
15362 型として解釈する (移植性なし)
1578015363 l 整数を C の "long" または "unsigned long" と解釈する
1578115364 h 整数を C の "short" または "unsigned short" と解釈する
1578215365 q, L or ll 整数を C の "long long", "unsigned long long",
1578315366 "quads"(典型的には 64 ビット整数) のどれかと解釈する
15784 t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する
15367 t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する
15785 z Perl 5.14 以降で整数を C の "size_t" 型として解釈する
15368 z Perl 5.14 以降で整数を C の "size_t" 型として解釈する
1578615369
1578715370=begin original
1578815371
1578915372As of 5.14, none of these raises an exception if they are not supported on
1579015373your platform. However, if warnings are enabled, a warning of the
1579115374C<printf> warning class is issued on an unsupported conversion flag.
1579215375Should you instead prefer an exception, do this:
1579315376
1579415377=end original
1579515378
15796153795.14 から、プラットフォームがこれらに対応していないときでも例外が
1579715380発生しなくなりました。
1579815381しかし、もし警告が有効になっているなら、
1579915382非対応変換フラグに関して C<printf> 警告クラスの警告が発生します。
1580015383例外の方がお好みなら、以下のようにします:
1580115384
1580215385 use warnings FATAL => "printf";
1580315386
1580415387=begin original
1580515388
1580615389If you would like to know about a version dependency before you
1580715390start running the program, put something like this at its top:
1580815391
1580915392=end original
1581015393
1581115394プログラムの実行開始前にバージョン依存について知りたいなら、先頭に
1581215395以下のようなものを書きます:
1581315396
1581415397 use 5.014; # for hh/j/t/z/ printf modifiers
1581515398
1581615399=begin original
1581715400
1581815401You can find out whether your Perl supports quads via L<Config>:
1581915402
1582015403=end original
1582115404
1582215405Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って
1582315406調べられます:
1582415407
1582515408 use Config;
15826 if ($Config{use64bitint} eq "define"
15409 if ($Config{use64bitint} eq "define" || $Config{longsize} >= 8) {
15827 || $Config{longsize} >= 8) {
1582815410 print "Nice quads!\n";
1582915411 }
1583015412
1583115413=begin original
1583215414
1583315415For floating-point conversions (C<e f g E F G>), numbers are usually assumed
1583415416to be the default floating-point size on your platform (double or long double),
1583515417but you can force "long double" with C<q>, C<L>, or C<ll> if your
1583615418platform supports them. You can find out whether your Perl supports long
1583715419doubles via L<Config>:
1583815420
1583915421=end original
1584015422
1584115423浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの
1584215424不動小数点数のサイズ (double か long double) を仮定します。
1584315425Perl が long double に対応しているかどうかは L<Config> を使って
1584415426調べられます:
1584515427
1584615428 use Config;
1584715429 print "long doubles\n" if $Config{d_longdbl} eq "define";
1584815430
1584915431=begin original
1585015432
1585115433You can find out whether Perl considers "long double" to be the default
1585215434floating-point size to use on your platform via L<Config>:
1585315435
1585415436=end original
1585515437
1585615438Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは
1585715439L<Config> を使って調べられます:
1585815440
1585915441 use Config;
1586015442 if ($Config{uselongdouble} eq "define") {
15861 print "long doubles by default\n";
15443 print "long doubles by default\n";
1586215444 }
1586315445
1586415446=begin original
1586515447
1586615448It can also be that long doubles and doubles are the same thing:
1586715449
1586815450=end original
1586915451
1587015452long double と double が同じ場合もあります:
1587115453
1587215454 use Config;
1587315455 ($Config{doublesize} == $Config{longdblsize}) &&
1587415456 print "doubles are long doubles\n";
1587515457
1587615458=begin original
1587715459
1587815460The size specifier C<V> has no effect for Perl code, but is supported for
1587915461compatibility with XS code. It means "use the standard size for a Perl
1588015462integer or floating-point number", which is the default.
1588115463
1588215464=end original
1588315465
1588415466サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは
1588515467XS コードとの互換性のために対応しています。
1588615468これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを
1588715469意味し、これはデフォルトです。
1588815470
1588915471=item order of arguments
1589015472
1589115473(引数の順序)
1589215474
1589315475=begin original
1589415476
1589515477Normally, sprintf() takes the next unused argument as the value to
1589615478format for each format specification. If the format specification
1589715479uses C<*> to require additional arguments, these are consumed from
1589815480the argument list in the order they appear in the format
1589915481specification I<before> the value to format. Where an argument is
1590015482specified by an explicit index, this does not affect the normal
1590115483order for the arguments, even when the explicitly specified index
1590215484would have been the next argument.
1590315485
1590415486=end original
1590515487
1590615488通常、sprintf() は各フォーマット指定について、使われていない次の引数を
1590715489フォーマットする値として使います。
1590815490追加の引数を要求するためにフォーマット指定 C<*> を使うと、
1590915491これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に
1591015492引数リストから消費されます。
1591115493引数の位置が明示的なインデックスを使って指定された場合、
1591215494(明示的に指定したインデックスが次の引数の場合でも)
1591315495これは通常の引数の順番に影響を与えません。
1591415496
1591515497=begin original
1591615498
1591715499So:
1591815500
1591915501=end original
1592015502
1592115503それで:
1592215504
1592315505 printf "<%*.*s>", $a, $b, $c;
1592415506
1592515507=begin original
1592615508
1592715509uses C<$a> for the width, C<$b> for the precision, and C<$c>
1592815510as the value to format; while:
1592915511
1593015512=end original
1593115513
1593215514とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に
1593315515使います; 一方:
1593415516
15935 printf '<%*1$.*s>', $a, $b;
15517 printf "<%*1$.*s>", $a, $b;
1593615518
1593715519=begin original
1593815520
1593915521would use C<$a> for the width and precision, and C<$b> as the
1594015522value to format.
1594115523
1594215524=end original
1594315525
1594415526とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。
1594515527
1594615528=begin original
1594715529
1594815530Here are some more examples; be aware that when using an explicit
1594915531index, the C<$> may need escaping:
1595015532
1595115533=end original
1595215534
1595315535以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は
1595415536エスケープする必要があることに注意してください:
1595515537
15956 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
15538 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
15957 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
15539 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
15958 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
15540 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
15959 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
15541 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
1596015542
1596115543=back
1596215544
1596315545=begin original
1596415546
1596515547If C<use locale> (including C<use locale 'not_characters'>) is in effect
1596615548and POSIX::setlocale() has been called,
1596715549the character used for the decimal separator in formatted floating-point
1596815550numbers is affected by the LC_NUMERIC locale. See L<perllocale>
1596915551and L<POSIX>.
1597015552
1597115553=end original
1597215554
1597315555(C<use locale 'not_characters'> を含む)C<use locale> が有効で、
1597415556POSIX::setlocale() が呼び出されている場合、フォーマットされた浮動小数点数の
1597515557小数点として使われる文字は LC_NUMERIC ロケールの影響を受けます。
1597615558L<perllocale> と L<POSIX> を参照してください。
1597715559
1597815560=item sqrt EXPR
1597915561X<sqrt> X<root> X<square root>
1598015562
1598115563=item sqrt
1598215564
1598315565=for Pod::Functions square root function
1598415566
1598515567=begin original
1598615568
1598715569Return the positive square root of EXPR. If EXPR is omitted, uses
1598815570C<$_>. Works only for non-negative operands unless you've
1598915571loaded the C<Math::Complex> module.
1599015572
1599115573=end original
1599215574
1599315575EXPR の正の平方根を返します。
1599415576EXPR が省略されると、C<$_> を使います。
1599515577C<Math::Complex> モジュールを使わない場合は、負の数の引数は扱えません。
1599615578
1599715579 use Math::Complex;
1599815580 print sqrt(-4); # prints 2i
1599915581
1600015582=item srand EXPR
1600115583X<srand> X<seed> X<randseed>
1600215584
1600315585=item srand
1600415586
1600515587=for Pod::Functions seed the random number generator
1600615588
1600715589=begin original
1600815590
1600915591Sets and returns the random number seed for the C<rand> operator.
1601015592
1601115593=end original
1601215594
1601315595C<rand> 演算子のためのシード値を設定して返します。
1601415596
1601515597=begin original
1601615598
1601715599The point of the function is to "seed" the C<rand> function so that C<rand>
1601815600can produce a different sequence each time you run your program. When
1601915601called with a parameter, C<srand> uses that for the seed; otherwise it
1602015602(semi-)randomly chooses a seed. In either case, starting with Perl 5.14,
1602115603it returns the seed. To signal that your code will work I<only> on Perls
1602215604of a recent vintage:
1602315605
1602415606=end original
1602515607
1602615608この関数のポイントは、プログラムを実行するごとに C<rand> 関数が
1602715609異なる乱数列を生成できるように C<rand> 関数の「種」を設定することです。
1602815610C<srand> を引数付きで呼び出すと、これを種として使います; さもなければ
1602915611(だいたい)ランダムに種を選びます。
1603015612どちらの場合でも、Perl 5.14 からは種を返します。
1603115613特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします:
1603215614
1603315615 use 5.014; # so srand returns the seed
1603415616
1603515617=begin original
1603615618
1603715619If C<srand()> is not called explicitly, it is called implicitly without a
16038parameter at the first use of the C<rand> operator.
15620parameter at the first use of the C<rand> operator. However, this was not true
16039However, there are a few situations where programs are likely to
15621of versions of Perl before 5.004, so if your script will run under older
16040want to call C<srand>. One is for generating predictable results, generally for
15622Perl versions, it should call C<srand>; otherwise most programs won't call
15623C<srand()> at all.
15624
15625=end original
15626
15627C<srand()> が明示的に呼び出されなかった場合、最初に C<rand> 演算子を使った
15628時点で暗黙に引数なしで呼び出されます。
15629しかし、これは Perl のバージョンが 5.004 より前では行われませんので、
15630プログラムが古い Perl で実行される場合は、C<srand> を呼ぶべきです;
15631さもなければ、ほとんどのプログラムは C<srand()> を一切呼び出す必要は
15632ありません。
15633
15634=begin original
15635
15636But there are a few situations in recent Perls where programs are likely to
15637want to call C<srand>. One is for generating predictable results generally for
1604115638testing or debugging. There, you use C<srand($seed)>, with the same C<$seed>
1604215639each time. Another case is that you may want to call C<srand()>
1604315640after a C<fork()> to avoid child processes sharing the same seed value as the
1604415641parent (and consequently each other).
1604515642
1604615643=end original
1604715644
16048C<srand()> が明示的に呼び出されなかった場合、最初に C<rand> 演算子を使った
16049時点で暗黙に引数なしで呼び出されます。
1605015645しかし、最近の Perl でプログラムが C<srand> を呼び出したいであろう状況が
1605115646いくつかあります。
1605215647一つはテストやデバッグのために予測可能な結果を生成するためです。
1605315648この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。
1605415649もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を
1605515650共有することを避けるために、C<fork()> の後に C<srand()> を
1605615651呼び出したいかもしれません。
1605715652
1605815653=begin original
1605915654
1606015655Do B<not> call C<srand()> (i.e., without an argument) more than once per
1606115656process. The internal state of the random number generator should
1606215657contain more entropy than can be provided by any seed, so calling
1606315658C<srand()> again actually I<loses> randomness.
1606415659
1606515660=end original
1606615661
1606715662C<srand()> (引数なし)をプロセス中で複数回呼び出しては B<いけません>。
1606815663乱数生成器の内部状態はどのような種によって提供されるものよりも
1606915664高いエントロピーを持っているので、C<srand()> を再び呼び出すと
1607015665ランダム性が I<失われます>。
1607115666
1607215667=begin original
1607315668
1607415669Most implementations of C<srand> take an integer and will silently
1607515670truncate decimal numbers. This means C<srand(42)> will usually
1607615671produce the same results as C<srand(42.1)>. To be safe, always pass
1607715672C<srand> an integer.
1607815673
1607915674=end original
1608015675
1608115676C<srand> のほとんどの実装では整数を取り、小数を暗黙に切り捨てます。
1608215677これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを
1608315678意味します。
1608415679安全のために、C<srand> には常に整数を渡しましょう。
1608515680
1608615681=begin original
1608715682
15683In versions of Perl prior to 5.004 the default seed was just the
15684current C<time>. This isn't a particularly good seed, so many old
15685programs supply their own seed value (often C<time ^ $$> or C<time ^
15686($$ + ($$ << 15))>), but that isn't necessary any more.
15687
15688=end original
15689
156905.004 以前の Perl では、デフォルトのシード値は現在の C<time> でした。
15691これは特によいシード値ではありませんでしたので、
15692多くの古いプログラムは自力でシード値を指定しています
15693(C<time ^ $$> または C<time ^ ($$ + ($$ << 15))> がよく使われました)が、
15694もはやこれは必要ありません。
15695
15696=begin original
15697
15698Frequently called programs (like CGI scripts) that simply use
15699
15700=end original
15701
15702(CGI スクリプトのような)頻繁に呼び出されるプログラムで単純に
15703
15704 time ^ $$
15705
15706=begin original
15707
15708for a seed can fall prey to the mathematical property that
15709
15710=end original
15711
15712を種として使うと、3 回に 1 回は以下の数学特性
15713
15714 a^b == (a+1)^(b+1)
15715
15716=begin original
15717
15718one-third of the time. So don't do that.
15719
15720=end original
15721
15722の餌食になります。
15723従ってこのようなことはしてはいけません。
15724
15725=begin original
15726
1608815727A typical use of the returned seed is for a test program which has too many
1608915728combinations to test comprehensively in the time available to it each run. It
1609015729can test a random subset each time, and should there be a failure, log the seed
1609115730used for that run so that it can later be used to reproduce the same results.
1609215731
1609315732=end original
1609415733
1609515734返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に
1609615735行うには組み合わせが多すぎるテストプログラム用です。
1609715736毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った
1609815737種をログに出力することで、後で同じ結果を再現するために使えます。
1609915738
1610015739=begin original
1610115740
1610215741B<C<rand()> is not cryptographically secure. You should not rely
1610315742on it in security-sensitive situations.> As of this writing, a
1610415743number of third-party CPAN modules offer random number generators
1610515744intended by their authors to be cryptographically secure,
1610615745including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1610715746and L<Math::TrulyRandom>.
1610815747
1610915748=end original
1611015749
1611115750B<C<rand()> は暗号学的に安全ではありません。
1611215751セキュリティ的に重要な状況でこれに頼るべきではありません。>
1611315752これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
1611415753作者によって暗号学的に安全であることを目的とした乱数生成器を
1611515754提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1611615755L<Math::TrulyRandom> などです。
1611715756
1611815757=item stat FILEHANDLE
1611915758X<stat> X<file, status> X<ctime>
1612015759
1612115760=item stat EXPR
1612215761
1612315762=item stat DIRHANDLE
1612415763
1612515764=item stat
1612615765
1612715766=for Pod::Functions get a file's status information
1612815767
1612915768=begin original
1613015769
1613115770Returns a 13-element list giving the status info for a file, either
1613215771the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
1613315772omitted, it stats C<$_> (not C<_>!). Returns the empty list if C<stat> fails. Typically
1613415773used as follows:
1613515774
1613615775=end original
1613715776
1613815777FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、
1613915778EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。
1614015779EXPR が省略されると、 C<$_> が用いられます (C<_> ではありません!)。
1614115780C<stat> に失敗した場合には、空リストを返します。
1614215781普通は、以下のようにして使います:
1614315782
1614415783 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1614515784 $atime,$mtime,$ctime,$blksize,$blocks)
1614615785 = stat($filename);
1614715786
1614815787=begin original
1614915788
1615015789Not all fields are supported on all filesystem types. Here are the
1615115790meanings of the fields:
1615215791
1615315792=end original
1615415793
1615515794全てのファイルシステムで全てのフィールドに対応しているわけではありません。
1615615795フィールドの意味は以下の通りです。
1615715796
1615815797=begin original
1615915798
1616015799 0 dev device number of filesystem
1616115800 1 ino inode number
1616215801 2 mode file mode (type and permissions)
1616315802 3 nlink number of (hard) links to the file
1616415803 4 uid numeric user ID of file's owner
1616515804 5 gid numeric group ID of file's owner
1616615805 6 rdev the device identifier (special files only)
1616715806 7 size total size of file, in bytes
1616815807 8 atime last access time in seconds since the epoch
1616915808 9 mtime last modify time in seconds since the epoch
1617015809 10 ctime inode change time in seconds since the epoch (*)
16171 11 blksize preferred I/O size in bytes for interacting with the
15810 11 blksize preferred block size for file system I/O
16172 file (may vary from file to file)
15811 12 blocks actual number of blocks allocated
16173 12 blocks actual number of system-specific blocks allocated
16174 on disk (often, but not always, 512 bytes each)
1617515812
1617615813=end original
1617715814
1617815815 0 dev ファイルシステムのデバイス番号
1617915816 1 ino inode 番号
1618015817 2 mode ファイルモード (タイプとパーミッション)
1618115818 3 nlink ファイルへの(ハード)リンクの数
1618215819 4 uid ファイル所有者のユーザー ID の数値
1618315820 5 gid ファイル所有者のグループ ID の数値
1618415821 6 rdev デバイス識別子(特殊ファイルのみ)
1618515822 7 size ファイルサイズ(バイト単位)
1618615823 8 atime 紀元から、最後にアクセスされた時刻までの秒数
1618715824 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数
1618815825 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*)
16189 11 blksize ファイルとの相互作用のために適した I/O ト数
15826 11 blksize ファイルシステム I/O に適したブロックサ
16190 (ファイルごと異なるかもし)
15827 12 blocks 実際割り当てらるブロックの数
16191 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは
16192 ありませんがたいていはそれぞれ 512 バイト)の数
1619315828
1619415829=begin original
1619515830
1619615831(The epoch was at 00:00 January 1, 1970 GMT.)
1619715832
1619815833=end original
1619915834
1620015835(紀元は GMT で 1970/01/01 00:00:00。)
1620115836
1620215837=begin original
1620315838
1620415839(*) Not all fields are supported on all filesystem types. Notably, the
1620515840ctime field is non-portable. In particular, you cannot expect it to be a
1620615841"creation time"; see L<perlport/"Files and Filesystems"> for details.
1620715842
1620815843=end original
1620915844
1621015845(*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは
1621115846ありません。
1621215847明らかに、ctime のフィールドは移植性がありません。
1621315848特に、これから「作成時刻」を想定することは出来ません;
1621415849詳細については L<perlport/"Files and Filesystems"> を参照してください。
1621515850
1621615851=begin original
1621715852
1621815853If C<stat> is passed the special filehandle consisting of an underline, no
1621915854stat is done, but the current contents of the stat structure from the
1622015855last C<stat>, C<lstat>, or filetest are returned. Example:
1622115856
1622215857=end original
1622315858
1622415859下線だけの _ という特別なファイルハンドルを C<stat> に渡すと、
1622515860実際には stat を行なわず、stat 構造体に残っている
1622615861前回の stat やファイルテストの情報が返されます。
1622715862例:
1622815863
1622915864 if (-x $file && (($d) = stat(_)) && $d < 0) {
1623015865 print "$file is executable NFS file\n";
1623115866 }
1623215867
1623315868=begin original
1623415869
1623515870(This works on machines only for which the device number is negative
1623615871under NFS.)
1623715872
1623815873=end original
1623915874
16240(これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。)
15875(これは、NFS のもとでデバイス番号が負になるマシンで
15876のみ動作します。)
1624115877
1624215878=begin original
1624315879
1624415880Because the mode contains both the file type and its permissions, you
1624515881should mask off the file type portion and (s)printf using a C<"%o">
1624615882if you want to see the real permissions.
1624715883
1624815884=end original
1624915885
1625015886モードにはファイルタイプとその権限の両方が含まれているので、
1625115887本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで
1625215888ファイルタイプをマスクするべきです。
1625315889
1625415890 $mode = (stat($filename))[2];
1625515891 printf "Permissions are %04o\n", $mode & 07777;
1625615892
1625715893=begin original
1625815894
1625915895In scalar context, C<stat> returns a boolean value indicating success
1626015896or failure, and, if successful, sets the information associated with
1626115897the special filehandle C<_>.
1626215898
1626315899=end original
1626415900
1626515901スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を返し、
1626615902成功した場合は、特別なファイルハンドル C<_> に結び付けられた
1626715903情報をセットします。
1626815904
1626915905=begin original
1627015906
1627115907The L<File::stat> module provides a convenient, by-name access mechanism:
1627215908
1627315909=end original
1627415910
1627515911L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。
1627615912
1627715913 use File::stat;
1627815914 $sb = stat($filename);
1627915915 printf "File is %s, size is %s, perm %04o, mtime %s\n",
1628015916 $filename, $sb->size, $sb->mode & 07777,
1628115917 scalar localtime $sb->mtime;
1628215918
1628315919=begin original
1628415920
1628515921You can import symbolic mode constants (C<S_IF*>) and functions
1628615922(C<S_IS*>) from the Fcntl module:
1628715923
1628815924=end original
1628915925
1629015926モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから
1629115927インポートできます。
1629215928
1629315929 use Fcntl ':mode';
1629415930
1629515931 $mode = (stat($filename))[2];
1629615932
1629715933 $user_rwx = ($mode & S_IRWXU) >> 6;
1629815934 $group_read = ($mode & S_IRGRP) >> 3;
1629915935 $other_execute = $mode & S_IXOTH;
1630015936
1630115937 printf "Permissions are %04o\n", S_IMODE($mode), "\n";
1630215938
1630315939 $is_setuid = $mode & S_ISUID;
1630415940 $is_directory = S_ISDIR($mode);
1630515941
1630615942=begin original
1630715943
1630815944You could write the last two using the C<-u> and C<-d> operators.
1630915945Commonly available C<S_IF*> constants are:
1631015946
1631115947=end original
1631215948
1631315949最後の二つは C<-u> と C<-d> 演算子を使っても書けます。
1631415950一般に利用可能な C<S_IF*> 定数は以下のものです。
1631515951
1631615952 # Permissions: read, write, execute, for user, group, others.
1631715953
1631815954 S_IRWXU S_IRUSR S_IWUSR S_IXUSR
1631915955 S_IRWXG S_IRGRP S_IWGRP S_IXGRP
1632015956 S_IRWXO S_IROTH S_IWOTH S_IXOTH
1632115957
1632215958 # Setuid/Setgid/Stickiness/SaveText.
1632315959 # Note that the exact meaning of these is system-dependent.
1632415960
1632515961 S_ISUID S_ISGID S_ISVTX S_ISTXT
1632615962
1632715963 # File types. Not all are necessarily available on
1632815964 # your system.
1632915965
1633015966 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR
1633115967 S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
1633215968
1633315969 # The following are compatibility aliases for S_IRUSR,
1633415970 # S_IWUSR, and S_IXUSR.
1633515971
1633615972 S_IREAD S_IWRITE S_IEXEC
1633715973
1633815974=begin original
1633915975
1634015976and the C<S_IF*> functions are
1634115977
1634215978=end original
1634315979
1634415980一般に利用可能な C<S_IF*> 関数は以下のものです。
1634515981
1634615982 S_IMODE($mode) the part of $mode containing the permission
1634715983 bits and the setuid/setgid/sticky bits
1634815984
1634915985 S_IFMT($mode) the part of $mode containing the file type
1635015986 which can be bit-anded with (for example)
1635115987 S_IFREG or with the following functions
1635215988
1635315989 # The operators -f, -d, -l, -b, -c, -p, and -S.
1635415990
1635515991 S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
1635615992 S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)
1635715993
1635815994 # No direct -X operator counterpart, but for the first one
1635915995 # the -g operator is often equivalent. The ENFMT stands for
1636015996 # record flocking enforcement, a platform-dependent feature.
1636115997
1636215998 S_ISENFMT($mode) S_ISWHT($mode)
1636315999
1636416000=begin original
1636516001
1636616002See your native chmod(2) and stat(2) documentation for more details
1636716003about the C<S_*> constants. To get status info for a symbolic link
1636816004instead of the target file behind the link, use the C<lstat> function.
1636916005
1637016006=end original
1637116007
1637216008C<S_*> 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の
1637316009ドキュメントを参照してください。
1637416010リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を
1637516011得たい場合は、C<lstat> 関数を使ってください。
1637616012
1637716013=begin original
1637816014
1637916015Portability issues: L<perlport/stat>.
1638016016
1638116017=end original
1638216018
1638316019移植性の問題: L<perlport/stat>。
1638416020
16385=item state VARLIST
16021=item state EXPR
1638616022X<state>
1638716023
16388=item state TYPE VARLIST
16024=item state TYPE EXPR
1638916025
16390=item state VARLIST : ATTRS
16026=item state EXPR : ATTRS
1639116027
16392=item state TYPE VARLIST : ATTRS
16028=item state TYPE EXPR : ATTRS
1639316029
1639416030=for Pod::Functions +state declare and assign a persistent lexical variable
1639516031
1639616032=begin original
1639716033
1639816034C<state> declares a lexically scoped variable, just like C<my>.
1639916035However, those variables will never be reinitialized, contrary to
1640016036lexical variables that are reinitialized each time their enclosing block
1640116037is entered.
1640216038See L<perlsub/"Persistent Private Variables"> for details.
1640316039
1640416040=end original
1640516041
1640616042C<state> はちょうど C<my> と同様に、レキシカルなスコープの変数を宣言します。
1640716043しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、
1640816044この変数は決して再初期化されません。
1640916045詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。
1641016046
1641116047=begin original
1641216048
16413If more than one variable is listed, the list must be placed in
16414parentheses. With a parenthesised list, C<undef> can be used as a
16415dummy placeholder. However, since initialization of state variables in
16416list context is currently not possible this would serve no purpose.
16417
16418=end original
16419
16420複数の変数を指定する場合、かっこで囲まなければなりません。
16421かっこで囲まれたリストでは、C<undef> はダミーのプレースホルダとして使えます。
16422しかし、リストコンテキストでの state 変数の初期化は現在のところできないので、
16423これは無意味です。
16424
16425=begin original
16426
1642716049C<state> variables are enabled only when the C<use feature "state"> pragma
1642816050is in effect, unless the keyword is written as C<CORE::state>.
1642916051See also L<feature>.
1643016052
1643116053=end original
1643216054
1643316055C<state> 変数は、キーワードが C<CORE::state> として書かれていない限り、
1643416056C<feature 'state'> プラグマが有効の場合のみ有効です。
1643516057L<feature> も参照してください。
1643616058
1643716059=item study SCALAR
1643816060X<study>
1643916061
1644016062=item study
1644116063
1644216064=for Pod::Functions optimize input data for repeated searches
1644316065
1644416066=begin original
1644516067
1644616068Takes extra time to study SCALAR (C<$_> if unspecified) in anticipation of
1644716069doing many pattern matches on the string before it is next modified.
1644816070This may or may not save time, depending on the nature and number of
1644916071patterns you are searching and the distribution of character
1645016072frequencies in the string to be searched; you probably want to compare
1645116073run times with and without it to see which is faster. Those loops
1645216074that scan for many short constant strings (including the constant
1645316075parts of more complex patterns) will benefit most.
1645416076(The way C<study> works is this: a linked list of every
1645516077character in the string to be searched is made, so we know, for
1645616078example, where all the C<'k'> characters are. From each search string,
1645716079the rarest character is selected, based on some static frequency tables
1645816080constructed from some C programs and English text. Only those places
1645916081that contain this "rarest" character are examined.)
1646016082
1646116083=end original
1646216084
1646316085次に変更される前に、何回も文字列に対するパターンマッチを行なう
1646416086アプリケーションで、そのような文字列 SCALAR(省略時には C<$_>) を予め
1646516087学習しておきます。
1646616088これは、検索のために、どのようなパターンを何回使うかによって、また、
1646716089検索される文字列内の文字頻度の分布によって、時間を節約することに
1646816090なるかもしれませんし、逆に浪費することになるかもしれません; 予習をした場合と
1646916091しない場合の実行時間を比較して、どちらが速いか調べることが必要でしょう。
1647016092短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん検索する
1647116093ループで、もっとも効果があるでしょう。
1647216094(この C<study> の仕組みは、まず、検索される文字列内のすべての文字の
1647316095リンクされたリストが作られ、たとえば、すべての C<'k'> がどこにあるかが
1647416096わかるようになります。
1647516097各々の検索文字列から、C プログラムや英語のテキストから作られた頻度の
1647616098統計情報に基づいて、もっとも珍しい文字が選ばれます。
1647716099この「珍しい」文字を含む場所だけが調べられるのです。)
1647816100
1647916101=begin original
1648016102
1648116103For example, here is a loop that inserts index producing entries
1648216104before any line containing a certain pattern:
1648316105
1648416106=end original
1648516107
1648616108たとえば、特定のパターンを含む行の前にインデックスを
1648716109付けるエントリを入れる例を示します。
1648816110
1648916111 while (<>) {
1649016112 study;
1649116113 print ".IX foo\n" if /\bfoo\b/;
1649216114 print ".IX bar\n" if /\bbar\b/;
1649316115 print ".IX blurfl\n" if /\bblurfl\b/;
1649416116 # ...
1649516117 print;
1649616118 }
1649716119
1649816120=begin original
1649916121
1650016122In searching for C</\bfoo\b/>, only locations in C<$_> that contain C<f>
1650116123will be looked at, because C<f> is rarer than C<o>. In general, this is
1650216124a big win except in pathological cases. The only question is whether
1650316125it saves you more time than it took to build the linked list in the
1650416126first place.
1650516127
1650616128=end original
1650716129
1650816130C<f> は C<o> よりも珍しいので、C</\bfoo\b/> を探すとき、C<$_> で C<f> を
1650916131含む場所だけが探されます。
1651016132一般に、病的な場合を除いて、かなりの結果が得られます。
1651116133唯一の問題は、節約できる時間が、最初にリンクリストを作る
1651216134時間よりも多いかどうかです、
1651316135
1651416136=begin original
1651516137
1651616138Note that if you have to look for strings that you don't know till
1651716139runtime, you can build an entire loop as a string and C<eval> that to
1651816140avoid recompiling all your patterns all the time. Together with
1651916141undefining C<$/> to input entire files as one record, this can be quite
1652016142fast, often faster than specialized programs like fgrep(1). The following
1652116143scans a list of files (C<@files>) for a list of words (C<@words>), and prints
1652216144out the names of those files that contain a match:
1652316145
1652416146=end original
1652516147
1652616148実行時まで、探そうとする文字列がわからないときには、
1652716149ループ全体を文字列として組み立てて、C<eval> すれば、
1652816150いつも、すべてのパターンを再コンパイルするという事態は避けられます。
1652916151ファイル全体を一つのレコードとして入力するために、
1653016152C<$/> を未定義にすれば、かなり速くなり、
1653116153多くの場合 fgrep(1) のような専用のプログラムより速くなります。
1653216154以下の例は、ファイルのリスト (C<@files>) から単語のリスト (C<@words>) を
1653316155探して、マッチするものがあったファイル名を出力します。
1653416156
1653516157 $search = 'while (<>) { study;';
1653616158 foreach $word (@words) {
1653716159 $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
1653816160 }
1653916161 $search .= "}";
1654016162 @ARGV = @files;
1654116163 undef $/;
1654216164 eval $search; # this screams
1654316165 $/ = "\n"; # put back to normal input delimiter
1654416166 foreach $file (sort keys(%seen)) {
1654516167 print $file, "\n";
1654616168 }
1654716169
1654816170=item sub NAME BLOCK
1654916171X<sub>
1655016172
1655116173=item sub NAME (PROTO) BLOCK
1655216174
1655316175=item sub NAME : ATTRS BLOCK
1655416176
1655516177=item sub NAME (PROTO) : ATTRS BLOCK
1655616178
1655716179=for Pod::Functions declare a subroutine, possibly anonymously
1655816180
1655916181=begin original
1656016182
1656116183This is subroutine definition, not a real function I<per se>. Without a
1656216184BLOCK it's just a forward declaration. Without a NAME, it's an anonymous
1656316185function declaration, so does return a value: the CODE ref of the closure
1656416186just created.
1656516187
1656616188=end original
1656716189
1656816190これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。
1656916191BLOCK なしの場合、これは単に前方宣言です。
1657016192NAME なしの場合は、無名関数定義であり、値(作成したブロックの
1657116193コードリファレンス)を返します: 単にクロージャの CODE リファレンスが
1657216194作成されます。
1657316195
1657416196=begin original
1657516197
1657616198See L<perlsub> and L<perlref> for details about subroutines and
1657716199references; see L<attributes> and L<Attribute::Handlers> for more
1657816200information about attributes.
1657916201
1658016202=end original
1658116203
1658216204サブルーチンとリファレンスに関する詳細については、L<perlsub> と
1658316205L<perlref> を参照してください; 属性に関する更なる情報については
1658416206L<attributes> と L<Attribute::Handlers> を参照してください。
1658516207
1658616208=item __SUB__
1658716209X<__SUB__>
1658816210
1658916211=for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine
1659016212
1659116213=begin original
1659216214
16593A special token that returns a reference to the current subroutine, or
16215A special token that returns the a reference to the current subroutine, or
1659416216C<undef> outside of a subroutine.
1659516217
1659616218=end original
1659716219
1659816220現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では
1659916221C<undef>。
1660016222
1660116223=begin original
1660216224
16603The behaviour of C<__SUB__> within a regex code block (such as C</(?{...})/>)
16604is subject to change.
16605
16606=end original
16607
16608(C</(?{...})/> のような) 正規表現コードブロックの中の C<__SUB__> の振る舞いは
16609変更される予定です。
16610
16611=begin original
16612
1661316225This token is only available under C<use v5.16> or the "current_sub"
1661416226feature. See L<feature>.
1661516227
1661616228=end original
1661716229
1661816230このトークンは C<use v5.16> または "current_sub" 機能でのみ利用可能です。
1661916231L<feature> を参照してください。
1662016232
1662116233=item substr EXPR,OFFSET,LENGTH,REPLACEMENT
1662216234X<substr> X<substring> X<mid> X<left> X<right>
1662316235
1662416236=item substr EXPR,OFFSET,LENGTH
1662516237
1662616238=item substr EXPR,OFFSET
1662716239
1662816240=for Pod::Functions get or alter a portion of a string
1662916241
1663016242=begin original
1663116243
1663216244Extracts a substring out of EXPR and returns it. First character is at
1663316245offset zero. If OFFSET is negative, starts
1663416246that far back from the end of the string. If LENGTH is omitted, returns
1663516247everything through the end of the string. If LENGTH is negative, leaves that
1663616248many characters off the end of the string.
1663716249
1663816250=end original
1663916251
1664016252EXPR から、部分文字列を取り出して返します。
1664116253最初の文字がオフセット 0 となります。
1664216254OFFSET に負の値を設定すると、EXPR の終わりからのオフセットとなります。
1664316255LENGTH を省略すると、EXPR の最後まですべてが返されます。
1664416256LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。
1664516257
1664616258 my $s = "The black cat climbed the green tree";
1664716259 my $color = substr $s, 4, 5; # black
1664816260 my $middle = substr $s, 4, -11; # black cat climbed the
1664916261 my $end = substr $s, 14; # climbed the green tree
1665016262 my $tail = substr $s, -4; # tree
1665116263 my $z = substr $s, -4, 2; # tr
1665216264
1665316265=begin original
1665416266
1665516267You can use the substr() function as an lvalue, in which case EXPR
1665616268must itself be an lvalue. If you assign something shorter than LENGTH,
1665716269the string will shrink, and if you assign something longer than LENGTH,
1665816270the string will grow to accommodate it. To keep the string the same
1665916271length, you may need to pad or chop your value using C<sprintf>.
1666016272
1666116273=end original
1666216274
1666316275substr() を左辺値として使用することも可能で、その場合には、
1666416276EXPR が自身左辺値でなければなりません。
1666516277LENGTH より短いものを代入したときには、
1666616278EXPR は短くなり、LENGTH より長いものを代入したときには、
1666716279EXPR はそれに合わせて伸びることになります。
1666816280EXPR の長さを一定に保つためには、C<sprintf> を使って、
1666916281代入する値の長さを調整することが、必要になるかもしれません。
1667016282
1667116283=begin original
1667216284
1667316285If OFFSET and LENGTH specify a substring that is partly outside the
1667416286string, only the part within the string is returned. If the substring
1667516287is beyond either end of the string, substr() returns the undefined
1667616288value and produces a warning. When used as an lvalue, specifying a
1667716289substring that is entirely outside the string raises an exception.
1667816290Here's an example showing the behavior for boundary cases:
1667916291
1668016292=end original
1668116293
1668216294OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、
1668316295文字列の内側の部分だけが返されます。
1668416296部分文字列が文字列の両端の外側の場合、substr() は未定義値を返し、
1668516297警告が出力されます。
1668616298左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると
1668716299例外が発生します。
1668816300以下は境界条件の振る舞いを示す例です:
1668916301
1669016302 my $name = 'fred';
1669116303 substr($name, 4) = 'dy'; # $name is now 'freddy'
1669216304 my $null = substr $name, 6, 2; # returns "" (no warning)
1669316305 my $oops = substr $name, 7; # returns undef, with warning
1669416306 substr($name, 7) = 'gap'; # raises an exception
1669516307
1669616308=begin original
1669716309
1669816310An alternative to using substr() as an lvalue is to specify the
1669916311replacement string as the 4th argument. This allows you to replace
1670016312parts of the EXPR and return what was there before in one operation,
1670116313just as you can with splice().
1670216314
1670316315=end original
1670416316
1670516317substr() を左辺値として使う代わりの方法は、置き換える文字列を 4 番目の
1670616318引数として指定することです。
1670716319これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、
1670816320ということを(splice() と同様) 1 動作で行えます。
1670916321
1671016322 my $s = "The black cat climbed the green tree";
1671116323 my $z = substr $s, 14, 7, "jumped from"; # climbed
1671216324 # $s is now "The black cat jumped from the green tree"
1671316325
1671416326=begin original
1671516327
1671616328Note that the lvalue returned by the three-argument version of substr() acts as
1671716329a 'magic bullet'; each time it is assigned to, it remembers which part
1671816330of the original string is being modified; for example:
1671916331
1672016332=end original
1672116333
16722163343 引数の substr() によって返された左辺値は「魔法の弾丸」のように振舞うことに
1672316335注意してください; これが代入される毎に、元の文字列のどの部分が変更されたかが
1672416336思い出されます; 例えば:
1672516337
1672616338 $x = '1234';
1672716339 for (substr($x,1,2)) {
1672816340 $_ = 'a'; print $x,"\n"; # prints 1a4
1672916341 $_ = 'xyz'; print $x,"\n"; # prints 1xyz4
1673016342 $x = '56789';
1673116343 $_ = 'pq'; print $x,"\n"; # prints 5pq9
1673216344 }
1673316345
1673416346=begin original
1673516347
1673616348With negative offsets, it remembers its position from the end of the string
1673716349when the target string is modified:
1673816350
1673916351=end original
1674016352
1674116353負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの
1674216354位置を覚えます:
1674316355
1674416356 $x = '1234';
1674516357 for (substr($x, -3, 2)) {
1674616358 $_ = 'a'; print $x,"\n"; # prints 1a4, as above
1674716359 $x = 'abcdefg';
1674816360 print $_,"\n"; # prints f
1674916361 }
1675016362
1675116363=begin original
1675216364
1675316365Prior to Perl version 5.10, the result of using an lvalue multiple times was
1675416366unspecified. Prior to 5.16, the result with negative offsets was
1675516367unspecified.
1675616368
1675716369=end original
1675816370
1675916371バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は
1676016372未定義でした。
16761163735.16 より前では、負のオフセットの結果は未定義です。
1676216374
1676316375=item symlink OLDFILE,NEWFILE
1676416376X<symlink> X<link> X<symbolic link> X<link, symbolic>
1676516377
1676616378=for Pod::Functions create a symbolic link to a file
1676716379
1676816380=begin original
1676916381
1677016382Creates a new filename symbolically linked to the old filename.
1677116383Returns C<1> for success, C<0> otherwise. On systems that don't support
1677216384symbolic links, raises an exception. To check for that,
1677316385use eval:
1677416386
1677516387=end original
1677616388
1677716389NEWFILE として、OLDFILE へのシンボリックリンクを生成します。
1677816390成功時には C<1> を返し、失敗時には C<0> を返します。
1677916391シンボリックリンクをサポートしていないシステムでは、
1678016392例外が発生します。
1678116393これをチェックするには、eval を使用します:
1678216394
1678316395 $symlink_exists = eval { symlink("",""); 1 };
1678416396
1678516397=begin original
1678616398
1678716399Portability issues: L<perlport/symlink>.
1678816400
1678916401=end original
1679016402
1679116403移植性の問題: L<perlport/symlink>。
1679216404
1679316405=item syscall NUMBER, LIST
1679416406X<syscall> X<system call>
1679516407
1679616408=for Pod::Functions execute an arbitrary system call
1679716409
1679816410=begin original
1679916411
1680016412Calls the system call specified as the first element of the list,
1680116413passing the remaining elements as arguments to the system call. If
1680216414unimplemented, raises an exception. The arguments are interpreted
1680316415as follows: if a given argument is numeric, the argument is passed as
1680416416an int. If not, the pointer to the string value is passed. You are
1680516417responsible to make sure a string is pre-extended long enough to
1680616418receive any result that might be written into a string. You can't use a
1680716419string literal (or other read-only string) as an argument to C<syscall>
1680816420because Perl has to assume that any string pointer might be written
1680916421through. If your
1681016422integer arguments are not literals and have never been interpreted in a
1681116423numeric context, you may need to add C<0> to them to force them to look
1681216424like numbers. This emulates the C<syswrite> function (or vice versa):
1681316425
1681416426=end original
1681516427
1681616428LIST の最初の要素で指定するシステムコールを、残りの要素をその
1681716429システムコールの引数として呼び出します。
1681816430実装されていない場合には、例外が発生します。
1681916431引数は、以下のように解釈されます: 引数が数字であれば、int として
1682016432引数を渡します。
1682116433そうでなければ、文字列値へのポインタが渡されます。
1682216434文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、
1682316435文字列を予め伸ばしておく必要があります。
1682416436文字列リテラル(あるいはその他の読み込み専用の文字列)を C<syscall> の
1682516437引数として使うことはできません; Perl は全ての文字列ポインタは書き込まれると
1682616438仮定しなければならないからです。
16827整数引数が、リテラルでなく、数値コンテキストで評価されたことのない
16439整数引数が、リテラルでなく、数値コンテキストで評価されたことの
16828ものであれば、数値として解釈されるように、
16440ないものであれば、数値として解釈されるように、
1682916441C<0> を足しておく必要があるかもしれません。
1683016442以下は C<syswrite> 関数(あるいはその逆)をエミュレートします。
1683116443
1683216444 require 'syscall.ph'; # may need to run h2ph
1683316445 $s = "hi there\n";
1683416446 syscall(&SYS_write, fileno(STDOUT), $s, length $s);
1683516447
1683616448=begin original
1683716449
1683816450Note that Perl supports passing of up to only 14 arguments to your syscall,
1683916451which in practice should (usually) suffice.
1684016452
1684116453=end original
1684216454
1684316455Perl は、システムコールに最大 14 個の引数しか渡せませんが、
1684416456(普通は)実用上問題はないでしょう。
1684516457
1684616458=begin original
1684716459
1684816460Syscall returns whatever value returned by the system call it calls.
1684916461If the system call fails, C<syscall> returns C<-1> and sets C<$!> (errno).
1685016462Note that some system calls I<can> legitimately return C<-1>. The proper
1685116463way to handle such calls is to assign C<$!=0> before the call, then
1685216464check the value of C<$!> if C<syscall> returns C<-1>.
1685316465
1685416466=end original
1685516467
1685616468syscall は、呼び出したシステムコールが返した値を返します。
1685716469システムコールが失敗すると、C<syscall> は C<-1> を返し、
1685816470C<$!>(errno) を設定します。
1685916471システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。
1686016472このようなシステムコールを正しく扱うには、
1686116473C<$!=0> をシステムコールの前に実行し、それから
1686216474C<syscall> が C<-1> を返した時には C<$!> の値を調べてください。
1686316475
1686416476=begin original
1686516477
1686616478There's a problem with C<syscall(&SYS_pipe)>: it returns the file
1686716479number of the read end of the pipe it creates, but there is no way
1686816480to retrieve the file number of the other end. You can avoid this
1686916481problem by using C<pipe> instead.
1687016482
1687116483=end original
1687216484
16873C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の
16485C<syscall(&SYS_pipe)> には問題があり、
16874ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。
16486作ったパイプの、読み出し側のファイル番号を返しますが、
16487もう一方のファイル番号を得る方法がありません。
1687516488この問題を避けるためには、代わりに C<pipe> を使ってください。
1687616489
1687716490=begin original
1687816491
1687916492Portability issues: L<perlport/syscall>.
1688016493
1688116494=end original
1688216495
1688316496移植性の問題: L<perlport/syscall>。
1688416497
1688516498=item sysopen FILEHANDLE,FILENAME,MODE
1688616499X<sysopen>
1688716500
1688816501=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
1688916502
1689016503=for Pod::Functions +5.002 open a file, pipe, or descriptor
1689116504
1689216505=begin original
1689316506
1689416507Opens the file whose filename is given by FILENAME, and associates it with
1689516508FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real
1689616509filehandle wanted; an undefined scalar will be suitably autovivified. This
1689716510function calls the underlying operating system's I<open>(2) function with the
1689816511parameters FILENAME, MODE, and PERMS.
1689916512
1690016513=end original
1690116514
1690216515FILENAME で与えられたファイル名のファイルをオープンし、
1690316516FILEHANDLE と結び付けます。
1690416517FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として
1690516518扱われます; 未定義のスカラは適切に自動有効化されます。
1690616519この関数呼び出しはシステムの I<open>(2) 関数を FILENAME, MODE, PERMS の
1690716520引数で呼び出すことを基礎としています。
1690816521
1690916522=begin original
1691016523
1691116524The possible values and flag bits of the MODE parameter are
1691216525system-dependent; they are available via the standard module C<Fcntl>. See
1691316526the documentation of your operating system's I<open>(2) syscall to see
1691416527which values and flag bits are available. You may combine several flags
1691516528using the C<|>-operator.
1691616529
1691716530=end original
1691816531
1691916532MODE パラメータに指定できるフラグビットと値はシステム依存です;
1692016533これは標準モジュール C<Fcntl> 経由で利用可能です。
1692116534どのようなフラグビットと値が利用可能であるかについては、
1692216535OS の I<open>(2) システムコールに関する文書を参照してください。
1692316536C<|> 演算子を使って複数のフラグを結合することができます。
1692416537
1692516538=begin original
1692616539
1692716540Some of the most common values are C<O_RDONLY> for opening the file in
1692816541read-only mode, C<O_WRONLY> for opening the file in write-only mode,
1692916542and C<O_RDWR> for opening the file in read-write mode.
1693016543X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1693116544
1693216545=end original
1693316546
1693416547もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、
1693516548ファイルを書き込み専用で開く C<O_WRONLY>、
1693616549ファイルを読み書き両用で開く C<O_RDWR> です。
1693716550X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1693816551
1693916552=begin original
1694016553
1694116554For historical reasons, some values work on almost every system
1694216555supported by Perl: 0 means read-only, 1 means write-only, and 2
1694316556means read/write. We know that these values do I<not> work under
16944OS/390 and on the Macintosh; you probably don't want to
16557OS/390 & VM/ESA Unix and on the Macintosh; you probably don't want to
1694516558use them in new code.
1694616559
1694716560=end original
1694816561
1694916562歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が
1695016563あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。
16951OS/390 と Macintosh では動作 I<しない> ことが分かっています;
16564OS/390 & VM/ESA Unix と Macintosh では動作 I<しない> ことが分かっています;
1695216565新しく書くコードではこれらは使わないほうがよいでしょう。
1695316566
1695416567=begin original
1695516568
1695616569If the file named by FILENAME does not exist and the C<open> call creates
1695716570it (typically because MODE includes the C<O_CREAT> flag), then the value of
1695816571PERMS specifies the permissions of the newly created file. If you omit
1695916572the PERMS argument to C<sysopen>, Perl uses the octal value C<0666>.
1696016573These permission values need to be in octal, and are modified by your
1696116574process's current C<umask>.
1696216575X<O_CREAT>
1696316576
1696416577=end original
1696516578
1696616579FILENAME という名前のファイルが存在せず、(典型的には MODE が
1696716580C<O_CREAT> フラグを含んでいたために) C<open> 呼び出しがそれを作った場合、
1696816581PERMS の値は新しく作られたファイルの権限を指定します。
1696916582C<sysopen> の PERMS 引数を省略した場合、Perl は 8 進数 C<0666> を使います。
1697016583これらの権限は 8 進数である必要があり、プロセスの現在の C<umask> で
1697116584修正されます。
1697216585X<O_CREAT>
1697316586
1697416587=begin original
1697516588
1697616589In many systems the C<O_EXCL> flag is available for opening files in
1697716590exclusive mode. This is B<not> locking: exclusiveness means here that
1697816591if the file already exists, sysopen() fails. C<O_EXCL> may not work
1697916592on network filesystems, and has no effect unless the C<O_CREAT> flag
1698016593is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from
1698116594being opened if it is a symbolic link. It does not protect against
1698216595symbolic links in the file's path.
1698316596X<O_EXCL>
1698416597
1698516598=end original
1698616599
1698716600多くのシステムではファイルを排他モードで開くために C<O_EXCL> が
1698816601利用可能です。
1698916602これはロック B<ではありません>: 排他性というのは既にファイルが
1699016603存在していた場合、sysopen() が失敗することを意味します。
1699116604C<O_EXCL> はネットワークファイルシステムでは動作せず、
1699216605またC<O_CREAT> フラグも有効でない限りは効果がありません。
1699316606C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は
1699416607ファイルを開くことを妨げます。
1699516608これはファイルパス中のシンボリックリンクは守りません。
1699616609X<O_EXCL>
1699716610
1699816611=begin original
1699916612
1700016613Sometimes you may want to truncate an already-existing file. This
1700116614can be done using the C<O_TRUNC> flag. The behavior of
1700216615C<O_TRUNC> with C<O_RDONLY> is undefined.
1700316616X<O_TRUNC>
1700416617
1700516618=end original
1700616619
1700716620既に存在しているファイルを切り詰めたい場合もあるかもしれません。
1700816621これは C<O_TRUNC> フラグを使うことで行えます。
1700916622C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。
1701016623X<O_TRUNC>
1701116624
1701216625=begin original
1701316626
1701416627You should seldom if ever use C<0644> as argument to C<sysopen>, because
1701516628that takes away the user's option to have a more permissive umask.
1701616629Better to omit it. See the perlfunc(1) entry on C<umask> for more
1701716630on this.
1701816631
1701916632=end original
1702016633
1702116634めったなことでは C<sysopen> の引数に C<0644> を指定するべきではないでしょう:
1702216635ユーザーがより寛大な umask を指定する選択肢を奪うからです。
1702316636省略した方がいいです。
1702416637これに関するさらなる情報については perlfunc(1) の C<umask> を
1702516638参照してください。
1702616639
1702716640=begin original
1702816641
1702916642Note that C<sysopen> depends on the fdopen() C library function.
1703016643On many Unix systems, fdopen() is known to fail when file descriptors
1703116644exceed a certain value, typically 255. If you need more file
17032descriptors than that, consider using the POSIX::open() function.
16645descriptors than that, consider rebuilding Perl to use the C<sfio>
16646library, or perhaps using the POSIX::open() function.
1703316647
1703416648=end original
1703516649
17036C<sysopen> は C の fdopen() ライブラリ関数に依存していることに
16650C<sysopen> は C の fdopen() ライブラリ関数に依存していることに注意してください。
17037注意してださい。
16651の Unix システムでは、fdopen() はファイル記述子がある値(例えば 255)を超えると
17038多くの Unix システムでは、fdopen() はファイル記述子があ値(例えば 255)を
16652失敗すことが知られています。
17039超えると失敗するとが知らています。
16653これより多くのファイル記述子が必要な場合は、
17040これより多くのファイル記述子が必要な場合は、POSIX::open() 関数使うこと
16654Perl C<sfio> ライブラリ使って再ビルドするか、
17041検討してください。
16655POSIX::open() 関数を使うことを健闘してください。
1704216656
1704316657=begin original
1704416658
1704516659See L<perlopentut> for a kinder, gentler explanation of opening files.
1704616660
1704716661=end original
1704816662
17049ファイルを開くことに関するより親切な説明については L<perlopentut> を
16663ファイル操作に関するより親切な説明については L<perlopentut> を参照してください。
17050参照してください。
1705116664
1705216665=begin original
1705316666
1705416667Portability issues: L<perlport/sysopen>.
1705516668
1705616669=end original
1705716670
1705816671移植性の問題: L<perlport/sysopen>。
1705916672
1706016673=item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
1706116674X<sysread>
1706216675
1706316676=item sysread FILEHANDLE,SCALAR,LENGTH
1706416677
1706516678=for Pod::Functions fixed-length unbuffered input from a filehandle
1706616679
1706716680=begin original
1706816681
1706916682Attempts to read LENGTH bytes of data into variable SCALAR from the
1707016683specified FILEHANDLE, using the read(2). It bypasses
1707116684buffered IO, so mixing this with other kinds of reads, C<print>,
1707216685C<write>, C<seek>, C<tell>, or C<eof> can cause confusion because the
1707316686perlio or stdio layers usually buffers data. Returns the number of
1707416687bytes actually read, C<0> at end of file, or undef if there was an
1707516688error (in the latter case C<$!> is also set). SCALAR will be grown or
1707616689shrunk so that the last byte actually read is the last byte of the
1707716690scalar after the read.
1707816691
1707916692=end original
1708016693
1708116694read(2) を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの
1708216695データの読み込みを試みます。
1708316696これは、バッファ付き IO ルーチンを通りませんから、他の入力関数, C<print>,
1708416697C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと、入力がおかしくなるかも
1708516698しれません; perlio 層や stdio 層は普通データをバッファリングするからです。
1708616699ファイルの最後では C<0>が、エラー時には undef が、
1708716700それ以外では実際に読み込まれたデータの長さが返されます (後者の場合は C<$!> も
1708816701セットされます)。
1708916702実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、
1709016703SCALAR は伸び縮みします。
1709116704
1709216705=begin original
1709316706
1709416707An OFFSET may be specified to place the read data at some place in the
1709516708string other than the beginning. A negative OFFSET specifies
1709616709placement at that many characters counting backwards from the end of
1709716710the string. A positive OFFSET greater than the length of SCALAR
1709816711results in the string being padded to the required size with C<"\0">
1709916712bytes before the result of the read is appended.
1710016713
1710116714=end original
1710216715
17103OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
16716OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なうことが
16717できます。
1710416718OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1710516719位置を指定します。
17106OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
16720OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は
17107追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
16721読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで
16722パッディングされます。
1710816723
1710916724=begin original
1711016725
1711116726There is no syseof() function, which is ok, since eof() doesn't work
1711216727well on device files (like ttys) anyway. Use sysread() and check
1711316728for a return value for 0 to decide whether you're done.
1711416729
1711516730=end original
1711616731
1711716732syseof() 関数はありませんが、問題ありません; どちらにしろ eof() は
1711816733(tty のような)デバイスファイルに対してはうまく動作しないからです。
17119sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを判断してください。
16734sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを
16735判断してください。
1712016736
1712116737=begin original
1712216738
1712316739Note that if the filehandle has been marked as C<:utf8> Unicode
1712416740characters are read instead of bytes (the LENGTH, OFFSET, and the
1712516741return value of sysread() are in Unicode characters).
1712616742The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
1712716743See L</binmode>, L</open>, and the C<open> pragma, L<open>.
1712816744
1712916745=end original
1713016746
1713116747ファイルハンドルが C<:utf8> であるとマークが付けられると、バイトではなく
1713216748Unicode 文字が読み込まれます (sysread() の LENGTH, OFFSET および返り値は
1713316749Unicode 文字になります)。
1713416750C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
1713516751L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。
1713616752
1713716753=item sysseek FILEHANDLE,POSITION,WHENCE
1713816754X<sysseek> X<lseek>
1713916755
1714016756=for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite
1714116757
1714216758=begin original
1714316759
1714416760Sets FILEHANDLE's system position in bytes using lseek(2). FILEHANDLE may
1714516761be an expression whose value gives the name of the filehandle. The values
1714616762for WHENCE are C<0> to set the new position to POSITION; C<1> to set the it
1714716763to the current position plus POSITION; and C<2> to set it to EOF plus
1714816764POSITION, typically negative.
1714916765
1715016766=end original
1715116767
1715216768FILEHANDLE のシステム位置をバイト単位で lseek(2) を使って設定します。
1715316769FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1715416770WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します;
1715516771C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、
1715616772EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を
1715716773設定します。
1715816774
1715916775=begin original
1716016776
1716116777Note the I<in bytes>: even if the filehandle has been set to operate
1716216778on characters (for example by using the C<:encoding(utf8)> I/O layer),
1716316779tell() will return byte offsets, not character offsets (because
1716416780implementing that would render sysseek() unacceptably slow).
1716516781
1716616782=end original
1716716783
1716816784I<バイト単位> に関する注意: 文字単位で扱うようにファイルハンドルが
1716916785設定されている場合(C<:encoding(utf8)> I/O 層を使っている場合など)でも、
1717016786tell() は文字のオフセットではなくバイトのオフセットを返します
1717116787(なぜならこれを実装すると sysseek() が受け入れられないほど
1717216788遅くなるからです)。
1717316789
1717416790=begin original
1717516791
1717616792sysseek() bypasses normal buffered IO, so mixing it with reads other
1717716793than C<sysread> (for example C<< <> >> or read()) C<print>, C<write>,
1717816794C<seek>, C<tell>, or C<eof> may cause confusion.
1717916795
1718016796=end original
1718116797
1718216798sysseek() は普通のバッファ付き IO をバイパスしますので、
1718316799C<sysread> 以外の (例えば C<< <> >> や read() の)読み込み、
1718416800C<print>, C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと
1718516801混乱を引き起こします。
1718616802
1718716803=begin original
1718816804
1718916805For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>,
1719016806and C<SEEK_END> (start of the file, current position, end of the file)
1719116807from the Fcntl module. Use of the constants is also more portable
1719216808than relying on 0, 1, and 2. For example to define a "systell" function:
1719316809
1719416810=end original
1719516811
1719616812WHENCE には、Fcntl モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>,
1719716813C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1719816814使うこともできます。
1719916815定数の使用は 0, 1, 2 に依存するよりも移植性があります。
1720016816例えば "systell" 関数を定義するには:
1720116817
1720216818 use Fcntl 'SEEK_CUR';
1720316819 sub systell { sysseek($_[0], 0, SEEK_CUR) }
1720416820
1720516821=begin original
1720616822
1720716823Returns the new position, or the undefined value on failure. A position
1720816824of zero is returned as the string C<"0 but true">; thus C<sysseek> returns
1720916825true on success and false on failure, yet you can still easily determine
1721016826the new position.
1721116827
1721216828=end original
1721316829
1721416830新しい位置を返します; 失敗したときは未定義値を返します。
1721516831位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って
1721616832C<sysseek> は成功時に真を返し、失敗時に偽を返しますが、簡単に新しい位置を
1721716833判定できます。
1721816834
1721916835=item system LIST
1722016836X<system> X<shell>
1722116837
1722216838=item system PROGRAM LIST
1722316839
1722416840=for Pod::Functions run a separate program
1722516841
1722616842=begin original
1722716843
1722816844Does exactly the same thing as C<exec LIST>, except that a fork is
1722916845done first and the parent process waits for the child process to
1723016846exit. Note that argument processing varies depending on the
1723116847number of arguments. If there is more than one argument in LIST,
1723216848or if LIST is an array with more than one value, starts the program
1723316849given by the first element of the list with arguments given by the
1723416850rest of the list. If there is only one scalar argument, the argument
1723516851is checked for shell metacharacters, and if there are any, the
1723616852entire argument is passed to the system's command shell for parsing
1723716853(this is C</bin/sh -c> on Unix platforms, but varies on other
1723816854platforms). If there are no shell metacharacters in the argument,
1723916855it is split into words and passed directly to C<execvp>, which is
17240more efficient. On Windows, only the C<system PROGRAM LIST> syntax will
16856more efficient.
17241reliably avoid using the shell; C<system LIST>, even with more than one
17242element, will fall back to the shell if the first spawn fails.
1724316857
1724416858=end original
1724516859
1724616860C<exec LIST> とほとんど同じですが、まず fork を行ない、
1724716861親プロセスではチャイルドプロセスが終了するのを wait します。
1724816862exec の項で述べたように、引数の処理は、引数の数によって異なることに
1724916863注意してください。
1725016864LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、
1725116865リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として
1725216866起動します。
1725316867スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし
1725416868あればパースのために引数全体がシステムコマンドシェル (これは
1725516869Unix プラットフォームでは C</bin/sh -c> ですが、他のプラットフォームでは
1725616870異なります)に渡されます。
1725716871シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に
1725816872渡されます; この方がより効率的です。
17259Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を
17260回避します; C<system LIST> は、2 要素以上でも、最初の spawn が失敗すると
17261シェルにフォールバックします。
1726216873
1726316874=begin original
1726416875
17265Perl will attempt to flush all files opened for
16876Beginning with v5.6.0, Perl will attempt to flush all files opened for
1726616877output before any operation that may do a fork, but this may not be
1726716878supported on some platforms (see L<perlport>). To be safe, you may need
1726816879to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
1726916880of C<IO::Handle> on any open handles.
1727016881
1727116882=end original
1727216883
1727316884v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
1727416885fork を行う前にフラッシュしようとしますが、これに対応していない
1727516886プラットフォームもあります(L<perlport> を参照してください)。
1727616887安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、
1727716888全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
1727816889呼び出す必要があるかもしれません。
1727916890
1728016891=begin original
1728116892
1728216893The return value is the exit status of the program as returned by the
1728316894C<wait> call. To get the actual exit value, shift right by eight (see
1728416895below). See also L</exec>. This is I<not> what you want to use to capture
1728516896the output from a command; for that you should use merely backticks or
1728616897C<qx//>, as described in L<perlop/"`STRING`">. Return value of -1
1728716898indicates a failure to start the program or an error of the wait(2) system
1728816899call (inspect $! for the reason).
1728916900
1729016901=end original
1729116902
1729216903返り値は、C<wait> が返すプログラムの exit 状態です。
1729316904実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。
1729416905L</exec> も参照してください。
1729516906これはコマンドからの出力を捕らえるために使うものI<ではありません>;
1729616907そのような用途には、L<perlop/"`STRING`"> に記述されている
1729716908逆クォートや C<qx//> を使用してください。
1729816909-1 の返り値はプログラムを開始させることに失敗したか、wait(2)
1729916910システムコールがエラーを出したことを示します
1730016911(理由は $! を調べてください)。
1730116912
1730216913=begin original
1730316914
1730416915If you'd like to make C<system> (and many other bits of Perl) die on error,
1730516916have a look at the L<autodie> pragma.
1730616917
1730716918=end original
1730816919
1730916920もし C<system> (及び Perl のその他の多くの部分) でエラー時に
1731016921die したいなら、L<autodie> プラグマを見てみてください。
1731116922
1731216923=begin original
1731316924
1731416925Like C<exec>, C<system> allows you to lie to a program about its name if
1731516926you use the C<system PROGRAM LIST> syntax. Again, see L</exec>.
1731616927
1731716928=end original
1731816929
1731916930C<exec> と同様に、C<system> でも C<system PROGRAM LIST> の文法を
1732016931使うことで、プログラムに対してその名前を嘘をつくことができます。
1732116932再び、L</exec> を参照してください。
1732216933
1732316934=begin original
1732416935
1732516936Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of
1732616937C<system>, if you expect your program to terminate on receipt of these
1732716938signals you will need to arrange to do so yourself based on the return
1732816939value.
1732916940
1733016941=end original
1733116942
1733216943C<SIGINT> と C<SIGQUIT> は C<system> の実行中は無視されるので、
1733316944これらのシグナルを受信して終了させることを想定したプログラムの場合、
1733416945返り値を利用するように変更する必要があります。
1733516946
1733616947 @args = ("command", "arg1", "arg2");
1733716948 system(@args) == 0
1733816949 or die "system @args failed: $?"
1733916950
1734016951=begin original
1734116952
1734216953If you'd like to manually inspect C<system>'s failure, you can check all
1734316954possible failure modes by inspecting C<$?> like this:
1734416955
1734516956=end original
1734616957
17347C<system> の失敗を手動で検査したいなら、以下のように C<$?> を調べることで、
16958C<system> の失敗を手動で検査したいなら、
17348全ての失敗の可能性をチェックできます:
16959以下のように C<$?> を調べることで、全ての失敗の可能性を
16960チェックできます:
1734916961
1735016962 if ($? == -1) {
1735116963 print "failed to execute: $!\n";
1735216964 }
1735316965 elsif ($? & 127) {
1735416966 printf "child died with signal %d, %s coredump\n",
1735516967 ($? & 127), ($? & 128) ? 'with' : 'without';
1735616968 }
1735716969 else {
1735816970 printf "child exited with value %d\n", $? >> 8;
1735916971 }
1736016972
1736116973=begin original
1736216974
1736316975Alternatively, you may inspect the value of C<${^CHILD_ERROR_NATIVE}>
1736416976with the C<W*()> calls from the POSIX module.
1736516977
1736616978=end original
1736716979
1736816980または、POSIX モジュールの C<W*()> 呼び出しを使って
1736916981C<${^CHILD_ERROR_NATIVE}> の値を調べることもできます。
1737016982
1737116983=begin original
1737216984
1737316985When C<system>'s arguments are executed indirectly by the shell,
1737416986results and return codes are subject to its quirks.
1737516987See L<perlop/"`STRING`"> and L</exec> for details.
1737616988
1737716989=end original
1737816990
1737916991C<system> の引数がシェルによって間接的に実行された場合、
1738016992結果と返り値はシェルの癖によって変更されることがあります。
1738116993詳細については L<perlop/"`STRING`"> と L</exec> を参照してください。
1738216994
1738316995=begin original
1738416996
1738516997Since C<system> does a C<fork> and C<wait> it may affect a C<SIGCHLD>
1738616998handler. See L<perlipc> for details.
1738716999
1738817000=end original
1738917001
1739017002C<system> は C<fork> と C<wait> を行うので、C<SIGCHLD> ハンドラの影響を
1739117003受けます。
1739217004詳しくは L<perlipc> を参照してください。
1739317005
1739417006=begin original
1739517007
1739617008Portability issues: L<perlport/system>.
1739717009
1739817010=end original
1739917011
1740017012移植性の問題: L<perlport/system>。
1740117013
1740217014=item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
1740317015X<syswrite>
1740417016
1740517017=item syswrite FILEHANDLE,SCALAR,LENGTH
1740617018
1740717019=item syswrite FILEHANDLE,SCALAR
1740817020
1740917021=for Pod::Functions fixed-length unbuffered output to a filehandle
1741017022
1741117023=begin original
1741217024
1741317025Attempts to write LENGTH bytes of data from variable SCALAR to the
1741417026specified FILEHANDLE, using write(2). If LENGTH is
1741517027not specified, writes whole SCALAR. It bypasses buffered IO, so
1741617028mixing this with reads (other than C<sysread())>, C<print>, C<write>,
1741717029C<seek>, C<tell>, or C<eof> may cause confusion because the perlio and
1741817030stdio layers usually buffer data. Returns the number of bytes
1741917031actually written, or C<undef> if there was an error (in this case the
1742017032errno variable C<$!> is also set). If the LENGTH is greater than the
1742117033data available in the SCALAR after the OFFSET, only as much data as is
1742217034available will be written.
1742317035
1742417036=end original
1742517037
1742617038write(2) を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの
1742717039データの書き込みを試みます。
1742817040LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。
1742917041これは、バッファ付き IO ルーチンを通りませんから、他の入力関数
1743017042(C<sysread()> 以外), C<print>, C<write>, C<seek>, C<tell>, C<eof> と
1743117043混ぜて使うと、出力がおかしくなるかもしれません; perlio 層と stdio 層は普通
1743217044データをバッファリングするからです。
1743317045実際に読み込まれたデータの長さか、エラー時には C<undef> が返されます
1743417046(この場合エラー変数 C<$!> もセットされます)。
1743517047LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、
1743617048利用可能なデータのみが書き込まれます。
1743717049
1743817050=begin original
1743917051
1744017052An OFFSET may be specified to write the data from some part of the
1744117053string other than the beginning. A negative OFFSET specifies writing
1744217054that many characters counting backwards from the end of the string.
1744317055If SCALAR is of length zero, you can only use an OFFSET of 0.
1744417056
1744517057=end original
1744617058
1744717059OFFSET を指定すると、SCALAR の先頭以外の場所から、
1744817060データを取り出して、書き込みを行なうことができます。
1744917061OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて
1745017062何バイト目から書き込むかを示します。
1745117063SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。
1745217064
1745317065=begin original
1745417066
1745517067B<WARNING>: If the filehandle is marked C<:utf8>, Unicode characters
1745617068encoded in UTF-8 are written instead of bytes, and the LENGTH, OFFSET, and
1745717069return value of syswrite() are in (UTF8-encoded Unicode) characters.
1745817070The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
1745917071Alternately, if the handle is not marked with an encoding but you
1746017072attempt to write characters with code points over 255, raises an exception.
1746117073See L</binmode>, L</open>, and the C<open> pragma, L<open>.
1746217074
1746317075=end original
1746417076
1746517077B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられると、
1746617078バイトではなく UTF-8 エンコードされた Unicode 文字が読み込まれ、
1746717079syswrite() の LENGTH, OFFSET および返り値は (UTF8 エンコードされた
1746817080Unicode) 文字単位になります。
1746917081C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
1747017082または、もしハンドルにエンコーディングが記録されていない状態で
1747117083255 を超える符号位置の文字を書き込もうとすると、例外が発生します。
1747217084L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。
1747317085
1747417086=item tell FILEHANDLE
1747517087X<tell>
1747617088
1747717089=item tell
1747817090
1747917091=for Pod::Functions get current seekpointer on a filehandle
1748017092
1748117093=begin original
1748217094
1748317095Returns the current position I<in bytes> for FILEHANDLE, or -1 on
1748417096error. FILEHANDLE may be an expression whose value gives the name of
1748517097the actual filehandle. If FILEHANDLE is omitted, assumes the file
1748617098last read.
1748717099
1748817100=end original
1748917101
1749017102FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を
1749117103返します。
1749217104FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
17493FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて
17105FILEHANDLE が省略された場合には、
17494調べます。
17106最後に読み込みを行なったファイルについて調べます。
1749517107
1749617108=begin original
1749717109
1749817110Note the I<in bytes>: even if the filehandle has been set to
1749917111operate on characters (for example by using the C<:encoding(utf8)> open
1750017112layer), tell() will return byte offsets, not character offsets (because
1750117113that would render seek() and tell() rather slow).
1750217114
1750317115=end original
1750417116
1750517117I<バイト単位> に関する注意: ファイルハンドルが (例えば
1750617118C<:encoding(utf8)> 層を使って)
1750717119文字を操作するように設定されていたとしても、tell() は文字の
1750817120オフセットではなくバイトのオフセットを返すことに注意してください
1750917121(なぜならこれは seek() と tell() が遅くなってしまうからです)。
1751017122
1751117123=begin original
1751217124
1751317125The return value of tell() for the standard streams like the STDIN
1751417126depends on the operating system: it may return -1 or something else.
1751517127tell() on pipes, fifos, and sockets usually returns -1.
1751617128
1751717129=end original
1751817130
1751917131STDIN のような標準ストリームに対する tell() の返り値は OS に依存します:
1752017132-1 やその他の値が返ってくるかもしれません。
1752117133パイプ、FIFO、ソケットに対して tell() を使うと、普通は -1 が返ります。
1752217134
1752317135=begin original
1752417136
1752517137There is no C<systell> function. Use C<sysseek(FH, 0, 1)> for that.
1752617138
1752717139=end original
1752817140
1752917141C<systell> 関数はありません。
1753017142代わりに C<sysseek(FH, 0, 1)> を使ってください。
1753117143
1753217144=begin original
1753317145
1753417146Do not use tell() (or other buffered I/O operations) on a filehandle
1753517147that has been manipulated by sysread(), syswrite(), or sysseek().
1753617148Those functions ignore the buffering, while tell() does not.
1753717149
1753817150=end original
1753917151
1754017152sysread(), syswrite(), sysseek() で操作されたファイルハンドルに tell()
1754117153(またはその他のバッファリング I/O 操作) を使わないでください。
1754217154これらの関数はバッファリングを無視しますが、tell() は違います。
1754317155
1754417156=item telldir DIRHANDLE
1754517157X<telldir>
1754617158
1754717159=for Pod::Functions get current seekpointer on a directory handle
1754817160
1754917161=begin original
1755017162
1755117163Returns the current position of the C<readdir> routines on DIRHANDLE.
1755217164Value may be given to C<seekdir> to access a particular location in a
1755317165directory. C<telldir> has the same caveats about possible directory
1755417166compaction as the corresponding system library routine.
1755517167
1755617168=end original
1755717169
1755817170DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を返します。
1755917171値は、そのディレクトリで特定の位置をアクセスするため、
1756017172C<seekdir> に渡すことができます。
1756117173C<telldir> は同名のシステムライブラリルーチンと同じく、
1756217174ディレクトリ縮小時の問題が考えられます。
1756317175
1756417176=item tie VARIABLE,CLASSNAME,LIST
1756517177X<tie>
1756617178
1756717179=for Pod::Functions +5.002 bind a variable to an object class
1756817180
1756917181=begin original
1757017182
1757117183This function binds a variable to a package class that will provide the
1757217184implementation for the variable. VARIABLE is the name of the variable
1757317185to be enchanted. CLASSNAME is the name of a class implementing objects
17574of correct type. Any additional arguments are passed to the
17186of correct type. Any additional arguments are passed to the C<new>
17575appropriate constructor
1757617187method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>,
1757717188or C<TIEHASH>). Typically these are arguments such as might be passed
17578to the C<dbm_open()> function of C. The object returned by the
17189to the C<dbm_open()> function of C. The object returned by the C<new>
17579constructor is also returned by the C<tie> function, which would be useful
17190method is also returned by the C<tie> function, which would be useful
1758017191if you want to access other methods in CLASSNAME.
1758117192
1758217193=end original
1758317194
1758417195この関数は、変数を、その変数の実装を行なうクラスと結び付けます。
1758517196VARIABLE は、魔法をかける変数の名前です。
1758617197CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。
17587他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます
17198他に引数があれば、そのクラスの C<new> メソッドに渡されます
1758817199(つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。
1758917200通常、これらは、C の C<dbm_open> などの関数に渡す引数となります。
17590コンストラクタで返されるオブジェクトはまた C<tie> 関数でも返されます;
17201C<new> メソッドで返されるオブジェクトはまた C<tie> 関数でも返されます;
1759117202これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。
1759217203
1759317204=begin original
1759417205
1759517206Note that functions such as C<keys> and C<values> may return huge lists
1759617207when used on large objects, like DBM files. You may prefer to use the
1759717208C<each> function to iterate over such. Example:
1759817209
1759917210=end original
1760017211
1760117212DBM ファイルのような大きなオブジェクトでは、C<keys> や C<values> のような
1760217213関数は、大きなリストを返す可能性があります。
1760317214そのような場合では、C<each> 関数を使って繰り返しを行なった方が
1760417215よいかもしれません。
1760517216例:
1760617217
1760717218 # print out history file offsets
1760817219 use NDBM_File;
1760917220 tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
1761017221 while (($key,$val) = each %HIST) {
1761117222 print $key, ' = ', unpack('L',$val), "\n";
1761217223 }
1761317224 untie(%HIST);
1761417225
1761517226=begin original
1761617227
1761717228A class implementing a hash should have the following methods:
1761817229
1761917230=end original
1762017231
1762117232ハッシュを実装するクラスでは、次のようなメソッドを用意します:
1762217233
1762317234 TIEHASH classname, LIST
1762417235 FETCH this, key
1762517236 STORE this, key, value
1762617237 DELETE this, key
1762717238 CLEAR this
1762817239 EXISTS this, key
1762917240 FIRSTKEY this
1763017241 NEXTKEY this, lastkey
1763117242 SCALAR this
1763217243 DESTROY this
1763317244 UNTIE this
1763417245
1763517246=begin original
1763617247
1763717248A class implementing an ordinary array should have the following methods:
1763817249
1763917250=end original
1764017251
1764117252通常の配列を実装するクラスでは、次のようなメソッドを用意します:
1764217253
1764317254 TIEARRAY classname, LIST
1764417255 FETCH this, key
1764517256 STORE this, key, value
1764617257 FETCHSIZE this
1764717258 STORESIZE this, count
1764817259 CLEAR this
1764917260 PUSH this, LIST
1765017261 POP this
1765117262 SHIFT this
1765217263 UNSHIFT this, LIST
1765317264 SPLICE this, offset, length, LIST
1765417265 EXTEND this, count
17655 DELETE this, key
17656 EXISTS this, key
1765717266 DESTROY this
1765817267 UNTIE this
1765917268
1766017269=begin original
1766117270
1766217271A class implementing a filehandle should have the following methods:
1766317272
1766417273=end original
1766517274
1766617275ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します:
1766717276
1766817277 TIEHANDLE classname, LIST
1766917278 READ this, scalar, length, offset
1767017279 READLINE this
1767117280 GETC this
1767217281 WRITE this, scalar, length, offset
1767317282 PRINT this, LIST
1767417283 PRINTF this, format, LIST
1767517284 BINMODE this
1767617285 EOF this
1767717286 FILENO this
1767817287 SEEK this, position, whence
1767917288 TELL this
1768017289 OPEN this, mode, LIST
1768117290 CLOSE this
1768217291 DESTROY this
1768317292 UNTIE this
1768417293
1768517294=begin original
1768617295
1768717296A class implementing a scalar should have the following methods:
1768817297
1768917298=end original
1769017299
1769117300スカラ変数を実装するクラスでは、次のようなメソッドを用意します:
1769217301
1769317302 TIESCALAR classname, LIST
1769417303 FETCH this,
1769517304 STORE this, value
1769617305 DESTROY this
1769717306 UNTIE this
1769817307
1769917308=begin original
1770017309
1770117310Not all methods indicated above need be implemented. See L<perltie>,
1770217311L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>.
1770317312
1770417313=end original
1770517314
1770617315上記の全てのメソッドを実装する必要はありません。
1770717316L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>,
1770817317L<Tie::Handle> を参照してください。
1770917318
1771017319=begin original
1771117320
1771217321Unlike C<dbmopen>, the C<tie> function will not C<use> or C<require> a module
1771317322for you; you need to do that explicitly yourself. See L<DB_File>
1771417323or the F<Config> module for interesting C<tie> implementations.
1771517324
1771617325=end original
1771717326
1771817327C<dbmopen> と違い、C<tie> 関数はモジュールを C<use> したり
1771917328C<require> したりしません; 自分で明示的に行う必要があります。
1772017329C<tie> の興味深い実装については L<DB_File> や F<Config> モジュールを
1772117330参照してください。
1772217331
1772317332=begin original
1772417333
1772517334For further details see L<perltie>, L<"tied VARIABLE">.
1772617335
1772717336=end original
1772817337
1772917338更なる詳細については L<perltie> や L<"tied VARIABLE"> を参照してください。
1773017339
1773117340=item tied VARIABLE
1773217341X<tied>
1773317342
1773417343=for Pod::Functions get a reference to the object underlying a tied variable
1773517344
1773617345=begin original
1773717346
1773817347Returns a reference to the object underlying VARIABLE (the same value
1773917348that was originally returned by the C<tie> call that bound the variable
1774017349to a package.) Returns the undefined value if VARIABLE isn't tied to a
1774117350package.
1774217351
1774317352=end original
1774417353
1774517354VARIABLE の基となるオブジェクトへのリファレンスを返します
1774617355(変数をパッケージに結びつけるために C<tie> 呼び出しをしたときの
1774717356返り値と同じものです)。
1774817357VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。
1774917358
1775017359=item time
1775117360X<time> X<epoch>
1775217361
1775317362=for Pod::Functions return number of seconds since 1970
1775417363
1775517364=begin original
1775617365
1775717366Returns the number of non-leap seconds since whatever time the system
1775817367considers to be the epoch, suitable for feeding to C<gmtime> and
1775917368C<localtime>. On most systems the epoch is 00:00:00 UTC, January 1, 1970;
1776017369a prominent exception being Mac OS Classic which uses 00:00:00, January 1,
17761173701904 in the current local time zone for its epoch.
1776217371
1776317372=end original
1776417373
1776517374C<gmtime> や C<localtime> への入力形式に合っている、
1776617375システムが紀元と考える時点からの連続秒数を返します。
1776717376ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です;
1776817377特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの
17769173781904 年 1 月 1 日 00:00:00 を紀元として使います。
1777017379
1777117380=begin original
1777217381
1777317382For measuring time in better granularity than one second, use the
1777417383L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or,
1777517384if you have gettimeofday(2), you may be able to use the C<syscall>
1777617385interface of Perl. See L<perlfaq8> for details.
1777717386
1777817387=end original
1777917388
17780173891 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では
1778117390CPANから)の L<Time::HiRes> モジュールを使うか、
1778217391gettimeofday(2) があるなら、Perl の C<syscall> インターフェースを
1778317392使ってください。
1778417393詳しくは L<perlfaq8> を参照してください。
1778517394
1778617395=begin original
1778717396
1778817397For date and time processing look at the many related modules on CPAN.
1778917398For a comprehensive date and time representation look at the
1779017399L<DateTime> module.
1779117400
1779217401=end original
1779317402
1779417403日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。
1779517404包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
1779617405参照してください。
1779717406
1779817407=item times
1779917408X<times>
1780017409
1780117410=for Pod::Functions return elapsed time for self and child processes
1780217411
1780317412=begin original
1780417413
1780517414Returns a four-element list giving the user and system times in
1780617415seconds for this process and any exited children of this process.
1780717416
1780817417=end original
1780917418
1781017419現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を
1781117420秒で示した、4 要素のリスト値を返します。
1781217421
1781317422 ($user,$system,$cuser,$csystem) = times;
1781417423
1781517424=begin original
1781617425
1781717426In scalar context, C<times> returns C<$user>.
1781817427
1781917428=end original
1782017429
1782117430スカラコンテキストでは、C<times> は C<$user> を返します。
1782217431
1782317432=begin original
1782417433
1782517434Children's times are only included for terminated children.
1782617435
1782717436=end original
1782817437
1782917438子プロセスに対する times は、終了した子プロセスのみ含められます。
1783017439
1783117440=begin original
1783217441
1783317442Portability issues: L<perlport/times>.
1783417443
1783517444=end original
1783617445
1783717446移植性の問題: L<perlport/times>。
1783817447
1783917448=item tr///
1784017449
1784117450=for Pod::Functions transliterate a string
1784217451
1784317452=begin original
1784417453
1784517454The transliteration operator. Same as C<y///>. See
17846L<perlop/"Quote-Like Operators">.
17455L<perlop/"Quote and Quote-like Operators">.
1784717456
1784817457=end original
1784917458
1785017459文字変換演算子です。
1785117460C<y///> と同じです。
17852L<perlop/"Quote-Like Operators"> を参照してください。
17461L<perlop/"Quote and Quote-like Operators"> を参照してください。
1785317462
1785417463=item truncate FILEHANDLE,LENGTH
1785517464X<truncate>
1785617465
1785717466=item truncate EXPR,LENGTH
1785817467
1785917468=for Pod::Functions shorten a file
1786017469
1786117470=begin original
1786217471
1786317472Truncates the file opened on FILEHANDLE, or named by EXPR, to the
1786417473specified length. Raises an exception if truncate isn't implemented
1786517474on your system. Returns true if successful, C<undef> on error.
1786617475
1786717476=end original
1786817477
1786917478FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、
1787017479指定した長さに切り詰めます。
1787117480システム上に truncate が実装されていなければ、例外が発生します。
1787217481成功すれば真を、エラー時には C<undef> を返します。
1787317482
1787417483=begin original
1787517484
1787617485The behavior is undefined if LENGTH is greater than the length of the
1787717486file.
1787817487
1787917488=end original
1788017489
1788117490LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。
1788217491
1788317492=begin original
1788417493
1788517494The position in the file of FILEHANDLE is left unchanged. You may want to
1788617495call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the file.
1788717496
1788817497=end original
1788917498
1789017499FILEHANDLE のファイルの位置は変わりません。
1789117500ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を
1789217501呼び出したいかもしれません。
1789317502
1789417503=begin original
1789517504
1789617505Portability issues: L<perlport/truncate>.
1789717506
1789817507=end original
1789917508
1790017509移植性の問題: L<perlport/truncate>。
1790117510
1790217511=item uc EXPR
1790317512X<uc> X<uppercase> X<toupper>
1790417513
1790517514=item uc
1790617515
1790717516=for Pod::Functions return upper-case version of a string
1790817517
1790917518=begin original
1791017519
1791117520Returns an uppercased version of EXPR. This is the internal function
1791217521implementing the C<\U> escape in double-quoted strings.
1791317522It does not attempt to do titlecase mapping on initial letters. See
1791417523L</ucfirst> for that.
1791517524
1791617525=end original
1791717526
1791817527EXPR を大文字に変換したものを返します。
1791917528これは、ダブルクォート文字列における、C<\U> エスケープを
1792017529実装する内部関数です。
1792117530先頭文字の タイトル文字マッピングは試みません。
1792217531このためには L</ucfirst> を参照してください。
1792317532
1792417533=begin original
1792517534
1792617535If EXPR is omitted, uses C<$_>.
1792717536
1792817537=end original
1792917538
1793017539EXPR が省略されると、C<$_> を使います。
1793117540
1793217541=begin original
1793317542
1793417543This function behaves the same way under various pragma, such as in a locale,
1793517544as L</lc> does.
1793617545
1793717546=end original
1793817547
1793917548この関数は、ロケールのようなさまざまなプラグマの影響下では、
1794017549L</lc> と同様に振る舞います。
1794117550
1794217551=item ucfirst EXPR
1794317552X<ucfirst> X<uppercase>
1794417553
1794517554=item ucfirst
1794617555
1794717556=for Pod::Functions return a string with just the next letter in upper case
1794817557
1794917558=begin original
1795017559
1795117560Returns the value of EXPR with the first character in uppercase
1795217561(titlecase in Unicode). This is the internal function implementing
1795317562the C<\u> escape in double-quoted strings.
1795417563
1795517564=end original
1795617565
1795717566最初の文字だけを大文字にした、EXPR を返します
1795817567(Unicode では titlecase)。
1795917568これは、ダブルクォート文字列における、C<\u> エスケープを
1796017569実装する内部関数です。
1796117570
1796217571=begin original
1796317572
1796417573If EXPR is omitted, uses C<$_>.
1796517574
1796617575=end original
1796717576
1796817577EXPR が省略されると、C<$_> を使います。
1796917578
1797017579=begin original
1797117580
1797217581This function behaves the same way under various pragma, such as in a locale,
1797317582as L</lc> does.
1797417583
1797517584=end original
1797617585
1797717586この関数は、ロケールのようなさまざまなプラグマの影響下では、
1797817587L</lc> と同様に振る舞います。
1797917588
1798017589=item umask EXPR
1798117590X<umask>
1798217591
1798317592=item umask
1798417593
1798517594=for Pod::Functions set file creation mode mask
1798617595
1798717596=begin original
1798817597
1798917598Sets the umask for the process to EXPR and returns the previous value.
1799017599If EXPR is omitted, merely returns the current umask.
1799117600
1799217601=end original
1799317602
1799417603現在のプロセスの umask を EXPR に設定し、以前の値を返します。
1799517604EXPR が省略されると、単にその時点の umask の値を返します。
1799617605
1799717606=begin original
1799817607
1799917608The Unix permission C<rwxr-x---> is represented as three sets of three
1800017609bits, or three octal digits: C<0750> (the leading 0 indicates octal
1800117610and isn't one of the digits). The C<umask> value is such a number
1800217611representing disabled permissions bits. The permission (or "mode")
1800317612values you pass C<mkdir> or C<sysopen> are modified by your umask, so
1800417613even if you tell C<sysopen> to create a file with permissions C<0777>,
1800517614if your umask is C<0022>, then the file will actually be created with
1800617615permissions C<0755>. If your C<umask> were C<0027> (group can't
1800717616write; others can't read, write, or execute), then passing
1800817617C<sysopen> C<0666> would create a file with mode C<0640> (because
1800917618C<0666 &~ 027> is C<0640>).
1801017619
1801117620=end original
1801217621
1801317622Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、
1801417623または 3 桁の 8 進数として表現されます:
1801517624C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。
1801617625C<umask> の値は無効にするパーミッションビットのこのような数値表現です。
1801717626C<mkdir> や C<sysopen> で渡されたパーミッション(または「モード」)の値は
1801817627umask で修正され、たとえ C<sysopen> で C<0777> のパーミッションで
1801917628ファイルを作るように指定しても、umask が C<0022> なら、
1802017629結果としてファイルは C<0755> のパーミッションで作成されます。
1802117630C<umask> が C<0027> (グループは書き込めない; その他は読み込み、書き込み、
1802217631実行できない) のとき、C<sysopen> に C<0666> を渡すと、
1802317632ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。
1802417633
1802517634=begin original
1802617635
1802717636Here's some advice: supply a creation mode of C<0666> for regular
1802817637files (in C<sysopen>) and one of C<0777> for directories (in
1802917638C<mkdir>) and executable files. This gives users the freedom of
1803017639choice: if they want protected files, they might choose process umasks
1803117640of C<022>, C<027>, or even the particularly antisocial mask of C<077>.
1803217641Programs should rarely if ever make policy decisions better left to
1803317642the user. The exception to this is when writing files that should be
1803417643kept private: mail files, web browser cookies, I<.rhosts> files, and
1803517644so on.
1803617645
1803717646=end original
1803817647
1803917648以下は助言です: 作成モードとして、(C<sysopen> による)通常ファイルでは
1804017649C<0666> を、(C<mkdir> による)ディレクトリでは C<0777> を指定しましょう。
1804117650これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、
1804217651プロセスの umask として C<022>, C<027>, あるいは特に非社交的な
1804317652C<077> を選択できます。
1804417653プログラムがユーザーより適切なポリシー選択ができることは稀です。
1804517654例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、
1804617655I<.rhosts> ファイルなど)を書く場合です。
1804717656
1804817657=begin original
1804917658
1805017659If umask(2) is not implemented on your system and you are trying to
1805117660restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>),
1805217661raises an exception. If umask(2) is not implemented and you are
1805317662not trying to restrict access for yourself, returns C<undef>.
1805417663
1805517664=end original
1805617665
1805717666umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを
1805817667制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。
1805917668umask(2) が実装されていないシステムで、自分自身へのアクセスは
1806017669制限しようとしなかった場合、C<undef> を返します。
1806117670
1806217671=begin original
1806317672
1806417673Remember that a umask is a number, usually given in octal; it is I<not> a
1806517674string of octal digits. See also L</oct>, if all you have is a string.
1806617675
1806717676=end original
1806817677
1806917678umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の
1807017679文字列 I<ではありません>。
1807117680文字列しかない場合、 L</oct> も参照してください。
1807217681
1807317682=begin original
1807417683
1807517684Portability issues: L<perlport/umask>.
1807617685
1807717686=end original
1807817687
1807917688移植性の問題: L<perlport/umask>。
1808017689
1808117690=item undef EXPR
1808217691X<undef> X<undefine>
1808317692
1808417693=item undef
1808517694
1808617695=for Pod::Functions remove a variable or function definition
1808717696
1808817697=begin original
1808917698
1809017699Undefines the value of EXPR, which must be an lvalue. Use only on a
1809117700scalar value, an array (using C<@>), a hash (using C<%>), a subroutine
1809217701(using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}>
1809317702will probably not do what you expect on most predefined variables or
1809417703DBM list values, so don't do that; see L</delete>. Always returns the
1809517704undefined value. You can omit the EXPR, in which case nothing is
1809617705undefined, but you still get an undefined value that you could, for
1809717706instance, return from a subroutine, assign to a variable, or pass as a
1809817707parameter. Examples:
1809917708
1810017709=end original
1810117710
1810217711左辺値である EXPR の値を未定義にします。
1810317712スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
1810417713サブルーチン、(C<*> を使った)型グロブだけに使用します。
1810517714特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても
1810617715おそらく期待通りの結果にはなりませんから、しないでください;
1810717716L</delete> を参照してください。
1810817717常に未定義値を返します。
1810917718EXPR は省略することができ、その場合には何も未定義にされませんが
1811017719未定義値は返されますので、それをたとえば、
1811117720サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。
1811217721例:
1811317722
1811417723 undef $foo;
1811517724 undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};
1811617725 undef @ary;
1811717726 undef %hash;
1811817727 undef &mysub;
1811917728 undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc.
1812017729 return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it;
1812117730 select undef, undef, undef, 0.25;
1812217731 ($a, $b, undef, $c) = &foo; # Ignore third value returned
1812317732
1812417733=begin original
1812517734
1812617735Note that this is a unary operator, not a list operator.
1812717736
1812817737=end original
1812917738
1813017739これはリスト演算子ではなく、単項演算子であることに注意してください。
1813117740
1813217741=item unlink LIST
1813317742X<unlink> X<delete> X<remove> X<rm> X<del>
1813417743
1813517744=item unlink
1813617745
1813717746=for Pod::Functions remove one link to a file
1813817747
1813917748=begin original
1814017749
1814117750Deletes a list of files. On success, it returns the number of files
1814217751it successfully deleted. On failure, it returns false and sets C<$!>
1814317752(errno):
1814417753
1814517754=end original
1814617755
1814717756LIST に含まれるファイルを削除します。
1814817757成功時は削除に成功したファイルの数を返します。
1814917758失敗時は偽を返して C<$!> (error) をセットします:
1815017759
1815117760 my $unlinked = unlink 'a', 'b', 'c';
1815217761 unlink @goners;
1815317762 unlink glob "*.bak";
1815417763
1815517764=begin original
1815617765
1815717766On error, C<unlink> will not tell you which files it could not remove.
1815817767If you want to know which files you could not remove, try them one
1815917768at a time:
1816017769
1816117770=end original
1816217771
1816317772エラーの場合、C<unlink> はどのファイルが削除できなかったかを知らせません。
1816417773どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください:
1816517774
1816617775 foreach my $file ( @goners ) {
1816717776 unlink $file or warn "Could not unlink $file: $!";
1816817777 }
1816917778
1817017779=begin original
1817117780
1817217781Note: C<unlink> will not attempt to delete directories unless you are
1817317782superuser and the B<-U> flag is supplied to Perl. Even if these
1817417783conditions are met, be warned that unlinking a directory can inflict
1817517784damage on your filesystem. Finally, using C<unlink> on directories is
1817617785not supported on many operating systems. Use C<rmdir> instead.
1817717786
1817817787=end original
1817917788
1818017789注: スーパーユーザ権限で、Perl に -U を付けて実行した場合でなければ、
1818117790C<unlink> はディレクトリを削除しようとすることはありません。
1818217791この条件にあう場合にも、ディレクトリの削除は、
1818317792ファイルシステムに多大な損害を与える可能性があります。
1818417793最後に、C<unlink> をディレクトリに使うのはほとんどの OS では
1818517794対応していません。
1818617795代わりに C<rmdir> を使ってください。
1818717796
1818817797=begin original
1818917798
1819017799If LIST is omitted, C<unlink> uses C<$_>.
1819117800
1819217801=end original
1819317802
1819417803LIST が省略されると、C<unlink> は C<$_> を使います。
1819517804
1819617805=item unpack TEMPLATE,EXPR
1819717806X<unpack>
1819817807
1819917808=item unpack TEMPLATE
1820017809
1820117810=for Pod::Functions convert binary structure into normal perl variables
1820217811
1820317812=begin original
1820417813
1820517814C<unpack> does the reverse of C<pack>: it takes a string
1820617815and expands it out into a list of values.
1820717816(In scalar context, it returns merely the first value produced.)
1820817817
1820917818=end original
1821017819
1821117820C<unpack> は C<pack> の逆を行ないます: 構造体を表わす文字列をとり、
1821217821リスト値に展開し、その配列値を返します。
1821317822(スカラコンテキストでは、単に最初の値を返します。)
1821417823
1821517824=begin original
1821617825
1821717826If EXPR is omitted, unpacks the C<$_> string.
1821817827See L<perlpacktut> for an introduction to this function.
1821917828
1822017829=end original
1822117830
1822217831EXPR が省略されると、C<$_> の文字列を unpack します。
1822317832この関数の説明については L<perlpacktut> を参照してください。
1822417833
1822517834=begin original
1822617835
1822717836The string is broken into chunks described by the TEMPLATE. Each chunk
1822817837is converted separately to a value. Typically, either the string is a result
1822917838of C<pack>, or the characters of the string represent a C structure of some
1823017839kind.
1823117840
1823217841=end original
1823317842
1823417843文字列は TEMPLATE で示された固まりに分割されます。
1823517844それぞれの固まりは別々に値に変換されます。
1823617845典型的には、文字列は C<pack> の結果あるいはある種の C の構造体の
1823717846文字列表現の文字列です。
1823817847
1823917848=begin original
1824017849
1824117850The TEMPLATE has the same format as in the C<pack> function.
1824217851Here's a subroutine that does substring:
1824317852
1824417853=end original
1824517854
1824617855TEMPLATE は、C<pack> 関数と同じフォーマットを使います。
1824717856部分文字列を取り出すうサブルーチンの例を示します:
1824817857
1824917858 sub substr {
1825017859 my($what,$where,$howmuch) = @_;
1825117860 unpack("x$where a$howmuch", $what);
1825217861 }
1825317862
1825417863=begin original
1825517864
1825617865and then there's
1825717866
1825817867=end original
1825917868
1826017869これもそうです。
1826117870
1826217871 sub ordinal { unpack("W",$_[0]); } # same as ord()
1826317872
1826417873=begin original
1826517874
1826617875In addition to fields allowed in pack(), you may prefix a field with
1826717876a %<number> to indicate that
1826817877you want a <number>-bit checksum of the items instead of the items
1826917878themselves. Default is a 16-bit checksum. Checksum is calculated by
1827017879summing numeric values of expanded values (for string fields the sum of
1827117880C<ord($char)> is taken; for bit fields the sum of zeroes and ones).
1827217881
1827317882=end original
1827417883
1827517884pack() で利用可能なフィールドの他に、
1827617885フィールドの前に %<数値> というものを付けて、
1827717886項目自身の代わりに、その項目の <数値>-ビットのチェックサムを
1827817887計算させることができます。
1827917888デフォルトは、16-ビットチェックサムです。
1828017889チェックサムは展開された値の数値としての値の合計
1828117890(文字列フィールドの場合は C<ord($char)> の合計;
1828217891ビットフィールドの場合は 0 と 1 の合計) が用いられます。
1828317892
1828417893=begin original
1828517894
1828617895For example, the following
1828717896computes the same number as the System V sum program:
1828817897
1828917898=end original
1829017899
1829117900たとえば、以下のコードは
1829217901System V の sum プログラムと同じ値を計算します。
1829317902
1829417903 $checksum = do {
1829517904 local $/; # slurp!
1829617905 unpack("%32W*",<>) % 65535;
1829717906 };
1829817907
1829917908=begin original
1830017909
1830117910The following efficiently counts the number of set bits in a bit vector:
1830217911
1830317912=end original
1830417913
1830517914以下は、効率的にビットベクターの設定されているビットを
1830617915数えるものです。
1830717916
1830817917 $setbits = unpack("%32b*", $selectmask);
1830917918
1831017919=begin original
1831117920
1831217921The C<p> and C<P> formats should be used with care. Since Perl
1831317922has no way of checking whether the value passed to C<unpack()>
1831417923corresponds to a valid memory location, passing a pointer value that's
1831517924not known to be valid is likely to have disastrous consequences.
1831617925
1831717926=end original
1831817927
1831917928C<p> と C<P> は注意深く使うべきです。
1832017929Perl は C<unpack()> に渡された値が有効なメモリ位置を指しているかどうかを
1832117930確認する方法がないので、有効かどうかわからないポインタ値を渡すと
1832217931悲惨な結果を引き起こすかもしれません。
1832317932
1832417933=begin original
1832517934
1832617935If there are more pack codes or if the repeat count of a field or a group
1832717936is larger than what the remainder of the input string allows, the result
1832817937is not well defined: the repeat count may be decreased, or
1832917938C<unpack()> may produce empty strings or zeros, or it may raise an exception.
1833017939If the input string is longer than one described by the TEMPLATE,
1833117940the remainder of that input string is ignored.
1833217941
1833317942=end original
1833417943
1833517944多くの pack コードがある場合や、フィールドやグループの繰り返し回数が
1833617945入力文字列の残りより大きい場合、結果は未定義です:
1833717946繰り返し回数が減らされる場合もありますし、C<unpack()> が空文字列や 0 を
1833817947返すこともありますし、例外が発生します。
1833917948もし入力文字列が TEMPLATE で表現されているものより大きい場合、
1834017949入力文字列の残りは無視されます。
1834117950
1834217951=begin original
1834317952
1834417953See L</pack> for more examples and notes.
1834517954
1834617955=end original
1834717956
1834817957さらなる例と注意に関しては L</pack> を参照してください。
1834917958
1835017959=item unshift ARRAY,LIST
1835117960X<unshift>
1835217961
1835317962=item unshift EXPR,LIST
1835417963
1835517964=for Pod::Functions prepend more elements to the beginning of a list
1835617965
1835717966=begin original
1835817967
1835917968Does the opposite of a C<shift>. Or the opposite of a C<push>,
1836017969depending on how you look at it. Prepends list to the front of the
1836117970array and returns the new number of elements in the array.
1836217971
1836317972=end original
1836417973
1836517974C<shift> の逆操作を行ないます。
1836617975見方を変えれば、C<push> の逆操作とも考えられます。
1836717976LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。
1836817977
1836917978 unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;
1837017979
1837117980=begin original
1837217981
1837317982Note the LIST is prepended whole, not one element at a time, so the
1837417983prepended elements stay in the same order. Use C<reverse> to do the
1837517984reverse.
1837617985
1837717986=end original
1837817987
1837917988LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。
1838017989逆順に登録するには、C<reverse> を使ってください。
1838117990
1838217991=begin original
1838317992
1838417993Starting with Perl 5.14, C<unshift> can take a scalar EXPR, which must hold
1838517994a reference to an unblessed array. The argument will be dereferenced
1838617995automatically. This aspect of C<unshift> is considered highly
1838717996experimental. The exact behaviour may change in a future version of Perl.
1838817997
1838917998=end original
1839017999
1839118000Perl 5.14 から、C<unshift> はスカラの EXPR を取ることができるようになりました;
1839218001これは bless されていない配列へのリファレンスでなければなりません。
1839318002引数は自動的にデリファレンスされます。
1839418003C<unshift> のこの動作は高度に実験的であると考えられています。
1839518004正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1839618005
1839718006=begin original
1839818007
1839918008To avoid confusing would-be users of your code who are running earlier
1840018009versions of Perl with mysterious syntax errors, put this sort of thing at
1840118010the top of your file to signal that your code will work I<only> on Perls of
1840218011a recent vintage:
1840318012
1840418013=end original
1840518014
1840618015あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1840718016文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
1840818017I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1840918018書いてください:
1841018019
1841118020 use 5.014; # so push/pop/etc work on scalars (experimental)
1841218021
1841318022=item untie VARIABLE
1841418023X<untie>
1841518024
1841618025=for Pod::Functions break a tie binding to a variable
1841718026
1841818027=begin original
1841918028
1842018029Breaks the binding between a variable and a package.
1842118030(See L<tie|/tie VARIABLE,CLASSNAME,LIST>.)
1842218031Has no effect if the variable is not tied.
1842318032
1842418033=end original
1842518034
1842618035変数とパッケージの間の結合を解きます。
1842718036(L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。)
1842818037結合されていない場合は何も起きません。
1842918038
1843018039=item use Module VERSION LIST
1843118040X<use> X<module> X<import>
1843218041
1843318042=item use Module VERSION
1843418043
1843518044=item use Module LIST
1843618045
1843718046=item use Module
1843818047
1843918048=item use VERSION
1844018049
1844118050=for Pod::Functions load in a module at compile time and import its namespace
1844218051
1844318052=begin original
1844418053
1844518054Imports some semantics into the current package from the named module,
1844618055generally by aliasing certain subroutine or variable names into your
1844718056package. It is exactly equivalent to
1844818057
1844918058=end original
1845018059
1845118060指定したモジュールから、現在のパッケージにさまざまな内容をインポートします;
1845218061多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、
1845318062実現されています。
1845418063これは、以下は等価ですが:
1845518064
1845618065 BEGIN { require Module; Module->import( LIST ); }
1845718066
1845818067=begin original
1845918068
1846018069except that Module I<must> be a bareword.
18461The importation can be made conditional by using the L<if> module.
18070The importation can be made conditional; see L<if>.
1846218071
1846318072=end original
1846418073
1846518074Module が I<裸の単語でなければならない> ことを除けば、です。
18466インポートは、L<if> を使って条件付きで行うことができます。
18075インポートは条件付きで行うことができます; L<if> を参照してください
1846718076
1846818077=begin original
1846918078
1847018079In the peculiar C<use VERSION> form, VERSION may be either a positive
1847118080decimal fraction such as 5.006, which will be compared to C<$]>, or a v-string
1847218081of the form v5.6.1, which will be compared to C<$^V> (aka $PERL_VERSION). An
1847318082exception is raised if VERSION is greater than the version of the
1847418083current Perl interpreter; Perl will not attempt to parse the rest of the
1847518084file. Compare with L</require>, which can do a similar check at run time.
1847618085Symmetrically, C<no VERSION> allows you to specify that you want a version
1847718086of Perl older than the specified one.
1847818087
1847918088=end original
1848018089
1848118090特に C<use VERSION> の形式では、
1848218091VERSION は 5.006 のような正の 10 進小数 (C<$]> と比較されます)か、v5.6.1 の形
1848318092(C<$^V> (またの名を $PERL_VERSION) と比較されます) のv-文字列で指定します。
1848418093VERSION が Perl の現在のバージョンより大きいと、例外が発生します;
1848518094Perl はファイルの残りを読み込みません。
1848618095L</require> と似ていますが、これは実行時にチェックされます。
1848718096対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で
1848818097動作させたいことを意味します。
1848918098
1849018099=begin original
1849118100
1849218101Specifying VERSION as a literal of the form v5.6.1 should generally be
1849318102avoided, because it leads to misleading error messages under earlier
1849418103versions of Perl (that is, prior to 5.6.0) that do not support this
1849518104syntax. The equivalent numeric version should be used instead.
1849618105
1849718106=end original
1849818107
1849918108VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
1850018109なぜなら、この文法に対応していない Perl の初期のバージョン
1850118110(つまり、 5.6.0 以前) では誤解させるようなエラーメッセージが出るからです。
1850218111代わりに等価な数値表現を使うべきです。
1850318112
1850418113 use v5.6.1; # compile time version check
1850518114 use 5.6.1; # ditto
1850618115 use 5.006_001; # ditto; preferred for backwards compatibility
1850718116
1850818117=begin original
1850918118
1851018119This is often useful if you need to check the current Perl version before
1851118120C<use>ing library modules that won't work with older versions of Perl.
1851218121(We try not to do this more than we have to.)
1851318122
1851418123=end original
1851518124
1851618125これは古いバージョンの Perl で動かなくなったライブラリモジュールを
1851718126C<use> する前に、現在の Perl のバージョンを調べたい場合に有用です。
1851818127(我々は必要な場合以外にそのようなことがないように努力していますが。)
1851918128
1852018129=begin original
1852118130
1852218131C<use VERSION> also enables all features available in the requested
1852318132version as defined by the C<feature> pragma, disabling any features
1852418133not in the requested version's feature bundle. See L<feature>.
1852518134Similarly, if the specified Perl version is greater than or equal to
185265.12.0, strictures are enabled lexically as
181355.11.0, strictures are enabled lexically as
1852718136with C<use strict>. Any explicit use of
1852818137C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes
1852918138before it. In both cases, the F<feature.pm> and F<strict.pm> files are
1853018139not actually loaded.
1853118140
1853218141=end original
1853318142
1853418143C<use VERSION> は、C<feature> プラグマで定義されたように、指定された
1853518144バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の
1853618145束にない機能を無効にします。
1853718146L<feature> を参照してください。
18538同様に、指定された Perl のバージョンが 5.12.0 以上の場合、
18147同様に、指定された Perl のバージョンが 5.11.0 以上の場合、
1853918148制限は C<use strict> と同様にレキシカルに有効になります。
1854018149明示的に C<use strict> や C<no strict> を使うと、例え先に
1854118150指定されていたとしても、C<use VERSION> を上書きします。
1854218151どちらの場合も、F<feature.pm> と F<strict.pm> ファイルは実際には
1854318152読み込まれません。
1854418153
1854518154=begin original
1854618155
1854718156The C<BEGIN> forces the C<require> and C<import> to happen at compile time. The
1854818157C<require> makes sure the module is loaded into memory if it hasn't been
1854918158yet. The C<import> is not a builtin; it's just an ordinary static method
1855018159call into the C<Module> package to tell the module to import the list of
1855118160features back into the current package. The module can implement its
1855218161C<import> method any way it likes, though most modules just choose to
1855318162derive their C<import> method via inheritance from the C<Exporter> class that
1855418163is defined in the C<Exporter> module. See L<Exporter>. If no C<import>
1855518164method can be found then the call is skipped, even if there is an AUTOLOAD
1855618165method.
1855718166
1855818167=end original
1855918168
1856018169C<BEGIN> によって、C<require> や C<import> は、コンパイル時に
1856118170実行されることになります。
1856218171C<require> は、モジュールがまだメモリにロードされていなければ、ロードします。
1856318172C<import> は、組込みの関数ではありません; さまざまな機能を現在のパッケージに
1856418173インポートするように C<Module> パッケージに伝えるために呼ばれる、
1856518174通常の静的メソッドです。
1856618175モジュール側では、C<import> メソッドをどのようにでも実装することが
1856718176できますが、多くのモジュールでは、C<Exporter> モジュールで定義された、
1856818177C<Exporter> クラスからの継承によって、C<import> メソッドを行なうように
1856918178しています。
1857018179L<Exporter>モジュールを参照してください。
1857118180C<import>メソッドが見つからなかった場合、AUTOLOAD メソッドがあったとしても
1857218181呼び出しはスキップされます。
1857318182
1857418183=begin original
1857518184
1857618185If you do not want to call the package's C<import> method (for instance,
1857718186to stop your namespace from being altered), explicitly supply the empty list:
1857818187
1857918188=end original
1858018189
1858118190パッケージの C<import> メソッドを呼び出したくない場合(例えば、名前空間を
1858218191変更したくない場合など)は、明示的に空リストを指定してください:
1858318192
1858418193 use Module ();
1858518194
1858618195=begin original
1858718196
1858818197That is exactly equivalent to
1858918198
1859018199=end original
1859118200
1859218201これは以下と完全に等価です:
1859318202
1859418203 BEGIN { require Module }
1859518204
1859618205=begin original
1859718206
1859818207If the VERSION argument is present between Module and LIST, then the
1859918208C<use> will call the VERSION method in class Module with the given
1860018209version as an argument. The default VERSION method, inherited from
1860118210the UNIVERSAL class, croaks if the given version is larger than the
1860218211value of the variable C<$Module::VERSION>.
1860318212
1860418213=end original
1860518214
1860618215Module と LIST の間に VERSION 引数がある場合、C<use> は Module クラスの
1860718216VERSION メソッドを、与えられたバージョンを引数として呼び出します。
1860818217デフォルトの VERSION メソッドは、 UNIVERSAL クラスから継承したもので、
1860918218与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に
1861018219警告を出します。
1861118220
1861218221=begin original
1861318222
1861418223Again, there is a distinction between omitting LIST (C<import> called
1861518224with no arguments) and an explicit empty LIST C<()> (C<import> not
1861618225called). Note that there is no comma after VERSION!
1861718226
1861818227=end original
1861918228
1862018229繰り返すと、LIST を省略する(C<import> が引数なしで呼び出される)ことと
1862118230明示的に空の LIST C<()> を指定する (C<import> は呼び出されない)ことは
1862218231違います。
1862318232VERSION の後ろにカンマが不要なことに注意してください!
1862418233
1862518234=begin original
1862618235
1862718236Because this is a wide-open interface, pragmas (compiler directives)
1862818237are also implemented this way. Currently implemented pragmas are:
1862918238
1863018239=end original
1863118240
1863218241これは、広く公開されているインタフェースですので、
1863318242プラグマ (コンパイラディレクティブ) も、この方法で実装されています。
1863418243現在実装されているプラグマには、以下のものがあります:
1863518244
1863618245 use constant;
1863718246 use diagnostics;
1863818247 use integer;
1863918248 use sigtrap qw(SEGV BUS);
1864018249 use strict qw(subs vars refs);
1864118250 use subs qw(afunc blurfl);
1864218251 use warnings qw(all);
1864318252 use sort qw(stable _quicksort _mergesort);
1864418253
1864518254=begin original
1864618255
1864718256Some of these pseudo-modules import semantics into the current
1864818257block scope (like C<strict> or C<integer>, unlike ordinary modules,
1864918258which import symbols into the current package (which are effective
1865018259through the end of the file).
1865118260
1865218261=end original
1865318262
1865418263通常のモジュールが、現在のパッケージにシンボルをインポートする
1865518264(これは、ファイルの終わりまで有効です) のに対して、
1865618265これらの擬似モジュールの一部(C<strict> や C<integer> など)は、
1865718266現在のブロックスコープにインポートを行ないます。
1865818267
1865918268=begin original
1866018269
1866118270Because C<use> takes effect at compile time, it doesn't respect the
1866218271ordinary flow control of the code being compiled. In particular, putting
1866318272a C<use> inside the false branch of a conditional doesn't prevent it
1866418273from being processed. If a module or pragma only needs to be loaded
1866518274conditionally, this can be done using the L<if> pragma:
1866618275
1866718276=end original
1866818277
1866918278C<use> はコンパイル時に有効なので、コードがコンパイルされる際の通常の
1867018279流れ制御には従いません。
1867118280特に、条件文のうち成立しない側の中に C<use> を書いても、
1867218281処理を妨げられません。
1867318282モジュールやプラグマを条件付きでのみ読み込みたい場合、
1867418283L<if> プラグマを使って実現できます:
1867518284
1867618285 use if $] < 5.008, "utf8";
1867718286 use if WANT_WARNINGS, warnings => qw(all);
1867818287
1867918288=begin original
1868018289
1868118290There's a corresponding C<no> declaration that unimports meanings imported
1868218291by C<use>, i.e., it calls C<unimport Module LIST> instead of C<import>.
1868318292It behaves just as C<import> does with VERSION, an omitted or empty LIST,
1868418293or no unimport method being found.
1868518294
1868618295=end original
1868718296
1868818297これに対して、C<no> 宣言という、C<use> によってインポートされたものを、
1868918298インポートされていないことにするものがあります; つまり、C<import> の代わりに
1869018299C<unimport Module LIST> を呼び出します。
1869118300これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない
1869218301場合などの観点では、C<import> と同様に振る舞います。
1869318302
1869418303 no integer;
1869518304 no strict 'refs';
1869618305 no warnings;
1869718306
1869818307=begin original
1869918308
1870018309Care should be taken when using the C<no VERSION> form of C<no>. It is
1870118310I<only> meant to be used to assert that the running Perl is of a earlier
1870218311version than its argument and I<not> to undo the feature-enabling side effects
1870318312of C<use VERSION>.
1870418313
1870518314=end original
1870618315
1870718316C<no> の C<no VERSION> 形式を使うときには注意を払うべきです。
1870818317これは引数で指定されたバージョンよりも前の Perl で実行されたときに
1870918318アサートされることを意味する I<だけ> で、C<use VERSION> によって
1871018319有効にされた副作用をなかったことにするもの I<ではありません>。
1871118320
1871218321=begin original
1871318322
1871418323See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun>
1871518324for the C<-M> and C<-m> command-line options to Perl that give C<use>
1871618325functionality from the command-line.
1871718326
1871818327=end original
1871918328
1872018329標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。
1872118330コマンドラインから C<use> 機能を指定するための C<-M> と C<-m> の
1872218331コマンドラインオプションについては L<perlrun> を参照してください。
1872318332
1872418333=item utime LIST
1872518334X<utime>
1872618335
1872718336=for Pod::Functions set a file's last access and modify times
1872818337
1872918338=begin original
1873018339
1873118340Changes the access and modification times on each file of a list of
1873218341files. The first two elements of the list must be the NUMERIC access
1873318342and modification times, in that order. Returns the number of files
1873418343successfully changed. The inode change time of each file is set
1873518344to the current time. For example, this code has the same effect as the
1873618345Unix touch(1) command when the files I<already exist> and belong to
1873718346the user running the program:
1873818347
1873918348=end original
1874018349
1874118350ファイルのアクセス時刻と修正(modification) 時刻を変更します。
1874218351LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を
1874318352順に指定します。
1874418353変更に成功したファイルの数を返します。
1874518354各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。
1874618355例えば、このコードはファイルが I<既に存在して> いて、ユーザーが
1874718356実行しているプログラムに従っているなら、
1874818357Unix の touch(1) コマンドと同じ効果があります。
1874918358
1875018359 #!/usr/bin/perl
1875118360 $atime = $mtime = time;
1875218361 utime $atime, $mtime, @ARGV;
1875318362
1875418363=begin original
1875518364
18756Since Perl 5.8.0, if the first two elements of the list are C<undef>,
18365Since Perl 5.7.2, if the first two elements of the list are C<undef>,
1875718366the utime(2) syscall from your C library is called with a null second
1875818367argument. On most systems, this will set the file's access and
1875918368modification times to the current time (i.e., equivalent to the example
1876018369above) and will work even on files you don't own provided you have write
1876118370permission:
1876218371
1876318372=end original
1876418373
18765Perl 5.8.0 から、リストの最初の二つの要素が C<undef> である場合、
18374Perl 5.7.2 から、リストの最初の二つの要素が C<undef> である場合、
1876618375C ライブラリの utime(2) システムコールを、秒の引数を null として
1876718376呼び出します。
1876818377ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を
1876918378現在の時刻にセットし(つまり、上記の例と等価です)、
1877018379書き込み権限があれば他のユーザーのファイルに対しても動作します。
1877118380
1877218381 for $file (@ARGV) {
1877318382 utime(undef, undef, $file)
1877418383 || warn "couldn't touch $file: $!";
1877518384 }
1877618385
1877718386=begin original
1877818387
1877918388Under NFS this will use the time of the NFS server, not the time of
1878018389the local machine. If there is a time synchronization problem, the
1878118390NFS server and local machine will have different times. The Unix
1878218391touch(1) command will in fact normally use this form instead of the
1878318392one shown in the first example.
1878418393
1878518394=end original
1878618395
1878718396NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が
1878818397使われます。
1878918398時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に
1879018399なっている場合があります。
1879118400実際のところ、Unix の touch(1) コマンドは普通、最初の例ではなく、
1879218401この形を使います。
1879318402
1879418403=begin original
1879518404
1879618405Passing only one of the first two elements as C<undef> is
1879718406equivalent to passing a 0 and will not have the effect
1879818407described when both are C<undef>. This also triggers an
1879918408uninitialized warning.
1880018409
1880118410=end original
1880218411
1880318412最初の二つの要素のうち、一つだけに C<undef> を渡すと、その要素は 0 を
1880418413渡すのと等価となり、上述の、両方に C<undef> を渡した時と同じ
1880518414効果ではありません。
1880618415この場合は、未初期化の警告が出ます。
1880718416
1880818417=begin original
1880918418
1881018419On systems that support futimes(2), you may pass filehandles among the
1881118420files. On systems that don't support futimes(2), passing filehandles raises
1881218421an exception. Filehandles must be passed as globs or glob references to be
1881318422recognized; barewords are considered filenames.
1881418423
1881518424=end original
1881618425
1881718426futimes(2) に対応しているシステムでは、ファイルハンドルを引数として
1881818427渡せます。
1881918428futimes(2) に対応していないシステムでは、ファイルハンドルを渡すと
1882018429例外が発生します。
1882118430ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
1882218431渡されなければなりません; 裸の単語はファイル名として扱われます。
1882318432
1882418433=begin original
1882518434
1882618435Portability issues: L<perlport/utime>.
1882718436
1882818437=end original
1882918438
1883018439移植性の問題: L<perlport/utime>。
1883118440
1883218441=item values HASH
1883318442X<values>
1883418443
1883518444=item values ARRAY
1883618445
1883718446=item values EXPR
1883818447
1883918448=for Pod::Functions return a list of the values in a hash
1884018449
1884118450=begin original
1884218451
1884318452In list context, returns a list consisting of all the values of the named
1884418453hash. In Perl 5.12 or later only, will also return a list of the values of
1884518454an array; prior to that release, attempting to use an array argument will
1884618455produce a syntax error. In scalar context, returns the number of values.
1884718456
1884818457=end original
1884918458
1885018459リストコンテキストでは、指定したハッシュのすべての値を返します。
18851Perl 5.12 以降でのみ、配列の全ての値からなるリストも返します;
18460Perl 5.12 以降でのみ、配列の全ての値からなるリストも
18852このリリースの前では、配列要素に使おうとすると文法エラーが発生します。
18461返します; このリリースの前では、配列要素に使おうとすると文法エラーが
18462発生します。
1885318463スカラコンテキストでは、値の数を返します。
1885418464
1885518465=begin original
1885618466
18857Hash entries are returned in an apparently random order. The actual random
18467When called on a hash, the values are returned in an apparently random
18858order is specific to a given hash; the exact same series of operations
18468order. The actual random order is subject to change in future versions of
18859on two hashes may result in a different order for each hash. Any insertion
18469Perl, but it is guaranteed to be the same order as either the C<keys> or
18860into the hash may change the order, as will any deletion, with the exception
18470C<each> function would produce on the same (unmodified) hash. Since Perl
18861that the most recent key returned by C<each> or C<keys> may be deleted
184715.8.1 the ordering is different even between different runs of Perl for
18862without changing the order. So long as a given hash is unmodified you may
18472security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
18863rely on C<keys>, C<values> and C<each> to repeatedly return the same order
18864as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
18865details on why hash order is randomized. Aside from the guarantees
18866provided here the exact details of Perl's hash algorithm and the hash
18867traversal order are subject to change in any release of Perl. Tied hashes
18868may behave differently to Perl's hashes with respect to changes in order on
18869insertion and deletion of items.
1887018473
1887118474=end original
1887218475
18873ハッシュ要素は見かけ上ランダムな順序で返されます。
18476ハッシュに対して呼び出されると、返される value の順序は、見た目に
18874実際のランダム順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
18477ばらばらものです
18875操作を行っても、ハッシュによって異った順序になります。
18478実際のランダムな順序は将来のバージョンの Perl では変わる可能性が
18876ハッシュへの挿入よっ順序が変わることがあります; 削除も同様ですが
18479ありますが、同じ(変更されていない)ハッシュに対して、
18877C<each> または C<keys> によってされたっとも最近キーは順序
18480C<keys>関数や C<each>関数がものと同じ順序であることは保証されます。
18878変えることなく削除きます。
18481Perl 5.8.1 以降はセキュリティ上の理由により、
18879ハッシュが変更されない限り、C<keys>, C<values>, C<each> が繰り返し同じ序で
18482実行される毎に番は変わります
18880返すことに依存してもかまません
18483(L<perlsec/"Algorithmic Complexity Attacks"> を参照してくださ)
18881なぜハッシュの順序がランダム化されているかの詳細については
18882L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
18883ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
18884正確な詳細は Perl のリリースによって変更される可能性があります。
18885tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
18886異なった振る舞いをします。
1888718484
1888818485=begin original
1888918486
1889018487As a side effect, calling values() resets the HASH or ARRAY's internal
1889118488iterator, see L</each>. (In particular, calling values() in void context
1889218489resets the iterator with no other overhead. Apart from resetting the
1889318490iterator, C<values @array> in list context is the same as plain C<@array>.
1889418491(We recommend that you use void context C<keys @array> for this, but
1889518492reasoned that taking C<values @array> out would require more
1889618493documentation than leaving it in.)
1889718494
1889818495=end original
1889918496
1890018497副作用として、values() を呼び出すと HASH や ARRAY の内部反復子を
1890118498リセットします; C</each> を参照してください。
1890218499(特に、values() を無効コンテキストで呼び出すとその他のオーバーヘッドなしで
1890318500反復子をリセットします。
1890418501反復子をリセットするということを除けば、
1890518502リストコンテキストでの C<values @array> は単なる C<@array> と同じです。
1890618503この目的のためには無効コンテキストで C<keys @array> を使うことを
1890718504お勧めしますが、C<values @array> を取り出すにはそのままにするよりも
1890818505より多くの文書が必要だと判断しました。)
1890918506
1891018507=begin original
1891118508
1891218509Note that the values are not copied, which means modifying them will
1891318510modify the contents of the hash:
1891418511
1891518512=end original
1891618513
1891718514値はコピーされないので、返されたリストを変更すると
1891818515ハッシュの中身が変更されることに注意してください。
1891918516
18920 for (values %hash) { s/foo/bar/g } # modifies %hash values
18517 for (values %hash) { s/foo/bar/g } # modifies %hash values
18921 for (@hash{keys %hash}) { s/foo/bar/g } # same
18518 for (@hash{keys %hash}) { s/foo/bar/g } # same
1892218519
1892318520=begin original
1892418521
1892518522Starting with Perl 5.14, C<values> can take a scalar EXPR, which must hold
1892618523a reference to an unblessed hash or array. The argument will be
1892718524dereferenced automatically. This aspect of C<values> is considered highly
1892818525experimental. The exact behaviour may change in a future version of Perl.
1892918526
1893018527=end original
1893118528
1893218529Perl 5.14 から、C<values> はスカラの EXPR を取ることができるようになりました;
1893318530これは bless されていないハッシュや配列へのリファレンスでなければなりません。
1893418531引数は自動的にデリファレンスされます。
1893518532C<values> のこの動作は高度に実験的であると考えられています。
1893618533正確な振る舞いは将来のバージョンの Perl で変わるかも知れません。
1893718534
1893818535 for (values $hashref) { ... }
1893918536 for (values $obj->get_arrayref) { ... }
1894018537
1894118538=begin original
1894218539
1894318540To avoid confusing would-be users of your code who are running earlier
1894418541versions of Perl with mysterious syntax errors, put this sort of thing at
1894518542the top of your file to signal that your code will work I<only> on Perls of
1894618543a recent vintage:
1894718544
1894818545=end original
1894918546
1895018547あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1895118548文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
1895218549I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1895318550書いてください:
1895418551
1895518552 use 5.012; # so keys/values/each work on arrays
1895618553 use 5.014; # so keys/values/each work on scalars (experimental)
1895718554
1895818555=begin original
1895918556
1896018557See also C<keys>, C<each>, and C<sort>.
1896118558
1896218559=end original
1896318560
1896418561C<keys>, C<each>, C<sort> も参照してください。
1896518562
1896618563=item vec EXPR,OFFSET,BITS
1896718564X<vec> X<bit> X<bit vector>
1896818565
1896918566=for Pod::Functions test or set particular bits in a string
1897018567
1897118568=begin original
1897218569
1897318570Treats the string in EXPR as a bit vector made up of elements of
1897418571width BITS and returns the value of the element specified by OFFSET
1897518572as an unsigned integer. BITS therefore specifies the number of bits
1897618573that are reserved for each element in the bit vector. This must
1897718574be a power of two from 1 to 32 (or 64, if your platform supports
1897818575that).
1897918576
1898018577=end original
1898118578
1898218579文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、
1898318580OFFSET で指定された要素を符号なし整数として返します。
1898418581従って、 BITS はビットベクターの中の各要素について予約されるビット数です。
1898518582BIT は、1 から 32 まで(プラットホームが
1898618583対応していれば 64 まで) の 2 のべき乗でなければなりません。
1898718584
1898818585=begin original
1898918586
1899018587If BITS is 8, "elements" coincide with bytes of the input string.
1899118588
1899218589=end original
1899318590
1899418591BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。
1899518592
1899618593=begin original
1899718594
1899818595If BITS is 16 or more, bytes of the input string are grouped into chunks
1899918596of size BITS/8, and each group is converted to a number as with
1900018597pack()/unpack() with big-endian formats C<n>/C<N> (and analogously
1900118598for BITS==64). See L<"pack"> for details.
1900218599
1900318600=end original
1900418601
1900518602BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに
1900618603グループ化され、各グループは pack()/unpack() のビッグエンディアン
1900718604フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。
1900818605詳細は L<"pack"> を参照してください。
1900918606
1901018607=begin original
1901118608
1901218609If bits is 4 or less, the string is broken into bytes, then the bits
1901318610of each byte are broken into 8/BITS groups. Bits of a byte are
1901418611numbered in a little-endian-ish way, as in C<0x01>, C<0x02>,
1901518612C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example,
1901618613breaking the single input byte C<chr(0x36)> into two groups gives a list
1901718614C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>.
1901818615
1901918616=end original
1902018617
1902118618BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは
19022186198/BITS 個のグループに分割されます。
1902318620ビットはリトルエンディアン風に、C<0x01>, C<0x02>,
1902418621C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。
1902518622例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、
1902618623C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に
1902718624なります。
1902818625
1902918626=begin original
1903018627
1903118628C<vec> may also be assigned to, in which case parentheses are needed
1903218629to give the expression the correct precedence as in
1903318630
1903418631=end original
1903518632
1903618633左辺値として、代入の対象にすることもできます; この場合、式を正しく
1903718634先行させるために以下のように括弧が必要です:
1903818635
1903918636 vec($image, $max_x * $x + $y, 8) = 3;
1904018637
1904118638=begin original
1904218639
1904318640If the selected element is outside the string, the value 0 is returned.
1904418641If an element off the end of the string is written to, Perl will first
1904518642extend the string with sufficiently many zero bytes. It is an error
1904618643to try to write off the beginning of the string (i.e., negative OFFSET).
1904718644
1904818645=end original
1904918646
1905018647選択された要素が文字列の外側だった場合、値 0 が返されます。
1905118648文字列の最後よりも後ろの要素に書き込もうとした場合、
1905218649Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。
1905318650文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった)
1905418651場合はエラーとなります。
1905518652
1905618653=begin original
1905718654
1905818655If the string happens to be encoded as UTF-8 internally (and thus has
1905918656the UTF8 flag set), this is ignored by C<vec>, and it operates on the
1906018657internal byte string, not the conceptual character string, even if you
1906118658only have characters with values less than 256.
1906218659
1906318660=end original
1906418661
1906518662文字列がなぜか内部で UTF-8 でエンコードされている場合(したがって UTF8 フラグが
1906618663セットされている場合)、これは C<vec> では無視され、たとえ値が 256 未満の
1906718664文字だけであったとしても、概念的な
1906818665文字列ではなく内部バイト文字列で操作されます。
1906918666
1907018667=begin original
1907118668
1907218669Strings created with C<vec> can also be manipulated with the logical
1907318670operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit
1907418671vector operation is desired when both operands are strings.
1907518672See L<perlop/"Bitwise String Operators">.
1907618673
1907718674=end original
1907818675
1907918676C<vec> で作られた文字列は、論理演算子 C<|>、C<&>、C<^> で
1908018677扱うこともできます。
1908118678これらの演算子は、両方の被演算子に文字列を使うと、
1908218679ビットベクター演算を行ないます。
1908318680L<perlop/"Bitwise String Operators"> を参照してください。
1908418681
1908518682=begin original
1908618683
1908718684The following code will build up an ASCII string saying C<'PerlPerlPerl'>.
1908818685The comments show the string after each step. Note that this code works
1908918686in the same way on big-endian or little-endian machines.
1909018687
1909118688=end original
1909218689
1909318690次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。
1909418691コメントは各行の実行後の文字列を示します。
1909518692このコードはビッグエンディアンでもリトルエンディアンでも同じように
1909618693動作することに注意してください。
1909718694
1909818695 my $foo = '';
1909918696 vec($foo, 0, 32) = 0x5065726C; # 'Perl'
1910018697
1910118698 # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits
1910218699 print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P')
1910318700
1910418701 vec($foo, 2, 16) = 0x5065; # 'PerlPe'
1910518702 vec($foo, 3, 16) = 0x726C; # 'PerlPerl'
1910618703 vec($foo, 8, 8) = 0x50; # 'PerlPerlP'
1910718704 vec($foo, 9, 8) = 0x65; # 'PerlPerlPe'
1910818705 vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02"
1910918706 vec($foo, 21, 4) = 7; # 'PerlPerlPer'
1911018707 # 'r' is "\x72"
1911118708 vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c"
1911218709 vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c"
1911318710 vec($foo, 94, 1) = 1; # 'PerlPerlPerl'
1911418711 # 'l' is "\x6c"
1911518712
1911618713=begin original
1911718714
1911818715To transform a bit vector into a string or list of 0's and 1's, use these:
1911918716
1912018717=end original
1912118718
1912218719ビットベクターを、0 と 1 の文字列や配列に変換するには、
1912318720以下のようにします。
1912418721
1912518722 $bits = unpack("b*", $vector);
1912618723 @bits = split(//, unpack("b*", $vector));
1912718724
1912818725=begin original
1912918726
1913018727If you know the exact length in bits, it can be used in place of the C<*>.
1913118728
1913218729=end original
1913318730
1913418731ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。
1913518732
1913618733=begin original
1913718734
1913818735Here is an example to illustrate how the bits actually fall in place:
1913918736
1914018737=end original
1914118738
1914218739これはビットが実際にどのような位置に入るかを図示する例です。
1914318740
19144 #!/usr/bin/perl -wl
18741 #!/usr/bin/perl -wl
1914518742
19146 print <<'EOT';
18743 print <<'EOT';
19147 0 1 2 3
18744 0 1 2 3
19148 unpack("V",$_) 01234567890123456789012345678901
18745 unpack("V",$_) 01234567890123456789012345678901
19149 ------------------------------------------------------------------
18746 ------------------------------------------------------------------
19150 EOT
18747 EOT
1915118748
19152 for $w (0..3) {
18749 for $w (0..3) {
19153 $width = 2**$w;
18750 $width = 2**$w;
19154 for ($shift=0; $shift < $width; ++$shift) {
18751 for ($shift=0; $shift < $width; ++$shift) {
19155 for ($off=0; $off < 32/$width; ++$off) {
18752 for ($off=0; $off < 32/$width; ++$off) {
19156 $str = pack("B*", "0"x32);
18753 $str = pack("B*", "0"x32);
19157 $bits = (1<<$shift);
18754 $bits = (1<<$shift);
19158 vec($str, $off, $width) = $bits;
18755 vec($str, $off, $width) = $bits;
19159 $res = unpack("b*",$str);
18756 $res = unpack("b*",$str);
19160 $val = unpack("V", $str);
18757 $val = unpack("V", $str);
19161 write;
18758 write;
19162 }
18759 }
19163 }
18760 }
19164 }
18761 }
1916518762
19166 format STDOUT =
18763 format STDOUT =
19167 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
18764 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
19168 $off, $width, $bits, $val, $res
18765 $off, $width, $bits, $val, $res
19169 .
18766 .
19170 __END__
18767 __END__
1917118768
1917218769=begin original
1917318770
1917418771Regardless of the machine architecture on which it runs, the
1917518772example above should print the following table:
1917618773
1917718774=end original
1917818775
1917918776実行するマシンのアーキテクチャに関わらず、
1918018777上記の例は以下の表を出力します。
1918118778
19182 0 1 2 3
18779 0 1 2 3
19183 unpack("V",$_) 01234567890123456789012345678901
18780 unpack("V",$_) 01234567890123456789012345678901
19184 ------------------------------------------------------------------
18781 ------------------------------------------------------------------
19185 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
18782 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
19186 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
18783 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
19187 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
18784 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
19188 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
18785 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
19189 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
18786 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
19190 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
18787 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
19191 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
18788 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
19192 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
18789 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
19193 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
18790 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
19194 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
18791 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
19195 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
18792 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
19196 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
18793 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
19197 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
18794 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
19198 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
18795 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
19199 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
18796 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
19200 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
18797 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
19201 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
18798 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
19202 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
18799 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
19203 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
18800 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
19204 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
18801 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
19205 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
18802 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
19206 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
18803 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
19207 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
18804 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
19208 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
18805 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
19209 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
18806 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
19210 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
18807 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
19211 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
18808 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
19212 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
18809 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
19213 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
18810 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
19214 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
18811 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
19215 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
18812 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
19216 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
18813 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
19217 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
18814 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
19218 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
18815 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
19219 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
18816 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
19220 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
18817 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
19221 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
18818 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
19222 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
18819 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
19223 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
18820 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
19224 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
18821 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
19225 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
18822 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
19226 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
18823 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
19227 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
18824 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
19228 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
18825 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
19229 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
18826 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
19230 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
18827 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
19231 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
18828 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
19232 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
18829 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
19233 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
18830 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
19234 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
18831 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
19235 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
18832 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
19236 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
18833 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
19237 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
18834 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
19238 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
18835 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
19239 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
18836 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
19240 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
18837 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
19241 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
18838 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
19242 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
18839 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
19243 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
18840 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
19244 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
18841 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
19245 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
18842 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
19246 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
18843 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
19247 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
18844 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
19248 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
18845 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
19249 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
18846 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
19250 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
18847 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
19251 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
18848 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
19252 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
18849 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
19253 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
18850 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
19254 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
18851 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
19255 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
18852 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
19256 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
18853 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
19257 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
18854 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
19258 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
18855 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
19259 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
18856 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
19260 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
18857 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
19261 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
18858 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
19262 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
18859 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
19263 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
18860 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
19264 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
18861 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
19265 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
18862 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
19266 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
18863 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
19267 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
18864 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
19268 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
18865 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
19269 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
18866 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
19270 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
18867 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
19271 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
18868 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
19272 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
18869 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
19273 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
18870 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
19274 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
18871 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
19275 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
18872 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
19276 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
18873 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
19277 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
18874 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
19278 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
18875 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
19279 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
18876 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
19280 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
18877 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
19281 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
18878 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
19282 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
18879 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
19283 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
18880 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
19284 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
18881 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
19285 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
18882 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
19286 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
18883 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
19287 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
18884 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
19288 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
18885 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
19289 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
18886 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
19290 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
18887 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
19291 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
18888 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
19292 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
18889 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
19293 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
18890 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
19294 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
18891 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
19295 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
18892 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
19296 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
18893 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
19297 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
18894 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
19298 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
18895 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
19299 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
18896 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
19300 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
18897 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
19301 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
18898 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
19302 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
18899 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
19303 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
18900 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
19304 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
18901 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
19305 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
18902 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
19306 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
18903 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
19307 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
18904 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
19308 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
18905 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
19309 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
18906 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
19310 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
18907 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
19311 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
18908 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
19312 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
18909 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
1931318910
1931418911=item wait
1931518912X<wait>
1931618913
1931718914=for Pod::Functions wait for any child process to die
1931818915
1931918916=begin original
1932018917
1932118918Behaves like wait(2) on your system: it waits for a child
1932218919process to terminate and returns the pid of the deceased process, or
1932318920C<-1> if there are no child processes. The status is returned in C<$?>
1932418921and C<${^CHILD_ERROR_NATIVE}>.
1932518922Note that a return value of C<-1> could mean that child processes are
1932618923being automatically reaped, as described in L<perlipc>.
1932718924
1932818925=end original
1932918926
1933018927wait(2) と同様に振る舞います: チャイルドプロセスが終了するのを待ち、消滅した
1933118928プロセスの pid を返します; チャイルドプロセスが存在しないときには、C<-1> を
1933218929返します。
1933318930ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されます。
1933418931L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが
1933518932自動的に刈り取られたことを意味するかもしれないことに注意してください。
1933618933
1933718934=begin original
1933818935
1933918936If you use wait in your handler for $SIG{CHLD} it may accidentally for the
1934018937child created by qx() or system(). See L<perlipc> for details.
1934118938
1934218939=end original
1934318940
1934418941wait を $SIG{CHLD} のハンドラで使うと、誤って qx() や system() に
1934518942適用されるかも知れません。
1934618943詳しくは L<perlipc> を参照してください。
1934718944
1934818945=begin original
1934918946
1935018947Portability issues: L<perlport/wait>.
1935118948
1935218949=end original
1935318950
1935418951移植性の問題: L<perlport/wait>。
1935518952
1935618953=item waitpid PID,FLAGS
1935718954X<waitpid>
1935818955
19359=for Pod::Functions wait for a particular child process to die
18956=for Pod::Functions wait for a particular child process to die
1936018957
1936118958=begin original
1936218959
1936318960Waits for a particular child process to terminate and returns the pid of
1936418961the deceased process, or C<-1> if there is no such child process. On some
1936518962systems, a value of 0 indicates that there are processes still running.
1936618963The status is returned in C<$?> and C<${^CHILD_ERROR_NATIVE}>. If you say
1936718964
1936818965=end original
1936918966
1937018967特定のチャイルドプロセスが終了するのを待ち、消滅したプロセスの pid を
1937118968返します; 指定したチャイルドプロセスが存在しないときには、C<-1> を返します。
1937218969値 0 がプロセスがまだ実行中であることを示すシステムもあります。
1937318970ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されます。
1937418971以下のようにすると
1937518972
1937618973 use POSIX ":sys_wait_h";
1937718974 #...
1937818975 do {
1937918976 $kid = waitpid(-1, WNOHANG);
1938018977 } while $kid > 0;
1938118978
1938218979=begin original
1938318980
1938418981then you can do a non-blocking wait for all pending zombie processes.
1938518982Non-blocking wait is available on machines supporting either the
1938618983waitpid(2) or wait4(2) syscalls. However, waiting for a particular
1938718984pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the
1938818985system call by remembering the status values of processes that have
1938918986exited but have not been harvested by the Perl script yet.)
1939018987
1939118988=end original
1939218989
1939318990ブロックが起こらないようにして、全ての待機中ゾンビプロセスを wait します。
1939418991ブロックなしの wait は、システムコール wait_pid(2) か、
1939518992システムコール wait4(2) をサポートしているマシンで利用可能です。
1939618993しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも
1939718994実装されています。
1939818995(exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを
1939918996エミュレートしますが、Perl スクリプトには取り入れられていません。)
1940018997
1940118998=begin original
1940218999
1940319000Note that on some systems, a return value of C<-1> could mean that child
1940419001processes are being automatically reaped. See L<perlipc> for details,
1940519002and for other examples.
1940619003
1940719004=end original
1940819005
1940919006システムによっては、返り値が C<-1> の場合は子プロセスが自動的に
1941019007刈り取られたことを意味するかもしれないことに注意してください。
1941119008詳細やその他の例については L<perlipc> を参照してください。
1941219009
1941319010=begin original
1941419011
1941519012Portability issues: L<perlport/waitpid>.
1941619013
1941719014=end original
1941819015
1941919016移植性の問題: L<perlport/waitpid>。
1942019017
1942119018=item wantarray
1942219019X<wantarray> X<context>
1942319020
1942419021=for Pod::Functions get void vs scalar vs list context of current subroutine call
1942519022
1942619023=begin original
1942719024
1942819025Returns true if the context of the currently executing subroutine or
1942919026C<eval> is looking for a list value. Returns false if the context is
1943019027looking for a scalar. Returns the undefined value if the context is
1943119028looking for no value (void context).
1943219029
1943319030=end original
1943419031
1943519032現在実行中のサブルーチンか eval() ブロックのコンテキストが、リスト値を
1943619033要求するものであれば、真を返します。
1943719034スカラを要求するコンテキストであれば、偽を返します。
1943819035何も値を要求しない(無効コンテキスト)場合は未定義値を返します。
1943919036
1944019037 return unless defined wantarray; # don't bother doing more
1944119038 my @a = complex_calculation();
1944219039 return wantarray ? @a : "@a";
1944319040
1944419041=begin original
1944519042
1944619043C<wantarray()>'s result is unspecified in the top level of a file,
1944719044in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or
1944819045in a C<DESTROY> method.
1944919046
1945019047=end original
1945119048
1945219049ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END>
1945319050ブロック内、C<DESTROY> メソッド内では C<wantarray()> の結果は未定義です。
1945419051
1945519052=begin original
1945619053
1945719054This function should have been named wantlist() instead.
1945819055
1945919056=end original
1946019057
1946119058この関数は wantlist() という名前にするべきでした。
1946219059
1946319060=item warn LIST
1946419061X<warn> X<warning> X<STDERR>
1946519062
1946619063=for Pod::Functions print debugging info
1946719064
1946819065=begin original
1946919066
1947019067Prints the value of LIST to STDERR. If the last element of LIST does
1947119068not end in a newline, it appends the same file/line number text as C<die>
1947219069does.
1947319070
1947419071=end original
1947519072
1947619073LIST の値を STDERR に出力します。
1947719074LIST の最後の要素が改行で終わっていない場合、C<die> が行うのと同様の
1947819075ファイル/行番号のテキストが追加されます。
1947919076
1948019077=begin original
1948119078
1948219079If the output is empty and C<$@> already contains a value (typically from a
1948319080previous eval) that value is used after appending C<"\t...caught">
1948419081to C<$@>. This is useful for staying almost, but not entirely similar to
1948519082C<die>.
1948619083
1948719084=end original
1948819085
1948919086出力が空かつ、(典型的には以前の eval によって) C<$@> に既に値が入っている
1949019087場合、C<$@> に C<"\t...caught"> を追加した値が用いられます。
1949119088これはほとんどそのままにするときに便利ですが、
1949219089C<die> と全体的に似ているわけではありません。
1949319090
1949419091=begin original
1949519092
1949619093If C<$@> is empty then the string C<"Warning: Something's wrong"> is used.
1949719094
1949819095=end original
1949919096
1950019097C<$@> が空の場合は、C<"Warning: Something's wrong"> という文字列が
1950119098使われます。
1950219099
1950319100=begin original
1950419101
1950519102No message is printed if there is a C<$SIG{__WARN__}> handler
1950619103installed. It is the handler's responsibility to deal with the message
1950719104as it sees fit (like, for instance, converting it into a C<die>). Most
1950819105handlers must therefore arrange to actually display the
1950919106warnings that they are not prepared to deal with, by calling C<warn>
1951019107again in the handler. Note that this is quite safe and will not
1951119108produce an endless loop, since C<__WARN__> hooks are not called from
1951219109inside one.
1951319110
1951419111=end original
1951519112
1951619113C<$SIG{__WARN__}> ハンドラが設定されている場合は何のメッセージも
1951719114表示されません。
1951819115メッセージをどう扱うか(例えば C<die> に変換するか)はハンドラの
1951919116責任ということです。
1952019117従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、
1952119118ハンドラの中で C<warn> を再び呼び出します。
1952219119C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、
1952319120無限ループを引き起こすことはないということに注意してください。
1952419121
1952519122=begin original
1952619123
1952719124You will find this behavior is slightly different from that of
1952819125C<$SIG{__DIE__}> handlers (which don't suppress the error text, but can
1952919126instead call C<die> again to change it).
1953019127
1953119128=end original
1953219129
1953319130この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは削除しませんが、
1953419131代わりに C<die> をもう一度呼び出すことで変更できます)とは
1953519132少し違うことに気付くことでしょう。
1953619133
1953719134=begin original
1953819135
1953919136Using a C<__WARN__> handler provides a powerful way to silence all
1954019137warnings (even the so-called mandatory ones). An example:
1954119138
1954219139=end original
1954319140
1954419141C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての
1954519142警告を黙らせる強力な手段となります。
1954619143例:
1954719144
1954819145 # wipe out *all* compile-time warnings
1954919146 BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
1955019147 my $foo = 10;
1955119148 my $foo = 20; # no warning about duplicate my $foo,
1955219149 # but hey, you asked for it!
1955319150 # no compile-time or run-time warnings before here
1955419151 $DOWARN = 1;
1955519152
1955619153 # run-time warnings enabled after here
1955719154 warn "\$foo is alive and $foo!"; # does show up
1955819155
1955919156=begin original
1956019157
1956119158See L<perlvar> for details on setting C<%SIG> entries and for more
1956219159examples. See the Carp module for other kinds of warnings using its
1956319160carp() and cluck() functions.
1956419161
1956519162=end original
1956619163
1956719164C<%SIG> エントリのセットに関する詳細とさらなる例に関しては
1956819165L<perlvar> を参照してください。
1956919166carp() 関数と cluck() 関数を用いた警告の方法に関しては
1957019167Carp モジュールを参照してください。
1957119168
1957219169=item write FILEHANDLE
1957319170X<write>
1957419171
1957519172=item write EXPR
1957619173
1957719174=item write
1957819175
1957919176=for Pod::Functions print a picture record
1958019177
1958119178=begin original
1958219179
1958319180Writes a formatted record (possibly multi-line) to the specified FILEHANDLE,
1958419181using the format associated with that file. By default the format for
1958519182a file is the one having the same name as the filehandle, but the
1958619183format for the current output channel (see the C<select> function) may be set
1958719184explicitly by assigning the name of the format to the C<$~> variable.
1958819185
1958919186=end original
1959019187
1959119188指定された FILEHANDLE に対して、そのファイルに対応させた
1959219189フォーマットを使って、(複数行の場合もある) 整形された
1959319190レコードを書き出します。
1959419191デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと
1959519192同じ名前のものですが、その時点の出力チャネル (C<select> 関数の項を
1959619193参照してください) のフォーマットは、その名前を明示的に変数 C<$~> に
1959719194代入することで、変更が可能です。
1959819195
1959919196=begin original
1960019197
1960119198Top of form processing is handled automatically: if there is insufficient
1960219199room on the current page for the formatted record, the page is advanced by
19603writing a form feed and a special top-of-page
19200writing a form feed, a special top-of-page format is used to format the new
19604format is used to format the new
1960519201page header before the record is written. By default, the top-of-page
19606format is the name of the filehandle with "_TOP" appended, or "top"
19202format is the name of the filehandle with "_TOP" appended. This would be a
19607in the current package if the former does not exist. This would be a
1960819203problem with autovivified filehandles, but it may be dynamically set to the
1960919204format of your choice by assigning the name to the C<$^> variable while
1961019205that filehandle is selected. The number of lines remaining on the current
1961119206page is in variable C<$->, which can be set to C<0> to force a new page.
1961219207
1961319208=end original
1961419209
1961519210ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された
1961619211レコードを出力するだけのスペースがない場合には、改ページを行なってページを
1961719212進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ、
1961819213その後でレコードが書かれます。
1961919214デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に
19620"_TOP" をつなげたものか、前者が存在しないなら、現在のパッケージの "top" です。
19215"_TOP" をつなげたものです。
1962119216これは自動有効化されたファイルハンドルで問題になる可能性がありますが、
1962219217ファイルハンドルが選択されている間に、
19623変数 C<$^> に名前を設定すれば、動的にフォーマットを変更することができます。
19218変数 C<$^> に名前を設定すれば、動的にフォーマットを
19219変更することができます。
1962419220そのページの残り行数は、変数 C<$-> に入っており、この変数を 0 に
1962519221設定することで、強制的に改ページを行なうことができます。
1962619222
1962719223=begin original
1962819224
1962919225If FILEHANDLE is unspecified, output goes to the current default output
1963019226channel, which starts out as STDOUT but may be changed by the
1963119227C<select> operator. If the FILEHANDLE is an EXPR, then the expression
1963219228is evaluated and the resulting string is used to look up the name of
1963319229the FILEHANDLE at run time. For more on formats, see L<perlform>.
1963419230
1963519231=end original
1963619232
1963719233FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して
1963819234行なわれます; これは、スクリプトの開始時点では STDOUT ですが、
1963919235select() 演算子で変更することができます。
1964019236FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が
1964119237実行時に FILEHANDLE の名前として見られます。
1964219238フォーマットについて、さらには、L<perlform> を参照してください。
1964319239
1964419240=begin original
1964519241
1964619242Note that write is I<not> the opposite of C<read>. Unfortunately.
1964719243
1964819244=end original
1964919245
1965019246write は C<read> の反対のことをするもの I<ではありません>。
1965119247残念ながら。
1965219248
1965319249=item y///
1965419250
1965519251=for Pod::Functions transliterate a string
1965619252
1965719253=begin original
1965819254
1965919255The transliteration operator. Same as C<tr///>. See
19660L<perlop/"Quote-Like Operators">.
19256L<perlop/"Quote and Quote-like Operators">.
1966119257
1966219258=end original
1966319259
1966419260文字変換演算子です。
1966519261C<tr///> と同じです。
19666L<perlop/"Quote-Like Operators"> を参照してください。
19262L<perlop/"Quote and Quote-like Operators"> を参照してください。
1966719263
1966819264=back
1966919265
1967019266=head2 Non-function Keywords by Cross-reference
1967119267
1967219268=head3 perldata
1967319269
1967419270=over
1967519271
1967619272=item __DATA__
1967719273
1967819274=item __END__
1967919275
1968019276=begin original
1968119277
1968219278These keywords are documented in L<perldata/"Special Literals">.
1968319279
1968419280=end original
1968519281
1968619282これらのキーワードは L<perldata/"Special Literals"> で文書化されています。
1968719283
1968819284=back
1968919285
1969019286=head3 perlmod
1969119287
1969219288=over
1969319289
1969419290=item BEGIN
1969519291
1969619292=item CHECK
1969719293
1969819294=item END
1969919295
1970019296=item INIT
1970119297
1970219298=item UNITCHECK
1970319299
1970419300=begin original
1970519301
1970619302These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">.
1970719303
1970819304=end original
1970919305
1971019306これらのコンパイルフェーズキーワードは
1971119307L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。
1971219308
1971319309=back
1971419310
1971519311=head3 perlobj
1971619312
1971719313=over
1971819314
1971919315=item DESTROY
1972019316
1972119317=begin original
1972219318
1972319319This method keyword is documented in L<perlobj/"Destructors">.
1972419320
1972519321=end original
1972619322
1972719323このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。
1972819324
1972919325=back
1973019326
1973119327=head3 perlop
1973219328
1973319329=over
1973419330
1973519331=item and
1973619332
1973719333=item cmp
1973819334
1973919335=item eq
1974019336
1974119337=item ge
1974219338
1974319339=item gt
1974419340
19341=item if
19342
1974519343=item le
1974619344
1974719345=item lt
1974819346
1974919347=item ne
1975019348
1975119349=item not
1975219350
1975319351=item or
1975419352
1975519353=item x
1975619354
1975719355=item xor
1975819356
1975919357=begin original
1976019358
1976119359These operators are documented in L<perlop>.
1976219360
1976319361=end original
1976419362
1976519363これらの演算子は L<perlop> で文書化されています。
1976619364
1976719365=back
1976819366
1976919367=head3 perlsub
1977019368
1977119369=over
1977219370
1977319371=item AUTOLOAD
1977419372
1977519373=begin original
1977619374
1977719375This keyword is documented in L<perlsub/"Autoloading">.
1977819376
1977919377=end original
1978019378
1978119379このキーワードは L<perlsub/"Autoloading"> で文書化されています。
1978219380
1978319381=back
1978419382
1978519383=head3 perlsyn
1978619384
1978719385=over
1978819386
1978919387=item else
1979019388
1979119389=item elseif
1979219390
1979319391=item elsif
1979419392
1979519393=item for
1979619394
1979719395=item foreach
1979819396
19799=item if
19800
1980119397=item unless
1980219398
1980319399=item until
1980419400
1980519401=item while
1980619402
1980719403=begin original
1980819404
1980919405These flow-control keywords are documented in L<perlsyn/"Compound Statements">.
1981019406
1981119407=end original
1981219408
1981319409これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で
1981419410文書化されています。
1981519411
1981619412=back
1981719413
1981819414=over
1981919415
1982019416=item default
1982119417
1982219418=item given
1982319419
1982419420=item when
1982519421
1982619422=begin original
1982719423
1982819424These flow-control keywords related to the experimental switch feature are
19829documented in L<perlsyn/"Switch Statements">.
19425documented in L<perlsyn/"Switch Statements"> .
1983019426
1983119427=end original
1983219428
1983319429これらの実験的な switch 機能に関連するフロー制御キーワードは
1983419430L<perlsyn/"Switch Statements"> で文書化されています。
1983519431
1983619432=back
1983719433
19838=cut
19839
1984019434=begin meta
1984119435
1984219436Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp>
1984319437Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
19844Status: completed
19438Status: in progress
1984519439
1984619440=end meta
19441
19442=cut