perlfunc > 5.10.1 との差分

perlfunc 5.10.1 と 5.10.0 の差分

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 a scalar context to its
2727argument, while a list operator may provide either scalar or list
2828contexts for its arguments. If it does both, the scalar arguments will
2929be first, and the list argument will follow. (Note that there can ever
3030be only 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これらは、大きく 2 つに分けられます:
3838リスト演算子と名前付き単項演算子です。
3939これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。 
4040(L<perlop> の優先順位の表を参照してください。)
4141リスト演算子は 2 個以上の引数をとるのに対して、
4242単項演算子が複数の引数をとることはありません。
4343つまり、コンマは単項演算子の引数の終わりとなりますが、
4444リスト演算子の場合には、引数の区切りでしかありません。
4545単項演算子は一般に、
4646引数に対してスカラコンテキストを与えるのに対して、
4747スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、
4848リストコンテキストを与える場合もあります。
49491 つのリスト演算子が
5050両方のコンテキストを与える場合には、スカラ引数がいくつか並び、
5151最後にリスト引数が 1 つ続きます。
5252(リスト引数は 1 つだけです。)
5353たとえば、splice() は 3 つのスカラ引数に 1 つのリスト引数が続きます。
5454一方 gethostbyname() は 4 つのスカラ引数を持ちます。
5555
5656=begin original
5757
5858In the syntax descriptions that follow, list operators that expect a
5959list (and provide list context for the elements of the list) are shown
6060with LIST as an argument. Such a list may consist of any combination
6161of scalar arguments or list values; the list values will be included
6262in the list as if each individual element were interpolated at that
6363point in the list, forming a longer single-dimensional list value.
6464Commas should separate elements of the LIST.
6565
6666=end original
6767
6868後に載せる構文記述では、リストをとり
6969(そのリストの要素にリストコンテキストを与える)
7070リスト演算子は、引数として LIST をとるように書いています。
7171そのようなリストには、任意のスカラ引数の組み合わせやリスト値を
7272含めることができ、リスト値はリストの中に、
7373個々の要素が展開されたように埋め込まれます。
74741 次元の長いリスト値が形成されることになります。
7575LIST の要素は、コンマで区切られます。
7676
7777=begin original
7878
7979Any function in the list below may be used either with or without
8080parentheses around its arguments. (The syntax descriptions omit the
8181parentheses.) If you use the parentheses, the simple (but occasionally
8282surprising) rule is this: It I<looks> like a function, therefore it I<is> a
8383function, and precedence doesn't matter. Otherwise it's a list
8484operator or unary operator, and precedence does matter. And whitespace
8585between the function and left parenthesis doesn't count--so you need to
8686be careful sometimes:
8787
8888=end original
8989
9090以下のリストの関数はすべて、引数の前後の括弧は省略可能と
9191なっています。
9292(構文記述では省略しています。)
9393括弧を使うときには、
9494単純な (しかし、ときには驚く結果となる) 規則が適用できます:
9595I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。
9696そう見えなければ、それはリスト演算子か単項演算子で、優先順位が
9797関係します。
9898また、関数と開き括弧の間の空白は関係ありませんので、
9999ときに気を付けなければなりません:
100100
101101 print 1+2+4; # Prints 7.
102102 print(1+2) + 4; # Prints 3.
103103 print (1+2)+4; # Also prints 3!
104104 print +(1+2)+4; # Prints 7.
105105 print ((1+2)+4); # Prints 7.
106106
107107=begin original
108108
109109If you run Perl with the B<-w> switch it can warn you about this. For
110110example, the third line above produces:
111111
112112=end original
113113
114114Perl に B<-w> スイッチを付けて実行すれば、こういったものには
115115警告を出してくれます。
116116たとえば、上記の 3 つめは、以下のような警告が出ます:
117117
118118 print (...) interpreted as function at - line 1.
119119 Useless use of integer addition in void context at - line 1.
120120
121121=begin original
122122
123123A few functions take no arguments at all, and therefore work as neither
124124unary nor list operators. These include such functions as C<time>
125125and C<endpwent>. For example, C<time+86_400> always means
126126C<time() + 86_400>.
127127
128128=end original
129129
130130いくつかの関数は引数を全くとらないので、単項演算子としても
131131リスト演算子としても動作しません。
132132このような関数としては C<time> や C<endpwent> があります。
133133例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。
134134
135135=begin original
136136
137137For functions that can be used in either a scalar or list context,
138138nonabortive failure is generally indicated in a scalar context by
139139returning the undefined value, and in a list context by returning the
140140null list.
141141
142142=end original
143143
144144スカラコンテキストでも、リストコンテキストでも使える関数は、
145145致命的でないエラーを示すために、スカラコンテキストでは
146146未定義値を返し、リストコンテキストでは空リストを返します。
147147
148148=begin original
149149
150150Remember the following important rule: There is B<no rule> that relates
151151the behavior of an expression in list context to its behavior in scalar
152152context, or vice versa. It might do two totally different things.
153153Each operator and function decides which sort of value it would be most
154154appropriate to return in scalar context. Some operators return the
155155length of the list that would have been returned in list context. Some
156156operators return the first value in the list. Some operators return the
157157last value in the list. Some operators return a count of successful
158158operations. In general, they do what you want, unless you want
159159consistency.
160160X<context>
161161
162162=end original
163163
164164以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの
165165振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に
166166B<ルールはありません>。
1671672 つの全く異なったことがあります。
168168それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と
169169思われる値を返します。
170170リストコンテキストで返す時のリストの長さを返す演算子もあります。
171171リストの最初の値を返す演算子もあります。
172172リストの最後の値を返す演算子もあります。
173173成功した操作の数を返す演算子もあります。
174174一般的には、一貫性を求めない限り、こちらが求めることをします。
175175X<context>
176176
177177=begin original
178178
179179A named array in scalar context is quite different from what would at
180180first glance appear to be a list in scalar context. You can't get a list
181181like C<(1,2,3)> into being in scalar context, because the compiler knows
182182the context at compile time. It would generate the scalar comma operator
183183there, not the list construction version of the comma. That means it
184184was never a list to start with.
185185
186186=end original
187187
188188スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを
189189一目見たものとは全く違います。
190190コンパイラはコンパイル時にコンテキストを知っているので、
191191C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。
192192これはスカラコンマ演算子を生成し、コンマのリスト作成版ではありません。
193193これは初めからリストであることはないことを意味します。
194194
195195=begin original
196196
197197In general, functions in Perl that serve as wrappers for system calls
198198of the same name (like chown(2), fork(2), closedir(2), etc.) all return
199199true when they succeed and C<undef> otherwise, as is usually mentioned
200200in the descriptions below. This is different from the C interfaces,
201201which return C<-1> on failure. Exceptions to this rule are C<wait>,
202202C<waitpid>, and C<syscall>. System calls also set the special C<$!>
203203variable on failure. Other functions do not, except accidentally.
204204
205205=end original
206206
207207一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数
208208(chown(2), fork(2), closedir(2) など)は、以下に述べるように、
209209成功時に真を返し、そうでなければ C<undef> を返します。
210210これは失敗時に C<-1> を返す C のインターフェースとは違います。
211211このルールの例外は C<wait>, C<waitpid>, C<syscall> です。
212212システムコールは失敗時に特殊変数 C<$!> をセットします。
213213その他の関数は、事故を除いて、セットしません。
214214
215215=head2 Perl Functions by Category
216216X<function>
217217
218218(カテゴリ別の Perl 関数)
219219
220220=begin original
221221
222222Here are Perl's functions (including things that look like
223223functions, like some keywords and named operators)
224224arranged by category. Some functions appear in more
225225than one place.
226226
227227=end original
228228
229229以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、
230230関数のように見えるものも含みます)を示します。
231231複数の場所に現れる関数もあります。
232232
233233=over 4
234234
235235=item Functions for SCALARs or strings
236236X<scalar> X<string> X<character>
237237
238238(スカラや文字列のための関数)
239239
240240C<chomp>, C<chop>, C<chr>, C<crypt>, C<hex>, C<index>, C<lc>, C<lcfirst>,
241241C<length>, C<oct>, C<ord>, C<pack>, C<q//>, C<qq//>, C<reverse>,
242242C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///>
243243
244244=item Regular expressions and pattern matching
245245X<regular expression> X<regex> X<regexp>
246246
247247(正規表現とパターンマッチング)
248248
249249C<m//>, C<pos>, C<quotemeta>, C<s///>, C<split>, C<study>, C<qr//>
250250
251251=item Numeric functions
252252X<numeric> X<number> X<trigonometric> X<trigonometry>
253253
254254(数値関数)
255255
256256C<abs>, C<atan2>, C<cos>, C<exp>, C<hex>, C<int>, C<log>, C<oct>, C<rand>,
257257C<sin>, C<sqrt>, C<srand>
258258
259259=item Functions for real @ARRAYs
260260X<array>
261261
262262(実配列のための関数)
263263
264264C<pop>, C<push>, C<shift>, C<splice>, C<unshift>
265265
266266=item Functions for list data
267267X<list>
268268
269269(リストデータのための関数)
270270
271271C<grep>, C<join>, C<map>, C<qw//>, C<reverse>, C<sort>, C<unpack>
272272
273273=item Functions for real %HASHes
274274X<hash>
275275
276276(実ハッシュのための関数)
277277
278278C<delete>, C<each>, C<exists>, C<keys>, C<values>
279279
280280=item Input and output functions
281281X<I/O> X<input> X<output> X<dbm>
282282
283283(入出力関数)
284284
285285C<binmode>, C<close>, C<closedir>, C<dbmclose>, C<dbmopen>, C<die>, C<eof>,
286286C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>,
287287C<readdir>, C<rewinddir>, C<say>, C<seek>, C<seekdir>, C<select>, C<syscall>,
288288C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>, C<truncate>,
289289C<warn>, C<write>
290290
291291=item Functions for fixed length data or records
292292
293293(固定長データやレコードのための関数)
294294
295295C<pack>, C<read>, C<syscall>, C<sysread>, C<syswrite>, C<unpack>, C<vec>
296296
297297=item Functions for filehandles, files, or directories
298298X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink>
299299
300300(ファイルハンドル、ファイル、ディレクトリのための関数)
301301
302302C<-I<X>>, C<chdir>, C<chmod>, C<chown>, C<chroot>, C<fcntl>, C<glob>,
303303C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>,
304304C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<sysopen>,
305305C<umask>, C<unlink>, C<utime>
306306
307307=item Keywords related to the control flow of your Perl program
308308X<control flow>
309309
310310(プログラムの流れを制御することに関連するキーワード)
311311
312312C<caller>, C<continue>, C<die>, C<do>, C<dump>, C<eval>, C<exit>,
313313C<goto>, C<last>, C<next>, C<redo>, C<return>, C<sub>, C<wantarray>
314314
315315=item Keywords related to switch
316316
317317(switch に関連するキーワード)
318318
319319C<break>, C<continue>, C<given>, C<when>, C<default>
320320
321321=begin original
322322
323323(These are only available if you enable the "switch" feature.
324324See L<feature> and L<perlsyn/"Switch statements">.)
325325
326326=end original
327327
328328(これらは "switch" 機能が有効の場合にのみ利用可能です。
329329L<feature> と L<perlsyn/"Switch statements"> を参照してください。)
330330
331331=item Keywords related to scoping
332332
333333(スコープに関するキーワード)
334334
335335C<caller>, C<import>, C<local>, C<my>, C<our>, C<state>, C<package>,
336336C<use>
337337
338338=begin original
339339
340340(C<state> is only available if the "state" feature is enabled. See
341341L<feature>.)
342342
343343=end original
344344
345345(C<state> は "state" 機能が有効の場合にのみ利用可能です。
346346L<feature> を参照してください。)
347347
348348=item Miscellaneous functions
349349
350350(さまざまな関数)
351351
352352C<defined>, C<dump>, C<eval>, C<formline>, C<local>, C<my>, C<our>,
353353C<reset>, C<scalar>, C<state>, C<undef>, C<wantarray>
354354
355355=item Functions for processes and process groups
356356X<process> X<pid> X<process id>
357357
358358(プロセスとプロセスグループのための関数)
359359
360360C<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>,
361361C<pipe>, C<qx//>, C<setpgrp>, C<setpriority>, C<sleep>, C<system>,
362362C<times>, C<wait>, C<waitpid>
363363
364364=item Keywords related to perl modules
365365X<module>
366366
367367(perl モジュールに関するキーワード)
368368
369369C<do>, C<import>, C<no>, C<package>, C<require>, C<use>
370370
371371=item Keywords related to classes and object-orientation
372372X<object> X<class> X<package>
373373
374374(クラスとオブジェクト指向に関するキーワード)
375375
376376C<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>,
377377C<untie>, C<use>
378378
379379=item Low-level socket functions
380380X<socket> X<sock>
381381
382382(低レベルソケット関数)
383383
384384C<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>,
385385C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>,
386386C<socket>, C<socketpair>
387387
388388=item System V interprocess communication functions
389389X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message>
390390
391391(System V プロセス間通信関数)
392392
393393C<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>,
394394C<shmctl>, C<shmget>, C<shmread>, C<shmwrite>
395395
396396=item Fetching user and group info
397397X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd>
398398
399399(ユーザーとグループの情報取得)
400400
401401C<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>,
402402C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>,
403403C<getpwuid>, C<setgrent>, C<setpwent>
404404
405405=item Fetching network info
406406X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service>
407407
408408(ネットワーク情報取得)
409409
410410C<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>,
411411C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
412412C<getprotobyname>, C<getprotobynumber>, C<getprotoent>,
413413C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>,
414414C<setnetent>, C<setprotoent>, C<setservent>
415415
416416=item Time-related functions
417417X<time> X<date>
418418
419419(時刻に関する関数)
420420
421421C<gmtime>, C<localtime>, C<time>, C<times>
422422
423423=item Functions new in perl5
424424X<perl5>
425425
426426(perl5 で新設された関数)
427427
428428C<abs>, C<bless>, C<break>, C<chomp>, C<chr>, C<continue>, C<default>,
429429C<exists>, C<formline>, C<given>, C<glob>, C<import>, C<lc>, C<lcfirst>,
430430C<lock>, C<map>, C<my>, C<no>, C<our>, C<prototype>, C<qr//>, C<qw//>, C<qx//>,
431431C<readline>, C<readpipe>, C<ref>, C<sub>*, C<sysopen>, C<tie>, C<tied>, C<uc>,
432432C<ucfirst>, C<untie>, C<use>, C<when>
433433
434434=begin original
435435
436436* - C<sub> was a keyword in perl4, but in perl5 it is an
437437operator, which can be used in expressions.
438438
439439=end original
440440
441441* - C<sub> は perl4 ではキーワードですが、perl5 では演算子なので、
442442式で使えます。
443443
444444=item Functions obsoleted in perl5
445445
446446(perl5 では古いものとなった関数)
447447
448448C<dbmclose>, C<dbmopen>
449449
450450=back
451451
452452=head2 Portability
453453X<portability> X<Unix> X<portable>
454454
455455(移植性)
456456
457457=begin original
458458
459459Perl was born in Unix and can therefore access all common Unix
460460system calls. In non-Unix environments, the functionality of some
461461Unix system calls may not be available, or details of the available
462462functionality may differ slightly. The Perl functions affected
463463by this are:
464464
465465=end original
466466
467467Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに
468468アクセスします。非 Unix 環境では、いくつかの Unix システムコールの
469469機能が使えなかったり、使える機能の詳細が多少異なったりします。
470470これによる影響を受ける Perl 関数は以下のものです:
471471
472472C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>,
473473C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>,
474474C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>,
475475C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostbyname>,
476476C<gethostent>, C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,
477477C<getppid>, C<getpgrp>, C<getpriority>, C<getprotobynumber>,
478478C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>,
479479C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>,
480480C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>,
481481C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>,
482482C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>,
483483C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>,
484484C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>,
485485C<shmwrite>, C<socket>, C<socketpair>,
486486C<stat>, C<symlink>, C<syscall>, C<sysopen>, C<system>,
487487C<times>, C<truncate>, C<umask>, C<unlink>,
488488C<utime>, C<wait>, C<waitpid>
489489
490490=begin original
491491
492492For more information about the portability of these functions, see
493493L<perlport> and other available platform-specific documentation.
494494
495495=end original
496496
497497これらの関数の移植性に関するさらなる情報については、
498498L<perlport> とその他のプラットホーム固有のドキュメントを参照して下さい。
499499
500500=head2 Alphabetical Listing of Perl Functions
501501
502502=over 8
503503
504504=item -X FILEHANDLE
505505X<-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>
506506X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
507507
508508=item -X EXPR
509509
510510=item -X DIRHANDLE
511511
512512=item -X
513513
514514=begin original
515515
516516A file test, where X is one of the letters listed below. This unary
517517operator takes one argument, either a filename, a filehandle, or a dirhandle,
518518and tests the associated file to see if something is true about it. If the
519519argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN.
520520Unless otherwise documented, it returns C<1> for true and C<''> for false, or
521521the undefined value if the file doesn't exist. Despite the funny
522522names, precedence is the same as any other named unary operator. The
523523operator may be any of:
524524
525525=end original
526526
527527X は以下にあげる文字で、ファイルテストを行ないます。
528528この単項演算子は、ファイル名かファイルハンドルを唯一の
529529引数として動作し、「あること」について真であるか否かを
530530判定した結果を返します。
531531引数が省略されると、C<-t> では STDIN を調べますが、その他は C<$_> を調べます。
532532特に記述されていなければ、真として C<1> を返し、偽として
533533C<''> を返し、ファイルが存在しなければ、未定義値を返します。
534534みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、
535535他の単項演算子と同じく、引数を括弧で括ることもできます。
536536演算子には以下のものがあります:
537537
538538=begin original
539539
540540 -r File is readable by effective uid/gid.
541541 -w File is writable by effective uid/gid.
542542 -x File is executable by effective uid/gid.
543543 -o File is owned by effective uid.
544544
545545=end original
546546
547547 -r ファイルが実効 uid/gid で読み出し可
548548 -w ファイルが実効 uid/gid で書き込み可
549549 -x ファイルが実効 uid/gid で実行可
550550 -o ファイルが実効 uid の所有物
551551
552552=begin original
553553
554554 -R File is readable by real uid/gid.
555555 -W File is writable by real uid/gid.
556556 -X File is executable by real uid/gid.
557557 -O File is owned by real uid.
558558
559559=end original
560560
561561 -R ファイルが実 uid/gid で読み出し可
562562 -W ファイルが実 uid/gid で書き込み可
563563 -X ファイルが実 uid/gid で実行可
564564 -O ファイルが実 uid の所有物
565565
566566=begin original
567567
568568 -e File exists.
569569 -z File has zero size (is empty).
570570 -s File has nonzero size (returns size in bytes).
571571
572572=end original
573573
574574 -e ファイルが存在する
575575 -z ファイルの大きさがゼロ(空)
576576 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)
577577
578578=begin original
579579
580580 -f File is a plain file.
581581 -d File is a directory.
582582 -l File is a symbolic link.
583583 -p File is a named pipe (FIFO), or Filehandle is a pipe.
584584 -S File is a socket.
585585 -b File is a block special file.
586586 -c File is a character special file.
587587 -t Filehandle is opened to a tty.
588588
589589=end original
590590
591591 -f ファイルは通常ファイル
592592 -d ファイルはディレクトリ
593593 -l ファイルはシンボリックリンク
594594 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ
595595 -S ファイルはソケット
596596 -b ファイルはブロック特殊ファイル
597597 -c ファイルはキャラクタ特殊ファイル
598598 -t ファイルハンドルは tty にオープンされている
599599
600600=begin original
601601
602602 -u File has setuid bit set.
603603 -g File has setgid bit set.
604604 -k File has sticky bit set.
605605
606606=end original
607607
608608 -u ファイルの setuid ビットがセットされている
609609 -g ファイルの setgid ビットがセットされている
610610 -k ファイルの sticky ビットがセットされている
611611
612612=begin original
613613
614614 -T File is an ASCII text file (heuristic guess).
615615 -B File is a "binary" file (opposite of -T).
616616
617617=end original
618618
619619 -T ファイルは ASCII テキストファイル (発見的に推測します)
620620 -B ファイルは「バイナリ」ファイル (-T の反対)
621621
622622=begin original
623623
624624 -M Script start time minus file modification time, in days.
625625 -A Same for access time.
626626 -C Same for inode change time (Unix, may differ for other platforms)
627627
628628=end original
629629
630630 -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)
631631 -A 同様にアクセスがあってからの日数
632632 -C 同様に(Unix では) inode が変更されてからの日数(それ以外のプラットフォームでは違うかもしれません)
633633
634634=begin original
635635
636636Example:
637637
638638=end original
639639
640640例:
641641
642642 while (<>) {
643643 chomp;
644644 next unless -f $_; # ignore specials
645645 #...
646646 }
647647
648648=begin original
649649
650650The interpretation of the file permission operators C<-r>, C<-R>,
651651C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode
652652of the file and the uids and gids of the user. There may be other
653653reasons you can't actually read, write, or execute the file: for
654654example network filesystem access controls, ACLs (access control lists),
655655read-only filesystems, and unrecognized executable formats. Note
656656that the use of these six specific operators to verify if some operation
657657is possible is usually a mistake, because it may be open to race
658658conditions.
659659
660660=end original
661661
662662ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>,
663663C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と
664664実効/実 gid のみから判断されます。
665665実際にファイルが読めたり、書けたり、実行できたりするためには、
666666別の条件が必要かもしれません:
667667例えば、ネットワークファイルシステムアクセスコントロール、
668668ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、
669669認識できない実行ファイルフォーマット、などです。
670670これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは
671671通常は誤りであることに注意してください; なぜなら、これらは競合条件を
672672招きやすいからです。
673673
674674=begin original
675675
676676Also note that, for the superuser on the local filesystems, the C<-r>,
677677C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1
678678if any execute bit is set in the mode. Scripts run by the superuser
679679may thus need to do a stat() to determine the actual mode of the file,
680680or temporarily set their effective uid to something else.
681681
682682=end original
683683
684684ローカルファイルシステムのスーパーユーザには、
685685C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の
686686いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が
687687返ることにも注意してください。
688688スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、
689689stat() を行なうか、実効 uid を一時的に別のものにする
690690必要があるでしょう。
691691
692692=begin original
693693
694694If you are using ACLs, there is a pragma called C<filetest> that may
695695produce more accurate results than the bare stat() mode bits.
696696When under the C<use filetest 'access'> the above-mentioned filetests
697697will test whether the permission can (not) be granted using the
698698access() family of system calls. Also note that the C<-x> and C<-X> may
699699under this pragma return true even if there are no execute permission
700700bits set (nor any extra execute permission ACLs). This strangeness is
701701due to the underlying system calls' definitions. Note also that, due to
702702the implementation of C<use filetest 'access'>, the C<_> special
703703filehandle won't cache the results of the file tests when this pragma is
704704in effect. Read the documentation for the C<filetest> pragma for more
705705information.
706706
707707=end original
708708
709709ACL を使っている場合は、生の stat() モードビットより
710710精度の高い結果を作成する C<filetest> プラグマがあります。
711711C<use filetest 'access'> とした場合、上述したファイルテストは
712712システムコールの access() ファミリーを使って権限が与えられているか
713713どうかをテストします。
714714また、このプラグマが指定されている場合、C<-x> と C<-X> は
715715たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない
716716場合でも真を返すことに注意してください。
717717この挙動は使用するシステムコールの定義によるものです。
718718C<use filetest 'access'> の実装により、このプラグマが有効の場合は
719719C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに
720720注意してください。
721721さらなる情報については C<filetest> プラグマのドキュメントを
722722参照してください。
723723
724724=begin original
725725
726726Note that C<-s/a/b/> does not do a negated substitution. Saying
727727C<-exp($foo)> still works as expected, however--only single letters
728728following a minus are interpreted as file tests.
729729
730730=end original
731731
732732C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。
733733しかし、C<-exp($foo)> は期待どおりに動作します。
734734マイナス記号の後に英字が 1 字続くときにのみ、ファイルテストと
735735解釈されます。
736736
737737=begin original
738738
739739The C<-T> and C<-B> switches work as follows. The first block or so of the
740740file is examined for odd characters such as strange control codes or
741741characters with the high bit set. If too many strange characters (>30%)
742742are found, it's a C<-B> file; otherwise it's a C<-T> file. Also, any file
743743containing null in the first block is considered a binary file. If C<-T>
744744or C<-B> is used on a filehandle, the current IO buffer is examined
745745rather than the first block. Both C<-T> and C<-B> return true on a null
746746file, or a file at EOF when testing a filehandle. Because you have to
747747read a file to do the C<-T> test, on most occasions you want to use a C<-f>
748748against the file first, as in C<next unless -f $file && -T $file>.
749749
750750=end original
751751
752752ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。
753753ファイルの最初の数ブロックを調べて、変わった制御コードや
754754上位ビットがセットされているような、通常のテキストには現れない文字を探します。
755755そのような文字が、たくさん (>30%) 見つかるようであれば、
756756そのファイルは C<-B> ファイルであると判断されます;
757757さもなければ C<-T> ファイルとなります。
758758最初のブロックにヌル文字が含まれるファイルも、
759759バイナリファイルとみなされます。
760760C<-T> や C<-B> をファイルハンドルに対して用いると、
761761最初のブロックを調べる代わりに、IO バッファを調べます。
762762調べたファイルの中身が何もないときや、
763763ファイルハンドルを調べたときに EOF に達して
764764いたときには、C<-T> も C<-B> も「真」を返します。
765765C<-T> テストをするためにはファイルを読み込まないといけないので、
766766たいていは C<next unless -f $file && -T $file> というような形で
767767まず調べたいファイルに対して C<-f> を使いたいはずです。
768768
769769=begin original
770770
771771If any of the file tests (or either the C<stat> or C<lstat> operators) are given
772772the special filehandle consisting of a solitary underline, then the stat
773773structure of the previous file test (or stat operator) is used, saving
774774a system call. (This doesn't work with C<-t>, and you need to remember
775775that lstat() and C<-l> will leave values in the stat structure for the
776776symbolic link, not the real file.) (Also, if the stat buffer was filled by
777777an C<lstat> call, C<-T> and C<-B> will reset it with the results of C<stat _>).
778778Example:
779779
780780=end original
781781
782782どのファイルテスト (あるいは、C<stat> や C<lstat>) 演算子にも、
783783下線だけから成る特別なファイルハンドルを与えると、
784784前回のファイルテスト (や stat) の stat 構造体が使われ、
785785システムコールを省きます。
786786(C<-t> には使えませんし、lstat() や C<-l> は実ファイルではなく、
787787シンボリックリンクの情報を stat 構造体に残すことを
788788覚えておく必要があります。)
789789(また、stat バッファが C<lstat> 呼び出しで埋まった場合、
790790C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。
791791例:
792792
793793 print "Can do.\n" if -r $a || -w _ || -x _;
794794
795795 stat($filename);
796796 print "Readable\n" if -r _;
797797 print "Writable\n" if -w _;
798798 print "Executable\n" if -x _;
799799 print "Setuid\n" if -u _;
800800 print "Setgid\n" if -g _;
801801 print "Sticky\n" if -k _;
802802 print "Text\n" if -T _;
803803 print "Binary\n" if -B _;
804804
805805=begin original
806806
807807As of Perl 5.9.1, as a form of purely syntactic sugar, you can stack file
808808test operators, in a way that C<-f -w -x $file> is equivalent to
809809C<-x $file && -w _ && -f _>. (This is only syntax fancy: if you use
810810the return value of C<-f $file> as an argument to another filetest
811811operator, no special magic will happen.)
812812
813813=end original
814814
815815Perl 5.9.1 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
816816スタックさせることができるので、C<-f -w -x $file> は
817817C<-x $file && -w _ && -f _> と等価です。
818818(これば文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト
819819演算子の引数として使う場合は、何の特別なことも起きません。)
820820
821821=item abs VALUE
822822X<abs> X<absolute>
823823
824824=item abs
825825
826826=begin original
827827
828828Returns the absolute value of its argument.
829829If VALUE is omitted, uses C<$_>.
830830
831831=end original
832832
833833引数の絶対値を返します。
834834VALUE が省略された場合は、C<$_> を使います。
835835
836836=item accept NEWSOCKET,GENERICSOCKET
837837X<accept>
838838
839839=begin original
840840
841841Accepts an incoming socket connect, just as the accept(2) system call
842842does. Returns the packed address if it succeeded, false otherwise.
843843See the example in L<perlipc/"Sockets: Client/Server Communication">.
844844
845845=end original
846846
847847accept(2) システムコールと同様に、着信するソケットの接続を受け付けます。
848848成功時にはパックされたアドレスを返し、失敗すれば偽を返します。
849849L<perlipc/"Sockets: Client/Server Communication"> の
850850例を参照してください。
851851
852852=begin original
853853
854854On systems that support a close-on-exec flag on files, the flag will
855855be set for the newly opened file descriptor, as determined by the
856856value of $^F. See L<perlvar/$^F>.
857857
858858=end original
859859
860860ファイルに対する close-on-exec フラグをサポートしているシステムでは、
861861フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
862セットされます。
862セットされます。L<perlvar/$^F> を参照してください。
863L<perlvar/$^F> を参照してください。
864863
865864=item alarm SECONDS
866865X<alarm>
867866X<SIGALRM>
868867X<timer>
869868
870869=item alarm
871870
872871=begin original
873872
874873Arranges to have a SIGALRM delivered to this process after the
875874specified number of wallclock seconds has elapsed. If SECONDS is not
876875specified, the value stored in C<$_> is used. (On some machines,
877876unfortunately, the elapsed time may be up to one second less or more
878877than you specified because of how seconds are counted, and process
879878scheduling may delay the delivery of the signal even further.)
880879
881880=end original
882881
883882指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が
884883送られてくるようにします。SECONDS が指定されていない場合は、
885884C<$_>に格納されている値を使います。
886885(マシンによっては、秒の数え方が異なるため、指定した秒数よりも
887886最大で 1 秒ずれます。)
888887
889888=begin original
890889
891890Only one timer may be counting at once. Each call disables the
892891previous timer, and an argument of C<0> may be supplied to cancel the
893892previous timer without starting a new one. The returned value is the
894893amount of time remaining on the previous timer.
895894
896895=end original
897896
898897一度には 1 つのタイマだけが設定可能です。
899898呼び出しを行なう度に、以前のタイマを無効にしますし、
900899新しくタイマを起動しないで以前のタイマをキャンセルするために
901900引数に C<0> を指定して呼び出すことができます。
902901以前のタイマの残り時間が、返り値となります。
903902
904903=begin original
905904
906905For delays of finer granularity than one second, the Time::HiRes module
907906(from CPAN, and starting from Perl 5.8 part of the standard
908907distribution) provides ualarm(). You may also use Perl's four-argument
909908version of select() leaving the first three arguments undefined, or you
910909might be able to use the C<syscall> interface to access setitimer(2) if
911910your system supports it. See L<perlfaq8> for details.
912911
913912=end original
914913
9159141 秒より精度の高いスリープを行なうには、
916915Time::HiRes モジュール(CPAN から、また Perl 5.8 からは
917916標準配布されています) が ualarm() を提供します。
918917Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、
919918setitimer(2) をサポートしているシステムでは、Perl の
920919C<syscall> インタフェースを使ってアクセスすることもできます。
921920詳しくは L<perlfaq8> を参照してください。
922921
923922=begin original
924923
925924It is usually a mistake to intermix C<alarm> and C<sleep> calls.
926925(C<sleep> may be internally implemented in your system with C<alarm>)
927926
928927=end original
929928
930929C<alarm> と C<sleep> を混ぜて使うのは普通は間違いです。
931930(C<sleep> は内部的に C<alarm> を使って内部的に実装されているかもしれません)
932931
933932=begin original
934933
935934If you want to use C<alarm> to time out a system call you need to use an
936935C<eval>/C<die> pair. You can't rely on the alarm causing the system call to
937936fail with C<$!> set to C<EINTR> because Perl sets up signal handlers to
938937restart system calls on some systems. Using C<eval>/C<die> always works,
939938modulo the caveats given in L<perlipc/"Signals">.
940939
941940=end original
942941
943942C<alarm> をシステムコールの時間切れのために使いたいなら、
944943C<eval>/C<die> のペアで使う必要があります。
945944システムコールが失敗したときに C<$!> に C<EINTR> がセットされることに
946945頼ってはいけません。なぜならシステムによっては Perl は
947946システムコールを再開するためにシグナルハンドラを設定するからです。
948947C<eval>/C<die> は常にうまく動きます。
949948注意点については L<perlipc/"Signals"> を参照して下さい。
950949
951950 eval {
952951 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
953952 alarm $timeout;
954953 $nread = sysread SOCKET, $buffer, $size;
955954 alarm 0;
956955 };
957956 if ($@) {
958957 die unless $@ eq "alarm\n"; # propagate unexpected errors
959958 # timed out
960959 }
961960 else {
962961 # didn't
963962 }
964963
965964=begin original
966965
967966For more information see L<perlipc>.
968967
969968=end original
970969
971970さらなる情報については L<perlipc> を参照してください。
972971
973972=item atan2 Y,X
974973X<atan2> X<arctangent> X<tan> X<tangent>
975974
976975=begin original
977976
978977Returns the arctangent of Y/X in the range -PI to PI.
979978
980979=end original
981980
982981-πからπの範囲で Y/X の逆正接を返します。
983982
984983=begin original
985984
986985For the tangent operation, you may use the C<Math::Trig::tan>
987986function, or use the familiar relation:
988987
989988=end original
990989
991990正接を求めたいときは、C<Math::Trig::tan> を使うか、
992991以下のよく知られた関係を使ってください。
993992
994993 sub tan { sin($_[0]) / cos($_[0]) }
995994
996995=begin original
997996
998The return value for C<atan2(0,0)> is implementation-defined; consult
997Note that atan2(0, 0) is not well-defined.
999your atan2(3) manpage for more information.
1000998
1001999=end original
10021000
1003C<atan2(0,0)> の返り値実装依存す; さらな情報つい
1001atan2(0, 0) は未定義こと注意しください。
1004atan2(3) man ページを参照してください。
10051002
10061003=item bind SOCKET,NAME
10071004X<bind>
10081005
10091006=begin original
10101007
10111008Binds a network address to a socket, just as the bind system call
10121009does. Returns true if it succeeded, false otherwise. NAME should be a
10131010packed address of the appropriate type for the socket. See the examples in
10141011L<perlipc/"Sockets: Client/Server Communication">.
10151012
10161013=end original
10171014
10181015bind(2) システムコールと同様に、ネットワークアドレスをソケットに結び付けます。
10191016成功時には真を返し、失敗時には偽を返します。
10201017NAME は、ソケットに対する、適切な型のパックされたアドレスでなければなりません。
10211018L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
10221019
10231020=item binmode FILEHANDLE, LAYER
10241021X<binmode> X<binary> X<text> X<DOS> X<Windows>
10251022
10261023=item binmode FILEHANDLE
10271024
10281025=begin original
10291026
10301027Arranges for FILEHANDLE to be read or written in "binary" or "text"
10311028mode on systems where the run-time libraries distinguish between
10321029binary and text files. If FILEHANDLE is an expression, the value is
10331030taken as the name of the filehandle. Returns true on success,
10341031otherwise it returns C<undef> and sets C<$!> (errno).
10351032
10361033=end original
10371034
10381035バイナリファイルとテキストファイルを区別する OS において、
10391036FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように
10401037指定します。
10411038FILEHANDLE が式である場合には、その式の値がファイルハンドルの
10421039名前として使われます。
10431040成功時には真を返し、失敗時には C<undef> を返して C<$!> (errno) を設定します。
10441041
10451042=begin original
10461043
10471044On some systems (in general, DOS and Windows-based systems) binmode()
10481045is necessary when you're not working with a text file. For the sake
10491046of portability it is a good idea to always use it when appropriate,
10501047and to never use it when it isn't appropriate. Also, people can
10511048set their I/O to be by default UTF-8 encoded Unicode, not bytes.
10521049
10531050=end original
10541051
10551052テキストファイルでないものを扱う場合に binmode() が必要な
10561053システムもあります(一般的には DOS と Windows ベースのシステムです)。
10571054移植性のために、適切なときには常にこれを使い、適切でないときには
10581055決して使わないというのは良い考えです。
10591056また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
10601057Unicode にセットすることも出来ます。
10611058
10621059=begin original
10631060
10641061In other words: regardless of platform, use binmode() on binary data,
10651062like for example images.
10661063
10671064=end original
10681065
10691066言い換えると: プラットフォームに関わらず、
10701067例のイメージのようなバイナリファイルに対しては binmode() を使ってください。
10711068
10721069=begin original
10731070
10741071If LAYER is present it is a single string, but may contain multiple
10751072directives. The directives alter the behaviour of the file handle.
1076When LAYER is present using binmode on a text file makes sense.
1073When LAYER is present using binmode on text file makes sense.
10771074
10781075=end original
10791076
10801077LAYER が存在すると、それは単一の文字列ですが、複数の指示子を
10811078含むことができます。
10821079指示子はファイルハンドルの振る舞いを変更します。
10831080LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。
10841081
10851082=begin original
10861083
10871084If LAYER is omitted or specified as C<:raw> the filehandle is made
10881085suitable for passing binary data. This includes turning off possible CRLF
10891086translation and marking it as bytes (as opposed to Unicode characters).
10901087Note that, despite what may be implied in I<"Programming Perl"> (the
10911088Camel) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>
10921089-- other layers which would affect the binary nature of the stream are
10931090I<also> disabled. See L<PerlIO>, L<perlrun> and the discussion about the
10941091PERLIO environment variable.
10951092
10961093=end original
10971094
10981095LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ
10991096データの通過に適するように設定されます。
11001097これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく)
11011098バイトであるとマークしたりすることを含みます。
11021099I<"プログラミング Perl">(ラクダ本) やその他で暗示されているにも関わらず、
11031100C<:raw> は単なる C<:crlf> の I<逆ではありません> -- ストリームの
11041101バイナリとしての性質に影響を与える I<その他の層も無効にされます>。
11051102L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。
11061103
11071104=begin original
11081105
11091106The C<:bytes>, C<:crlf>, and C<:utf8>, and any other directives of the
11101107form C<:...>, are called I/O I<layers>. The C<open> pragma can be used to
11111108establish default I/O layers. See L<open>.
11121109
11131110=end original
11141111
11151112C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は
11161113I/O I<層> が呼び出されます。
11171114C<open> プラグマはデフォルト I/O 層を指定するために使われます。
11181115L<open> を参照してください。
11191116
11201117=begin original
11211118
11221119I<The LAYER parameter of the binmode() function is described as "DISCIPLINE"
11231120in "Programming Perl, 3rd Edition". However, since the publishing of this
11241121book, by many known as "Camel III", the consensus of the naming of this
11251122functionality has moved from "discipline" to "layer". All documentation
11261123of this version of Perl therefore refers to "layers" rather than to
11271124"disciplines". Now back to the regularly scheduled documentation...>
11281125
11291126=end original
11301127
11311128I<binmode() 関数の LAYER パラメータは 「プログラミングPerl 第3版」では
11321129「ディシプリン(DISCIPLINE)」と表現されていました。
11331130しかし、「ラクダ本第3版」として知られているこの本の出版後、この機能の名前は
11341131「ディシプリン」から「層」に変更することで合意されました。
11351132従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく
11361133「層」と記述されています。では通常の解説に戻ります…。>
11371134
11381135=begin original
11391136
11401137To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(utf8)>.
11411138C<:utf8> just marks the data as UTF-8 without further checking,
11421139while C<:encoding(utf8)> checks the data for actually being valid
11431140UTF-8. More details can be found in L<PerlIO::encoding>.
11441141
11451142=end original
11461143
11471144FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か
11481145C<:encoding(utf8)> を使ってください。
11491146C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、
11501147C<:encoding(utf8)> はデータが実際に有効な UTF-8 かどうかをチェックします。
11511148さらなる詳細は L<PerlIO::encoding> にあります。
11521149
11531150=begin original
11541151
11551152In general, binmode() should be called after open() but before any I/O
11561153is done on the filehandle. Calling binmode() will normally flush any
11571154pending buffered output data (and perhaps pending input data) on the
11581155handle. An exception to this is the C<:encoding> layer that
11591156changes the default character encoding of the handle, see L<open>.
11601157The C<:encoding> layer sometimes needs to be called in
11611158mid-stream, and it doesn't flush the stream. The C<:encoding>
11621159also implicitly pushes on top of itself the C<:utf8> layer because
11631160internally Perl will operate on UTF-8 encoded Unicode characters.
11641161
11651162=end original
11661163
11671164一般的に binmode() は open() を呼び出した後、このファイルハンドルに対する
11681165I/O 操作をする前に呼び出すべきです。
11691166binmode() を呼び出すと、普通はこのファイルハンドルに対して
11701167バッファリングされている全ての出力データ
11711168(およびおそらくは入力データ)をフラッシュします。
11721169例外は、このハンドルに対するデフォルト文字エンコーディングを変更する
11731170C<:encoding> 層です; L<open> を参照してください。
11741171C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、
11751172それによってストリームはフラッシュされません。
11761173Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、
11771174C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。
11781175
11791176=begin original
11801177
11811178The operating system, device drivers, C libraries, and Perl run-time
11821179system all work together to let the programmer treat a single
11831180character (C<\n>) as the line terminator, irrespective of the external
11841181representation. On many operating systems, the native text file
11851182representation matches the internal representation, but on some
11861183platforms the external representation of C<\n> is made up of more than
11871184one character.
11881185
11891186=end original
11901187
11911188オペレーティングシステム、デバイスドライバ、C ライブラリ、
11921189Perl ランタイムシステムは全て、プログラマが外部表現に関わらず
119311901 文字 (C<\n>) を行終端として扱えるように協調作業します。
11941191多くのオペレーティングシステムでは、ネイティブテキストファイル表現は
11951192内部表現と同じですが、C<\n> の外部表現が複数文字になる
11961193プラットフォームもあります。
11971194
11981195=begin original
11991196
12001197Mac OS, all variants of Unix, and Stream_LF files on VMS use a single
12011198character to end each line in the external representation of text (even
12021199though that single character is CARRIAGE RETURN on Mac OS and LINE FEED
12031200on Unix and most VMS files). In other systems like OS/2, DOS and the
12041201various flavors of MS-Windows your program sees a C<\n> as a simple C<\cJ>,
12051202but what's stored in text files are the two characters C<\cM\cJ>. That
12061203means that, if you don't use binmode() on these systems, C<\cM\cJ>
12071204sequences on disk will be converted to C<\n> on input, and any C<\n> in
12081205your program will be converted back to C<\cM\cJ> on output. This is what
12091206you want for text files, but it can be disastrous for binary files.
12101207
12111208=end original
12121209
12131210Mac OS、全ての Unix 系、VMS の Stream_LF ファイルは
12141211テキストの外部表現として各行の末尾に 1 つの文字を
12151212使っています(その文字は Mac OS では復帰で、
12161213Unix とほとんどのVMS のファイルでは改行です)。
12171214VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、
12181215プログラムからは C<\n> は単純に C<\cJ> に見えますが、
12191216テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。
12201217つまり、もしこれらのシステムで binmode() を使わないと、
12211218ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
12221219プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。
12231220これはテキストファイルの場合は思い通りの結果でしょうが、
12241221バイナリファイルの場合は悲惨です。
12251222
12261223=begin original
12271224
12281225Another consequence of using binmode() (on some systems) is that
12291226special end-of-file markers will be seen as part of the data stream.
12301227For systems from the Microsoft family this means that if your binary
12311228data contains C<\cZ>, the I/O subsystem will regard it as the end of
12321229the file, unless you use binmode().
12331230
12341231=end original
12351232
12361233binmode() を(いくつかのシステムで)使うことによるその他の作用としては、
12371234特別なファイル終端マーカーがデータストリームの一部として
12381235見られることです。
12391236Microsoft ファミリーのシステムでは、binmode() を使っていないと
12401237もしバイナリデータに C<\cZ> が含まれていたときに、I/O サブシステムが
12411238これをファイル終端とみなすことを意味します。
12421239
12431240=begin original
12441241
12451242binmode() is not only important for readline() and print() operations,
12461243but also when using read(), seek(), sysread(), syswrite() and tell()
12471244(see L<perlport> for more details). See the C<$/> and C<$\> variables
12481245in L<perlvar> for how to manually set your input and output
12491246line-termination sequences.
12501247
12511248=end original
12521249
12531250binmode() は readline() と print() 操作にだけではなく、
12541251read(), seek(), sysread(), syswrite(), tell() を使うときにも重要です
12551252(詳細は L<perlport> を参照してください)。
12561253入出力の行端末シーケンスを手動でセットする方法については
12571254L<perlvar> の C<$/> 変数と C<$\> 変数を参照してください。
12581255
12591256=item bless REF,CLASSNAME
12601257X<bless>
12611258
12621259=item bless REF
12631260
12641261=begin original
12651262
12661263This function tells the thingy referenced by REF that it is now an object
12671264in the CLASSNAME package. If CLASSNAME is omitted, the current package
12681265is used. Because a C<bless> is often the last thing in a constructor,
12691266it returns the reference for convenience. Always use the two-argument
12701267version if a derived class might inherit the function doing the blessing.
12711268See L<perltoot> and L<perlobj> for more about the blessing (and blessings)
12721269of objects.
12731270
12741271=end original
12751272
12761273この関数は、REF で渡された オブジェクトに対し、
12771274CLASSNAME 内のオブジェクトとなったことを伝えます。
12781275CLASSNAME が省略された場合には、その時点のパッケージとなります。
12791276C<bless> は通常、コンストラクタの最後に置かれますので、
12801277簡便のためにそのリファレンスを返します。
12811278派生クラスが bless される関数を継承する場合は、
12821279常に 2 引数版を使ってください。
12831280オブジェクトの bless (や再 bless) について、
12841281詳しくは L<perltoot> と L<perlobj> を参照してください。
12851282
12861283=begin original
12871284
12881285Consider always blessing objects in CLASSNAMEs that are mixed case.
12891286Namespaces with all lowercase names are considered reserved for
12901287Perl pragmata. Builtin types have all uppercase names. To prevent
12911288confusion, you may wish to avoid such package names as well. Make sure
12921289that CLASSNAME is a true value.
12931290
12941291=end original
12951292
12961293大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを
12971294考慮してください。
12981295全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。
12991296組み込みの型は全て大文字の名前を持ちます。
13001297混乱を避けるために、
13011298パッケージ名としてこのような名前は避けるべきです。
13021299CLASSNAME は真の値を持つようにしてください。
13031300
13041301=begin original
13051302
13061303See L<perlmod/"Perl Modules">.
13071304
13081305=end original
13091306
13101307L<perlmod/"Perl Modules"> を参照して下さい。
13111308
13121309=item break
13131310
13141311=begin original
13151312
13161313Break out of a C<given()> block.
13171314
13181315=end original
13191316
13201317C<given()> ブロックから脱出します。
13211318
13221319=begin original
13231320
13241321This keyword is enabled by the "switch" feature: see L<feature>
13251322for more information.
13261323
13271324=end original
13281325
13291326このキーワードは "switch" 機能によって有効になります:
13301327さらなる情報については L<feature> を参照してください。
13311328
13321329=item caller EXPR
13331330X<caller> X<call stack> X<stack> X<stack trace>
13341331
13351332=item caller
13361333
13371334=begin original
13381335
13391336Returns the context of the current subroutine call. In scalar context,
13401337returns the caller's package name if there is a caller, that is, if
13411338we're in a subroutine or C<eval> or C<require>, and the undefined value
13421339otherwise. In list context, returns
13431340
13441341=end original
13451342
13461343その時点のサブルーチン呼び出しのコンテキストを返します。
13471344スカラコンテキストでは、呼び元がある場合
13481345(サブルーチン、C<eval>、C<require> の中にいるとき) には
13491346呼び出し元のパッケージ名を返し、その他のときには未定義値を返します。
13501347リストコンテキストでは、以下を返します:
13511348
13521349 # 0 1 2
13531350 ($package, $filename, $line) = caller;
13541351
13551352=begin original
13561353
13571354With EXPR, it returns some extra information that the debugger uses to
13581355print a stack trace. The value of EXPR indicates how many call frames
13591356to go back before the current one.
13601357
13611358=end original
13621359
13631360EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。
13641361EXPR の値は、現状から数えて、
13651362いくつ前のコールフレームまで戻るかを示します。
13661363
13671364 # 0 1 2 3 4
13681365 ($package, $filename, $line, $subroutine, $hasargs,
13691366
13701367 # 5 6 7 8 9 10
13711368 $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
13721369 = caller($i);
13731370
13741371=begin original
13751372
13761373Here $subroutine may be C<(eval)> if the frame is not a subroutine
13771374call, but an C<eval>. In such a case additional elements $evaltext and
13781375C<$is_require> are set: C<$is_require> is true if the frame is created by a
13791376C<require> or C<use> statement, $evaltext contains the text of the
13801377C<eval EXPR> statement. In particular, for an C<eval BLOCK> statement,
13811378$subroutine is C<(eval)>, but $evaltext is undefined. (Note also that
13821379each C<use> statement creates a C<require> frame inside an C<eval EXPR>
13831380frame.) $subroutine may also be C<(unknown)> if this particular
13841381subroutine happens to have been deleted from the symbol table.
13851382C<$hasargs> is true if a new instance of C<@_> was set up for the frame.
13861383C<$hints> and C<$bitmask> contain pragmatic hints that the caller was
13871384compiled with. The C<$hints> and C<$bitmask> values are subject to change
13881385between versions of Perl, and are not meant for external use.
13891386
13901387=end original
13911388
13921389もしフレームがサブルーチン呼び出しではなく C<eval> だった場合、この
13931390$subroutine は C<(eval)> になります。
13941391この場合、追加の要素である $evaltext と C<$is_require> がセットされます:
13951392C<$is_require> はフレームが C<require> または C<use> で作られた場合に
13961393真になり、$evaltext は C<eval EXPR> のテキストが入ります。
13971394特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、
13981395$evaltext は未定義値になります。
13991396(それぞれの C<use> は C<eval EXPR> の中で C<require> フレームを作ることに
14001397注意してください。)
14011398$subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は
14021399C<(unknown)> になります。
14031400C<$hasargs> はこのフレーム用に C<@_> の新しい実体が設定された場合に真となります。
14041401C<$hints> と C<$bitmask> は caller がコンパイルされたときの
14051402実際的なヒントを含みます。
14061403C<$hints> は C<$bitmask> は Perl のバージョンによって変更される
14071404可能性があるので、外部での使用を想定していません。
14081405
14091406=begin original
14101407
14111408C<$hinthash> is a reference to a hash containing the value of C<%^H> when the
14121409caller was compiled, or C<undef> if C<%^H> was empty. Do not modify the values
14131410of this hash, as they are the actual values stored in the optree.
14141411
14151412=end original
14161413
14171414C<$hinthash> は、caller がコンパイルされた時の C<%^H> の値を含む
14181415ハッシュへのリファレンスか、あるいは C<%^H> が空の場合は C<undef> です。
14191416このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。
14201417
14211418=begin original
14221419
14231420Furthermore, when called from within the DB package, caller returns more
14241421detailed information: it sets the list variable C<@DB::args> to be the
14251422arguments with which the subroutine was invoked.
14261423
14271424=end original
14281425
14291426さらに、DB パッケージの中から呼ばれた場合は、caller は
14301427より詳細な情報を返します。
14311428サブルーチンが起動されたときの引数を変数 C<@DB::args> に設定します。
14321429
14331430=begin original
14341431
14351432Be aware that the optimizer might have optimized call frames away before
14361433C<caller> had a chance to get the information. That means that C<caller(N)>
14371434might not return information about the call frame you expect it do, for
14381435C<< N > 1 >>. In particular, C<@DB::args> might have information from the
14391436previous time C<caller> was called.
14401437
14411438=end original
14421439
14431440C<caller> が情報を得る前にオプティマイザが呼び出しフレームを最適化して
14441441しまうかもしれないことに注意してください。
14451442これは、C<caller(N)> が C<< N > 1 >> のとき、
14461443あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。
14471444特に、C<@DB::args> は C<caller> が前回呼び出された時の情報を
14481445持っているかもしれません。
14491446
14501447=item chdir EXPR
14511448X<chdir>
14521449X<cd>
14531450X<directory, change>
14541451
14551452=item chdir FILEHANDLE
14561453
14571454=item chdir DIRHANDLE
14581455
14591456=item chdir
14601457
14611458=begin original
14621459
14631460Changes the working directory to EXPR, if possible. If EXPR is omitted,
14641461changes to the directory specified by C<$ENV{HOME}>, if set; if not,
14651462changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the
14661463variable C<$ENV{SYS$LOGIN}> is also checked, and used if it is set.) If
14671464neither is set, C<chdir> does nothing. It returns true upon success,
14681465false otherwise. See the example under C<die>.
14691466
14701467=end original
14711468
14721469(可能であれば、) カレントディレクトリを EXPR に移します。
14731470EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、
14741471そのディレクトリに移ります。
14751472そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに移ります。
14761473(VMS では C<$ENV{SYS$LOGIN}> もチェックされ、もしセットされていれば使われます。)
14771474どちらも設定されていなければ、C<chdir> は何もしません。
14781475成功時には真を返し、そうでなければ偽を返します。
14791476C<die> の項の例を参照してください。
14801477
14811478=begin original
14821479
14831480On systems that support fchdir, you might pass a file handle or
14841481directory handle as argument. On systems that don't support fchdir,
14851482passing handles produces a fatal error at run time.
14861483
14871484=end original
14881485
14891486fchdir に対応しているシステムでは、ファイルハンドルやディレクトリハンドルを
14901487引数として渡せます。
14911488fchdir に対応していないシステムでは、ハンドルを渡すと実行時に
14921489致命的エラーになります。
14931490
14941491=item chmod LIST
14951492X<chmod> X<permission> X<mode>
14961493
14971494=begin original
14981495
14991496Changes the permissions of a list of files. The first element of the
15001497list must be the numerical mode, which should probably be an octal
15011498number, and which definitely should I<not> be a string of octal digits:
15021499C<0644> is okay, C<'0644'> is not. Returns the number of files
15031500successfully changed. See also L</oct>, if all you have is a string.
15041501
15051502=end original
15061503
15071504LIST に含まれるファイルの、パーミッションを変更します。
15081505LIST の最初の要素は、数値表現のモードでなければなりません。
15091506恐らく 8 進表記の数であるべきでしょう。しかし、8 進表記のC<文字列ではいけません>。
15101507C<0644> は OK ですが、 C<'0644'> はだめ、ということです。
15111508変更に成功したファイルの数を返します。
15121509文字列を使いたい場合は、L</oct> を参照してください。
15131510
15141511 $cnt = chmod 0755, 'foo', 'bar';
15151512 chmod 0755, @executables;
15161513 $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to
15171514 # --w----r-T
15181515 $mode = '0644'; chmod oct($mode), 'foo'; # this is better
15191516 $mode = 0644; chmod $mode, 'foo'; # this is best
15201517
15211518=begin original
15221519
15231520On systems that support fchmod, you might pass file handles among the
15241521files. On systems that don't support fchmod, passing file handles
15251522produces a fatal error at run time. The file handles must be passed
15261523as globs or references to be recognized. Barewords are considered
15271524file names.
15281525
15291526=end original
15301527
15311528fchmod に対応しているシステムでは、ファイルハンドルを引数として渡せます。
15321529fchmod に対応していないシステムでは、ファイルハンドルを渡すと実行時に
15331530致命的エラーになります。
15341531ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
15351532渡されなければなりません。
15361533裸の単語はファイル名として扱われます。
15371534
15381535 open(my $fh, "<", "foo");
15391536 my $perm = (stat $fh)[2] & 07777;
15401537 chmod($perm | 0600, $fh);
15411538
15421539=begin original
15431540
15441541You can also import the symbolic C<S_I*> constants from the Fcntl
15451542module:
15461543
15471544=end original
15481545
15491546シンボリックな C<S_I*> 定数を Fcntl モジュールからインポートすることもできます。
15501547
15511548 use Fcntl ':mode';
15521549
15531550 chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
15541551 # This is identical to the chmod 0755 of the above example.
15551552
15561553=item chomp VARIABLE
15571554X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol>
15581555
15591556=item chomp( LIST )
15601557
15611558=item chomp
15621559
15631560=begin original
15641561
15651562This safer version of L</chop> removes any trailing string
15661563that corresponds to the current value of C<$/> (also known as
15671564$INPUT_RECORD_SEPARATOR in the C<English> module). It returns the total
15681565number of characters removed from all its arguments. It's often used to
15691566remove the newline from the end of an input record when you're worried
15701567that the final record may be missing its newline. When in paragraph
15711568mode (C<$/ = "">), it removes all trailing newlines from the string.
15721569When in slurp mode (C<$/ = undef>) or fixed-length record mode (C<$/> is
15731570a reference to an integer or the like, see L<perlvar>) chomp() won't
15741571remove anything.
15751572If VARIABLE is omitted, it chomps C<$_>. Example:
15761573
15771574=end original
15781575
15791576より安全な C<chop> (以下を参照してください) です。
15801577C<$/> (C<English> モジュールでは、$INPUT_RECORD_SEPARATOR
15811578とも言う) のその時点の値に対応する行末文字を削除します。
15821579全ての引数から削除した文字数の合計を返します。
15831580入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が
15841581入っているのかわからないような場合に、使用できます。
15851582段落モード (C<$/ = "">) では、レコードの最後の改行をすべて取り除きます。
15861583吸い込みモード (C<$/ = undef>) や 固定長レコードモード
15871584(C<$/> が整数へのリファレンスや類似のものの場合。L<perlvar>を参照してください)
15881585では、chomp() は何も取り除きません。
15891586VARIABLE が省略されると、$_ を対象として chomp します。
15901587例:
15911588
15921589 while (<>) {
15931590 chomp; # avoid \n on last field
15941591 @array = split(/:/);
15951592 # ...
15961593 }
15971594
15981595=begin original
15991596
16001597If VARIABLE is a hash, it chomps the hash's values, but not its keys.
16011598
16021599=end original
16031600
16041601VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp します。
16051602
16061603=begin original
16071604
16081605You can actually chomp anything that's an lvalue, including an assignment:
16091606
16101607=end original
16111608
16121609左辺値であれば、代入を含めて、任意のものを chomp できます:
16131610
16141611 chomp($cwd = `pwd`);
16151612 chomp($answer = <STDIN>);
16161613
16171614=begin original
16181615
16191616If you chomp a list, each element is chomped, and the total number of
16201617characters removed is returned.
16211618
16221619=end original
16231620
16241621リストを chomp すると、個々の要素が chomp され、
16251622削除された文字数の合計が返されます。
16261623
16271624=begin original
16281625
16291626Note that parentheses are necessary when you're chomping anything
16301627that is not a simple variable. This is because C<chomp $cwd = `pwd`;>
16311628is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as
16321629C<chomp( $cwd = `pwd` )> which you might expect. Similarly,
16331630C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than
16341631as C<chomp($a, $b)>.
16351632
16361633=end original
16371634
16381635単純な変数以外のものを chomp する場合はかっこが必要であることに
16391636注意してください。
16401637これは、C<chomp $cwd = `pwd`;> は、予測している
16411638C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と
16421639解釈されるからです。
16431640同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b>
16441641と解釈されます。
16451642
16461643=item chop VARIABLE
16471644X<chop>
16481645
16491646=item chop( LIST )
16501647
16511648=item chop
16521649
16531650=begin original
16541651
16551652Chops off the last character of a string and returns the character
16561653chopped. It is much more efficient than C<s/.$//s> because it neither
16571654scans nor copies the string. If VARIABLE is omitted, chops C<$_>.
16581655If VARIABLE is a hash, it chops the hash's values, but not its keys.
16591656
16601657=end original
16611658
16621659文字列の最後の文字を切り捨てて、その切り取った文字を返します。
16631660文字列の検索もコピーも行ないませんので
16641661C<s/.$//s> よりも、ずっと効率的です。
16651662VARIABLE が省略されると、C<$_> を対象として chop します。
16661663VARIABLE がハッシュの場合、ハッシュの value を chop しますが、
16671664key は chop しません。
16681665
16691666=begin original
16701667
16711668You can actually chop anything that's an lvalue, including an assignment.
16721669
16731670=end original
16741671
16751672実際のところ、代入を含む左辺値となりうるなんでも chop できます。
16761673
16771674=begin original
16781675
16791676If you chop a list, each element is chopped. Only the value of the
16801677last C<chop> is returned.
16811678
16821679=end original
16831680
16841681リストを chop すると、個々の要素が chop されます。
16851682最後の C<chop> の値だけが返されます。
16861683
16871684=begin original
16881685
16891686Note that C<chop> returns the last character. To return all but the last
16901687character, use C<substr($string, 0, -1)>.
16911688
16921689=end original
16931690
16941691C<chop> は最後の文字を返すことに注意してください。
16951692最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を
16961693使ってください。
16971694
16981695=begin original
16991696
17001697See also L</chomp>.
17011698
17021699=end original
17031700
17041701L</chomp> も参照してください。
17051702
17061703=item chown LIST
17071704X<chown> X<owner> X<user> X<group>
17081705
17091706=begin original
17101707
17111708Changes the owner (and group) of a list of files. The first two
17121709elements of the list must be the I<numeric> uid and gid, in that
17131710order. A value of -1 in either position is interpreted by most
17141711systems to leave that value unchanged. Returns the number of files
17151712successfully changed.
17161713
17171714=end original
17181715
17191716LIST に含まれるファイルの所有者 (とグループ) を変更します。
17201717LIST の最初の 2 つの要素には、I<数値表現> の uid と gid を
17211718この順序で与えなければなりません。
17221719どちらかの値を -1 にすると、ほとんどのシステムではその値は
17231720変更しないと解釈します。
17241721変更に成功したファイルの数が返されます。
17251722
17261723 $cnt = chown $uid, $gid, 'foo', 'bar';
17271724 chown $uid, $gid, @filenames;
17281725
17291726=begin original
17301727
17311728On systems that support fchown, you might pass file handles among the
17321729files. On systems that don't support fchown, passing file handles
17331730produces a fatal error at run time. The file handles must be passed
17341731as globs or references to be recognized. Barewords are considered
17351732file names.
17361733
17371734=end original
17381735
17391736fchown に対応しているシステムでは、ファイルハンドルを引数として渡せます。
17401737fchown に対応していないシステムでは、ファイルハンドルを渡すと実行時に
17411738致命的エラーになります。
17421739ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
17431740渡されなければなりません。
17441741裸の単語はファイル名として扱われます。
17451742
17461743=begin original
17471744
17481745Here's an example that looks up nonnumeric uids in the passwd file:
17491746
17501747=end original
17511748
17521749passwd ファイルから数値表現でない uid を検索する例を
17531750示します:
17541751
17551752 print "User: ";
17561753 chomp($user = <STDIN>);
17571754 print "Files: ";
17581755 chomp($pattern = <STDIN>);
17591756
17601757 ($login,$pass,$uid,$gid) = getpwnam($user)
17611758 or die "$user not in passwd file";
17621759
17631760 @ary = glob($pattern); # expand filenames
17641761 chown $uid, $gid, @ary;
17651762
17661763=begin original
17671764
17681765On most systems, you are not allowed to change the ownership of the
17691766file unless you're the superuser, although you should be able to change
17701767the group to any of your secondary groups. On insecure systems, these
17711768restrictions may be relaxed, but this is not a portable assumption.
17721769On POSIX systems, you can detect this condition this way:
17731770
17741771=end original
17751772
17761773ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を
17771774変更できますが、グループは実行者の副グループに変更できるべきです。
17781775安全でないシステムでは、この制限はゆるめられています。
17791776しかしこれは移植性のある仮定ではありません。
17801777POSIX システムでは、以下のようにしてこの条件を検出できます:
17811778
17821779 use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
17831780 $can_chown_giveaway = not sysconf(_PC_CHOWN_RESTRICTED);
17841781
17851782=item chr NUMBER
17861783X<chr> X<character> X<ASCII> X<Unicode>
17871784
17881785=item chr
17891786
17901787=begin original
17911788
17921789Returns the character represented by that NUMBER in the character set.
17931790For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and
17941791chr(0x263a) is a Unicode smiley face.
17951792
17961793=end original
17971794
17981795特定の文字セットでの NUMBER で表わされる文字を返します。
17991796たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります。
18001797chr(0x263a) は Unicode のスマイリーフェイスです。
18011798
18021799=begin original
18031800
18041801Negative values give the Unicode replacement character (chr(0xfffd)),
18051802except under the L<bytes> pragma, where low eight bits of the value
18061803(truncated to an integer) are used.
18071804
18081805=end original
18091806
18101807負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、
18111808L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが
18121809使われます。
18131810
18141811=begin original
18151812
18161813If NUMBER is omitted, uses C<$_>.
18171814
18181815=end original
18191816
18201817NUMBER が省略された場合、C<$_> を使います。
18211818
18221819=begin original
18231820
18241821For the reverse, use L</ord>.
18251822
18261823=end original
18271824
18281825逆を行うためには、L</ord> を参照してください。
18291826
18301827=begin original
18311828
18321829Note that characters from 128 to 255 (inclusive) are by default
18331830internally not encoded as UTF-8 for backward compatibility reasons.
18341831
18351832=end original
18361833
18371834128 から 255 までの文字は過去との互換性のために
18381835デフォルトでは UTF-8 Unicode にエンコードされません。
18391836
18401837=begin original
18411838
18421839See L<perlunicode> for more about Unicode.
18431840
18441841=end original
18451842
18461843Unicode についてもっと知りたいなら、L<perlunicode> を
18471844参照してください。
18481845
18491846=item chroot FILENAME
18501847X<chroot> X<root>
18511848
18521849=item chroot
18531850
18541851=begin original
18551852
18561853This function works like the system call by the same name: it makes the
18571854named directory the new root directory for all further pathnames that
18581855begin with a C</> by your process and all its children. (It doesn't
18591856change your current working directory, which is unaffected.) For security
18601857reasons, this call is restricted to the superuser. If FILENAME is
18611858omitted, does a C<chroot> to C<$_>.
18621859
18631860=end original
18641861
18651862同じ名前のシステムコールと同じことをします。
18661863現在のプロセス及び子プロセスに対して、C</>で始まるパス名に関して
18671864指定されたディレクトリを新しいルートディレクトリとして扱います。
18681865(これはカレントディレクトリを変更しません。カレントディレクトリはそのままです)。
18691866セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。
18701867FILENAME を省略すると、C<$_> へ C<chroot> します。
18711868
18721869=item close FILEHANDLE
18731870X<close>
18741871
18751872=item close
18761873
18771874=begin original
18781875
18791876Closes the file or pipe associated with the file handle, flushes the IO
18801877buffers, and closes the system file descriptor. Returns true if those
18811878operations have succeeded and if no error was reported by any PerlIO
18821879layer. Closes the currently selected filehandle if the argument is
18831880omitted.
18841881
18851882=end original
18861883
18871884FILEHANDLE に対応したファイルまたはパイプをクローズして、
18881885IO バッファをフラッシュし、システムファイル記述子をクローズします。
18891886操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。
18901887引数が省略された場合、現在選択されているファイルハンドルをクローズします。
18911888
18921889=begin original
18931890
18941891You don't have to close FILEHANDLE if you are immediately going to do
18951892another C<open> on it, because C<open> will close it for you. (See
18961893C<open>.) However, an explicit C<close> on an input file resets the line
18971894counter (C<$.>), while the implicit close done by C<open> does not.
18981895
18991896=end original
19001897
19011898クローズしてすぐにまた、同じファイルハンドルに
19021899対してオープンを行なう場合には、C<open> が自動的に C<close>
19031900を行ないますので、close FILEHANDLE する必要はありません
19041901(C<open> を参照してください)。
19051902ただし、明示的にクローズを行なったときにのみ入力ファイルの
19061903行番号 (C<$.>) のリセットが行なわれ、C<open> によって行なわれる
19071904暗黙の C<close>では行なわれません。
19081905
19091906=begin original
19101907
19111908If the file handle came from a piped open, C<close> will additionally
19121909return false if one of the other system calls involved fails, or if the
19131910program exits with non-zero status. (If the only problem was that the
19141911program exited non-zero, C<$!> will be set to C<0>.) Closing a pipe
19151912also waits for the process executing on the pipe to complete, in case you
19161913want to look at the output of the pipe afterwards, and
19171914implicitly puts the exit status value of that command into C<$?> and
19181915C<${^CHILD_ERROR_NATIVE}>.
19191916
19201917=end original
19211918
19221919ファイルハンドルがパイプつきオープンなら、
19231920C<close> はその他のシステムコールが失敗したり
19241921プログラムが非ゼロのステータスで終了した場合にも偽を返します
19251922(プログラムが非ゼロで終了しただけの場合は、C<$!>がC<0>にセットされます)。
19261923後でパイプの出力を見たい場合のために、
19271924パイプのクローズでは、パイプ上で実行されている
19281925プロセスの完了を待ちます。
19291926また自動的にコマンドのステータス値を C<$?> と
19301927C<${^CHILD_ERROR_NATIVE}> に設定します。
19311928
19321929=begin original
19331930
19341931Prematurely closing the read end of a pipe (i.e. before the process
19351932writing to it at the other end has closed it) will result in a
19361933SIGPIPE being delivered to the writer. If the other end can't
19371934handle that, be sure to read all the data before closing the pipe.
19381935
19391936=end original
19401937
19411938途中で(つまり、書き込み側が閉じる前に)
19421939パイプの読み込み側が閉じた場合、
19431940書き込み側に SIGPIPE が配送されます。
19441941書き込み側がこれを扱えない場合、パイプを閉じる前に
19451942確実に全てのデータが読み込まれるようにする必要があります。
19461943
19471944=begin original
19481945
19491946Example:
19501947
19511948=end original
19521949
19531950例:
19541951
19551952 open(OUTPUT, '|sort >foo') # pipe to sort
19561953 or die "Can't start sort: $!";
19571954 #... # print stuff to output
19581955 close OUTPUT # wait for sort to finish
19591956 or warn $! ? "Error closing sort pipe: $!"
19601957 : "Exit status $? from sort";
19611958 open(INPUT, 'foo') # get sort's results
19621959 or die "Can't open 'foo' for input: $!";
19631960
19641961=begin original
19651962
19661963FILEHANDLE may be an expression whose value can be used as an indirect
19671964filehandle, usually the real filehandle name.
19681965
19691966=end original
19701967
19711968FILEHANDLE は式でもかまいません。この場合、値は間接ファイルハンドルと
19721969して扱われ、普通は実際のファイルハンドル名です。
19731970
19741971=item closedir DIRHANDLE
19751972X<closedir>
19761973
19771974=begin original
19781975
19791976Closes a directory opened by C<opendir> and returns the success of that
19801977system call.
19811978
19821979=end original
19831980
19841981C<opendir> でオープンしたディレクトリをクローズし、
19851982システムコールの返り値を返します。
19861983
19871984=item connect SOCKET,NAME
19881985X<connect>
19891986
19901987=begin original
19911988
19921989Attempts to connect to a remote socket, just as the connect system call
19931990does. Returns true if it succeeded, false otherwise. NAME should be a
19941991packed address of the appropriate type for the socket. See the examples in
19951992L<perlipc/"Sockets: Client/Server Communication">.
19961993
19971994=end original
19981995
19991996connect(2) システムコールと同様に、リモートソケットへの接続を試みます。
20001997成功時には真を返し、失敗時には偽を返します。
20011998NAME は、ソケットに対する、適切な型のパックされた
20021999アドレスでなければなりません。
20032000L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
20042001
20052002=item continue BLOCK
20062003X<continue>
20072004
20082005=item continue
20092006
20102007=begin original
20112008
20122009C<continue> is actually a flow control statement rather than a function. If
20132010there is a C<continue> BLOCK attached to a BLOCK (typically in a C<while> or
20142011C<foreach>), it is always executed just before the conditional is about to
20152012be evaluated again, just like the third part of a C<for> loop in C. Thus
20162013it can be used to increment a loop variable, even when the loop has been
20172014continued via the C<next> statement (which is similar to the C C<continue>
20182015statement).
20192016
20202017=end original
20212018
20222019C<continue> は実際には関数ではなく、実行制御文です。
20232020C<continue> BLOCK が BLOCK (典型的には C<while> または C<foreach> の中)にあると、
20242021これは条件文が再評価される直前に常に実行されます。
20252022これは C における C<for> ループの 3 番目の部分と同様です。
20262023従って、これは C<next> 文
20272024(これは C の C<continue> 文と似ています)を使ってループが繰り返されるときでも
20282025ループ変数を増やしたいときに使えます。
20292026
20302027=begin original
20312028
20322029C<last>, C<next>, or C<redo> may appear within a C<continue>
20332030block. C<last> and C<redo> will behave as if they had been executed within
20342031the main block. So will C<next>, but since it will execute a C<continue>
20352032block, it may be more entertaining.
20362033
20372034=end original
20382035
20392036C<last>, C<next>, C<redo> が C<continue> ブロック内に現れる可能性があります。
20402037C<last> と C<redo> はメインブロックの中で実行されたのと同じように振舞います。
20412038C<next> の場合は、C<continue> ブロックを実行することになるので、
20422039より面白いことになります。
20432040
20442041 while (EXPR) {
20452042 ### redo always comes here
20462043 do_something;
20472044 } continue {
20482045 ### next always comes here
20492046 do_something_else;
20502047 # then back the top to re-check EXPR
20512048 }
20522049 ### last always comes here
20532050
20542051=begin original
20552052
20562053Omitting the C<continue> section is semantically equivalent to using an
20572054empty one, logically enough. In that case, C<next> goes directly back
20582055to check the condition at the top of the loop.
20592056
20602057=end original
20612058
20622059C<continue> 節を省略するのは、文法的には空の節を指定したのと同じで、
20632060論理的には十分です。
20642061この場合、C<next> は直接ループ先頭の条件チェックに戻ります。
20652062
20662063=begin original
20672064
20682065If the "switch" feature is enabled, C<continue> is also a
20692066function that will break out of the current C<when> or C<default>
20702067block, and fall through to the next case. See L<feature> and
20712068L<perlsyn/"Switch statements"> for more information.
20722069
20732070=end original
20742071
20752072"switch" 機能が有効なら、C<continue> は現在の C<when> や C<default> の
20762073ブロックから飛び出して、次の場合に移動するための文となります。
20772074さらなる情報については L<feature> と L<perlsyn/"Switch statements"> を
20782075参照してください。
20792076
20802077=item cos EXPR
20812078X<cos> X<cosine> X<acos> X<arccosine>
20822079
20832080=item cos
20842081
20852082=begin original
20862083
20872084Returns the cosine of EXPR (expressed in radians). If EXPR is omitted,
20882085takes cosine of C<$_>.
20892086
20902087=end original
20912088
20922089(ラジアンで示した) EXPR の余弦を返します。
20932090EXPR が省略されたときには、C<$_> の余弦を取ります。
20942091
20952092=begin original
20962093
20972094For the inverse cosine operation, you may use the C<Math::Trig::acos()>
20982095function, or use this relation:
20992096
21002097=end original
21012098
21022099逆余弦を求めるためには、C<Math::Trig::acos()> 関数を使うか、
21032100以下の関係を使ってください。
21042101
21052102 sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
21062103
21072104=item crypt PLAINTEXT,SALT
21082105X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password>
21092106X<decrypt> X<cryptography> X<passwd> X<encrypt>
21102107
21112108=begin original
21122109
21132110Creates a digest string exactly like the crypt(3) function in the C
21142111library (assuming that you actually have a version there that has not
2115been extirpated as a potential munition).
2112been extirpated as a potential munitions).
21162113
21172114=end original
21182115
21192116C ライブラリの crypt(3) 関数と全く同じように、ダイジェスト文字列を
21202117作成します(一時的な必需品として、まだ絶滅していないバージョンを
21212118持っていると仮定しています)。
21222119
21232120=begin original
21242121
21252122crypt() is a one-way hash function. The PLAINTEXT and SALT is turned
21262123into a short string, called a digest, which is returned. The same
21272124PLAINTEXT and SALT will always return the same string, but there is no
21282125(known) way to get the original PLAINTEXT from the hash. Small
21292126changes in the PLAINTEXT or SALT will result in large changes in the
21302127digest.
21312128
21322129=end original
21332130
21342131crypt() は一方向ハッシュ関数です。
21352132PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、
21362133それが返されます。
21372134PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから
21382135元の PLAINTEXT を得る(既知の)方法はありません。
21392136PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。
21402137
21412138=begin original
21422139
21432140There is no decrypt function. This function isn't all that useful for
21442141cryptography (for that, look for F<Crypt> modules on your nearby CPAN
21452142mirror) and the name "crypt" is a bit of a misnomer. Instead it is
21462143primarily used to check if two pieces of text are the same without
21472144having to transmit or store the text itself. An example is checking
21482145if a correct password is given. The digest of the password is stored,
21492146not the password itself. The user types in a password that is
21502147crypt()'d with the same salt as the stored digest. If the two digests
21512148match the password is correct.
21522149
21532150=end original
21542151
21552152復号化関数はありません。
21562153この関数は暗号化のためにはまったく役に立ちません(このためには、
21572154お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、
21582155"crypt" という名前は少し間違った名前です。
21592156その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを
21602157転送したり保管したりせずにチェックするために使います。
21612158例としては、正しいパスワードが与えられたかどうかをチェックがあります。
21622159パスワード自身ではなく、パスワードのダイジェストが保管されます。
21632160ユーザーがパスワードを入力すると、保管されているダイジェストと同じ
21642161salt で crypt() します。
21652162二つのダイジェストが同じなら、パスワードは正しいです。
21662163
21672164=begin original
21682165
21692166When verifying an existing digest string you should use the digest as
21702167the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used
21712168to create the digest is visible as part of the digest. This ensures
21722169crypt() will hash the new string with the same salt as the digest.
21732170This allows your code to work with the standard L<crypt|/crypt> and
21742171with more exotic implementations. In other words, do not assume
21752172anything about the returned string itself, or how many bytes in the
21762173digest matter.
21772174
21782175=end original
21792176
21802177すでにあるダイジェスト文字列を検証するには、ダイジェストを
21812178(C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。
21822179ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。
21832180これにより、crypt() は同じ salt で新しい文字列をダイジェストとして
21842181ハッシュ化できるようにします。
21852182これによって標準的な C<crypt|/crypt> や、より風変わりな実装でも動作します。
21862183言い換えると、返される文字列そのものや、ダイジェスト文字列が
21872184何バイトあるかといったことに対して、どのような仮定もしてはいけません。
21882185
21892186=begin original
21902187
21912188Traditionally the result is a string of 13 bytes: two first bytes of
21922189the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
2193the first eight bytes of PLAINTEXT mattered. But alternative
2190the first eight bytes of the digest string mattered, but alternative
21942191hashing schemes (like MD5), higher level security schemes (like C2),
21952192and implementations on non-UNIX platforms may produce different
21962193strings.
21972194
21982195=end original
21992196
22002197伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて
2201集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の
2198集合 C<[./0-9A-Za-z]> からの 11 バイトで、ダイジェスト文字列の最初の
22028 バイトだけが意味があります
21998 バイトだけが意味がありますが、(MD5 のように) 異なったハッシュ手法、
2203しかし、(MD5 のように) 異なったハッシュ手法、
22042200(C2 のような) 高レベルセキュリティ手法、非 UNIX プラットフォームでの
22052201実装などでは異なった文字列が生成されることがあります。
22062202
22072203=begin original
22082204
22092205When choosing a new salt create a random two character string whose
22102206characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.',
22112207'/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of
22122208characters is just a recommendation; the characters allowed in
22132209the salt depend solely on your system's crypt library, and Perl can't
22142210restrict what salts C<crypt()> accepts.
22152211
22162212=end original
22172213
22182214新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から
22192215(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> のようにして)
22202216ランダムに2 つの文字を選びます。
22212217この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化
22222218ライブラリだけに依存し、Perl は C<crypt()> がどのような salt を受け付けるかに
22232219ついて制限しません。
22242220
22252221=begin original
22262222
22272223Here's an example that makes sure that whoever runs this program knows
22282224their password:
22292225
22302226=end original
22312227
22322228プログラムを実行する人が、
22332229自分のパスワードを知っていることを確認する例です:
22342230
22352231 $pwd = (getpwuid($<))[1];
22362232
22372233 system "stty -echo";
22382234 print "Password: ";
22392235 chomp($word = <STDIN>);
22402236 print "\n";
22412237 system "stty echo";
22422238
22432239 if (crypt($word, $pwd) ne $pwd) {
22442240 die "Sorry...\n";
22452241 } else {
22462242 print "ok\n";
22472243 }
22482244
22492245=begin original
22502246
22512247Of course, typing in your own password to whoever asks you
22522248for it is unwise.
22532249
22542250=end original
22552251
22562252もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。
22572253
22582254=begin original
22592255
22602256The L<crypt|/crypt> function is unsuitable for hashing large quantities
22612257of data, not least of all because you can't get the information
22622258back. Look at the L<Digest> module for more robust algorithms.
22632259
22642260=end original
22652261
22662262L<crypt|/crypt> 関数は大量のデータのハッシュ化には向いていません。
22672263これは情報を戻せないという理由だけではありません。
22682264より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。
22692265
22702266=begin original
22712267
22722268If using crypt() on a Unicode string (which I<potentially> has
22732269characters with codepoints above 255), Perl tries to make sense
22742270of the situation by trying to downgrade (a copy of the string)
22752271the string back to an eight-bit byte string before calling crypt()
22762272(on that copy). If that works, good. If not, crypt() dies with
22772273C<Wide character in crypt>.
22782274
22792275=end original
22802276
22812277Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を
22822278含みます)に crypt() を使った場合、Perl は crypt() を呼び出す前に与えられた
22832279文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る)
22842280ことで状況のつじつまを合わせようとします。
22852281うまく動けば、それでよし。動かなければ、crypt() は
22862282C<Wide character in crypt> というメッセージと共に die します。
22872283
22882284=item dbmclose HASH
22892285X<dbmclose>
22902286
22912287=begin original
22922288
22932289[This function has been largely superseded by the C<untie> function.]
22942290
22952291=end original
22962292
22972293[この関数は、C<untie> 関数に大きくとって代わられました。]
22982294
22992295=begin original
23002296
23012297Breaks the binding between a DBM file and a hash.
23022298
23032299=end original
23042300
23052301DBM ファイルとハッシュの連結をはずします。
23062302
23072303=item dbmopen HASH,DBNAME,MASK
23082304X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm>
23092305
23102306=begin original
23112307
23122308[This function has been largely superseded by the C<tie> function.]
23132309
23142310=end original
23152311
23162312[この関数は、C<tie> 関数に大きくとって代わられました。]
23172313
23182314=begin original
23192315
23202316This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a
23212317hash. HASH is the name of the hash. (Unlike normal C<open>, the first
23222318argument is I<not> a filehandle, even though it looks like one). DBNAME
23232319is the name of the database (without the F<.dir> or F<.pag> extension if
23242320any). If the database does not exist, it is created with protection
23252321specified by MASK (as modified by the C<umask>). If your system supports
23262322only the older DBM functions, you may perform only one C<dbmopen> in your
23272323program. In older versions of Perl, if your system had neither DBM nor
23282324ndbm, calling C<dbmopen> produced a fatal error; it now falls back to
23292325sdbm(3).
23302326
23312327=end original
23322328
23332329dbm(3), ndbm(3), sdbm(3), gdbm(3) ファイルまたは Berkeley DB
23342330ファイルを連想配列に結び付けます。
23352331HASH は、その連想配列の名前です。
23362332(普通の C<open> とは違って、最初の引数はファイルハンドル
23372333I<ではありません>。まあ、似たようなものですが。)
23382334DBNAME は、データベースの名前です (拡張子の .dir や
23392335.pag はもしあってもつけません)。
23402336データベースが存在しなければ、MODE MASK (を C<umask> で修正したもの) で
23412337指定されたモードで作られます。
23422338古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ
23432339dbmopen() を実行することができます。
23442340昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、
23452341dbmopen() を呼び出すと致命的エラーになります。
23462342現在では sdbm(3) にフォールバックします。
23472343
23482344=begin original
23492345
23502346If you don't have write access to the DBM file, you can only read hash
23512347variables, not set them. If you want to test whether you can write,
23522348either use file tests or try setting a dummy hash entry inside an C<eval>,
23532349which will trap the error.
23542350
23552351=end original
23562352
23572353DBM ファイルに対して、書き込み権が無いときには、ハッシュ
23582354配列を読みだすことだけができ、設定することはできません。
23592355書けるか否かを調べたい場合には、ファイルテスト
23602356演算子を使うか、エラーをトラップしてくれる、C<eval>
23612357の中で、ダミーのハッシュエントリを設定してみることになります。
23622358
23632359=begin original
23642360
23652361Note that functions such as C<keys> and C<values> may return huge lists
23662362when used on large DBM files. You may prefer to use the C<each>
23672363function to iterate over large DBM files. Example:
23682364
23692365=end original
23702366
23712367大きな DBM ファイルを扱うときには、C<keys> や C<values> のような関数は、
23722368巨大なリストを返します。
23732369大きな DBM ファイルでは、C<each> 関数を使って繰り返しを行なった方が
23742370良いかもしれません。
23752371例:
23762372
23772373 # print out history file offsets
23782374 dbmopen(%HIST,'/usr/lib/news/history',0666);
23792375 while (($key,$val) = each %HIST) {
23802376 print $key, ' = ', unpack('L',$val), "\n";
23812377 }
23822378 dbmclose(%HIST);
23832379
23842380=begin original
23852381
23862382See also L<AnyDBM_File> for a more general description of the pros and
23872383cons of the various dbm approaches, as well as L<DB_File> for a particularly
23882384rich implementation.
23892385
23902386=end original
23912387
23922388様々な dbm 手法に対する利点欠点に関するより一般的な記述および
23932389特にリッチな実装である L<DB_File> に関しては
23942390L<AnyDBM_File> も参照してください。
23952391
23962392=begin original
23972393
23982394You can control which DBM library you use by loading that library
23992395before you call dbmopen():
24002396
24012397=end original
24022398
24032399dbmopen() を呼び出す前にライブラリを読み込むことで、
24042400どの DBM ライブラリを使うかを制御できます:
24052401
24062402 use DB_File;
24072403 dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
24082404 or die "Can't open netscape history file: $!";
24092405
24102406=item defined EXPR
24112407X<defined> X<undef> X<undefined>
24122408
24132409=item defined
24142410
24152411=begin original
24162412
24172413Returns a Boolean value telling whether EXPR has a value other than
24182414the undefined value C<undef>. If EXPR is not present, C<$_> will be
24192415checked.
24202416
24212417=end original
24222418
24232419左辺値 EXPR が未定義値 C<undef> 以外の値を持つか否かを示す、ブール値を
24242420返します。
24252421EXPR がない場合は、C<$_> がチェックされます。
24262422
24272423=begin original
24282424
24292425Many operations return C<undef> to indicate failure, end of file,
24302426system error, uninitialized variable, and other exceptional
24312427conditions. This function allows you to distinguish C<undef> from
24322428other values. (A simple Boolean test will not distinguish among
24332429C<undef>, zero, the empty string, and C<"0">, which are all equally
24342430false.) Note that since C<undef> is a valid scalar, its presence
24352431doesn't I<necessarily> indicate an exceptional condition: C<pop>
24362432returns C<undef> when its argument is an empty array, I<or> when the
24372433element to return happens to be C<undef>.
24382434
24392435=end original
24402436
24412437多くの演算子が、EOF や未初期化変数、システムエラーといった、
24422438例外的な条件で C<undef> を返すようになっています。
24432439この関数は、他の値と C<undef> とを区別するために使えます。
24442440(単純な真偽値テストでは、C<undef>、0、空文字、C<"0"> のいずれも偽を返すので、
24452441区別することができません。)
24462442C<undef> は有効なスカラ値なので、その存在が I<必ずしも>
24472443例外的な状況を表すとは限らないということに注意してください:
24482444C<pop> は引数が空の配列だったときに C<undef> を返しますが、
24492445I<あるいは> 返すべき要素がたまたま C<undef> だったのかもしれません。
24502446
24512447=begin original
24522448
24532449You may also use C<defined(&func)> to check whether subroutine C<&func>
24542450has ever been defined. The return value is unaffected by any forward
24552451declarations of C<&func>. Note that a subroutine which is not defined
24562452may still be callable: its package may have an C<AUTOLOAD> method that
24572453makes it spring into existence the first time that it is called -- see
24582454L<perlsub>.
24592455
24602456=end original
24612457
24622458C<defined(&func)> とすることでサブルーチン C<&func> の存在を、
24632459確かめることもできます。
24642460返り値は C<&func> の前方定義には影響されません。
24652461定義されていないサブルーチンも呼び出し可能であることに注意してください。
24662462最初に呼び出されたときに存在するようにするための
24672463C<AUTOLOAD> メソッドを持ったパッケージかもしれません--
24682464L<perlsub> を参照して下さい。
24692465
24702466=begin original
24712467
24722468Use of C<defined> on aggregates (hashes and arrays) is deprecated. It
24732469used to report whether memory for that aggregate has ever been
24742470allocated. This behavior may disappear in future versions of Perl.
24752471You should instead use a simple test for size:
24762472
24772473=end original
24782474
24792475集合(ハッシュや配列)への C<defined> の使用は非推奨です。
24802476これはその集合にメモリが割り当てられたかを報告するのに
24812477用いられていました。
24822478この振る舞いは将来のバージョンの Perl では消滅するかもしれません。
24832479代わりにサイズに対する簡単なテストを使うべきです。
24842480
24852481 if (@an_array) { print "has array elements\n" }
24862482 if (%a_hash) { print "has hash members\n" }
24872483
24882484=begin original
24892485
24902486When used on a hash element, it tells you whether the value is defined,
24912487not whether the key exists in the hash. Use L</exists> for the latter
24922488purpose.
24932489
24942490=end original
24952491
24962492ハッシュの要素に対して用いると、value が定義されているか否かを
24972493返すものであって、ハッシュに key が存在するか否かを返すのではありません。
24982494この用途には、L</exists> を使ってください。
24992495
25002496=begin original
25012497
25022498Examples:
25032499
25042500=end original
25052501
25062502例:
25072503
25082504 print if defined $switch{'D'};
25092505 print "$val\n" while defined($val = pop(@ary));
25102506 die "Can't readlink $sym: $!"
25112507 unless defined($value = readlink $sym);
25122508 sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
25132509 $debugging = 0 unless defined $debugging;
25142510
25152511=begin original
25162512
25172513Note: Many folks tend to overuse C<defined>, and then are surprised to
25182514discover that the number C<0> and C<""> (the zero-length string) are, in fact,
25192515defined values. For example, if you say
25202516
25212517=end original
25222518
25232519注意: 多くの人々が C<defined> を使いすぎて、C<0> と C<"">(空文字列) が
25242520実際のところ定義された値であることに驚くようです。
25252521例えば、以下のように書くと:
25262522
25272523 "ab" =~ /a(.*)b/;
25282524
25292525=begin original
25302526
25312527The pattern match succeeds, and C<$1> is defined, despite the fact that it
25322528matched "nothing". It didn't really fail to match anything. Rather, it
25332529matched something that happened to be zero characters long. This is all
25342530very above-board and honest. When a function returns an undefined value,
25352531it's an admission that it couldn't give you an honest answer. So you
25362532should use C<defined> only when you're questioning the integrity of what
25372533you're trying to do. At other times, a simple comparison to C<0> or C<""> is
25382534what you want.
25392535
25402536=end original
25412537
25422538パターンマッチングが成功し、C<$1> が定義されても、実際には
25432539「なし」にマッチしています。
25442540しかしこれは何にもマッチしていないわけではありません。
25452541何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。
25462542これは非常に率直で正直なことです。
25472543関数が未定義値を返すとき、正直な答えを返すことができないことを
25482544告白しています。
25492545ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ
25502546C<defined> を使うべきです。
25512547その他の場合では、単に C<0> または C<""> と比較するというのがあなたの
25522548求めているものです。
25532549
25542550=begin original
25552551
25562552See also L</undef>, L</exists>, L</ref>.
25572553
25582554=end original
25592555
25602556L</undef>, L</exists>, L</ref> も参照してください。
25612557
25622558=item delete EXPR
25632559X<delete>
25642560
25652561=begin original
25662562
25672563Given an expression that specifies a hash element, array element, hash slice,
25682564or array slice, deletes the specified element(s) from the hash or array.
25692565In the case of an array, if the array elements happen to be at the end,
25702566the size of the array will shrink to the highest element that tests
25712567true for exists() (or 0 if no such element exists).
25722568
25732569=end original
25742570
25752571ハッシュ要素、配列要素、ハッシュスライス、配列スライスを指定する式を取り、
25762572指定された要素をハッシュや配列からを削除します。
25772573配列の場合、配列要素が最後にあった場合は、
25782574配列の大きさは exists() が真を返す最後尾の要素に縮みます
25792575(そのような要素がない場合は 0 になります)。
25802576
25812577=begin original
25822578
25832579Returns a list with the same number of elements as the number of elements
25842580for which deletion was attempted. Each element of that list consists of
25852581either the value of the element deleted, or the undefined value. In scalar
25862582context, this means that you get the value of the last element deleted (or
25872583the undefined value if that element did not exist).
25882584
25892585=end original
25902586
25912587削除をしようとしたようその数と同じ数の要素からなるリストを返します。
25922588このリストの各要素は、削除された値か未定義値のどちらかです。
25932589スカラコンテキストでは、これは削除された最後の要素(または削除された要素が
25942590ない場合は未定義値)を得ることを意味します。
25952591
25962592 %hash = (foo => 11, bar => 22, baz => 33);
25972593 $scalar = delete $hash{foo}; # $scalar is 11
25982594 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
25992595 @array = delete @hash{qw(foo bar baz)}; # @array is (undef,undef,33)
26002596
26012597=begin original
26022598
26032599Deleting from C<%ENV> modifies the environment. Deleting from
26042600a hash tied to a DBM file deletes the entry from the DBM file. Deleting
26052601from a C<tie>d hash or array may not necessarily return anything.
26062602
26072603=end original
26082604
26092605C<%ENV> から削除を行なうと、実際に環境変数を変更します。
26102606DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを
26112607削除します。
26122608しかし、C<tie> されたハッシュや配列からの削除は、
26132609値を返すとは限りません。
26142610
26152611=begin original
26162612
26172613Deleting an array element effectively returns that position of the array
26182614to its initial, uninitialized state. Subsequently testing for the same
26192615element with exists() will return false. Also, deleting array elements
26202616in the middle of an array will not shift the index of the elements
26212617after them down. Use splice() for that. See L</exists>.
26222618
26232619=end original
26242620
26252621配列要素を削除した場合、配列の位置は初期の、初期化されていない状態になります。
26262622引き続いて同じ要素に対して exists() でテストすると偽を返します。
26272623また、配列の途中の配列要素を削除してもインデックスはシフトしません。
26282624このためには splice() を使ってください。
26292625L</exists> を参照してください。
26302626
26312627=begin original
26322628
26332629The following (inefficiently) deletes all the values of %HASH and @ARRAY:
26342630
26352631=end original
26362632
26372633以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します:
26382634
26392635 foreach $key (keys %HASH) {
26402636 delete $HASH{$key};
26412637 }
26422638
26432639 foreach $index (0 .. $#ARRAY) {
26442640 delete $ARRAY[$index];
26452641 }
26462642
26472643=begin original
26482644
26492645And so do these:
26502646
26512647=end original
26522648
26532649そして以下のようにもできます:
26542650
26552651 delete @HASH{keys %HASH};
26562652
26572653 delete @ARRAY[0 .. $#ARRAY];
26582654
26592655=begin original
26602656
26612657But both of these are slower than just assigning the empty list
26622658or undefining %HASH or @ARRAY:
26632659
26642660=end original
26652661
26662662しかし、これら二つは単に空リストを代入するか、%HASH や @ARRAY を
26672663undef するより遅いです:
26682664
26692665 %HASH = (); # completely empty %HASH
26702666 undef %HASH; # forget %HASH ever existed
26712667
26722668 @ARRAY = (); # completely empty @ARRAY
26732669 undef @ARRAY; # forget @ARRAY ever existed
26742670
26752671=begin original
26762672
26772673Note that the EXPR can be arbitrarily complicated as long as the final
26782674operation is a hash element, array element, hash slice, or array slice
26792675lookup:
26802676
26812677=end original
26822678
26832679最終的な操作がハッシュ要素、配列要素、ハッシュスライス、配列スライスの
26842680いずれかである限りは、EXPR には任意の複雑な式を置くことができることに
26852681注意してください:
26862682
26872683 delete $ref->[$x][$y]{$key};
26882684 delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};
26892685
26902686 delete $ref->[$x][$y][$index];
26912687 delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
26922688
26932689=item die LIST
26942690X<die> X<throw> X<exception> X<raise> X<$@> X<abort>
26952691
26962692=begin original
26972693
26982694Outside an C<eval>, prints the value of LIST to C<STDERR> and
26992695exits with the current value of C<$!> (errno). If C<$!> is C<0>,
27002696exits with the value of C<<< ($? >> 8) >>> (backtick `command`
27012697status). If C<<< ($? >> 8) >>> is C<0>, exits with C<255>. Inside
27022698an C<eval(),> the error message is stuffed into C<$@> and the
27032699C<eval> is terminated with the undefined value. This makes
27042700C<die> the way to raise an exception.
27052701
27062702=end original
27072703
27082704C<eval> の外では、LIST の値を C<STDERR> に出力し、その時点の
27092705C<$!> (errno) の値で exit します。
27102706C<$!> の値が C<0> ならば、
27112707C<<< ($? >> 8) >>> (backtick `command` のステータス) の値で exitします。
27122708C<<< ($? >> 8) >>> も C<0> であれば、C<255> で exit することになります。
27132709C<eval> の中で使用すると、エラーメッセージが、
27142710C<$@> に入れられます。
27152711C<eval> は中断され、未定義値を返します。
27162712これが C<die> が例外を発生させる方法です。
27172713
27182714=begin original
27192715
27202716Equivalent examples:
27212717
27222718=end original
27232719
27242720等価な例:
27252721
27262722 die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
27272723 chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
27282724
27292725=begin original
27302726
27312727If the last element of LIST does not end in a newline, the current
27322728script line number and input line number (if any) are also printed,
27332729and a newline is supplied. Note that the "input line number" (also
27342730known as "chunk") is subject to whatever notion of "line" happens to
27352731be currently in effect, and is also available as the special variable
27362732C<$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
27372733
27382734=end original
27392735
27402736LIST の最後の要素が改行で終わっていなければ、その時点の
27412737スクリプト名とスクリプトの行番号、(もしあれば)
27422738入力ファイルの行番号と改行文字が、続けて表示されます。
27432739「入力行番号」("chunk" とも呼ばれます)は
27442740「行」という概念が現在有効であると仮定しています。
27452741また特殊変数 C<$.> でも利用可能です。
27462742L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。
27472743
27482744=begin original
27492745
27502746Hint: sometimes appending C<", stopped"> to your message will cause it
27512747to make better sense when the string C<"at foo line 123"> is appended.
27522748Suppose you are running script "canasta".
27532749
27542750=end original
27552751
27562752ヒント: メッセージの最後を C<", stopped"> のようなもので
27572753終わるようにしておけば、C<"at foo line 123"> のように
27582754追加されて、わかりやすくなります。
27592755"canasta" というスクリプトを実行しているとします。
27602756
27612757 die "/etc/games is no good";
27622758 die "/etc/games is no good, stopped";
27632759
27642760=begin original
27652761
27662762produce, respectively
27672763
27682764=end original
27692765
27702766これは、それぞれ以下のように表示します。
27712767
27722768 /etc/games is no good at canasta line 123.
27732769 /etc/games is no good, stopped at canasta line 123.
27742770
27752771=begin original
27762772
27772773See also exit(), warn(), and the Carp module.
27782774
27792775=end original
27802776
27812777exit() と warn() と Carp モジュールも参照してください。
27822778
27832779=begin original
27842780
27852781If LIST is empty and C<$@> already contains a value (typically from a
27862782previous eval) that value is reused after appending C<"\t...propagated">.
27872783This is useful for propagating exceptions:
27882784
27892785=end original
27902786
27912787LIST が空で C<$@> が(典型的には前回の eval で)既に値を持っている場合、
27922788値は C<"\t...propagated"> を追加した後再利用されます。
27932789これは例外を伝播させる場合に有効です:
27942790
27952791 eval { ... };
27962792 die unless $@ =~ /Expected exception/;
27972793
27982794=begin original
27992795
28002796If LIST is empty and C<$@> contains an object reference that has a
28012797C<PROPAGATE> method, that method will be called with additional file
28022798and line number parameters. The return value replaces the value in
28032799C<$@>. i.e. as if C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >>
28042800were called.
28052801
28062802=end original
28072803
28082804LIST が空で、C<$@> が C<PROPAGATE> メソッドを含むオブジェクトへの
28092805リファレンスを含む場合、このメソッドが追加ファイルと行番号を引数として
28102806呼び出されます。
28112807返り値は C<$@> の値を置き換えます。
28122808つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が
28132809呼び出されたかのようになります。
28142810
28152811=begin original
28162812
28172813If C<$@> is empty then the string C<"Died"> is used.
28182814
28192815=end original
28202816
28212817C<$@> が空の場合、C<"Died"> が使われます。
28222818
28232819=begin original
28242820
28252821die() can also be called with a reference argument. If this happens to be
28262822trapped within an eval(), $@ contains the reference. This behavior permits
28272823a more elaborate exception handling implementation using objects that
28282824maintain arbitrary state about the nature of the exception. Such a scheme
28292825is sometimes preferable to matching particular string values of $@ using
28302826regular expressions. Because $@ is a global variable, and eval() may be
28312827used within object implementations, care must be taken that analyzing the
28322828error object doesn't replace the reference in the global variable. The
28332829easiest solution is to make a local copy of the reference before doing
28342830other manipulations. Here's an example:
28352831
28362832=end original
28372833
28382834die() はリファレンス引数と共に呼び出すこともできます。
28392835eval() 内部でこのように呼び出された場合、$@ はリファレンスを持ちます。
28402836この振る舞いは、例外の性質にすいて任意の状態を管理するオブジェクトを使った
28412837より複雑な例外処理の実装を可能にします。
28422838このようなスキーマは $@ の特定の文字列値を正規表現を使って
28432839マッチングするときに時々好まれます。
28442840$@ はグローバル変数で、eval() はオブジェクト実装の内部で
28452841使われることがあるので、エラーオブジェクトの解析はグローバル変数の
28462842リファレンスを置き換えないことに注意を払わなければなりません。
28472843最も簡単な解決方法は、他の操作をする前にリファレンスのローカルコピーを
28482844作ることです。
28492845以下に例を示します:
28502846
28512847 use Scalar::Util 'blessed';
28522848
28532849 eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) };
28542850 if (my $ev_err = $@) {
28552851 if (blessed($ev_err) && $ev_err->isa("Some::Module::Exception")) {
28562852 # handle Some::Module::Exception
28572853 }
28582854 else {
28592855 # handle all other possible exceptions
28602856 }
28612857 }
28622858
28632859=begin original
28642860
28652861Because perl will stringify uncaught exception messages before displaying
28662862them, you may want to overload stringification operations on such custom
28672863exception objects. See L<overload> for details about that.
28682864
28692865=end original
28702866
28712867perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、
28722868このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと
28732869思うかもしれません。
28742870これに関する詳細は L<overload> を参照してください。
28752871
28762872=begin original
28772873
28782874You can arrange for a callback to be run just before the C<die>
28792875does its deed, by setting the C<$SIG{__DIE__}> hook. The associated
28802876handler will be called with the error text and can change the error
28812877message, if it sees fit, by calling C<die> again. See
28822878L<perlvar/$SIG{expr}> for details on setting C<%SIG> entries, and
28832879L<"eval BLOCK"> for some examples. Although this feature was
28842880to be run only right before your program was to exit, this is not
28852881currently the case--the C<$SIG{__DIE__}> hook is currently called
28862882even inside eval()ed blocks/strings! If one wants the hook to do
28872883nothing in such situations, put
28882884
28892885=end original
28902886
28912887C<$SIG{__DIE__}> フックをセットすることで、C<die> がその行動を行う
28922888直前に実行されるコールバックを設定できます。
28932889結び付けられたハンドラはエラーテキストと共に呼び出され、
28942890必要なら再び C<die> を呼び出すことでエラーテキストを変更できアス。
28952891C<%SIG> のエントリをセットする詳細については、L<perlvar/$SIG{expr}> を、
28962892例については L<"eval BLOCK"> を参照してください。
28972893この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、
28982894現在ではそうではありません --
28992895C<$SIG{__DIE__}> フックは eval() されたブロック/文字列の中でも
29002896呼ばれるのです!
29012897もしそのような状況で何もしなくない時は:
29022898
29032899 die @_ if $^S;
29042900
29052901=begin original
29062902
29072903as the first line of the handler (see L<perlvar/$^S>). Because
29082904this promotes strange action at a distance, this counterintuitive
29092905behavior may be fixed in a future release.
29102906
29112907=end original
29122908
29132909をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。
29142910これは離れたところで不思議な行動を引き起こすので、
29152911この直感的でない振る舞いは将来のリリースで修正されるかもしれません。
29162912
29172913=item do BLOCK
29182914X<do> X<block>
29192915
29202916=begin original
29212917
29222918Not really a function. Returns the value of the last command in the
29232919sequence of commands indicated by BLOCK. When modified by the C<while> or
29242920C<until> loop modifier, executes the BLOCK once before testing the loop
29252921condition. (On other statements the loop modifiers test the conditional
29262922first.)
29272923
29282924=end original
29292925
29302926実際は関数ではありません。
29312927BLOCK で示されるコマンド列の最後の値を返します。
29322928C<while> や C<until> ループ修飾子で修飾すると、
29332929ループ条件を調べる前に 1 度、BLOCK を実行します。
29342930(これ以外の実行文は、ループ修飾子により、条件が最初に
29352931調べられます。)
29362932
29372933=begin original
29382934
29392935C<do BLOCK> does I<not> count as a loop, so the loop control statements
29402936C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
29412937See L<perlsyn> for alternative strategies.
29422938
29432939=end original
29442940
29452941C<do BLOCK> はループとしては I<扱われません>。
29462942従って、C<next>, C<last>, C<redo> といったループ制御文は
29472943ブロックから抜けたり再開することはできません。
29482944その他の戦略については L<perlsyn> を参照して下さい。
29492945
29502946=item do SUBROUTINE(LIST)
29512947X<do>
29522948
29532949=begin original
29542950
29552951This form of subroutine call is deprecated. See L<perlsub>.
29562952
29572953=end original
29582954
29592955この形のサブルーチン呼び出しは非推奨です。
29602956L<perlsub> を参照してください。
29612957
29622958=item do EXPR
29632959X<do>
29642960
29652961=begin original
29662962
29672963Uses the value of EXPR as a filename and executes the contents of the
29682964file as a Perl script.
29692965
29702966=end original
29712967
29722968EXPR の値をファイル名として用い、そのファイルの中身を
29732969Perl のスクリプトとして実行します。
29742970
29752971 do 'stat.pl';
29762972
29772973=begin original
29782974
29792975is just like
29802976
29812977=end original
29822978
29832979は以下のものと同じようなものですが、
29842980
29852981 eval `cat stat.pl`;
29862982
29872983=begin original
29882984
29892985except that it's more efficient and concise, keeps track of the current
29902986filename for error messages, searches the @INC directories, and updates
29912987C<%INC> if the file is found. See L<perlvar/Predefined Names> for these
29922988variables. It also differs in that code evaluated with C<do FILENAME>
29932989cannot see lexicals in the enclosing scope; C<eval STRING> does. It's the
29942990same, however, in that it does reparse the file every time you call it,
29952991so you probably don't want to do this inside a loop.
29962992
29972993=end original
29982994
29992995より効率的で、簡潔であり、エラーメッセージでファイル名がわかる、
30002996カレントディレクトリでファイルが見つからなかったときに
30012997@INC ディレクトリを検索する、ファイルがあったときに C<%INC> を更新する、
30022998といったことがあります。
30032999L<perlvar/Predefined Names> も参照してください。
30043000C<do FILENAME> で評価されたコードは、入れ子のスコープにある
30053001レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、
30063002という違いがあります。
30073003しかし、呼び出すたびにファイルを解析し直すという点では同じですから、
30083004ループ内でこれを使おうなどとは、間違っても思ったりしないように。
30093005
30103006=begin original
30113007
30123008If C<do> cannot read the file, it returns undef and sets C<$!> to the
30133009error. If C<do> can read the file but cannot compile it, it
30143010returns undef and sets an error message in C<$@>. If the file is
30153011successfully compiled, C<do> returns the value of the last expression
30163012evaluated.
30173013
30183014=end original
30193015
30203016C<do>がファイルを読み込めなかった場合、undef を返して C<$!> に
30213017エラーを設定します。
30223018C<do> がファイルを読み込めたがコンパイルできなかった場合、
30233019undef を返して C<$@> にエラーメッセージを設定します。
30243020ファイルのコンパイルに成功した場合、C<do> は最後に評価した表現の値を返します。
30253021
30263022=begin original
30273023
30283024Note that inclusion of library modules is better done with the
30293025C<use> and C<require> operators, which also do automatic error checking
30303026and raise an exception if there's a problem.
30313027
30323028=end original
30333029
30343030ライブラリモジュールのインクルードには、C<use> 演算子や
30353031C<require> 演算子を使った方がよいことに注意してください。
30363032これらは自動的にエラーをチェックして、問題があれば例外を発生させます。
30373033
30383034=begin original
30393035
30403036You might like to use C<do> to read in a program configuration
30413037file. Manual error checking can be done this way:
30423038
30433039=end original
30443040
30453041C<do> をプログラム設定ファイルを読み込むのに使いたいかもしれません。
30463042手動のエラーチェックは以下のようにして行えます:
30473043
30483044 # read in config files: system first, then user
30493045 for $file ("/share/prog/defaults.rc",
30503046 "$ENV{HOME}/.someprogrc")
30513047 {
30523048 unless ($return = do $file) {
30533049 warn "couldn't parse $file: $@" if $@;
30543050 warn "couldn't do $file: $!" unless defined $return;
30553051 warn "couldn't run $file" unless $return;
30563052 }
30573053 }
30583054
30593055=item dump LABEL
30603056X<dump> X<core> X<undump>
30613057
30623058=item dump
30633059
30643060=begin original
30653061
30663062This function causes an immediate core dump. See also the B<-u>
30673063command-line switch in L<perlrun>, which does the same thing.
30683064Primarily this is so that you can use the B<undump> program (not
30693065supplied) to turn your core dump into an executable binary after
30703066having initialized all your variables at the beginning of the
30713067program. When the new binary is executed it will begin by executing
30723068a C<goto LABEL> (with all the restrictions that C<goto> suffers).
30733069Think of it as a goto with an intervening core dump and reincarnation.
30743070If C<LABEL> is omitted, restarts the program from the top.
30753071
30763072=end original
30773073
30783074この関数は即座にコアダンプを行ないます。
30793075同様のことを行う L<perlrun> の B<-u> オプションも参照してください。
30803076プログラムの先頭で、
30813077すべての変数を初期化したあとのコアダンプを B<undump>
30823078プログラム(提供していません)を使って実行ファイルに返ることができます。
30833079この新しいバイナリが実行されると、C<goto LABEL> から始めます
30843080(C<goto> に関する制限はすべて適用されます)。
30853081コアダンプをはさんで再生する goto と考えてください。
30863082C<LABEL> が省略されると、プログラムを先頭から再開します。
30873083
30883084=begin original
30893085
30903086B<WARNING>: Any files opened at the time of the dump will I<not>
30913087be open any more when the program is reincarnated, with possible
30923088resulting confusion on the part of Perl.
30933089
30943090=end original
30953091
30963092B<警告>: dump 時点でオープンされていたファイルは、
30973093プログラムが再生されたときには、もはやオープンされていません。
30983094Perl を部分的に混乱させる可能性があります。
30993095
31003096=begin original
31013097
31023098This function is now largely obsolete, mostly because it's very hard to
31033099convert a core file into an executable. That's why you should now invoke
31043100it as C<CORE::dump()>, if you don't want to be warned against a possible
31053101typo.
31063102
31073103=end original
31083104
31093105この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを
31103106実行形式に変換するのが非常に困難であることです。
31113107これが、今ではタイプミスの可能性を警告されたくないなら
31123108C<CORE::dump()> として起動するべき理由です。
31133109
31143110=item each HASH
31153111X<each> X<hash, iterator>
31163112
31173113=begin original
31183114
31193115When called in list context, returns a 2-element list consisting of the
31203116key and value for the next element of a hash, so that you can iterate over
31213117it. When called in scalar context, returns only the key for the next
31223118element in the hash.
31233119
31243120=end original
31253121
31263122リストコンテキストで呼び出した場合は、
31273123ハッシュの次の 要素 に対する、key と 要素 からなる
312831242 要素のリストを返しますので、ハッシュ上での繰り返しを
31293125行なうことができます。
31303126スカラコンテキストで呼び出した場合は、
31313127ハッシュの次の要素のための key を返します。
31323128
31333129=begin original
31343130
31353131Entries are returned in an apparently random order. The actual random
31363132order is subject to change in future versions of perl, but it is
31373133guaranteed to be in the same order as either the C<keys> or C<values>
31383134function would produce on the same (unmodified) hash. Since Perl
31395.8.2 the ordering can be different even between different runs of Perl
31355.8.1 the ordering is different even between different runs of Perl
31403136for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
31413137
31423138=end original
31433139
31443140エントリは見かけ上、ランダムな順序で返されます。
31453141実際のランダムな順番は perl の将来のバージョンでは変わるかもしれませんが、
31463142C<keys> や C<values> 関数が同じ(変更されていない)ハッシュに対して
31473143生成するのと同じ順番であることは保証されます。
3148Perl 5.8.2 以降ではセキュリティ上の理由により、
3144Perl 5.8.1 以降ではセキュリティ上の理由により、
3149実行される毎に順番は変わるかもしれせん
3145実行される毎に順番は変わ
31503146(L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。
31513147
31523148=begin original
31533149
31543150When the hash is entirely read, a null array is returned in list context
31553151(which when assigned produces a false (C<0>) value), and C<undef> in
31563152scalar context. The next call to C<each> after that will start iterating
31573153again. There is a single iterator for each hash, shared by all C<each>,
31583154C<keys>, and C<values> function calls in the program; it can be reset by
31593155reading all the elements from the hash, or by evaluating C<keys HASH> or
31603156C<values HASH>. If you add or delete elements of a hash while you're
31613157iterating over it, you may get entries skipped or duplicated, so
31623158don't. Exception: It is always safe to delete the item most recently
31633159returned by C<each()>, which means that the following code will work:
31643160
31653161=end original
31663162
31673163ハッシュをすべて読み込んでしまうと、リストコンテキストでは空配列が
31683164返されます(これは代入されると、偽 (C<0>) となります)。
31693165スカラコンテキストでは C<undef> が返されます。
31703166そのあと、もう一度 C<each> を呼び出すと、
31713167再び繰り返しを始めます。
31723168ハッシュごとに反復子が 1 つあり、プログラム中のすべての
31733169C<each> 関数、C<keys> 関数、C<values> 関数で共用されます。
31743170反復子は、配列の要素をすべて読むことによって、またはC<keys HASH>,
31753171C<values HASH>を評価することでリセットすることができます。
31763172繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、
31773173要素が飛ばされたり重複したりするので、してはいけません。
31783174例外: 一番最近に C<each()> から返されたものを削除するのは常に安全です。
31793175これは以下のようなコードが正しく動くことを意味します:
31803176
31813177 while (($key, $value) = each %hash) {
31823178 print $key, "\n";
31833179 delete $hash{$key}; # This is safe
31843180 }
31853181
31863182=begin original
31873183
31883184The following prints out your environment like the printenv(1) program,
31893185only in a different order:
31903186
31913187=end original
31923188
31933189以下のプログラムは、順番が異なるものの、
31943190printenv(1) プログラムのように環境変数を表示します:
31953191
31963192 while (($key,$value) = each %ENV) {
31973193 print "$key=$value\n";
31983194 }
31993195
32003196=begin original
32013197
32023198See also C<keys>, C<values> and C<sort>.
32033199
32043200=end original
32053201
32063202C<keys> や C<values> や C<sort> も参照してください。
32073203
32083204=item eof FILEHANDLE
32093205X<eof>
32103206X<end of file>
32113207X<end-of-file>
32123208
32133209=item eof ()
32143210
32153211=item eof
32163212
32173213=begin original
32183214
32193215Returns 1 if the next read on FILEHANDLE will return end of file, or if
32203216FILEHANDLE is not open. FILEHANDLE may be an expression whose value
32213217gives the real filehandle. (Note that this function actually
32223218reads a character and then C<ungetc>s it, so isn't very useful in an
32233219interactive context.) Do not read from a terminal file (or call
32243220C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such
32253221as terminals may lose the end-of-file condition if you do.
32263222
32273223=end original
32283224
32293225次に FILEHANDLE 上で読み込みを行なったときに、 EOF が返されるときか、
32303226FILEHANDLE がオープンされていないと、1 を返します。
32313227FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。
32323228(この関数は、実際に文字を読み、C<ungetc> を行ないますので、
32333229対話型の場合には、それ程有用ではありません。)
32343230端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を
32353231呼び出したりしてはいけません。
32363232そのようなことをすると、端末のようなファイルタイプは
32373233EOF 状態を失ってしまうかもしれません。
32383234
32393235=begin original
32403236
32413237An C<eof> without an argument uses the last file read. Using C<eof()>
32423238with empty parentheses is very different. It refers to the pseudo file
32433239formed from the files listed on the command line and accessed via the
32443240C<< <> >> operator. Since C<< <> >> isn't explicitly opened,
32453241as a normal filehandle is, an C<eof()> before C<< <> >> has been
32463242used will cause C<@ARGV> to be examined to determine if input is
32473243available. Similarly, an C<eof()> after C<< <> >> has returned
32483244end-of-file will assume you are processing another C<@ARGV> list,
32493245and if you haven't set C<@ARGV>, will read input from C<STDIN>;
32503246see L<perlop/"I/O Operators">.
32513247
32523248=end original
32533249
32543250引数を省略した C<eof> は、最後に読み込みを行なったファイルを使います。
32553251空の括弧をつけた C<eof()> は大きく異なります。
32563252これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で
32573253アクセスされる擬似ファイルを示すために用いられます。
32583254通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、
32593255C<< <> >> を使う前に C<eof()> を使うと、
32603256入力が正常か確認するために C<@ARGV> がテストされます。
32613257同様に、C<< <> >> が EOF を返した後の C<eof()> は、
32623258他の C<@ARGV> リストを処理していると仮定し、もし C<@ARGV> を
32633259セットしていないときは C<STDIN> から読み込みます;
32643260L<perlop/"I/O Operators"> を参照してください。
32653261
32663262=begin original
32673263
32683264In a C<< while (<>) >> loop, C<eof> or C<eof(ARGV)> can be used to
32693265detect the end of each file, C<eof()> will only detect the end of the
32703266last file. Examples:
32713267
32723268=end original
32733269
32743270C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、
32753271C<eof> か C<eof(ARGV)> を用います。
32763272C<eof()> は最後のファイルの終わりのみを調べます。
32773273例:
32783274
32793275 # reset line numbering on each input file
32803276 while (<>) {
32813277 next if /^\s*#/; # skip comments
32823278 print "$.\t$_";
32833279 } continue {
32843280 close ARGV if eof; # Not eof()!
32853281 }
32863282
32873283 # insert dashes just before last line of last file
32883284 while (<>) {
32893285 if (eof()) { # check for end of last file
32903286 print "--------------\n";
32913287 }
32923288 print;
32933289 last if eof(); # needed if we're reading from a terminal
32943290 }
32953291
32963292=begin original
32973293
32983294Practical hint: you almost never need to use C<eof> in Perl, because the
32993295input operators typically return C<undef> when they run out of data, or if
33003296there was an error.
33013297
33023298=end original
33033299
33043300現実的なヒント: Perl で C<eof> が必要となることは、ほとんどありません。
33053301基本的には、
33063302データがなくなったときやエラーがあったときに、入力演算子が
33073303C<undef> を返してくれるからです。
33083304
33093305=item eval EXPR
33103306X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute>
33113307X<error, handling> X<exception, handling>
33123308
33133309=item eval BLOCK
33143310
33153311=item eval
33163312
33173313=begin original
33183314
33193315In the first form, the return value of EXPR is parsed and executed as if it
33203316were a little Perl program. The value of the expression (which is itself
33213317determined within scalar context) is first parsed, and if there weren't any
33223318errors, executed in the lexical context of the current Perl program, so
33233319that any variable settings or subroutine and format definitions remain
33243320afterwards. Note that the value is parsed every time the C<eval> executes.
33253321If EXPR is omitted, evaluates C<$_>. This form is typically used to
33263322delay parsing and subsequent execution of the text of EXPR until run time.
33273323
33283324=end original
33293325
33303326第一の形式では、EXPR の返り値が Perl のプログラムであるかのように
33313327解析され、実行されます。
33323328式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、
33333329エラーがなければ
33343330Perl プログラムのレキシカルコンテキストの中で実行されますので、変数の設定、
33353331サブルーチンやフォーマットの定義は、その後も残っています。 
33363332返される値は C<eval> が実行されるごとにパースされることに注意してください。
33373333EXPR を省略すると、C<$_> を評価します。
33383334この形は主に EXPR のテキストのパースと実行を実行時にまで
33393335遅延させるのに用います。
33403336
33413337=begin original
33423338
33433339In the second form, the code within the BLOCK is parsed only once--at the
33443340same time the code surrounding the C<eval> itself was parsed--and executed
33453341within the context of the current Perl program. This form is typically
33463342used to trap exceptions more efficiently than the first (see below), while
33473343also providing the benefit of checking the code within BLOCK at compile
33483344time.
33493345
33503346=end original
33513347
33523348第二の形式では、BLOCK 内部のコードは一度だけパースされ -- コードを
33533349囲む C<eval> 自身がパースされるのと同じ時点です -- 現在の Perl プログラムの
33543350コンテキストで実行されます。
33553351この形式は典型的には第一の形式より効率的に例外をトラップします(後述)。
33563352また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。
33573353
33583354=begin original
33593355
33603356The final semicolon, if any, may be omitted from the value of EXPR or within
33613357the BLOCK.
33623358
33633359=end original
33643360
33653361最後のセミコロンは、もしあれば、EXPR の値や BLOCK の中身から省くことができます。
33663362
33673363=begin original
33683364
33693365In both forms, the value returned is the value of the last expression
33703366evaluated inside the mini-program; a return statement may be also used, just
33713367as with subroutines. The expression providing the return value is evaluated
33723368in void, scalar, or list context, depending on the context of the C<eval>
33733369itself. See L</wantarray> for more on how the evaluation context can be
33743370determined.
33753371
33763372=end original
33773373
33783374どちらの形式でも、返される値はミニプログラムの内部で最後に評価された
33793375表現の値です; サブルーチンと同様、return 文も使えます。
33803376返り値として提供される表現は、C<eval> 自身のコンテキストに依存して
33813377無効・スカラ・リストのいずれかのコンテキストで評価されます。
33823378評価コンテキストの決定方法についての詳細は L</wantarray> を参照してください。
33833379
33843380=begin original
33853381
33863382If there is a syntax error or runtime error, or a C<die> statement is
3387executed, C<eval> returns an undefined value in scalar context
3383executed, an undefined value is returned by C<eval>, and C<$@> is set to the
3388or an empty list in list context, and C<$@> is set to the
33893384error message. If there was no error, C<$@> is guaranteed to be a null
33903385string. Beware that using C<eval> neither silences perl from printing
33913386warnings to STDERR, nor does it stuff the text of warning messages into C<$@>.
33923387To do either of those, you have to use the C<$SIG{__WARN__}> facility, or
33933388turn off warnings inside the BLOCK or EXPR using S<C<no warnings 'all'>>.
33943389See L</warn>, L<perlvar>, L<warnings> and L<perllexwarn>.
33953390
33963391=end original
33973392
33983393構文エラーや実行エラーが発生するか、C<die> 文が実行されると、
3399C<eval> はスカラコンテキストでは未定義値が、リストコンテキストでは
3394C<eval> の値として未定義値が返されC<$@> にエラーメッセージが設定されます。
3400空リストが返され、C<$@> にエラーメッセージが設定されます。
34013395エラーがなければ、C<$@> は、空文字列であることが保証されます。 
34023396C<eval> を、STDERR に警告メッセージを表示させない目的や、
34033397警告メッセージを C<$@> に格納する目的では使わないでください。
34043398そのような用途では、C<$SIG{__WARN__}> 機能を使うか、
34053399S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を
34063400オフにする必要があります。
34073401L</warn>, L<perlvar>, L<warnings>, L<perllexwarn> を参照してください。
34083402
34093403=begin original
34103404
34113405Note that, because C<eval> traps otherwise-fatal errors, it is useful for
34123406determining whether a particular feature (such as C<socket> or C<symlink>)
34133407is implemented. It is also Perl's exception trapping mechanism, where
34143408the die operator is used to raise exceptions.
34153409
34163410=end original
34173411
34183412C<eval> は、致命的エラーとなるようなものをトラップすることができますから、
34193413(C<socket> や C<symlink> といった) 特定の機能が実装されているかを、
34203414調べるために使うことができることに注意してください。
34213415die 演算子が例外を発生させるものとすれば、
34223416これはまた、Perl の例外捕捉機能と捉えることもできます。
34233417
34243418=begin original
34253419
3426If you want to trap errors when loading an XS module, some problems with
3427the binary interface (such as Perl version skew) may be fatal even with
3428C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See L<perlrun>.
3429
3430=end original
3431
3432XS モジュールのロード中のエラーをトラップしたいなら、
3433(Perl バージョンの違いのような) バイナリインターフェースに関する問題に
3434ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない C<eval> でも
3435致命的エラーになるかもしれません。
3436L<perlrun> を参照してください。
3437
3438=begin original
3439
34403420If the code to be executed doesn't vary, you may use the eval-BLOCK
34413421form to trap run-time errors without incurring the penalty of
34423422recompiling each time. The error, if any, is still returned in C<$@>.
34433423Examples:
34443424
34453425=end original
34463426
34473427実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、
34483428実行時エラーのトラップを行なうために、
34493429eval-BLOCK 形式を使うことができます。
34503430エラーがあれば、やはり $@ に返されます。
34513431例:
34523432
34533433 # make divide-by-zero nonfatal
34543434 eval { $answer = $a / $b; }; warn $@ if $@;
34553435
34563436 # same thing, but less efficient
34573437 eval '$answer = $a / $b'; warn $@ if $@;
34583438
34593439 # a compile-time error
34603440 eval { $answer = }; # WRONG
34613441
34623442 # a run-time error
34633443 eval '$answer ='; # sets $@
34643444
34653445=begin original
34663446
34673447Using the C<eval{}> form as an exception trap in libraries does have some
34683448issues. Due to the current arguably broken state of C<__DIE__> hooks, you
34693449may wish not to trigger any C<__DIE__> hooks that user code may have installed.
34703450You can use the C<local $SIG{__DIE__}> construct for this purpose,
34713451as shown in this example:
34723452
34733453=end original
34743454
34753455C<eval{}> 形式をライブラリの例外を捕捉するために使うときには
34763456問題があります。
34773457現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、
34783458ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。
34793459この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。
34803460
34813461 # a very private exception trap for divide-by-zero
34823462 eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
34833463 warn $@ if $@;
34843464
34853465=begin original
34863466
34873467This is especially significant, given that C<__DIE__> hooks can call
34883468C<die> again, which has the effect of changing their error messages:
34893469
34903470=end original
34913471
34923472これは特に顕著です。与えられた C<__DIE__> フックは C<die> をもう一度
34933473呼び出すことができ、これによってエラーメッセージを変える効果があります:
34943474
34953475 # __DIE__ hooks may modify error messages
34963476 {
34973477 local $SIG{'__DIE__'} =
34983478 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
34993479 eval { die "foo lives here" };
35003480 print $@ if $@; # prints "bar lives here"
35013481 }
35023482
35033483=begin original
35043484
35053485Because this promotes action at a distance, this counterintuitive behavior
35063486may be fixed in a future release.
35073487
35083488=end original
35093489
35103490これは距離の離れた行動であるため、この直感的でない振る舞いは
35113491将来のリリースでは修正されるかもしれません。
35123492
35133493=begin original
35143494
35153495With an C<eval>, you should be especially careful to remember what's
35163496being looked at when:
35173497
35183498=end original
35193499
35203500C<eval> では、以下のような場合に、
35213501何が調べられるかに特に注意しておくことが必要です:
35223502
35233503 eval $x; # CASE 1
35243504 eval "$x"; # CASE 2
35253505
35263506 eval '$x'; # CASE 3
35273507 eval { $x }; # CASE 4
35283508
35293509 eval "\$$x++"; # CASE 5
35303510 $$x++; # CASE 6
35313511
35323512=begin original
35333513
35343514Cases 1 and 2 above behave identically: they run the code contained in
35353515the variable $x. (Although case 2 has misleading double quotes making
35363516the reader wonder what else might be happening (nothing is).) Cases 3
35373517and 4 likewise behave in the same way: they run the code C<'$x'>, which
35383518does nothing but return the value of $x. (Case 4 is preferred for
35393519purely visual reasons, but it also has the advantage of compiling at
35403520compile-time instead of at run-time.) Case 5 is a place where
35413521normally you I<would> like to use double quotes, except that in this
35423522particular situation, you can just use symbolic references instead, as
35433523in case 6.
35443524
35453525=end original
35463526
35473527上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の
35483528コードを実行します。
35493529(ただし、CASE 2 では、必要のないダブルクォートによって、
35503530読む人が何が起こるか混乱することでしょう (何も起こりませんが)。)
35513531同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に
35523532何もしない C<$x> というコードを実行します
35533533(純粋に見た目の問題で、CASE 4 が好まれますが、
35543534実行時でなくコンパイル時にコンパイルされるという利点もあります)。
35553535CASE 5 の場合は、通常ダブルクォートを使用します。
35563536この状況を除けば、CASE 6 のように、単に
35573537シンボリックリファレンスを使えば良いでしょう。
35583538
35593539=begin original
35603540
3561The assignment to C<$@> occurs before restoration of localised variables,
3562which means a temporary is required if you want to mask some but not all
3563errors:
3564
3565=end original
3566
3567C<$@> への代入はローカル化された変数の復帰の前に起きるので、
3568全てではなく一部だけののエラーをマスクしたい場合には一時変数が必要です:
3569
3570 # alter $@ on nefarious repugnancy only
3571 {
3572 my $e;
3573 {
3574 local $@; # protect existing $@
3575 eval { test_repugnancy() };
3576 # $@ =~ /nefarious/ and die $@; # DOES NOT WORK
3577 $@ =~ /nefarious/ and $e = $@;
3578 }
3579 die $e if defined $e
3580 }
3581
3582=begin original
3583
35843541C<eval BLOCK> does I<not> count as a loop, so the loop control statements
35853542C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
35863543
35873544=end original
35883545
35893546C<eval BLOCK> はループとして I<扱われません>。
35903547従って、C<next>, C<last>, C<redo> といったループ制御文でブロックから離れたり
35913548再実行したりはできません。
35923549
35933550=begin original
35943551
35953552Note that as a very special case, an C<eval ''> executed within the C<DB>
35963553package doesn't see the usual surrounding lexical scope, but rather the
35973554scope of the first non-DB piece of code that called it. You don't normally
35983555need to worry about this unless you are writing a Perl debugger.
35993556
36003557=end original
36013558
36023559とても特殊な場合として、C<DB> パッケージ内で C<eval ''> を実行すると、
36033560通常のレキシカルスコープではなく、これを呼び出した最初の非 DB コード片の
36043561スコープになります。
36053562Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は
36063563ありません。
36073564
36083565=item exec LIST
36093566X<exec> X<execute>
36103567
36113568=item exec PROGRAM LIST
36123569
36133570=begin original
36143571
36153572The C<exec> function executes a system command I<and never returns>--
36163573use C<system> instead of C<exec> if you want it to return. It fails and
36173574returns false only if the command does not exist I<and> it is executed
36183575directly instead of via your system's command shell (see below).
36193576
36203577=end original
36213578
36223579C<exec> 関数は、システムのコマンドを実行し、I<戻ってはきません>。
36233580戻って欲しい場合には、C<exec>ではなく C<system> 関数を使ってください。
36243581コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく
36253582直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。
36263583
36273584=begin original
36283585
36293586Since it's a common mistake to use C<exec> instead of C<system>, Perl
36303587warns you if there is a following statement which isn't C<die>, C<warn>,
36313588or C<exit> (if C<-w> is set - but you always do that). If you
36323589I<really> want to follow an C<exec> with some other statement, you
36333590can use one of these styles to avoid the warning:
36343591
36353592=end original
36363593
36373594C<system> の代わりに C<exec> を使うというよくある間違いを防ぐために、
36383595引き続く文が C<die>, C<warn>, C<exit>(C<-w> がセットされている場合 -
36393596でもいつもセットしてますよね) 以外の場合、Perl は警告を出します。
36403597もし I<本当に> C<exec> の後に他の文を書きたい場合、
36413598以下のどちらかのスタイルを使うことで警告を回避できます:
36423599
36433600 exec ('foo') or print STDERR "couldn't exec foo: $!";
36443601 { exec ('foo') }; print STDERR "couldn't exec foo: $!";
36453602
36463603=begin original
36473604
36483605If there is more than one argument in LIST, or if LIST is an array
36493606with more than one value, calls execvp(3) with the arguments in LIST.
36503607If there is only one scalar argument or an array with one element in it,
36513608the argument is checked for shell metacharacters, and if there are any,
36523609the entire argument is passed to the system's command shell for parsing
36533610(this is C</bin/sh -c> on Unix platforms, but varies on other platforms).
36543611If there are no shell metacharacters in the argument, it is split into
36553612words and passed directly to C<execvp>, which is more efficient.
36563613Examples:
36573614
36583615=end original
36593616
36603617LIST に複数の引数がある場合か、LIST が複数の値を持つ
36613618配列の場合には、LIST の引数を使って、execvp(3) を呼び出します。
366236191 つのスカラ引数のみまたは要素が 1 つの配列の場合には、その引数から
36633620シェルのメタ文字をチェックし、もし、メタ文字があれば、
36643621引数全体をシステムのコマンドシェル(これはUnix では
36653622C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。
36663623もし、メタキャラクタがなければ、その引数を単語に分け、
36673624より効率的な C<execvp> に直接渡します。
36683625例:
36693626
36703627 exec '/bin/echo', 'Your arguments are: ', @ARGV;
36713628 exec "sort $outfile | uniq";
36723629
36733630=begin original
36743631
36753632If you don't really want to execute the first argument, but want to lie
36763633to the program you are executing about its own name, you can specify
36773634the program you actually want to run as an "indirect object" (without a
36783635comma) in front of the LIST. (This always forces interpretation of the
36793636LIST as a multivalued list, even if there is only a single scalar in
36803637the list.) Example:
36813638
36823639=end original
36833640
36843641第一引数に指定するものを本当に実行したいが、実行する
36853642プログラムに対して別の名前を教えたい場合には、LISTの前に、
36863643「間接オブジェクト」(コンマなし) として、実際に
36873644実行したいプログラムを指定することができます。
36883645(これによって、LIST に単一のスカラしかなくても、複数
36893646値のリストであるように、LIST の解釈を行ないます。)
36903647例:
36913648
36923649 $shell = '/bin/csh';
36933650 exec $shell '-sh'; # pretend it's a login shell
36943651
36953652=begin original
36963653
36973654or, more directly,
36983655
36993656=end original
37003657
37013658あるいは、より直接的に、
37023659
37033660 exec {'/bin/csh'} '-sh'; # pretend it's a login shell
37043661
37053662=begin original
37063663
37073664When the arguments get executed via the system shell, results will
37083665be subject to its quirks and capabilities. See L<perlop/"`STRING`">
37093666for details.
37103667
37113668=end original
37123669
37133670引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって
37143671変わります。
37153672詳細については L<perlop/"`STRING`"> を参照してください。
37163673
37173674=begin original
37183675
37193676Using an indirect object with C<exec> or C<system> is also more
37203677secure. This usage (which also works fine with system()) forces
37213678interpretation of the arguments as a multivalued list, even if the
37223679list had just one argument. That way you're safe from the shell
37233680expanding wildcards or splitting up words with whitespace in them.
37243681
37253682=end original
37263683
37273684C<exec> や C<system> で間接オブジェクトを使うのもより安全です。
37283685この使い方(system() でも同様にうまく動きます)は、たとえ引数が一つだけの
37293686場合も、複数の値を持つリストとして引数を解釈することを強制します。
37303687この方法で、シェルによるワイルドカード展開や、空白による単語の分割から
37313688守られます。
37323689
37333690 @args = ( "echo surprise" );
37343691
37353692 exec @args; # subject to shell escapes
37363693 # if @args == 1
37373694 exec { $args[0] } @args; # safe even with one-arg list
37383695
37393696=begin original
37403697
37413698The first version, the one without the indirect object, ran the I<echo>
37423699program, passing it C<"surprise"> an argument. The second version
37433700didn't--it tried to run a program literally called I<"echo surprise">,
37443701didn't find it, and set C<$?> to a non-zero value indicating failure.
37453702
37463703=end original
37473704
37483705間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、
37493706C<"surprise"> が引数として渡されます。
37503707二つ目のバージョンでは違います -- 文字通り I<"echo surprise"> という名前の
37513708プログラムを実行しようとして、見つからないので、失敗したことを示すために
37523709C<$?> に非 0 がセットされます。
37533710
37543711=begin original
37553712
37563713Beginning with v5.6.0, Perl will attempt to flush all files opened for
37573714output before the exec, but this may not be supported on some platforms
37583715(see L<perlport>). To be safe, you may need to set C<$|> ($AUTOFLUSH
37593716in English) or call the C<autoflush()> method of C<IO::Handle> on any
37603717open handles in order to avoid lost output.
37613718
37623719=end original
37633720
37643721v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを
37653722フラッシュしようとしますが、これに対応していないプラットフォームもあります
37663723(L<perlport> を参照してください)。
37673724安全のためには、出力が重複するのを避けるために、全てのオープンしている
37683725ハンドルに対して C<$|> (English モジュールでは $AUTOFLUSH) を設定するか、
37693726C<IO::Handle> モジュールの C<autoflush()> メソッドをを呼ぶ必要が
37703727あるかもしれません。
37713728
37723729=begin original
37733730
37743731Note that C<exec> will not call your C<END> blocks, nor will it call
37753732any C<DESTROY> methods in your objects.
37763733
37773734=end original
37783735
37793736C<exec> は C<END> ブロックや、オブジェクトの C<DESTROY> メソッドを
37803737呼び出さないことに注意してください。
37813738
37823739=item exists EXPR
37833740X<exists> X<autovivification>
37843741
37853742=begin original
37863743
37873744Given an expression that specifies a hash element or array element,
37883745returns true if the specified element in the hash or array has ever
3789been initialized, even if the corresponding value is undefined.
3746been initialized, even if the corresponding value is undefined. The
3747element is not autovivified if it doesn't exist.
37903748
37913749=end original
37923750
37933751ハッシュ要素か配列要素を示す表現が与えられ、
37943752指定された要素が、ハッシュか配列に存在すれば、
37953753たとえ対応する value が未定義でも真を返します。
3754要素が存在しなかった場合は自動活性化されません。
37963755
37973756 print "Exists\n" if exists $hash{$key};
37983757 print "Defined\n" if defined $hash{$key};
37993758 print "True\n" if $hash{$key};
38003759
38013760 print "Exists\n" if exists $array[$index];
38023761 print "Defined\n" if defined $array[$index];
38033762 print "True\n" if $array[$index];
38043763
38053764=begin original
38063765
38073766A hash or array element can be true only if it's defined, and defined if
38083767it exists, but the reverse doesn't necessarily hold true.
38093768
38103769=end original
38113770
38123771ハッシュまたは配列要素は、定義されているときにのみ真となり、
38133772存在しているときにのみ定義されますが、逆は必ずしも真ではありません。
38143773
38153774=begin original
38163775
38173776Given an expression that specifies the name of a subroutine,
38183777returns true if the specified subroutine has ever been declared, even
38193778if it is undefined. Mentioning a subroutine name for exists or defined
38203779does not count as declaring it. Note that a subroutine which does not
38213780exist may still be callable: its package may have an C<AUTOLOAD>
38223781method that makes it spring into existence the first time that it is
38233782called -- see L<perlsub>.
38243783
38253784=end original
38263785
38273786引数としてサブルーチンの名前が指定された場合、
38283787指定されたサブルーチンが宣言されていれば(たとえ未定義でも)
38293788真を返します。
38303789exists や defined のために言及されているサブルーチン名は
38313790宣言としてのカウントに入りません。
38323791存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください:
38333792パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に
38343793存在を作り出すかもしれません -- L<perlsub> を参照してください。
38353794
38363795 print "Exists\n" if exists &subroutine;
38373796 print "Defined\n" if defined &subroutine;
38383797
38393798=begin original
38403799
38413800Note that the EXPR can be arbitrarily complicated as long as the final
38423801operation is a hash or array key lookup or subroutine name:
38433802
38443803=end original
38453804
38463805最終的な操作がハッシュや配列の key による検索またはサブルーチン名である限りは、
38473806EXPR には任意の複雑な式を置くことができます:
38483807
38493808 if (exists $ref->{A}->{B}->{$key}) { }
38503809 if (exists $hash{A}{B}{$key}) { }
38513810
38523811 if (exists $ref->{A}->{B}->[$ix]) { }
38533812 if (exists $hash{A}{B}[$ix]) { }
38543813
38553814 if (exists &{$ref->{A}{B}{$key}}) { }
38563815
38573816=begin original
38583817
38593818Although the deepest nested array or hash will not spring into existence
38603819just because its existence was tested, any intervening ones will.
38613820Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring
38623821into existence due to the existence test for the $key element above.
38633822This happens anywhere the arrow operator is used, including even:
38643823
38653824=end original
38663825
38673826ネストした配列やハッシュの一番深い部分は、その存在をテストしただけでは
38683827存在するようにはなりませんが、途中のものは存在するようになります。
38693828従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の $key の
38703829存在をテストしたことによって存在するようになります。
38713830これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも
38723831起こります。
38733832
38743833 undef $ref;
38753834 if (exists $ref->{"Some key"}) { }
38763835 print $ref; # prints HASH(0x80d3d5c)
38773836
38783837=begin original
38793838
38803839This surprising autovivification in what does not at first--or even
38813840second--glance appear to be an lvalue context may be fixed in a future
38823841release.
38833842
38843843=end original
38853844
38863845一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの
38873846自動有効化は将来のリリースでは修正されるでしょう。
38883847
38893848=begin original
38903849
38913850Use of a subroutine call, rather than a subroutine name, as an argument
38923851to exists() is an error.
38933852
38943853=end original
38953854
38963855exists() の引数としてサブルーチン名でなくサブルーチン呼び出しを使うと、
38973856エラーになります。
38983857
38993858 exists &sub; # OK
39003859 exists &sub(); # Error
39013860
39023861=item exit EXPR
39033862X<exit> X<terminate> X<abort>
39043863
39053864=item exit
39063865
39073866=begin original
39083867
39093868Evaluates EXPR and exits immediately with that value. Example:
39103869
39113870=end original
39123871
39133872EXPR を評価し、即座にその値を持って終了します。
39143873例:
39153874
39163875 $ans = <STDIN>;
39173876 exit 0 if $ans =~ /^[Xx]/;
39183877
39193878=begin original
39203879
39213880See also C<die>. If EXPR is omitted, exits with C<0> status. The only
39223881universally recognized values for EXPR are C<0> for success and C<1>
39233882for error; other values are subject to interpretation depending on the
39243883environment in which the Perl program is running. For example, exiting
3925388469 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause
39263885the mailer to return the item undelivered, but that's not true everywhere.
39273886
39283887=end original
39293888
39303889C<die> も参照してください。
39313890EXPR が省略された場合には、ステータスを C<0> として終了します。
39323891EXPR の値として広く利用可能なのは C<0> が成功で C<1> がエラーということだけです。
39333892その他の値は、 Perl が実行される環境によって異なる解釈がされる
39343893可能性があります。
39353894例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると
39363895メーラーはアイテムを配達せずに差し戻しますが、
39373896これはいつでも真ではありません。
39383897
39393898=begin original
39403899
39413900Don't use C<exit> to abort a subroutine if there's any chance that
39423901someone might want to trap whatever error happened. Use C<die> instead,
39433902which can be trapped by an C<eval>.
39443903
39453904=end original
39463905
39473906誰かが発生したエラーをトラップしようと考えている可能性がある場合は、
39483907サブルーチンの中断に C<exit> を使わないでください。
39493908代わりに C<eval> でトラップできる C<die> を使ってください。
39503909
39513910=begin original
39523911
39533912The exit() function does not always exit immediately. It calls any
39543913defined C<END> routines first, but these C<END> routines may not
39553914themselves abort the exit. Likewise any object destructors that need to
39563915be called are called before the real exit. If this is a problem, you
39573916can call C<POSIX:_exit($status)> to avoid END and destructor processing.
39583917See L<perlmod> for details.
39593918
39603919=end original
39613920
39623921exit() 関数は常に直ちに終了するわけではありません。
39633922まず、定義されている END ルーチンを呼び出しますが、
39643923C<END> ルーチン自身は exit を止められません。
39653924同様に、呼び出す必要のあるオブジェクトデストラクタは
39663925すべて、実際の終了前に呼び出されます。
39673926これが問題になる場合は、END やデストラクタが実行されることを
39683927防ぐために C<POSIX:_exit($status)> を呼び出してください。
39693928詳しくは L<perlmod> を参照してください。
39703929
39713930=item exp EXPR
39723931X<exp> X<exponential> X<antilog> X<antilogarithm> X<e>
39733932
39743933=item exp
39753934
39763935=begin original
39773936
39783937Returns I<e> (the natural logarithm base) to the power of EXPR.
39793938If EXPR is omitted, gives C<exp($_)>.
39803939
39813940=end original
39823941
39833942I<e> (自然対数の底) の EXPR 乗を返します。 
39843943EXPR を省略した場合には、C<exp($_)> を返します。
39853944
39863945=item fcntl FILEHANDLE,FUNCTION,SCALAR
39873946X<fcntl>
39883947
39893948=begin original
39903949
39913950Implements the fcntl(2) function. You'll probably have to say
39923951
39933952=end original
39943953
39953954fcntl(2) 関数を実装します。
39963955正しい定数定義を得るために、まず、
39973956
39983957 use Fcntl;
39993958
40003959=begin original
40013960
40023961first to get the correct constant definitions. Argument processing and
40033962value return works just like C<ioctl> below.
40043963For example:
40053964
40063965=end original
40073966
40083967と書くことが必要でしょう。
40093968引数の処理と返り値については、下記の C<ioctl> と同様に動作します。
40103969例:
40113970
40123971 use Fcntl;
40133972 fcntl($filehandle, F_GETFL, $packed_return_buffer)
40143973 or die "can't fcntl F_GETFL: $!";
40153974
40163975=begin original
40173976
40183977You don't have to check for C<defined> on the return from C<fcntl>.
40193978Like C<ioctl>, it maps a C<0> return from the system call into
40203979C<"0 but true"> in Perl. This string is true in boolean context and C<0>
40213980in numeric context. It is also exempt from the normal B<-w> warnings
40223981on improper numeric conversions.
40233982
40243983=end original
40253984
40263985C<fcntl> からの返り値のチェックに C<defined> を使う必要はありません。
40273986C<ioctl> と違って、C<fnctl> はシステムコールの結果が C<0> だった場合は
40283987C<"0 だが真">を返します。
40293988この文字列は真偽値コンテキストでは真となり、
40303989数値コンテキストでは C<0> になります。
40313990これはまた、不適切な数値変換に関する通常の B<-w> 警告を回避します。
40323991
40333992=begin original
40343993
40353994Note that C<fcntl> will produce a fatal error if used on a machine that
40363995doesn't implement fcntl(2). See the Fcntl module or your fcntl(2)
40373996manpage to learn what functions are available on your system.
40383997
40393998=end original
40403999
40414000fcntl(2) が実装されていないマシンでは、C<fcntl>は致命的エラーを
40424001引き起こすことに注意してください。
40434002システムでどの関数が利用可能かについては Fcntl モジュールや
40444003fcntl(2) man ページを参照してください。
40454004
40464005=begin original
40474006
40484007Here's an example of setting a filehandle named C<REMOTE> to be
40494008non-blocking at the system level. You'll have to negotiate C<$|>
40504009on your own, though.
40514010
40524011=end original
40534012
40544013これは C<REMOTE> というファイルハンドルをシステムレベルで
40554014非ブロックモードにセットする例です。
40564015ただし、 C<$|> を自分で管理しなければなりません。
40574016
40584017 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
40594018
40604019 $flags = fcntl(REMOTE, F_GETFL, 0)
40614020 or die "Can't get flags for the socket: $!\n";
40624021
40634022 $flags = fcntl(REMOTE, F_SETFL, $flags | O_NONBLOCK)
40644023 or die "Can't set flags for the socket: $!\n";
40654024
40664025=item fileno FILEHANDLE
40674026X<fileno>
40684027
40694028=begin original
40704029
40714030Returns the file descriptor for a filehandle, or undefined if the
40724031filehandle is not open. This is mainly useful for constructing
40734032bitmaps for C<select> and low-level POSIX tty-handling operations.
40744033If FILEHANDLE is an expression, the value is taken as an indirect
40754034filehandle, generally its name.
40764035
40774036=end original
40784037
40794038ファイルハンドルに対するファイル記述子を返します。
40804039ファイルハンドルがオープンしていない場合は未定義値を返します。
40814040これは主に C<select> や低レベル POSIX tty 操作に対する、ビットマップを
40824041構成するときに便利です。
40834042FILEHANDLE が式であれば、
40844043その値が間接ファイルハンドル(普通は名前)として使われます。
40854044
40864045=begin original
40874046
40884047You can use this to find out whether two handles refer to the
40894048same underlying descriptor:
40904049
40914050=end original
40924051
40934052これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに
40944053使えます:
40954054
40964055 if (fileno(THIS) == fileno(THAT)) {
40974056 print "THIS and THAT are dups\n";
40984057 }
40994058
41004059=begin original
41014060
41024061(Filehandles connected to memory objects via new features of C<open> may
41034062return undefined even though they are open.)
41044063
41054064=end original
41064065
41074066(C<open> の新機能によってメモリに接続されたファイルハンドルは、
41084067開いている時でも未定義値を返します。)
41094068
41104069
41114070=item flock FILEHANDLE,OPERATION
41124071X<flock> X<lock> X<locking>
41134072
41144073=begin original
41154074
41164075Calls flock(2), or an emulation of it, on FILEHANDLE. Returns true
41174076for success, false on failure. Produces a fatal error if used on a
41184077machine that doesn't implement flock(2), fcntl(2) locking, or lockf(3).
41194078C<flock> is Perl's portable file locking interface, although it locks
41204079only entire files, not records.
41214080
41224081=end original
41234082
41244083FILEHANDLE に対して flock(2)、またはそのエミュレーションを呼び出します。
41254084成功時には真を、失敗時には偽を返します。
41264085flock(2), fcntl(2) ロック, lockf(3) のいずれかを実装していない
41274086マシンで使うと、致命的エラーが発生します。
41284087C<flock> は Perl の移植性のあるファイルロックインターフェースです。
41294088しかしレコードではなく、ファイル全体のみをロックします。
41304089
41314090=begin original
41324091
41334092Two potentially non-obvious but traditional C<flock> semantics are
41344093that it waits indefinitely until the lock is granted, and that its locks
41354094B<merely advisory>. Such discretionary locks are more flexible, but offer
41364095fewer guarantees. This means that programs that do not also use C<flock>
41374096may modify files locked with C<flock>. See L<perlport>,
41384097your port's specific documentation, or your system-specific local manpages
41394098for details. It's best to assume traditional behavior if you're writing
41404099portable programs. (But if you're not, you should as always feel perfectly
41414100free to write for your own system's idiosyncrasies (sometimes called
41424101"features"). Slavish adherence to portability concerns shouldn't get
41434102in the way of your getting your job done.)
41444103
41454104=end original
41464105
41474106明白ではないものの、伝統的な C<flock> の動作としては、ロックが得られるまで
41484107無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。
41494108このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。
41504109これは、C<flock> を使わないプログラムが C<flock> でロックされたファイルを
41514110書き換えるかもしれないことを意味します。
41524111詳細については、L<perlport>、システム固有のドキュメント、システム固有の
41534112ローカルの man ページを参照してください。
41544113移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが
41554114ベストです。
41564115(しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば
41574116「仕様」と呼ばれます)に合わせて書くことも完全に自由です。
41584117盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは
41594118ありません。)
41604119
41614120=begin original
41624121
41634122OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with
41644123LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but
41654124you can use the symbolic names if you import them from the Fcntl module,
41664125either individually, or as a group using the ':flock' tag. LOCK_SH
41674126requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN
41684127releases a previously requested lock. If LOCK_NB is bitwise-or'ed with
41694128LOCK_SH or LOCK_EX then C<flock> will return immediately rather than blocking
41704129waiting for the lock (check the return status to see if you got it).
41714130
41724131=end original
41734132
41744133OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と
41754134組み合わされることもあります。
41764135これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、Fcntl モジュールから
41774136シンボル名を独立してインポートするか、 ':flock' タグを使うグループとして、
41784137シンボル名をを使うことができます。
41794138LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は
41804139前回要求したロックを開放します。
41814140LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、C<flock> は
41824141ロックを取得するまで待つのではなく、すぐに返ります(ロックが取得できたか
41834142どうかは返り値を調べます)。
41844143
41854144=begin original
41864145
41874146To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE
41884147before locking or unlocking it.
41894148
41904149=end original
41914150
41924151不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に
41934152FILEHANDLE をフラッシュします。
41944153
41954154=begin original
41964155
41974156Note that the emulation built with lockf(3) doesn't provide shared
41984157locks, and it requires that FILEHANDLE be open with write intent. These
41994158are the semantics that lockf(3) implements. Most if not all systems
42004159implement lockf(3) in terms of fcntl(2) locking, though, so the
42014160differing semantics shouldn't bite too many people.
42024161
42034162=end original
42044163
42054164lockf(3) で作成されたエミュレーションは共有ロックを提供せず、
42064165FILEHANDLE が書き込みモードで開いていることを必要とすることに
42074166注意してください。
42084167これは lockf(3) が実装している動作です。
42094168しかし、全てではないにしてもほとんどのシステムでは fcntl(2) を使って
42104169lockf(3) を実装しているので、異なった動作で多くの人々を混乱させることは
42114170ないはずです。
42124171
42134172=begin original
42144173
42154174Note that the fcntl(2) emulation of flock(3) requires that FILEHANDLE
42164175be open with read intent to use LOCK_SH and requires that it be open
42174176with write intent to use LOCK_EX.
42184177
42194178=end original
42204179
42214180flock(3) の fcntl(2) エミュレーションは、 LOCK_SH を使うためには
42224181FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには
42234182書き込みで開いている必要があることに注意してください。
42244183
42254184=begin original
42264185
42274186Note also that some versions of C<flock> cannot lock things over the
42284187network; you would need to use the more system-specific C<fcntl> for
42294188that. If you like you can force Perl to ignore your system's flock(2)
42304189function, and so provide its own fcntl(2)-based emulation, by passing
42314190the switch C<-Ud_flock> to the F<Configure> program when you configure
42324191perl.
42334192
42344193=end original
42354194
42364195ネットワーク越しにはロックできない C<flock> もあることに注意してください;
42374196このためには、よりシステム依存な C<fcntl> を使う必要があります。
42384197Perl にシステムの flock(2) 関数を無視させ、自身の fcntl(2) ベースの
42394198エミュレーションを使う場合は、perl を設定するときに F<Configure>
42404199プログラムに C<-Ud_flock> オプションを渡してください。
42414200
42424201=begin original
42434202
42444203Here's a mailbox appender for BSD systems.
42454204
42464205=end original
42474206
42484207BSD システムでのメールボックスへの追加処理の例を示します。
42494208
4250 use Fcntl qw(:flock SEEK_END); # import LOCK_* and SEEK_END constants
4209 use Fcntl ':flock'; # import LOCK_* constants
42514210
42524211 sub lock {
4253 my ($fh) = @_;
4212 flock(MBOX,LOCK_EX);
4254 flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
4213 # and, in case someone appended
4214 # while we were waiting...
4256 # and, in case someone appended while we were waiting...
4215 seek(MBOX, 0, 2);
4257 seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
42584216 }
42594217
42604218 sub unlock {
4261 my ($fh) = @_;
4219 flock(MBOX,LOCK_UN);
4262 flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
42634220 }
42644221
4265 open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
4222 open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
42664223 or die "Can't open mailbox: $!";
42674224
4268 lock($mbox);
4225 lock();
4269 print $mbox $msg,"\n\n";
4226 print MBOX $msg,"\n\n";
4270 unlock($mbox);
4227 unlock();
42714228
42724229=begin original
42734230
42744231On systems that support a real flock(), locks are inherited across fork()
42754232calls, whereas those that must resort to the more capricious fcntl()
42764233function lose the locks, making it harder to write servers.
42774234
42784235=end original
42794236
42804237真の flock() に対応しているシステムではロックは fork() を通して
42814238継承されるのに対して、より不安定な fcntl() に頼らなければならない場合、
42824239サーバを書くのはより難しくなります。
42834240
42844241=begin original
42854242
42864243See also L<DB_File> for other flock() examples.
42874244
42884245=end original
42894246
42904247その他の flock() の例としては L<DB_File> も参照してください。
42914248
42924249=item fork
42934250X<fork> X<child> X<parent>
42944251
42954252=begin original
42964253
42974254Does a fork(2) system call to create a new process running the
42984255same program at the same point. It returns the child pid to the
42994256parent process, C<0> to the child process, or C<undef> if the fork is
43004257unsuccessful. File descriptors (and sometimes locks on those descriptors)
43014258are shared, while everything else is copied. On most systems supporting
43024259fork(), great care has gone into making it extremely efficient (for
43034260example, using copy-on-write technology on data pages), making it the
43044261dominant paradigm for multitasking over the last few decades.
43054262
43064263=end original
43074264
43084265同じプログラムの同じ地点から開始する新しいプロセスを作成するために
43094266システムコール fork(2) を行ないます。
43104267親プロセスには、チャイルドプロセスの pid を、
43114268チャイルドプロセスに C<0> を返しますが、
43124269fork に失敗したときには、C<undef>を返します。
43134270ファイル記述子(および記述子に関連するロック)は共有され、
43144271その他の全てはコピーされます。
43154272fork() に対応するほとんどのシステムでは、
43164273これを極めて効率的にするために多大な努力が払われてきました
43174274(例えば、データページへの copy-on-write テクノロジーなどです)。
43184275これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。
43194276
43204277=begin original
43214278
43224279Beginning with v5.6.0, Perl will attempt to flush all files opened for
43234280output before forking the child process, but this may not be supported
43244281on some platforms (see L<perlport>). To be safe, you may need to set
43254282C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method of
43264283C<IO::Handle> on any open handles in order to avoid duplicate output.
43274284
43284285=end original
43294286
43304287v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての
43314288ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも
43324289あります(L<perlport> を参照してください)。
43334290安全のためには、出力が重複するのを避けるために、
43344291全てのオープンしているハンドルに対して C<$|> (English モジュールでは
43354292$AUTOFLUSH) を設定するか、
43364293C<IO::Handle> モジュールの C<autoflush()>メソッドをを呼ぶ必要が
43374294あるかもしれません。
43384295
43394296=begin original
43404297
43414298If you C<fork> without ever waiting on your children, you will
43424299accumulate zombies. On some systems, you can avoid this by setting
43434300C<$SIG{CHLD}> to C<"IGNORE">. See also L<perlipc> for more examples of
43444301forking and reaping moribund children.
43454302
43464303=end original
43474304
43484305チャイルドプロセスの終了を待たずに、C<fork> を繰り返せば、
43494306ゾンビをためこむことになります。
43504307C<$SIG{CHLD}> に C<"IGNORE"> を指定することでこれを回避できるシステムもあります。
43514308fork と消滅しかけている子プロセスを回収するための更なる例については
43524309L<perlipc> も参照してください。
43534310
43544311=begin original
43554312
43564313Note that if your forked child inherits system file descriptors like
43574314STDIN and STDOUT that are actually connected by a pipe or socket, even
43584315if you exit, then the remote server (such as, say, a CGI script or a
43594316backgrounded job launched from a remote shell) won't think you're done.
43604317You should reopen those to F</dev/null> if it's any issue.
43614318
43624319=end original
43634320
43644321fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を
43654322継承する場合、(CGI スクリプトやリモートシェルといった
43664323バックグラウンドジョブのような)リモートサーバは考え通りに
43674324動かないであろうことに注意してください。
43684325このような場合ではこれらを F</dev/null> として再オープンするべきです。
43694326
43704327=item format
43714328X<format>
43724329
43734330=begin original
43744331
43754332Declare a picture format for use by the C<write> function. For
43764333example:
43774334
43784335=end original
43794336
43804337C<write> 関数で使うピクチャーフォーマットを宣言します。
43814338例:
43824339
43834340 format Something =
43844341 Test: @<<<<<<<< @||||| @>>>>>
43854342 $str, $%, '$' . int($num)
43864343 .
43874344
43884345 $str = "widget";
43894346 $num = $cost/$quantity;
43904347 $~ = 'Something';
43914348 write;
43924349
43934350=begin original
43944351
43954352See L<perlform> for many details and examples.
43964353
43974354=end original
43984355
43994356詳細と例については L<perlform> を参照して下さい。
44004357
44014358=item formline PICTURE,LIST
44024359X<formline>
44034360
44044361=begin original
44054362
44064363This is an internal function used by C<format>s, though you may call it,
44074364too. It formats (see L<perlform>) a list of values according to the
44084365contents of PICTURE, placing the output into the format output
44094366accumulator, C<$^A> (or C<$ACCUMULATOR> in English).
44104367Eventually, when a C<write> is done, the contents of
44114368C<$^A> are written to some filehandle. You could also read C<$^A>
44124369and then set C<$^A> back to C<"">. Note that a format typically
44134370does one C<formline> per line of form, but the C<formline> function itself
44144371doesn't care how many newlines are embedded in the PICTURE. This means
44154372that the C<~> and C<~~> tokens will treat the entire PICTURE as a single line.
44164373You may therefore need to use multiple formlines to implement a single
44174374record format, just like the format compiler.
44184375
44194376=end original
44204377
44214378これは、C<format> が使用する内部関数ですが、直接呼び出すこともできます。
44224379これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を
44234380参照してください)、結果をフォーマット出力アキュムレータC<$^A>
44244381(English モジュールでは C<$ACCUMULATOR>) に納めます。
44254382最終的に、C<write> が実行されると、C<$^A> の中身が、
44264383何らかのファイルハンドルに書き出されます。
44274384また、自分で C<$^A> を読んで、C<$^A> の内容を C<""> に戻してもかまいません。
44284385format は通常、1 行ごとに C<formline> を行ないますが、
44294386C<formline> 関数自身は、PICTURE の中にいくつの改行が入っているかは、
44304387関係がありません。
44314388これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。
44324389従って、1 レコードフォーマットを実装するためには
44334390フォーマットコンパイラのような複数 formline を使う必要があります。
44344391
44354392=begin original
44364393
44374394Be careful if you put double quotes around the picture, because an C<@>
44384395character may be taken to mean the beginning of an array name.
44394396C<formline> always returns true. See L<perlform> for other examples.
44404397
44414398=end original
44424399
44434400ダブルクォートで PICTURE を囲む場合には、C<@> という文字が
44444401配列名の始まりと解釈されますので、注意してください。
44454402C<formline> は常に真を返します。
44464403その他の例については L<perlform> を参照してください。
44474404
44484405=item getc FILEHANDLE
44494406X<getc> X<getchar> X<character> X<file, read>
44504407
44514408=item getc
44524409
44534410=begin original
44544411
44554412Returns the next character from the input file attached to FILEHANDLE,
44564413or the undefined value at end of file, or if there was an error (in
44574414the latter case C<$!> is set). If FILEHANDLE is omitted, reads from
44584415STDIN. This is not particularly efficient. However, it cannot be
44594416used by itself to fetch single characters without waiting for the user
44604417to hit enter. For that, try something more like:
44614418
44624419=end original
44634420
44644421FILEHANDLE につながれている入力ファイルから、次の一文字を返します。
44654422ファイルの最後、またはエラーが発生した場合は、未定義値を返します
44664423(後者の場合は C<$!> がセットされます)。
44674424FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。
44684425これは特に効率的ではありません。
44694426しかし、これはユーザーがリターンキーを押すのを待つことなく
44704427一文字を読み込む用途には使えません。
44714428そのような場合には、以下のようなものを試して見てください:
44724429
44734430 if ($BSD_STYLE) {
44744431 system "stty cbreak </dev/tty >/dev/tty 2>&1";
44754432 }
44764433 else {
44774434 system "stty", '-icanon', 'eol', "\001";
44784435 }
44794436
44804437 $key = getc(STDIN);
44814438
44824439 if ($BSD_STYLE) {
44834440 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
44844441 }
44854442 else {
44864443 system "stty", 'icanon', 'eol', '^@'; # ASCII null
44874444 }
44884445 print "\n";
44894446
44904447=begin original
44914448
44924449Determination of whether $BSD_STYLE should be set
44934450is left as an exercise to the reader.
44944451
44954452=end original
44964453
44974454$BSD_STYLE をセットするべきかどうかを決定する方法については
44984455読者への宿題として残しておきます。
44994456
45004457=begin original
45014458
45024459The C<POSIX::getattr> function can do this more portably on
45034460systems purporting POSIX compliance. See also the C<Term::ReadKey>
45044461module from your nearest CPAN site; details on CPAN can be found on
45054462L<perlmodlib/CPAN>.
45064463
45074464=end original
45084465
45094466C<POSIX::getattr> 関数は POSIX 準拠を主張するシステムでこれを
45104467より移植性のある形で行います。
45114468お近くの CPAN サイトから C<Term::ReadKey> モジュールも参照して下さい;
45124469CPAN に関する詳細は L<perlmodlib/CPAN> にあります。
45134470
45144471=item getlogin
45154472X<getlogin> X<login>
45164473
45174474=begin original
45184475
45194476This implements the C library function of the same name, which on most
45204477systems returns the current login from F</etc/utmp>, if any. If null,
45214478use C<getpwuid>.
45224479
45234480=end original
45244481
45254482これは同じ名前の C ライブラリ関数を実装していて、
45264483多くのシステムでは、もしあれば、/etc/utmp から現在のログイン名を返します。
45274484ヌルであれば、getpwuid() を使ってください。
45284485
45294486 $login = getlogin || getpwuid($<) || "Kilroy";
45304487
45314488=begin original
45324489
45334490Do not consider C<getlogin> for authentication: it is not as
45344491secure as C<getpwuid>.
45354492
45364493=end original
45374494
45384495C<getlogin> を認証に使ってはいけません。
45394496これは C<getpwuid> のように安全ではありません。
45404497
45414498=item getpeername SOCKET
45424499X<getpeername> X<peer>
45434500
45444501=begin original
45454502
45464503Returns the packed sockaddr address of other end of the SOCKET connection.
45474504
45484505=end original
45494506
45504507SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。
45514508
45524509 use Socket;
45534510 $hersockaddr = getpeername(SOCK);
45544511 ($port, $iaddr) = sockaddr_in($hersockaddr);
45554512 $herhostname = gethostbyaddr($iaddr, AF_INET);
45564513 $herstraddr = inet_ntoa($iaddr);
45574514
45584515=item getpgrp PID
45594516X<getpgrp> X<group>
45604517
45614518=begin original
45624519
45634520Returns the current process group for the specified PID. Use
45644521a PID of C<0> to get the current process group for the
45654522current process. Will raise an exception if used on a machine that
45664523doesn't implement getpgrp(2). If PID is omitted, returns process
45674524group of current process. Note that the POSIX version of C<getpgrp>
45684525does not accept a PID argument, so only C<PID==0> is truly portable.
45694526
45704527=end original
45714528
45724529指定された PID の現在のプロセスグループを返します。
45734530PID に C<0> を与えるとカレントプロセスの指定となります。
45744531getpgrp(2) を実装していないマシンで実行した場合には、例外が発生します。
45754532PID を省略するとカレントプロセスのプロセスグループを返します。
45764533POSIX 版の C<getpgrp> は PID 引数を受け付けないので、
45774534C<PID==0> のみが完全に移植性があります。
45784535
45794536=item getppid
45804537X<getppid> X<parent> X<pid>
45814538
45824539=begin original
45834540
45844541Returns the process id of the parent process.
45854542
45864543=end original
45874544
45884545親プロセスのプロセス id を返します。
45894546
45904547=begin original
45914548
45924549Note for Linux users: on Linux, the C functions C<getpid()> and
45934550C<getppid()> return different values from different threads. In order to
45944551be portable, this behavior is not reflected by the perl-level function
45954552C<getppid()>, that returns a consistent value across threads. If you want
45964553to call the underlying C<getppid()>, you may use the CPAN module
45974554C<Linux::Pid>.
45984555
45994556=end original
46004557
46014558Linux ユーザーへの注意: Linux では C<getpid()> と C<getppid()> の C 関数は
46024559スレッドが異なると異なった値を返します。
46034560移植性のために、この振る舞いは perl レベルの関数 C<getppid()> には
46044561反映されず、スレッドをまたいで一貫性のある値を返します。
46054562基礎となる C<getppid()> を呼び出したい場合は、CPAN モジュールである
46064563C<Linux::Pid> を使ってください。
46074564
46084565=item getpriority WHICH,WHO
46094566X<getpriority> X<priority> X<nice>
46104567
46114568=begin original
46124569
46134570Returns the current priority for a process, a process group, or a user.
4614(See C<getpriority(2)>.) Will raise a fatal exception if used on a
4571(See L<getpriority(2)>.) Will raise a fatal exception if used on a
46154572machine that doesn't implement getpriority(2).
46164573
46174574=end original
46184575
46194576プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。
4620(C<getpriority(2)> を参照してください。)
4577(L<getpriority(2)> を参照してください。)
46214578getpriority(2) を実装していない
46224579マシンで実行した場合には、致命的例外が発生します。
46234580
46244581=item getpwnam NAME
46254582X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname>
46264583X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr>
46274584X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent>
46284585X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent>
46294586X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent>
46304587X<endnetent> X<endprotoent> X<endservent>
46314588
46324589=item getgrnam NAME
46334590
46344591=item gethostbyname NAME
46354592
46364593=item getnetbyname NAME
46374594
46384595=item getprotobyname NAME
46394596
46404597=item getpwuid UID
46414598
46424599=item getgrgid GID
46434600
46444601=item getservbyname NAME,PROTO
46454602
46464603=item gethostbyaddr ADDR,ADDRTYPE
46474604
46484605=item getnetbyaddr ADDR,ADDRTYPE
46494606
46504607=item getprotobynumber NUMBER
46514608
46524609=item getservbyport PORT,PROTO
46534610
46544611=item getpwent
46554612
46564613=item getgrent
46574614
46584615=item gethostent
46594616
46604617=item getnetent
46614618
46624619=item getprotoent
46634620
46644621=item getservent
46654622
46664623=item setpwent
46674624
46684625=item setgrent
46694626
46704627=item sethostent STAYOPEN
46714628
46724629=item setnetent STAYOPEN
46734630
46744631=item setprotoent STAYOPEN
46754632
46764633=item setservent STAYOPEN
46774634
46784635=item endpwent
46794636
46804637=item endgrent
46814638
46824639=item endhostent
46834640
46844641=item endnetent
46854642
46864643=item endprotoent
46874644
46884645=item endservent
46894646
46904647=begin original
46914648
46924649These routines perform the same functions as their counterparts in the
46934650system library. In list context, the return values from the
46944651various get routines are as follows:
46954652
46964653=end original
46974654
46984655これらのルーチンは、システムライブラリの同名の関数を実行します。
46994656リストコンテキストでは、さまざまな
47004657get ルーチンからの返り値は、次のようになります:
47014658
47024659 ($name,$passwd,$uid,$gid,
47034660 $quota,$comment,$gcos,$dir,$shell,$expire) = getpw*
47044661 ($name,$passwd,$gid,$members) = getgr*
47054662 ($name,$aliases,$addrtype,$length,@addrs) = gethost*
47064663 ($name,$aliases,$addrtype,$net) = getnet*
47074664 ($name,$aliases,$proto) = getproto*
47084665 ($name,$aliases,$port,$proto) = getserv*
47094666
47104667=begin original
47114668
47124669(If the entry doesn't exist you get a null list.)
47134670
47144671=end original
47154672
47164673(エントリが存在しなければ、空リストが返されます。)
47174674
47184675=begin original
47194676
47204677The exact meaning of the $gcos field varies but it usually contains
47214678the real name of the user (as opposed to the login name) and other
47224679information pertaining to the user. Beware, however, that in many
47234680system users are able to change this information and therefore it
47244681cannot be trusted and therefore the $gcos is tainted (see
47254682L<perlsec>). The $passwd and $shell, user's encrypted password and
47264683login shell, are also tainted, because of the same reason.
47274684
47284685=end original
47294686
47304687$gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく)
47314688ユーザーの実際の名前とユーザーに付随する情報を含みます。
47324689但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は
47334690信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。
47344691ユーザーの暗号化されたパスワードとログインシェルである $passwd と
47354692$shell も、同様の理由で汚染されます。
47364693
47374694=begin original
47384695
47394696In scalar context, you get the name, unless the function was a
47404697lookup by name, in which case you get the other thing, whatever it is.
47414698(If the entry doesn't exist you get the undefined value.) For example:
47424699
47434700=end original
47444701
47454702スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、
47464703name を返し、NAME で検索するものは、何か別のものを返します。
47474704(エントリが存在しなければ、未定義値が返ります。)
47484705例:
47494706
47504707 $uid = getpwnam($name);
47514708 $name = getpwuid($num);
47524709 $name = getpwent();
47534710 $gid = getgrnam($name);
47544711 $name = getgrgid($num);
47554712 $name = getgrent();
47564713 #etc.
47574714
47584715=begin original
47594716
47604717In I<getpw*()> the fields $quota, $comment, and $expire are special
47614718cases in the sense that in many systems they are unsupported. If the
47624719$quota is unsupported, it is an empty scalar. If it is supported, it
47634720usually encodes the disk quota. If the $comment field is unsupported,
47644721it is an empty scalar. If it is supported it usually encodes some
47654722administrative comment about the user. In some systems the $quota
47664723field may be $change or $age, fields that have to do with password
47674724aging. In some systems the $comment field may be $class. The $expire
47684725field, if present, encodes the expiration period of the account or the
47694726password. For the availability and the exact meaning of these fields
47704727in your system, please consult your getpwnam(3) documentation and your
47714728F<pwd.h> file. You can also find out from within Perl what your
47724729$quota and $comment fields mean and whether you have the $expire field
47734730by using the C<Config> module and the values C<d_pwquota>, C<d_pwage>,
47744731C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password
47754732files are only supported if your vendor has implemented them in the
47764733intuitive fashion that calling the regular C library routines gets the
47774734shadow versions if you're running under privilege or if there exists
47784735the shadow(3) functions as found in System V (this includes Solaris
47794736and Linux.) Those systems that implement a proprietary shadow password
47804737facility are unlikely to be supported.
47814738
47824739=end original
47834740
47844741I<getpw*()> では、$quota, $comment, $expire フィールドは、
47854742多くのシステムでは対応していないので特別な処理がされます。
47864743$quota が非対応の場合、空のスカラになります。
47874744対応している場合、通常はディスククォータの値が入ります。
47884745$comment フィールドが非対応の場合、空のスカラになります。
47894746対応している場合、通常はユーザーに関する管理上のコメントが入ります。
47904747$quota フィールドはパスワードの寿命を示す $change や $age である
47914748システムもあります。
47924749$comment フィールドは $class であるシステムもあります。
47934750$expire フィールドがある場合は、アカウントやパスワードが時間切れになる
47944751期間が入ります。
47954752動作させるシステムでのこれらのフィールドの有効性と正確な意味については、
47964753getpwnam(3) のドキュメントと F<pwd.h> ファイルを参照してください。
47974754$quota と $comment フィールドが何を意味しているかと、$expire フィールドが
47984755あるかどうかは、C<Config> モジュールを使って、C<d_pwquota>, C<d_pwage>,
47994756C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を調べることによって
48004757Perl 自身で調べることも出来ます。
48014758シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で
48024759呼び出すことでシャドウ版が取得できるか、System V にあるような
48034760(Solaris と Linux を含みます) shadow(3) 関数があるといった、
48044761直感的な方法で実装されている場合にのみ対応されます。
48054762独占的なシャドウパスワード機能を実装しているシステムでは、
48064763それに対応されることはないでしょう。
48074764
48084765=begin original
48094766
48104767The $members value returned by I<getgr*()> is a space separated list of
48114768the login names of the members of the group.
48124769
48134770=end original
48144771
48154772I<getgr*()> によって返る値 $members は、グループのメンバの
48164773ログイン名をスペースで区切ったものです。
48174774
48184775=begin original
48194776
48204777For the I<gethost*()> functions, if the C<h_errno> variable is supported in
48214778C, it will be returned to you via C<$?> if the function call fails. The
48224779C<@addrs> value returned by a successful call is a list of the raw
48234780addresses returned by the corresponding system library call. In the
48244781Internet domain, each address is four bytes long and you can unpack it
48254782by saying something like:
48264783
48274784=end original
48284785
48294786I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、
48304787関数呼出が失敗したときに、C<$?> を通して、その値が返されます。
48314788成功時に返される C<@addrs> 値は、対応するシステムコールが返す、
48324789生のアドレスのリストです。
48334790インターネットドメインでは、個々のアドレスは、4 バイト長で、
48344791以下のようにして unpack することができます。
48354792
48364793 ($a,$b,$c,$d) = unpack('W4',$addr[0]);
48374794
48384795=begin original
48394796
48404797The Socket library makes this slightly easier:
48414798
48424799=end original
48434800
48444801Socket ライブラリを使うともう少し簡単になります。
48454802
48464803 use Socket;
48474804 $iaddr = inet_aton("127.1"); # or whatever address
48484805 $name = gethostbyaddr($iaddr, AF_INET);
48494806
48504807 # or going the other way
48514808 $straddr = inet_ntoa($iaddr);
48524809
48534810=begin original
48544811
48554812In the opposite way, to resolve a hostname to the IP address
48564813you can write this:
48574814
48584815=end original
48594816
48604817逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます:
48614818
48624819 use Socket;
48634820 $packed_ip = gethostbyname("www.perl.org");
48644821 if (defined $packed_ip) {
48654822 $ip_address = inet_ntoa($packed_ip);
48664823 }
48674824
48684825=begin original
48694826
48704827Make sure <gethostbyname()> is called in SCALAR context and that
48714828its return value is checked for definedness.
48724829
48734830=end original
48744831
48754832C<gethostbyname()> はスカラコンテキストで呼び出すようにして、返り値が
48764833定義されているかを必ずチェックしてください。
48774834
48784835=begin original
48794836
48804837If you get tired of remembering which element of the return list
48814838contains which return value, by-name interfaces are provided
48824839in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>,
48834840C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
48844841and C<User::grent>. These override the normal built-ins, supplying
48854842versions that return objects with the appropriate names
48864843for each field. For example:
48874844
48884845=end original
48894846
48904847返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、
48914848名前ベースのインターフェースが標準モジュールで提供されています:
48924849C<File::stat>, C<Net::hostent>, C<Net::netent>,
48934850C<Net::protoent>, C<Net::servent>, C<Time::gmtime>, C<Time::localtime>,
48944851C<User::grent> です。
48954852これらは通常の組み込みを上書きし、
48964853それぞれのフィールドに適切な名前をつけたオブジェクトを返します。
48974854例:
48984855
48994856 use File::stat;
49004857 use User::pwent;
49014858 $is_his = (stat($filename)->uid == pwent($whoever)->uid);
49024859
49034860=begin original
49044861
49054862Even though it looks like they're the same method calls (uid),
49064863they aren't, because a C<File::stat> object is different from
49074864a C<User::pwent> object.
49084865
49094866=end original
49104867
49114868同じメソッド(uid)を呼び出しているように見えますが、違います。
49124869なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは
49134870異なるからです。
49144871
49154872=item getsockname SOCKET
49164873X<getsockname>
49174874
49184875=begin original
49194876
49204877Returns the packed sockaddr address of this end of the SOCKET connection,
49214878in case you don't know the address because you have several different
49224879IPs that the connection might have come in on.
49234880
49244881=end original
49254882
49264883SOCKET 接続のこちら側の pack された sockaddr アドレスを返します。
49274884複数の異なる IP から接続されるためにアドレスがわからない場合に使います。
49284885
49294886 use Socket;
49304887 $mysockaddr = getsockname(SOCK);
49314888 ($port, $myaddr) = sockaddr_in($mysockaddr);
49324889 printf "Connect to %s [%s]\n",
49334890 scalar gethostbyaddr($myaddr, AF_INET),
49344891 inet_ntoa($myaddr);
49354892
49364893=item getsockopt SOCKET,LEVEL,OPTNAME
49374894X<getsockopt>
49384895
49394896=begin original
49404897
49414898Queries the option named OPTNAME associated with SOCKET at a given LEVEL.
49424899Options may exist at multiple protocol levels depending on the socket
49434900type, but at least the uppermost socket level SOL_SOCKET (defined in the
49444901C<Socket> module) will exist. To query options at another level the
49454902protocol number of the appropriate protocol controlling the option
49464903should be supplied. For example, to indicate that an option is to be
49474904interpreted by the TCP protocol, LEVEL should be set to the protocol
49484905number of TCP, which you can get using getprotobyname.
49494906
49504907=end original
49514908
49524909与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを
49534910問い合わせます。
49544911オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも
49554912ありますが、少なくとも最上位ソケットレベル SOL_SOCKET (C<Socket> モジュールで
49564913定義されています)は存在します。
49574914その他のレベルのオプションを問い合わせるには、そのオプションを制御する
49584915適切なプロトコルのプロトコル番号を指定します。
49594916例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、
49604917LEVEL は getprotobyname で得られる TCP のプロトコル番号を設定します。
49614918
49624919=begin original
49634920
49644921The call returns a packed string representing the requested socket option,
49654922or C<undef> if there is an error (the error reason will be in $!). What
49664923exactly is in the packed string depends in the LEVEL and OPTNAME, consult
49674924your system documentation for details. A very common case however is that
49684925the option is an integer, in which case the result will be a packed
49694926integer which you can decode using unpack with the C<i> (or C<I>) format.
49704927
49714928=end original
49724929
49734930この呼び出しは、要求されたソケットオプションの pack された文字列表現か、
49744931あるいはエラーがある場合は C<undef> を返します(エラーの理由は $! にあります)。
49754932pack された文字列の正確な中身は LEVEL と OPTNAME に依存するので、
49764933詳細についてはシステムドキュメントを確認してください。
49774934しかし、とても一般的な場合というのはオプションが整数の場合で、この場合
49784935結果は unpack の C<i> (あるいは C<I>)フォーマットでデコードできる pack された
49794936整数です。
49804937
49814938=begin original
49824939
49834940An example testing if Nagle's algorithm is turned on on a socket:
49844941
49854942=end original
49864943
49874944あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です:
49884945
49894946 use Socket qw(:all);
49904947
49914948 defined(my $tcp = getprotobyname("tcp"))
49924949 or die "Could not determine the protocol number for tcp";
49934950 # my $tcp = IPPROTO_TCP; # Alternative
49944951 my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
49954952 or die "Could not query TCP_NODELAY socket option: $!";
49964953 my $nodelay = unpack("I", $packed);
49974954 print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n";
49984955
49994956
50004957=item glob EXPR
50014958X<glob> X<wildcard> X<filename, expansion> X<expand>
50024959
50034960=item glob
50044961
50054962=begin original
50064963
50074964In list context, returns a (possibly empty) list of filename expansions on
50084965the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
50094966scalar context, glob iterates through such filename expansions, returning
50104967undef when the list is exhausted. This is the internal function
50114968implementing the C<< <*.c> >> operator, but you can use it directly. If
50124969EXPR is omitted, C<$_> is used. The C<< <*.c> >> operator is discussed in
50134970more detail in L<perlop/"I/O Operators">.
50144971
50154972=end original
50164973
50174974リストコンテキストでは、
50184975EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように
50194976ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。
50204977スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、
50214978リストがなくなったら undef を返します。
50224979これは、C<< <*.c> >> 演算子を実装する内部関数ですが、
50234980直接使用することもできます。
50244981EXPR を省略すると、C<$_>が使われます。
50254982C<< <*.c> >>演算子については
50264983L<perlop/"I/O Operators"> でより詳細に議論しています。
50274984
50284985=begin original
50294986
5030Note that C<glob> will split its arguments on whitespace, treating
5031each segment as separate pattern. As such, C<glob('*.c *.h')> would
5032match all files with a F<.c> or F<.h> extension. The expression
5033C<glob('.* *')> would match all files in the current working directory.
5034
5035=end original
5036
5037Note that
5038C<glob> は引数を空白で分割して、それぞれの部分を別々のパターンとして
5039扱うことに注意してください。
5040それにより、C<glob('*.c *.h')> は F<.c> と F<.h> の拡張子を持つ全ての
5041ファイルにマッチングします。
5042C<glob('.* *')> という式はカレントワーキングディレクトリの
5043全てのファイルにマッチングします。
5044
5045=begin original
5046
50474987Beginning with v5.6.0, this operator is implemented using the standard
5048C<File::Glob> extension. See L<File::Glob> for details, including
4988C<File::Glob> extension. See L<File::Glob> for details.
5049C<bsd_glob> which does not treat whitespace as a pattern separator.
50504989
50514990=end original
50524991
50534992v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って
50544993実装されています。
5055空白をパターンのセパレータとして扱わない C<bsd_glob> を含めた
50564994詳細は L<File::Glob> を参照して下さい。
50574995
50584996=item gmtime EXPR
50594997X<gmtime> X<UTC> X<Greenwich>
50604998
50614999=item gmtime
50625000
50635001=begin original
50645002
50655003Works just like L<localtime> but the returned values are
50665004localized for the standard Greenwich time zone.
50675005
50685006=end original
50695007
50705008L<localtime> と同様に働きますが、返り値はグリニッジ標準時に
50715009ローカライズされています。
50725010
50735011=begin original
50745012
50755013Note: when called in list context, $isdst, the last value
50765014returned by gmtime is always C<0>. There is no
50775015Daylight Saving Time in GMT.
50785016
50795017=end original
50805018
50815019注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である
50825020$isdst は常に C<0> です。
50835021GMT には夏時間はありません。
50845022
50855023=begin original
50865024
50875025See L<perlport/gmtime> for portability concerns.
50885026
50895027=end original
50905028
50915029移植性の問題については L<perlport/gmtime> を参照してください。
50925030
50935031=item goto LABEL
50945032X<goto> X<jump> X<jmp>
50955033
50965034=item goto EXPR
50975035
50985036=item goto &NAME
50995037
51005038=begin original
51015039
51025040The C<goto-LABEL> form finds the statement labeled with LABEL and resumes
51035041execution there. It may not be used to go into any construct that
51045042requires initialization, such as a subroutine or a C<foreach> loop. It
51055043also can't be used to go into a construct that is optimized away,
51065044or to get out of a block or subroutine given to C<sort>.
51075045It can be used to go almost anywhere else within the dynamic scope,
51085046including out of subroutines, but it's usually better to use some other
51095047construct such as C<last> or C<die>. The author of Perl has never felt the
51105048need to use this form of C<goto> (in Perl, that is--C is another matter).
51115049(The difference being that C does not offer named loops combined with
51125050loop control. Perl does, and this replaces most structured uses of C<goto>
51135051in other languages.)
51145052
51155053=end original
51165054
51175055C<goto-LABEL> の形式は、LABEL というラベルの付いた文を
51185056探して、そこへ実行を移すものです。 サブルーチンや
51195057C<foreach> ループなど、何らかの初期化が必要な構造の中に
51205058入り込むことは許されません。 最適化によってなくなってしまう構造の中にも
51215059goto することはできません。
51225060また、C<sort>で与えられたブロックやサブルーチンから外へ出ることもできません。
51235061これ以外は、サブルーチンの外を含む、動的スコープ内の
51245062ほとんどすべての場所へ行くために使用できますが、普通は、
51255063C<last> や C<die> といった別の構造を使った方が良いでしょう。
51265064Perl の作者はこの形式の C<goto> を使う必要を感じたことは、
512750651 度もありません (Perl では。C は別のお話です)。
51285066(違いは、C にはループ制御と結びついた名前つきのループがないことです。
51295067Perl にはあり、これが他の言語でのほとんどの構造的な C<goto> の使用法を
51305068置き換えます。)
51315069
51325070=begin original
51335071
51345072The C<goto-EXPR> form expects a label name, whose scope will be resolved
51355073dynamically. This allows for computed C<goto>s per FORTRAN, but isn't
51365074necessarily recommended if you're optimizing for maintainability:
51375075
51385076=end original
51395077
51405078C<goto-EXPR> の形式はラベル名を予測し、このスコープは動的に解決されます。
51415079これにより FORTRAN のような算術 C<goto> が可能になりますが、
51425080保守性を重視するならお勧めしません。
51435081
51445082 goto ("FOO", "BAR", "GLARCH")[$i];
51455083
51465084=begin original
51475085
51485086The C<goto-&NAME> form is quite different from the other forms of
51495087C<goto>. In fact, it isn't a goto in the normal sense at all, and
51505088doesn't have the stigma associated with other gotos. Instead, it
51515089exits the current subroutine (losing any changes set by local()) and
51525090immediately calls in its place the named subroutine using the current
51535091value of @_. This is used by C<AUTOLOAD> subroutines that wish to
51545092load another subroutine and then pretend that the other subroutine had
51555093been called in the first place (except that any modifications to C<@_>
51565094in the current subroutine are propagated to the other subroutine.)
51575095After the C<goto>, not even C<caller> will be able to tell that this
51585096routine was called first.
51595097
51605098=end original
51615099
51625100C<goto-&NAME> の形式は、その他の C<goto> の形式とはかなり
51635101異なったものです。
51645102実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、
51655103他の goto が持つ不名誉を持っていません。
51665104現在のサブルーチンを終了し (local() による変更は失われます)、
51675105直ちに現在の @_ の値を使って指定された名前のサブルーチンを呼び出します。
51685106これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、
51695107その別のサブルーチンが最初に呼ばれたようにするために使われます
51705108(ただし、現在のサブルーチンで C<@_> を修正した場合には、
51715109その別のサブルーチンに伝えられます)。
51725110C<goto> のあとは、C<caller> でさえも、現在のサブルーチンが
51735111最初に呼び出されたと言うことができません。
51745112
51755113=begin original
51765114
51775115NAME needn't be the name of a subroutine; it can be a scalar variable
51785116containing a code reference, or a block that evaluates to a code
51795117reference.
51805118
51815119=end original
51825120
51835121NAME はサブルーチンの名前である必要はありません; コードリファレンスを
51845122含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。
51855123
51865124=item grep BLOCK LIST
51875125X<grep>
51885126
51895127=item grep EXPR,LIST
51905128
51915129=begin original
51925130
51935131This is similar in spirit to, but not the same as, grep(1) and its
51945132relatives. In particular, it is not limited to using regular expressions.
51955133
51965134=end original
51975135
51985136これは grep(1) とその親類と同じようなものですが、同じではありません。
51995137特に、正規表現の使用に制限されません。
52005138
52015139=begin original
52025140
52035141Evaluates the BLOCK or EXPR for each element of LIST (locally setting
52045142C<$_> to each element) and returns the list value consisting of those
52055143elements for which the expression evaluated to true. In scalar
52065144context, returns the number of times the expression was true.
52075145
52085146=end original
52095147
52105148LIST の個々の要素に対して、BLOCK か EXPR を評価し
52115149(C<$_> は、ローカルに個々の要素が設定されます) 、
52125150その要素のうち、評価した式が真となったものからなるリスト値が返されます。
52135151スカラコンテキストでは、式が真となった回数を返します。 例:
52145152
52155153 @foo = grep(!/^#/, @bar); # weed out comments
52165154
52175155=begin original
52185156
52195157or equivalently,
52205158
52215159=end original
52225160
52235161あるいは等価な例として:
52245162
52255163 @foo = grep {!/^#/} @bar; # weed out comments
52265164
52275165=begin original
52285166
52295167Note that C<$_> is an alias to the list value, so it can be used to
52305168modify the elements of the LIST. While this is useful and supported,
52315169it can cause bizarre results if the elements of LIST are not variables.
52325170Similarly, grep returns aliases into the original list, much as a for
52335171loop's index variable aliases the list elements. That is, modifying an
52345172element of a list returned by grep (for example, in a C<foreach>, C<map>
52355173or another C<grep>) actually modifies the element in the original list.
52365174This is usually something to be avoided when writing clear code.
52375175
52385176=end original
52395177
52405178C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
52415179変更するために使うことができます。
52425180これは、便利でサポートされていますが、
52435181LIST の要素が変数でないと、おかしな結果になります。
52445182同様に、grep は元のリストへのエイリアスを返します。
52455183for ループのインデックス変数がリスト要素のエイリアスであるのと
52465184同様です。
52475185つまり、grep で返されたリストの要素を
52485186(C<foreach>, C<map>, または他の C<grep> で)修正すると
52495187元のリストの要素が変更されます。
52505188これはきれいなコードを書こうとする邪魔になることが多いです。
52515189
52525190=begin original
52535191
52545192If C<$_> is lexical in the scope where the C<grep> appears (because it has
52555193been declared with C<my $_>) then, in addition to being locally aliased to
52565194the list elements, C<$_> keeps being lexical inside the block; i.e. it
52575195can't be seen from the outside, avoiding any potential side-effects.
52585196
52595197=end original
52605198
52615199(C<my $_> として宣言されることによって) C<$_> が C<grep> が現れるスコープ内で
52625200レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加えて、
52635201C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、
52645202起こりうる副作用を回避します。
52655203
52665204=begin original
52675205
52685206See also L</map> for a list composed of the results of the BLOCK or EXPR.
52695207
52705208=end original
52715209
52725210BLOCK や EXPR の結果をリストの形にしたい場合は L</map> を参照してください。
52735211
52745212=item hex EXPR
52755213X<hex> X<hexadecimal>
52765214
52775215=item hex
52785216
52795217=begin original
52805218
52815219Interprets EXPR as a hex string and returns the corresponding value.
52825220(To convert strings that might start with either C<0>, C<0x>, or C<0b>, see
52835221L</oct>.) If EXPR is omitted, uses C<$_>.
52845222
52855223=end original
52865224
52875225EXPR を 16 進数の文字列と解釈して、対応する値を返します。
52885226(C<0>, C<0x>, C<0b> で始まる文字列の変換には、L</oct> を
52895227参照してください。)
52905228EXPR が省略されると、C<$_> を使用します。
52915229
52925230 print hex '0xAf'; # prints '175'
52935231 print hex 'aF'; # same
52945232
52955233=begin original
52965234
52975235Hex strings may only represent integers. Strings that would cause
52985236integer overflow trigger a warning. Leading whitespace is not stripped,
52995237unlike oct(). To present something as hex, look into L</printf>,
53005238L</sprintf>, or L</unpack>.
53015239
53025240=end original
53035241
5304524216 進文字列は整数のみを表現します。
53055243整数オーバーフローを起こすような文字列は警告を引き起こします。
53065244oct() とは違って、先頭の空白は除去されません。
53075245何かを 16 進で表現したい場合は、L</printf>, L</sprintf>, L</unpack> を
53085246参照してください。
53095247
53105248=item import LIST
53115249X<import>
53125250
53135251=begin original
53145252
53155253There is no builtin C<import> function. It is just an ordinary
53165254method (subroutine) defined (or inherited) by modules that wish to export
53175255names to another module. The C<use> function calls the C<import> method
53185256for the package used. See also L</use>, L<perlmod>, and L<Exporter>.
53195257
53205258=end original
53215259
53225260組み込みの C<import> 関数というものはありません。
53235261これは単に、別のモジュールに名前をエクスポートしたいモジュールが
53245262定義した(または継承した)、通常のメソッド(サブルーチン)です。
53255263C<use> 関数はパッケージを使う時に C<import> メソッドを呼び出します。
53265264L</use>, L<perlmod>, L<Exporter> も参照してください。
53275265
53285266=item index STR,SUBSTR,POSITION
53295267X<index> X<indexOf> X<InStr>
53305268
53315269=item index STR,SUBSTR
53325270
53335271=begin original
53345272
53355273The index function searches for one string within another, but without
53365274the wildcard-like behavior of a full regular-expression pattern match.
53375275It returns the position of the first occurrence of SUBSTR in STR at
53385276or after POSITION. If POSITION is omitted, starts searching from the
53395277beginning of the string. POSITION before the beginning of the string
53405278or after its end is treated as if it were the beginning or the end,
53415279respectively. POSITION and the return value are based at C<0> (or whatever
53425280you've set the C<$[> variable to--but don't do that). If the substring
53435281is not found, C<index> returns one less than the base, ordinarily C<-1>.
53445282
53455283=end original
53465284
53475285index 関数は ある文字列をもうひとつの文字列から検索しますが、
53485286完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。
53495287STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。
53505288POSITION が省略された場合には、STR の最初から探し始めます。
53515289POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、
53525290それぞれ先頭と末尾を指定されたものとして扱われます。
53535291POSITION と返り値のベースは、C<0> (もしくは、変数 C<$[> に設定した値です --
53545292しかし、これは使ってはいけません)。
53555293SUBSTR が見つからなかった場合には、C<index> はベースよりも 1 小さい値、
53565294通常は C<-1> が返されます。
53575295
53585296=item int EXPR
53595297X<int> X<integer> X<truncate> X<trunc> X<floor>
53605298
53615299=item int
53625300
53635301=begin original
53645302
53655303Returns the integer portion of EXPR. If EXPR is omitted, uses C<$_>.
53665304You should not use this function for rounding: one because it truncates
53675305towards C<0>, and two because machine representations of floating point
53685306numbers can sometimes produce counterintuitive results. For example,
53695307C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's
53705308because it's really more like -268.99999999999994315658 instead. Usually,
53715309the C<sprintf>, C<printf>, or the C<POSIX::floor> and C<POSIX::ceil>
53725310functions will serve you better than will int().
53735311
53745312=end original
53755313
53765314EXPR の整数部を返します。
53775315EXPR を省略すると、C<$_> を使います。
53785316この関数を丸めのために使うべきではありません。
53795317第一の理由として C<0> の方向への切捨てを行うから、第二の理由として
53805318浮動小数点数の機械表現は時々直感に反した結果を生み出すからです。
53815319たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく
53825320-268 を返します。
53835321これは実際には -268.99999999999994315658 というような値になっているからです。
53845322通常、C<sprintf>, C<printf>, C<POSIX::floor>, C<POSIX::ceil> の方が
53855323int() より便利です。
53865324
53875325=item ioctl FILEHANDLE,FUNCTION,SCALAR
53885326X<ioctl>
53895327
53905328=begin original
53915329
53925330Implements the ioctl(2) function. You'll probably first have to say
53935331
53945332=end original
53955333
53965334ioctl(2) 関数を実装します。
53975335正しい関数の定義を得るために、おそらく最初に
53985336
53995337 require "sys/ioctl.ph"; # probably in $Config{archlib}/sys/ioctl.ph
54005338
54015339=begin original
54025340
54035341to get the correct function definitions. If F<sys/ioctl.ph> doesn't
54045342exist or doesn't have the correct definitions you'll have to roll your
54055343own, based on your C header files such as F<< <sys/ioctl.h> >>.
54065344(There is a Perl script called B<h2ph> that comes with the Perl kit that
54075345may help you in this, but it's nontrivial.) SCALAR will be read and/or
54085346written depending on the FUNCTION--a pointer to the string value of SCALAR
54095347will be passed as the third argument of the actual C<ioctl> call. (If SCALAR
54105348has no string value but does have a numeric value, that value will be
54115349passed rather than a pointer to the string value. To guarantee this to be
54125350true, add a C<0> to the scalar before using it.) The C<pack> and C<unpack>
54135351functions may be needed to manipulate the values of structures used by
54145352C<ioctl>.
54155353
54165354=end original
54175355
54185356としなくてはならないでしょう。
54195357F<sys/ioctl.ph> がないか、間違った定義をしている場合には、
54205358F<< <sys/ioctl.ph> >>のような C のヘッダファイルをもとに、
54215359自分で作らなければなりません。
54225360(Perl の配布キットに入っている B<h2ph> という
54235361Perl スクリプトがこれを手助けしてくれるでしょうが、これは重要です。)
54245362FOUNCTION に応じて SCALAR が読み書きされます。
54255363SCALAR の文字列値へのポインタが、実際の C<ioctl> コールの
542653643 番目の引数として渡されます。
54275365(SCALAR が文字列値を持っておらず、数値を持っている場合には、
54285366文字列値へのポインタの代わりに、その値が渡されます。
54295367このことを保証するためには、使用する前に SCALAR にC<0> を足してください。)
54305368C<ioctl> で使われる構造体の値を操作するには、
54315369C<pack> 関数と C<unpack> 関数が必要となるでしょう。
54325370
54335371=begin original
54345372
54355373The return value of C<ioctl> (and C<fcntl>) is as follows:
54365374
54375375=end original
54385376
54395377C<ioctl> (と C<fcntl>) の返り値は、以下のようになります:
54405378
54415379=begin original
54425380
54435381 if OS returns: then Perl returns:
54445382 -1 undefined value
54455383 0 string "0 but true"
54465384 anything else that number
54475385
54485386=end original
54495387
54505388 OS が返した値: Perl が返す値:
54515389 -1 未定義値
54525390 0 「0 だが真」の文字列
54535391 その他 その値そのもの
54545392
54555393=begin original
54565394
54575395Thus Perl returns true on success and false on failure, yet you can
54585396still easily determine the actual value returned by the operating
54595397system:
54605398
54615399=end original
54625400
54635401つまり Perl は、成功時に「真」、失敗時に「偽」を返す
54645402ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。
54655403
54665404 $retval = ioctl(...) || -1;
54675405 printf "System returned %d\n", $retval;
54685406
54695407=begin original
54705408
54715409The special string C<"0 but true"> is exempt from B<-w> complaints
54725410about improper numeric conversions.
54735411
54745412=end original
54755413
54765414特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する
54775415B<-w> 警告を回避します。
54785416
54795417=item join EXPR,LIST
54805418X<join>
54815419
54825420=begin original
54835421
54845422Joins the separate strings of LIST into a single string with fields
54855423separated by the value of EXPR, and returns that new string. Example:
54865424
54875425=end original
54885426
54895427LIST の個別の文字列を、EXPR の値で区切って
549054281 つの文字列につなげ、その文字列を返します。
54915429例:
54925430
54935431 $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
54945432
54955433=begin original
54965434
54975435Beware that unlike C<split>, C<join> doesn't take a pattern as its
54985436first argument. Compare L</split>.
54995437
55005438=end original
55015439
55025440C<split> と違って、C<join> は最初の引数にパターンは取れないことに
55035441注意してください。
55045442L</split> と比較してください。
55055443
55065444=item keys HASH
55075445X<keys> X<key>
55085446
55095447=begin original
55105448
55115449Returns a list consisting of all the keys of the named hash.
55125450(In scalar context, returns the number of keys.)
55135451
55145452=end original
55155453
55165454指定したハッシュのすべての key からなる、リストを返します。
55175455(スカラコンテキストでは、key の数を返します。)
55185456
55195457=begin original
55205458
55215459The keys are returned in an apparently random order. The actual
55225460random order is subject to change in future versions of perl, but it
55235461is guaranteed to be the same order as either the C<values> or C<each>
55245462function produces (given that the hash has not been modified). Since
55255463Perl 5.8.1 the ordering is different even between different runs of
55265464Perl for security reasons (see L<perlsec/"Algorithmic Complexity
55275465Attacks">).
55285466
55295467=end original
55305468
55315469キーは見たところではランダムな順番に返されます。
55325470実際のランダムな順番は perl の将来のバージョンでは変わるかもしれませんが、
55335471C<values> や C<each> 関数が同じ(変更されていない)ハッシュに対して
55345472生成するのと同じ順番であることは保証されます。
55355473Perl 5.8.1 以降ではセキュリティ上の理由により、
55365474実行される毎に順番は変わります
55375475(L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。
55385476
55395477=begin original
55405478
55415479As a side effect, calling keys() resets the HASH's internal iterator
55425480(see L</each>). In particular, calling keys() in void context resets
55435481the iterator with no other overhead.
55445482
55455483=end original
55465484
55475485副作用として、HASH の反復子を初期化します
55485486(L</each> を参照してください)。
55495487特に、無効コンテキストで keys() を呼び出すと
55505488オーバーヘッドなしで反復子を初期化します。
55515489
55525490=begin original
55535491
55545492Here is yet another way to print your environment:
55555493
55565494=end original
55575495
55585496環境変数を表示する別の例です:
55595497
55605498 @keys = keys %ENV;
55615499 @values = values %ENV;
55625500 while (@keys) {
55635501 print pop(@keys), '=', pop(@values), "\n";
55645502 }
55655503
55665504=begin original
55675505
55685506or how about sorted by key:
55695507
55705508=end original
55715509
55725510key でソートしてもいいでしょう:
55735511
55745512 foreach $key (sort(keys %ENV)) {
55755513 print $key, '=', $ENV{$key}, "\n";
55765514 }
55775515
55785516=begin original
55795517
55805518The returned values are copies of the original keys in the hash, so
55815519modifying them will not affect the original hash. Compare L</values>.
55825520
55835521=end original
55845522
55855523返される値はハッシュにある元のキーのコピーなので、
55865524これを変更しても元のハッシュには影響を与えません。
55875525L</values> と比較してください。
55885526
55895527=begin original
55905528
55915529To sort a hash by value, you'll need to use a C<sort> function.
55925530Here's a descending numeric sort of a hash by its values:
55935531
55945532=end original
55955533
55965534ハッシュを値でソートするためには、C<sort> 関数を使う必要があります。
55975535以下ではハッシュの値を数値の降順でソートしています:
55985536
55995537 foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
56005538 printf "%4d %s\n", $hash{$key}, $key;
56015539 }
56025540
56035541=begin original
56045542
56055543As an lvalue C<keys> allows you to increase the number of hash buckets
56065544allocated for the given hash. This can gain you a measure of efficiency if
56075545you know the hash is going to get big. (This is similar to pre-extending
56085546an array by assigning a larger number to $#array.) If you say
56095547
56105548=end original
56115549
56125550左辺値としては、C<keys> を使うことで与えられたハッシュに割り当てられた
56135551ハッシュ表の大きさを増やすことができます。
56145552これによって、ハッシュが大きくなっていくなっていくときの
56155553効率の測定ができます。以下のようにすると:
56165554
56175555 keys %hash = 200;
56185556
56195557=begin original
56205558
56215559then C<%hash> will have at least 200 buckets allocated for it--256 of them,
56225560in fact, since it rounds up to the next power of two. These
56235561buckets will be retained even if you do C<%hash = ()>, use C<undef
56245562%hash> if you want to free the storage while C<%hash> is still in scope.
56255563You can't shrink the number of buckets allocated for the hash using
56265564C<keys> in this way (but you needn't worry about doing this by accident,
56275565as trying has no effect).
56285566
56295567=end original
56305568
56315569C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
56325570実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。
56335571この表はたとえ C<%hash = ()> としても残るので、
56345572もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は
56355573C<undef %hash> を使います。
56365574この方法で C<keys> を使うことで、表の大きさを小さくすることはできません
56375575(間違えてそのようなことをしても何も起きないので気にすることはありません)。
56385576
56395577=begin original
56405578
56415579See also C<each>, C<values> and C<sort>.
56425580
56435581=end original
56445582
56455583C<each>, C<values>, C<sort> も参照してください。
56465584
56475585=item kill SIGNAL, LIST
56485586X<kill> X<signal>
56495587
56505588=begin original
56515589
56525590Sends a signal to a list of processes. Returns the number of
56535591processes successfully signaled (which is not necessarily the
56545592same as the number actually killed).
56555593
56565594=end original
56575595
56585596プロセスのリストにシグナルを送ります。シグナル送信に成功したプロセスの
56595597数を返します
56605598(実際に kill に成功したプロセスと同じとは限りません)。
56615599
56625600 $cnt = kill 1, $child1, $child2;
56635601 kill 9, @goners;
56645602
56655603=begin original
56665604
56675605If SIGNAL is zero, no signal is sent to the process, but the kill(2)
56685606system call will check whether it's possible to send a signal to it (that
56695607means, to be brief, that the process is owned by the same user, or we are
56705608the super-user). This is a useful way to check that a child process is
56715609alive (even if only as a zombie) and hasn't changed its UID. See
56725610L<perlport> for notes on the portability of this construct.
56735611
56745612=end original
56755613
56765614SIGNAL がゼロの場合、プロセスにシグナルは送られませんが、
56775615but the kill(2)
56785616system call will check whether it's possible to send a signal to it (that
56795617means, to be brief, that the process is owned by the same user, or we are
56805618the super-user)
56815619これは子プロセスが(ゾンビとしてだけでも)生きていて、 UID が
56825620変わっていないことを調べる時に有用です。
56835621この構成の移植性に関する注意については L<perlport> を参照して下さい。
56845622
56855623=begin original
56865624
56875625Unlike in the shell, if SIGNAL is negative, it kills
56885626process groups instead of processes. (On System V, a negative I<PROCESS>
56895627number will also kill process groups, but that's not portable.) That
56905628means you usually want to use positive not negative signals. You may also
56915629use a signal name in quotes.
56925630
56935631=end original
56945632
56955633シェルとは異なり、シグナルに負の数を与えると、
56965634プロセスではなくプロセスグループに対して kill を行ないます。
56975635(Syetem V では、プロセス番号として負の値を与えても、
56985636プロセスグループの kill を行ないますが、
56995637移植性がありません。)
57005638すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。
57015639シグナル名をクォートして使うこともできます。
57025640
57035641=begin original
57045642
57055643See L<perlipc/"Signals"> for more details.
57065644
57075645=end original
57085646
57095647詳細はL<perlipc/"Signals">を参照してください。
57105648
57115649=item last LABEL
57125650X<last> X<break>
57135651
57145652=item last
57155653
57165654=begin original
57175655
57185656The C<last> command is like the C<break> statement in C (as used in
57195657loops); it immediately exits the loop in question. If the LABEL is
57205658omitted, the command refers to the innermost enclosing loop. The
57215659C<continue> block, if any, is not executed:
57225660
57235661=end original
57245662
57255663C<last> コマンドは、(ループ内で使った) C の C<break> 文と
57265664同じようなもので、LABEL で指定されるループを即座に抜けます。
57275665LABEL が省略されると、一番内側のループが対象となります。
57285666C<continue> ブロックがあっても実行されません:
57295667
57305668 LINE: while (<STDIN>) {
57315669 last LINE if /^$/; # exit when done with header
57325670 #...
57335671 }
57345672
57355673=begin original
57365674
57375675C<last> cannot be used to exit a block which returns a value such as
57385676C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit
57395677a grep() or map() operation.
57405678
57415679=end original
57425680
57435681C<last> は C<eval {}>, C<sub {}>, C<do {}> といった
57445682値を返すブロックを終了するのには使えませんし、
57455683grep() や map() 操作を終了するのに使うべきではありません。
57465684
57475685=begin original
57485686
57495687Note that a block by itself is semantically identical to a loop
57505688that executes once. Thus C<last> can be used to effect an early
57515689exit out of such a block.
57525690
57535691=end original
57545692
57555693ブロックはそれ自体文法的には一度だけ実行されるループと同等であることに
57565694注意してください。従って、C<last> でそのようなブロックを
57575695途中で抜け出すことができます。
57585696
57595697=begin original
57605698
57615699See also L</continue> for an illustration of how C<last>, C<next>, and
57625700C<redo> work.
57635701
57645702=end original
57655703
57665704C<last>, C<next>, C<redo> がどのように働くかについては
5767L</continue> 参照して下さい。
5705L</continue> 参照して下さい。
57685706
57695707=item lc EXPR
57705708X<lc> X<lowercase>
57715709
57725710=item lc
57735711
57745712=begin original
57755713
57765714Returns a lowercased version of EXPR. This is the internal function
57775715implementing the C<\L> escape in double-quoted strings. Respects
57785716current LC_CTYPE locale if C<use locale> in force. See L<perllocale>
57795717and L<perlunicode> for more details about locale and Unicode support.
57805718
57815719=end original
57825720
57835721EXPR を小文字に変換したものを返します。
57845722これは、ダブルクォート文字列における、
57855723C<\L> エスケープを実装する内部関数です。
57865724C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。
57875725ロケールと Unicode のサポートに関するさらなる詳細については
57885726L<perllocale> と L<perlunicode> を参照してください。
57895727
57905728=begin original
57915729
57925730If EXPR is omitted, uses C<$_>.
57935731
57945732=end original
57955733
5796EXPR が省略されると、C<$_> を使います。
5734EXPR が省略されると、C<$_>を使います。
57975735
57985736=item lcfirst EXPR
57995737X<lcfirst> X<lowercase>
58005738
58015739=item lcfirst
58025740
58035741=begin original
58045742
58055743Returns the value of EXPR with the first character lowercased. This
58065744is the internal function implementing the C<\l> escape in
58075745double-quoted strings. Respects current LC_CTYPE locale if C<use
58085746locale> in force. See L<perllocale> and L<perlunicode> for more
58095747details about locale and Unicode support.
58105748
58115749=end original
58125750
58135751最初の文字だけを小文字にした、EXPR を返します。
58145752これは、ダブルクォート文字列における、C<\l> エスケープを
58155753実装する内部関数です。
58165754C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。
58175755ロケールと Unicode のサポートに関するさらなる詳細については
58185756L<perllocale> と L<perlunicode> を参照してください。
58195757
58205758=begin original
58215759
58225760If EXPR is omitted, uses C<$_>.
58235761
58245762=end original
58255763
5826EXPR が省略されると、C<$_> を使います。
5764EXPR が省略されると、C<$_>を使います。
58275765
58285766=item length EXPR
58295767X<length> X<size>
58305768
58315769=item length
58325770
58335771=begin original
58345772
58355773Returns the length in I<characters> of the value of EXPR. If EXPR is
58365774omitted, returns length of C<$_>. Note that this cannot be used on
58375775an entire array or hash to find out how many elements these have.
58385776For that, use C<scalar @array> and C<scalar keys %hash> respectively.
58395777
58405778=end original
58415779
58425780EXPR の値の I<文字> の長さを返します。
58435781EXPR が省略されたときには、C<$_> の長さを返します。
58445782これは配列やハッシュ全体に対してどれだけの要素を含んでいるかを
58455783調べるためには使えません。
58465784そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を
58475785利用してください。
58485786
58495787=begin original
58505788
58515789Note the I<characters>: if the EXPR is in Unicode, you will get the
58525790number of characters, not the number of bytes. To get the length
58535791of the internal string in bytes, use C<bytes::length(EXPR)>, see
58545792L<bytes>. Note that the internal encoding is variable, and the number
58555793of bytes usually meaningless. To get the number of bytes that the
58565794string would have when encoded as UTF-8, use
58575795C<length(Encoding::encode_utf8(EXPR))>.
58585796
58595797=end original
58605798
58615799I<文字> 関する注意:
58625800EXPR が Unicode の場合、バイト数ではなく、文字の数が返ります。
58635801内部文字列のバイト数が必要な場合は L<bytes> を参照して、
58645802C<do { use bytes; length(EXPR) }> を使ってください。
58655803内部エンコーディングは様々なので、バイト数は普通は無意味です。
58665804UTF-8 でエンコードされている場合の文字列のバイト数を得たい場合は、
58675805C<length(Encoding::encode_utf8(EXPR))> を使ってください。
58685806
58695807=item link OLDFILE,NEWFILE
58705808X<link>
58715809
58725810=begin original
58735811
58745812Creates a new filename linked to the old filename. Returns true for
58755813success, false otherwise.
58765814
58775815=end original
58785816
58795817OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。
58805818成功時には true を、失敗時には false を返します。
58815819
58825820=item listen SOCKET,QUEUESIZE
58835821X<listen>
58845822
58855823=begin original
58865824
58875825Does the same thing that the listen system call does. Returns true if
58885826it succeeded, false otherwise. See the example in
58895827L<perlipc/"Sockets: Client/Server Communication">.
58905828
58915829=end original
58925830
58935831listen システムコールと同じことをします。成功時には真を返し、
58945832失敗時には偽を返します。
58955833L<perlipc/"Sockets: Client/Server Communication">の例を参照してください。
58965834
58975835=item local EXPR
58985836X<local>
58995837
59005838=begin original
59015839
59025840You really probably want to be using C<my> instead, because C<local> isn't
59035841what most people think of as "local". See
59045842L<perlsub/"Private Variables via my()"> for details.
59055843
59065844=end original
59075845
59085846あなたはが本当に望んでいるのは C<my> の方でしょう。
59095847C<local> はほとんどの人々が「ローカル」と考えるものと違うからです。
59105848詳細は L<perlsub/"Private Variables via my()"> を参照してください。
59115849
59125850=begin original
59135851
59145852A local modifies the listed variables to be local to the enclosing
59155853block, file, or eval. If more than one value is listed, the list must
59165854be placed in parentheses. See L<perlsub/"Temporary Values via local()">
59175855for details, including issues with tied arrays and hashes.
59185856
59195857=end original
59205858
59215859"local" はリストアップされた変数を、囲っているブロック、
59225860ファイル、eval の中で、ローカルなものにします。
59235861複数の値を指定する場合は、リストは括弧でくくらなければなりません。
59245862tie した配列とハッシュに関する事項を含む詳細については
59255863L<perlsub/"Temporary Values via local()"> を参照してください。
59265864
59275865=item localtime EXPR
59285866X<localtime> X<ctime>
59295867
59305868=item localtime
59315869
59325870=begin original
59335871
59345872Converts a time as returned by the time function to a 9-element list
59355873with the time analyzed for the local time zone. Typically used as
59365874follows:
59375875
59385876=end original
59395877
59405878time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、
594158799 要素の配列に変換します。
59425880通常は、以下のようにして使用します。
59435881
59445882 # 0 1 2 3 4 5 6 7 8
59455883 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
59465884 localtime(time);
59475885
59485886=begin original
59495887
59505888All list elements are numeric, and come straight out of the C `struct
59515889tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours
59525890of the specified time.
59535891
59545892=end original
59555893
59565894すべてのリスト要素は数値で、C の `struct tm' 構造体から
59575895直接持ってきます。
59585896C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。
59595897
59605898=begin original
59615899
59625900C<$mday> is the day of the month, and C<$mon> is the month itself, in
59635901the range C<0..11> with 0 indicating January and 11 indicating December.
59645902This makes it easy to get a month name from a list:
59655903
59665904=end original
59675905
59685906C<$mday> は月の何日目か、C<$mon> は月の値です。
59695907月の値は C<0..11> で、0 が 1 月、11 が 12 月です。
59705908これにより、リストから月の名前を得るのが簡単になります:
59715909
59725910 my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
59735911 print "$abbr[$mon] $mday";
59745912 # $mon=9, $mday=18 gives "Oct 18"
59755913
59765914=begin original
59775915
59785916C<$year> is the number of years since 1900, not just the last two digits
59795917of the year. That is, C<$year> is C<123> in year 2023. The proper way
59805918to get a complete 4-digit year is simply:
59815919
59825920=end original
59835921
59845922C<$year> は 1900 年からの年数であり、単に西暦の下 2 桁を表しているのでは
59855923ありません。
59865924つまり、$year が C<123> なら 2023 年です。
59875925完全な 4 桁の西暦を得るには単に以下のようにしてください:
59885926
59895927 $year += 1900;
59905928
59915929=begin original
59925930
59935931Otherwise you create non-Y2K-compliant programs--and you wouldn't want
59945932to do that, would you?
59955933
59965934=end original
59975935
59985936さもなければ、Y2K 問題を含んだプログラムを作ることになります --
59995937それはお望みじゃないでしょう?
60005938
60015939=begin original
60025940
60035941To get the last two digits of the year (e.g., '01' in 2001) do:
60045942
60055943=end original
60065944
60075945西暦の下 2 桁(2001 年では '01')がほしい場合は以下のようにします:
60085946
60095947 $year = sprintf("%02d", $year % 100);
60105948
60115949=begin original
60125950
60135951C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating
60145952Wednesday. C<$yday> is the day of the year, in the range C<0..364>
60155953(or C<0..365> in leap years.)
60165954
60175955=end original
60185956
60195957C<$wday> は曜日で、0 が日曜日、3 が水曜日です。
60205958C<$yday> はその年の何日目かで、C<0..364> の値を取ります
60215959(うるう年は C<0..365> です)。
60225960
60235961=begin original
60245962
60255963C<$isdst> is true if the specified time occurs during Daylight Saving
60265964Time, false otherwise.
60275965
60285966=end original
60295967
60305968C<$isdst> は指定された時刻が夏時間の場合は真、そうでなければ偽です。
60315969
60325970=begin original
60335971
6034If EXPR is omitted, C<localtime()> uses the current time (as returned
5972If EXPR is omitted, C<localtime()> uses the current time (C<localtime(time)>).
6035by time(3)).
60365973
60375974=end original
60385975
6039EXPR が省略されると、C<localtime()> は(time(3) によって返される)
5976EXPR が省略されると、C<localtime()> は現在時刻を使います
6040現在時刻を使います
5977(C<localtime(time())>
60415978
60425979=begin original
60435980
60445981In scalar context, C<localtime()> returns the ctime(3) value:
60455982
60465983=end original
60475984
60485985スカラコンテキストでは、C<localtime()> は ctime(3) の値を返します:
60495986
60505987 $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
60515988
60525989=begin original
60535990
60545991This scalar value is B<not> locale dependent but is a Perl builtin. For GMT
60555992instead of local time use the L</gmtime> builtin. See also the
60565993C<Time::Local> module (to convert the second, minutes, hours, ... back to
60575994the integer value returned by time()), and the L<POSIX> module's strftime(3)
60585995and mktime(3) functions.
60595996
60605997=end original
60615998
60625999スカラ値はロケール依存 B<ではなく>、Perl の組み込みの値です。
60636000ローカル時刻ではなく GMT がほしい場合は L</gmtime> 組み込み関数を
60646001使ってください。
60656002また、(秒、分、時…の形から、time() が返す値である
606660031970 年 1 月 1 日の真夜中からの秒数に変換する) C<Time::Local> モジュール
60676004及び POSIX モジュールで提供される strftime(3) と mktime(3) 関数も
60686005参照してください。
60696006
60706007=begin original
60716008
60726009To get somewhat similar but locale dependent date strings, set up your
60736010locale environment variables appropriately (please see L<perllocale>) and
60746011try for example:
60756012
60766013=end original
60776014
60786015似たような、しかしロケール依存の日付文字列がほしい場合は、
60796016ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、
60806017以下の例を試してください:
60816018
60826019 use POSIX qw(strftime);
60836020 $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
60846021 # or for GMT formatted appropriately for your locale:
60856022 $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
60866023
60876024=begin original
60886025
60896026Note that the C<%a> and C<%b>, the short forms of the day of the week
60906027and the month of the year, may not necessarily be three characters wide.
60916028
60926029=end original
60936030
60946031曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに
60956032注意してください。
60966033
60976034=begin original
60986035
60996036See L<perlport/localtime> for portability concerns.
61006037
61016038=end original
61026039
61036040移植性については L<perlport/localtime> を参照してください。
61046041
61056042=begin original
61066043
61076044The L<Time::gmtime> and L<Time::localtime> modules provides a convenient,
61086045by-name access mechanism to the gmtime() and localtime() functions,
61096046respectively.
61106047
61116048=end original
61126049
61136050L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ
61146051gmtime() 関数と localtime() 関数に、名前でアクセスする機構を提供する
61156052便利なモジュールです。
61166053
61176054=begin original
61186055
61196056For a comprehensive date and time representation look at the
61206057L<DateTime> module on CPAN.
61216058
61226059=end original
61236060
61246061包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
61256062参照してください。
61266063
61276064=item lock THING
61286065X<lock>
61296066
61306067=begin original
61316068
61326069This function places an advisory lock on a shared variable, or referenced
61336070object contained in I<THING> until the lock goes out of scope.
61346071
61356072=end original
61366073
61376074この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、
61386075スコープから出るまでアドバイサリロックを掛けます.
61396076
61406077=begin original
61416078
61426079lock() is a "weak keyword" : this means that if you've defined a function
61436080by this name (before any calls to it), that function will be called
61446081instead. (However, if you've said C<use threads>, lock() is always a
61456082keyword.) See L<threads>.
61466083
61476084=end original
61486085
61496086lock() は「弱いキーワード」です: もしユーザーが(呼び出し前に)
61506087この名前で関数を定義すると、定義された関数の方が呼び出されます
61516088(ただし、C<use threads> とすると、lock() は常にキーワードです)。
61526089L<threads> を参照してください。
61536090
61546091=item log EXPR
61556092X<log> X<logarithm> X<e> X<ln> X<base>
61566093
61576094=item log
61586095
61596096=begin original
61606097
61616098Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted,
61626099returns log of C<$_>. To get the log of another base, use basic algebra:
61636100The base-N log of a number is equal to the natural log of that number
61646101divided by the natural log of N. For example:
61656102
61666103=end original
61676104
61686105EXPR の (I<e> を底とする) 自然対数を返します。
61696106EXPR が省略されると、C<$_> の対数を返します。
61706107底の異なる対数を求めるためには、基礎代数を利用してください:
61716108ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。
61726109例:
61736110
61746111 sub log10 {
61756112 my $n = shift;
61766113 return log($n)/log(10);
61776114 }
61786115
61796116=begin original
61806117
61816118See also L</exp> for the inverse operation.
61826119
61836120=end original
61846121
61856122逆操作については L</exp> を参照して下さい。
61866123
61876124=item lstat EXPR
61886125X<lstat>
61896126
61906127=item lstat
61916128
61926129=begin original
61936130
61946131Does the same thing as the C<stat> function (including setting the
61956132special C<_> filehandle) but stats a symbolic link instead of the file
61966133the symbolic link points to. If symbolic links are unimplemented on
61976134your system, a normal C<stat> is done. For much more detailed
61986135information, please see the documentation for C<stat>.
61996136
62006137=end original
62016138
62026139(特別なファイルハンドルである C<_> の設定を含めて)
62036140C<stat> 関数と同じことをしますが、シンボリックリンクが
62046141指しているファイルではなく、シンボリックリンク自体の stat をとります。
62056142シンボリックリンクがシステムに実装されていないと、通常の C<stat> が行なわれます。
62066143さらにより詳細な情報については、L<stat> の文書を参照してください。
62076144
62086145=begin original
62096146
62106147If EXPR is omitted, stats C<$_>.
62116148
62126149=end original
62136150
62146151EXPR が省略されると、C<$_> の stat をとります。
62156152
62166153=item m//
62176154
62186155=begin original
62196156
6220The match operator. See L<perlop/"Regexp Quote-Like Operators">.
6157The match operator. See L<perlop>.
62216158
62226159=end original
62236160
62246161マッチ演算子です。
6225L<perlop/"Regexp Quote-Like Operators"> を参照してください。
6162L<perlop> を参照してください。
62266163
62276164=item map BLOCK LIST
62286165X<map>
62296166
62306167=item map EXPR,LIST
62316168
62326169=begin original
62336170
62346171Evaluates the BLOCK or EXPR for each element of LIST (locally setting
62356172C<$_> to each element) and returns the list value composed of the
62366173results of each such evaluation. In scalar context, returns the
62376174total number of elements so generated. Evaluates BLOCK or EXPR in
62386175list context, so each element of LIST may produce zero, one, or
62396176more elements in the returned value.
62406177
62416178=end original
62426179
62436180LIST の個々の要素に対して、BLOCK か EXPR を評価し
62446181(C<$_> は、ローカルに個々の要素が設定されます) 、
62456182それぞれの評価結果からなるリスト値が返されます。
62466183スカラコンテキストでは、生成された要素の数を返します。
62476184BLOCK や EXPR をリストコンテキストで評価しますので、LIST の
62486185個々の要素によって作られる、返り値であるリストの要素数は、
624961860 個の場合もあれば、複数の場合もあります。
62506187
62516188 @chars = map(chr, @nums);
62526189
62536190=begin original
62546191
62556192translates a list of numbers to the corresponding characters. And
62566193
62576194=end original
62586195
62596196は、数のリストを対応する文字に変換します。
62606197また:
62616198
62626199 %hash = map { get_a_key_for($_) => $_ } @array;
62636200
62646201=begin original
62656202
62666203is just a funny way to write
62676204
62686205=end original
62696206
62706207は以下のものをちょっと変わった書き方で書いたものです。
62716208
62726209 %hash = ();
62736210 foreach (@array) {
62746211 $hash{get_a_key_for($_)} = $_;
62756212 }
62766213
62776214=begin original
62786215
62796216Note that C<$_> is an alias to the list value, so it can be used to
62806217modify the elements of the LIST. While this is useful and supported,
62816218it can cause bizarre results if the elements of LIST are not variables.
62826219Using a regular C<foreach> loop for this purpose would be clearer in
62836220most cases. See also L</grep> for an array composed of those items of
62846221the original list for which the BLOCK or EXPR evaluates to true.
62856222
62866223=end original
62876224
62886225C<$_> は、LIST の値へのエイリアスですので、LIST の要素を
62896226変更するために使うことができます。
62906227これは、便利でサポートされていますが、
62916228LIST の要素が変数でないと、おかしな結果になります。
62926229この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は
62936230より明確になります。
62946231BLOCK や EXPR が真になる元のリストの要素からなる配列については、
62956232L</grep> も参照してください。
62966233
62976234=begin original
62986235
62996236If C<$_> is lexical in the scope where the C<map> appears (because it has
63006237been declared with C<my $_>), then, in addition to being locally aliased to
63016238the list elements, C<$_> keeps being lexical inside the block; that is, it
63026239can't be seen from the outside, avoiding any potential side-effects.
63036240
63046241=end original
63056242
63066243(C<my $_> として宣言されることによって) C<$_> が C<map> が現れるスコープ内で
63076244レキシカルな場合は、ローカルではリスト要素へのエイリアスであることに加えて、
63086245C<$_> はブロック内でレキシカルでありつづけます; つまり、外側からは見えず、
63096246起こりうる副作用を回避します。
63106247
63116248=begin original
63126249
63136250C<{> starts both hash references and blocks, so C<map { ...> could be either
63146251the start of map BLOCK LIST or map EXPR, LIST. Because perl doesn't look
63156252ahead for the closing C<}> it has to take a guess at which its dealing with
63166253based what it finds just after the C<{>. Usually it gets it right, but if it
63176254doesn't it won't realize something is wrong until it gets to the C<}> and
63186255encounters the missing (or unexpected) comma. The syntax error will be
63196256reported close to the C<}> but you'll need to change something near the C<{>
63206257such as using a unary C<+> to give perl some help:
63216258
63226259=end original
63236260
63246261C<{> はハッシュリファレンスとブロックの両方の開始文字なので、
63256262C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。
63266263perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て
63276264どちらとして扱うかを推測します。
63286265通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで
63296266カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに
63306267気付きません。
63316268C<}> の近くで文法エラーが出ますが、perl を助けるために単項の C<+> を
63326269使うというように、C<{> の近くの何かを変更する必要があります。
63336270
63346271 %hash = map { "\L$_", 1 } @array # perl guesses EXPR. wrong
63356272 %hash = map { +"\L$_", 1 } @array # perl guesses BLOCK. right
63366273 %hash = map { ("\L$_", 1) } @array # this also works
63376274 %hash = map { lc($_), 1 } @array # as does this.
63386275 %hash = map +( lc($_), 1 ), @array # this is EXPR and works!
63396276
63406277 %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
63416278
63426279=begin original
63436280
63446281or to force an anon hash constructor use C<+{>:
63456282
63466283=end original
63476284
63486285または C<+{> を使って無名ハッシュコンストラクタを強制します:
63496286
63506287 @hashes = map +{ lc($_), 1 }, @array # EXPR, so needs , at end
63516288
63526289=begin original
63536290
63546291and you get list of anonymous hashes each with only 1 entry.
63556292
63566293=end original
63576294
63586295こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。
63596296
63606297=item mkdir FILENAME,MASK
63616298X<mkdir> X<md> X<directory, create>
63626299
63636300=item mkdir FILENAME
63646301
63656302=item mkdir
63666303
63676304=begin original
63686305
63696306Creates the directory specified by FILENAME, with permissions
63706307specified by MASK (as modified by C<umask>). If it succeeds it
63716308returns true, otherwise it returns false and sets C<$!> (errno).
63726309If omitted, MASK defaults to 0777. If omitted, FILENAME defaults
63736310to C<$_>.
63746311
63756312=end original
63766313
63776314FILENAME で指定したディレクトリを、MASK で指定した許可モード(を
63786315C<umask> で修正したもの) で作成します。
63796316成功時には真を返し、失敗時には偽を返して C<$!> (errno) を設定します。
63806317MASK を省略すると、0777 とみなします。
63816318FILENAME を省略すると、C<$_> を使います。
63826319
63836320=begin original
63846321
63856322In general, it is better to create directories with permissive MASK,
63866323and let the user modify that with their C<umask>, than it is to supply
63876324a restrictive MASK and give the user no way to be more permissive.
63886325The exceptions to this rule are when the file or directory should be
63896326kept private (mail files, for instance). The perlfunc(1) entry on
63906327C<umask> discusses the choice of MASK in more detail.
63916328
63926329=end original
63936330
63946331一般的に、制限された MASK を使ってユーザーがより寛容にする方法を
63956332与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の C<umask> で
63966333修正するようにした方がよいです。
63976334例外は、(例えばメールファイルのような)プライベートに保つべきファイルや
63986335ディレクトリを書く場合です。
63996336perlfunc(1) の C<umask> で、MASK の選択に関して詳細に議論しています。
64006337
64016338=begin original
64026339
64036340Note that according to the POSIX 1003.1-1996 the FILENAME may have any
64046341number of trailing slashes. Some operating and filesystems do not get
64056342this right, so Perl automatically removes all trailing slashes to keep
64066343everyone happy.
64076344
64086345=end original
64096346
64106347POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを
64116348つけることができます。
64126349このようには動かない OS やファイルシステムもあるので、Perl はみんなが
64136350幸せになれるように、自動的に末尾のスラッシュを削除します。
64146351
64156352=begin original
64166353
64176354In order to recursively create a directory structure look at
64186355the C<mkpath> function of the L<File::Path> module.
64196356
64206357=end original
64216358
64226359ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの
64236360C<makepath> 関数を参照してください。
64246361
64256362=item msgctl ID,CMD,ARG
64266363X<msgctl>
64276364
64286365=begin original
64296366
64306367Calls the System V IPC function msgctl(2). You'll probably have to say
64316368
64326369=end original
64336370
64346371System V IPC 関数 msgctl を呼び出します。正しい定数定義を得るために、まず
64356372
64366373 use IPC::SysV;
64376374
64386375=begin original
64396376
64406377first to get the correct constant definitions. If CMD is C<IPC_STAT>,
64416378then ARG must be a variable that will hold the returned C<msqid_ds>
64426379structure. Returns like C<ioctl>: the undefined value for error,
64436380C<"0 but true"> for zero, or the actual return value otherwise. See also
64446381L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::Semaphore> documentation.
64456382
64466383=end original
64476384
64486385と宣言する必要があるでしょう。
64496386CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を
64506387納める変数でなければなりません。
64516388C<ioctl> と同じように、エラー時には未定義値、
64526389ゼロのときは C<"0 but true">、それ以外なら、その値そのものを返します。
64536390L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。
64546391
64556392=item msgget KEY,FLAGS
64566393X<msgget>
64576394
64586395=begin original
64596396
64606397Calls the System V IPC function msgget(2). Returns the message queue
64616398id, or the undefined value if there is an error. See also
64626399L<perlipc/"SysV IPC"> and C<IPC::SysV> and C<IPC::Msg> documentation.
64636400
64646401=end original
64656402
64666403System V IPC 関数 msgget を呼び出します。
64676404メッセージキューの ID か、エラー時には未定義値を返します。
64686405L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Msg> も参照してください。
64696406
64706407=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
64716408X<msgrcv>
64726409
64736410=begin original
64746411
64756412Calls the System V IPC function msgrcv to receive a message from
64766413message queue ID into variable VAR with a maximum message size of
64776414SIZE. Note that when a message is received, the message type as a
64786415native long integer will be the first thing in VAR, followed by the
64796416actual message. This packing may be opened with C<unpack("l! a*")>.
64806417Taints the variable. Returns true if successful, or false if there is
64816418an error. See also L<perlipc/"SysV IPC">, C<IPC::SysV>, and
64826419C<IPC::SysV::Msg> documentation.
64836420
64846421=end original
64856422
64866423System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、
64876424変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。
64886425メッセージが受信された時、ネイティブな long 整数のメッセージタイプが
64896426VAR の先頭となり、実際のメッセージが続きます。
64906427このパッキングは C<unpack("l! a*")> で展開できます。
64916428変数は汚染されます。
64926429成功時には真を返し、エラー時には偽を返します。
64936430L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Msg> も参照してください。
64946431
64956432=item msgsnd ID,MSG,FLAGS
64966433X<msgsnd>
64976434
64986435=begin original
64996436
65006437Calls the System V IPC function msgsnd to send the message MSG to the
65016438message queue ID. MSG must begin with the native long integer message
65026439type, and be followed by the length of the actual message, and finally
65036440the message itself. This kind of packing can be achieved with
65046441C<pack("l! a*", $type, $message)>. Returns true if successful,
65056442or false if there is an error. See also C<IPC::SysV>
65066443and C<IPC::SysV::Msg> documentation.
65076444
65086445=end original
65096446
65106447System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に
65116448メッセージ MSG を送信します。
65126449MSG の先頭は、ネイティブなlong 整数のメッセージタイプでなければならず、
65136450メッセージの長さ、メッセージ本体と続きます。
65146451これは、C<pack("l! a*", $type, $message)> として生成できます。
65156452成功時には真を、エラー時には偽を返します。
65166453C<IPC::SysV> と C<IPC::SysV::Msg> も参照してください。
65176454
65186455=item my EXPR
65196456X<my>
65206457
65216458=item my TYPE EXPR
65226459
65236460=item my EXPR : ATTRS
65246461
65256462=item my TYPE EXPR : ATTRS
65266463
65276464=begin original
65286465
65296466A C<my> declares the listed variables to be local (lexically) to the
65306467enclosing block, file, or C<eval>. If more than one value is listed,
65316468the list must be placed in parentheses.
65326469
65336470=end original
65346471
65356472C<my> はリストアップされた変数を、囲っているブロック、ファイル、
65366473C<eval> の中でローカルな (レキシカルな) ものにします。
65376474複数の値を並べる場合には、括弧で括る必要があります。
65386475
65396476=begin original
65406477
65416478The exact semantics and interface of TYPE and ATTRS are still
65426479evolving. TYPE is currently bound to the use of C<fields> pragma,
65436480and attributes are handled using the C<attributes> pragma, or starting
65446481from Perl 5.8.0 also via the C<Attribute::Handlers> module. See
65456482L<perlsub/"Private Variables via my()"> for details, and L<fields>,
65466483L<attributes>, and L<Attribute::Handlers>.
65476484
65486485=end original
65496486
65506487TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
65516488現在のところ、TYPE は C<fields> プラグマの使用と結び付けられていて、
65526489属性は C<attributes> プラグマか、Perl 5.8.0 からは
65536490C<Attribute::Handlers> モジュールと結び付けられています。
65546491詳しくはL<perlsub/"Private Variables via my()">, L<fields>,
65556492L<attributes>, L<Attribute::Handlers> を参照してください。
65566493
65576494=item next LABEL
65586495X<next> X<continue>
65596496
65606497=item next
65616498
65626499=begin original
65636500
65646501The C<next> command is like the C<continue> statement in C; it starts
65656502the next iteration of the loop:
65666503
65676504=end original
65686505
65696506C<next> コマンドは、C での C<continue> 文のようなもので、
65706507ループの次の繰り返しを開始します:
65716508
65726509 LINE: while (<STDIN>) {
65736510 next LINE if /^#/; # discard comments
65746511 #...
65756512 }
65766513
65776514=begin original
65786515
65796516Note that if there were a C<continue> block on the above, it would get
65806517executed even on discarded lines. If the LABEL is omitted, the command
65816518refers to the innermost enclosing loop.
65826519
65836520=end original
65846521
65856522C<continue> ブロックが存在すれば、たとえ捨てられる行に
65866523あっても、それが実行されます。
65876524LABEL が省略されると、このコマンドはもっとも内側のループを参照します。
65886525
65896526=begin original
65906527
65916528C<next> cannot be used to exit a block which returns a value such as
65926529C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit
65936530a grep() or map() operation.
65946531
65956532=end original
65966533
65976534C<next> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
65986535ブロックから抜けるのには使えません。
65996536また、grep() や map() 操作から抜けるのに使うべきではありません。
66006537
66016538=begin original
66026539
66036540Note that a block by itself is semantically identical to a loop
66046541that executes once. Thus C<next> will exit such a block early.
66056542
66066543=end original
66076544
66086545ブロック自身は一回だけ実行されるループと文法的に同一であることに
66096546注意してください。
66106547従って、C<next> はそのようなブロックから早く抜けるのに使えます。
66116548
66126549=begin original
66136550
66146551See also L</continue> for an illustration of how C<last>, C<next>, and
66156552C<redo> work.
66166553
66176554=end original
66186555
66196556C<last>, C<next>, C<redo> がどのように働くかについては
66206557L</continue> も参照して下さい。
66216558
66226559=item no Module VERSION LIST
66236560X<no>
66246561
66256562=item no Module VERSION
66266563
66276564=item no Module LIST
66286565
66296566=item no Module
66306567
66316568=item no VERSION
66326569
66336570=begin original
66346571
66356572See the C<use> function, of which C<no> is the opposite.
66366573
66376574=end original
66386575
66396576L<use> 関数を参照してください。C<no> は、その逆を行なうものです。
66406577
66416578=item oct EXPR
66426579X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin>
66436580
66446581=item oct
66456582
66466583=begin original
66476584
66486585Interprets EXPR as an octal string and returns the corresponding
66496586value. (If EXPR happens to start off with C<0x>, interprets it as a
66506587hex string. If EXPR starts off with C<0b>, it is interpreted as a
66516588binary string. Leading whitespace is ignored in all three cases.)
66526589The following will handle decimal, binary, octal, and hex in the standard
66536590Perl or C notation:
66546591
66556592=end original
66566593
66576594EXPR を 8 進数文字列と解釈して、対応する値を返します。
66586595(EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。
66596596EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。
66606597どの場合でも、先頭の空白は無視されます。)
66616598以下の例は、標準的な Perl や C の記法での
6662659910 進数、2 進数、8 進数、16 進数を扱います:
66636600
66646601 $val = oct($val) if $val =~ /^0/;
66656602
66666603=begin original
66676604
66686605If EXPR is omitted, uses C<$_>. To go the other way (produce a number
66696606in octal), use sprintf() or printf():
66706607
66716608=end original
66726609
66736610EXPR を省略すると、C<$_> を使用します。
66746611(8 進数を扱う)その他の方法としては sprintf() または printf()があります。
66756612
66766613 $perms = (stat("filename"))[2] & 07777;
66776614 $oct_perms = sprintf "%lo", $perms;
66786615
66796616=begin original
66806617
66816618The oct() function is commonly used when a string such as C<644> needs
66826619to be converted into a file mode, for example. (Although perl will
66836620automatically convert strings into numbers as needed, this automatic
66846621conversion assumes base 10.)
66856622
66866623=end original
66876624
66886625oct() 関数は例えば、 C<644> といった文字列をファイルモードに変換する時に
66896626よく使います。
66906627(Perl は必要に応じて自動的に文字列を数値に変換しますが、
66916628この自動変換は十進数を仮定します。)
66926629
66936630=item open FILEHANDLE,EXPR
66946631X<open> X<pipe> X<file, open> X<fopen>
66956632
66966633=item open FILEHANDLE,MODE,EXPR
66976634
66986635=item open FILEHANDLE,MODE,EXPR,LIST
66996636
67006637=item open FILEHANDLE,MODE,REFERENCE
67016638
67026639=item open FILEHANDLE
67036640
67046641=begin original
67056642
67066643Opens the file whose filename is given by EXPR, and associates it with
67076644FILEHANDLE.
67086645
67096646=end original
67106647
67116648EXPR で与えられたファイル名のファイルを開き、FILEHANDLE と結び付けます。
67126649
67136650=begin original
67146651
6715Simple examples to open a file for reading:
6716
6717=end original
6718
6719読み込みのためにファイルを開くための簡単な例は以下のもので:
6720
6721 open(my $fh, '<', "input.txt") or die $!;
6722
6723=begin original
6724
6725and for writing:
6726
6727=end original
6728
6729書き込み用は以下のものです:
6730
6731 open(my $fh, '>', "output.txt") or die $!;
6732
6733=begin original
6734
67356652(The following is a comprehensive reference to open(): for a gentler
67366653introduction you may consider L<perlopentut>.)
67376654
67386655=end original
67396656
67406657(以下は総合的な open() のリファレンスです: より親切な説明については
67416658L<perlopentut> を参照してください。)
67426659
67436660=begin original
67446661
67456662If FILEHANDLE is an undefined scalar variable (or array or hash element)
67466663the variable is assigned a reference to a new anonymous filehandle,
67476664otherwise if FILEHANDLE is an expression, its value is used as the name of
67486665the real filehandle wanted. (This is considered a symbolic reference, so
67496666C<use strict 'refs'> should I<not> be in effect.)
67506667
67516668=end original
67526669
67536670FILEHANDLE が未定義のスカラ変数(または配列かハッシュの要素)の場合、その
67546671変数は新しい無名ファイルハンドルへのリファレンスが代入され、
67556672さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の
67566673ファイルハンドルの名前として使います。
67576674(これはシンボリックリファレンスとして扱われるので、
67586675C<use strict 'refs'> の影響を I<受けません>。)
67596676
67606677=begin original
67616678
67626679If EXPR is omitted, the scalar variable of the same name as the
67636680FILEHANDLE contains the filename. (Note that lexical variables--those
67646681declared with C<my>--will not work for this purpose; so if you're
67656682using C<my>, specify EXPR in your call to open.)
67666683
67676684=end original
67686685
67696686EXPR が省略された場合、FILEHANDLE と同じ名前のスカラ変数にファイル名が
67706687入っています。
67716688(レキシカル変数 -- C<my> で宣言されたもの -- はこの用途には使えないことに
67726689注意してください; 従って、C<my> を使っている場合は、open を呼び出すときに
67736690EXPR を指定してください。)
67746691
67756692=begin original
67766693
67776694If three or more arguments are specified then the mode of opening and
67786695the file name are separate. If MODE is C<< '<' >> or nothing, the file
67796696is opened for input. If MODE is C<< '>' >>, the file is truncated and
67806697opened for output, being created if necessary. If MODE is C<<< '>>' >>>,
67816698the file is opened for appending, again being created if necessary.
67826699
67836700=end original
67846701
678567023 以上の引数が指定された場合、開く時のモードとファイル名は分離されます。
67866703MODE が C<< '<' >> か空の場合、ファイルは入力用に開かれます。
67876704MODE が C<< '>' >> の場合、ファイルは切り詰められて出力用に開かれ、
67886705必要なら作成されます。
67896706MODE が C<<< '>>' >>> の場合、ファイルは追加用に開かれ、やはり必要なら
67906707作成されます。
67916708
67926709=begin original
67936710
67946711You can put a C<'+'> in front of the C<< '>' >> or C<< '<' >> to
67956712indicate that you want both read and write access to the file; thus
67966713C<< '+<' >> is almost always preferred for read/write updates--the C<<
67976714'+>' >> mode would clobber the file first. You can't usually use
67986715either read-write mode for updating textfiles, since they have
67996716variable length records. See the B<-i> switch in L<perlrun> for a
68006717better approach. The file is created with permissions of C<0666>
68016718modified by the process' C<umask> value.
68026719
68036720=end original
68046721
68056722ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、
68066723C<< '>' >> や C<< '<' >> の前に C<'+'> を付けることができます:
68076724従って、ほとんど常に C<< '+<' >> が読み書き更新のために使われます --
68086725C<< '+>' >> モードはまずファイルを上書きします。
68096726普通はこれらの読み書きモードをテキストファイルの更新のためには使えません;
68106727なぜなら可変長のレコードで構成されているからです。
68116728よりよい手法については L<perlrun> の B<-i> オプションを参照してください。
68126729ファイルは C<0666> をプロセスの C<umask> 値で修正したパーミッションで
68136730作成されます。
68146731
68156732=begin original
68166733
68176734These various prefixes correspond to the fopen(3) modes of C<'r'>,
68186735C<'r+'>, C<'w'>, C<'w+'>, C<'a'>, and C<'a+'>.
68196736
68206737=end original
68216738
68226739これらの様々な前置詞は fopen(3) の C<'r'>, C<'r+'>,
68236740C<'w'>, C<'w+'>, C<'a'>, C<'a+'> のモードに対応します。
68246741
68256742=begin original
68266743
68276744In the 2-arguments (and 1-argument) form of the call the mode and
68286745filename should be concatenated (in this order), possibly separated by
68296746spaces. It is possible to omit the mode in these forms if the mode is
68306747C<< '<' >>.
68316748
68326749=end original
68336750
683467512 引数(と 1 引数) の形式ではモードとファイル名は(この順番で)
68356752結合されます(空白によって分割されているかもしれません)。
68366753この形式で、モードが C<< '<' >> の場合はモードを省略できます。
68376754
68386755=begin original
68396756
68406757If the filename begins with C<'|'>, the filename is interpreted as a
68416758command to which output is to be piped, and if the filename ends with a
68426759C<'|'>, the filename is interpreted as a command which pipes output to
68436760us. See L<perlipc/"Using open() for IPC">
68446761for more examples of this. (You are not allowed to C<open> to a command
68456762that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>,
68466763and L<perlipc/"Bidirectional Communication with Another Process">
68476764for alternatives.)
68486765
68496766=end original
68506767
68516768ファイル名の先頭に C<'|'> を付けると、
68526769そのファイル名をコマンドとして解釈し、ファイルハンドルへの
68536770出力がパイプを通じて、そのコマンドへ入力されます。
68546771逆にファイル名の最後に C<'|'> を付けた場合には、
68556772同様にファイル名をコマンドと解釈し、そのコマンドの出力が
68566773パイプを通じて、ファイルハンドルから入力として
68576774読み込むことができるようになります。
68586775これに関する例については L<perlipc/"Using open() for IPC"> を参照してください。
68596776(C<open> を入出力両用にパイプすることは出来ませんが
68606777代替案としては L<IPC::Open2>, L<IPC::Open3>,
68616778L<perlipc/"Bidirectional Communication with Another Process">
68626779を参照してください。)
68636780
68646781=begin original
68656782
68666783For three or more arguments if MODE is C<'|-'>, the filename is
68676784interpreted as a command to which output is to be piped, and if MODE
68686785is C<'-|'>, the filename is interpreted as a command which pipes
68696786output to us. In the 2-arguments (and 1-argument) form one should
68706787replace dash (C<'-'>) with the command.
68716788See L<perlipc/"Using open() for IPC"> for more examples of this.
68726789(You are not allowed to C<open> to a command that pipes both in I<and>
68736790out, but see L<IPC::Open2>, L<IPC::Open3>, and
68746791L<perlipc/"Bidirectional Communication"> for alternatives.)
68756792
68766793=end original
68776794
687867953 引数以上の形式で
68796796MODE が C<'|-'> の場合、ファイル名は出力がパイプされるコマンドとして
68806797解釈され、MODE が C<'-|'> の場合、ファイル名は出力がこちらに
68816798パイプされるコマンドとして解釈されます。
688267992 引数(と 1 引数) の形式ではハイフン(C<'-'>)をコマンドの代わりに
68836800使えます。
68846801これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
68856802参照してください。
68866803(C<open> を入出力 I<両用> にパイプすることは出来ませんが
68876804代替案としては L<IPC::Open2>, L<IPC::Open3>,
68886805L<perlipc/"Bidirectional Communication"> を参照してください。)
68896806
68906807=begin original
68916808
68926809In the three-or-more argument form of pipe opens, if LIST is specified
68936810(extra arguments after the command name) then LIST becomes arguments
68946811to the command invoked if the platform supports it. The meaning of
68956812C<open> with more than three arguments for non-pipe modes is not yet
68966813specified. Experimental "layers" may give extra LIST arguments
68976814meaning.
68986815
68996816=end original
69006817
69016818パイプでの 3 つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が
69026819指定されると、プラットフォームが対応していれば、LIST は起動される
69036820コマンドへの引数となります。
69046821パイプモードではない C<open> での 3 つ以上の引数の意味はまだ未定義です。
69056822実験的な「層」は追加の LIST 引数の意味を与えます。
69066823
69076824=begin original
69086825
69096826In the 2-arguments (and 1-argument) form opening C<'-'> opens STDIN
69106827and opening C<< '>-' >> opens STDOUT.
69116828
69126829=end original
69136830
691468312 引数(と 1 引数)で C<'-'> を open すると STDIN がオープンされ、
69156832C<< '>-' >> を open すると STDOUT がオープンされます。
69166833
69176834=begin original
69186835
69196836You may use the three-argument form of open to specify IO "layers"
69206837(sometimes also referred to as "disciplines") to be applied to the handle
69216838that affect how the input and output are processed (see L<open> and
69226839L<PerlIO> for more details). For example
69236840
69246841=end original
69256842
69266843open の 3 引数形式では、どのように入出力が処理されるかに影響を与える
69276844IO 「層」(「ディシプリン」とも呼ばれます)を指定できます
69286845(詳細については L<open> と L<PerlIO> を参照してください)。
69296846例えば:
69306847
6931 open(my $fh, "<:encoding(UTF-8)", "file")
6848 open(FH, "<:encoding(UTF-8)", "file")
69326849
69336850=begin original
69346851
69356852will open the UTF-8 encoded file containing Unicode characters,
69366853see L<perluniintro>. Note that if layers are specified in the
69376854three-arg form then default layers stored in ${^OPEN} (see L<perlvar>;
69386855usually set by the B<open> pragma or the switch B<-CioD>) are ignored.
69396856
69406857=end original
69416858
69426859は、Unicode 文字を含む UTF-8 エンコードされたファイルを開きます;
69436860L<perluniintro> を参照してください。
694468613 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください;
69456862通常はC<open> プラグマか B<-CioD> オプションでセットされます)
69466863に保存されたデフォルト層は無視されることに注意してください。
69476864
69486865=begin original
69496866
69506867Open returns nonzero upon success, the undefined value otherwise. If
69516868the C<open> involved a pipe, the return value happens to be the pid of
69526869the subprocess.
69536870
69546871=end original
69556872
69566873open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。
69576874パイプに関る C<open> のときには、返り値はサブプロセスの pid となります。
69586875
69596876=begin original
69606877
69616878If you're running Perl on a system that distinguishes between text
69626879files and binary files, then you should check out L</binmode> for tips
69636880for dealing with this. The key distinction between systems that need
69646881C<binmode> and those that don't is their text file formats. Systems
69656882like Unix, Mac OS, and Plan 9, which delimit lines with a single
69666883character, and which encode that character in C as C<"\n">, do not
69676884need C<binmode>. The rest need it.
69686885
69696886=end original
69706887
69716888テキストファイルとバイナリファイルを区別するシステムで Perl を実行している
69726889場合、これを扱うための小技のために L</binmode> をチェックするべきです。
69736890動作させているシステムで C<binmode> が必要か不要化を区別する鍵は、テキスト
69746891ファイルの形式です。
69756892Unix, Mac OS, Plan 9 といった、行の境界を 1 文字で表現し、それが C では
69766893C<"\n"> でエンコードされる場合、C<binmode> は不要です。
69776894それ以外では必要です。
69786895
69796896=begin original
69806897
69816898When opening a file, it's usually a bad idea to continue normal execution
69826899if the request failed, so C<open> is frequently used in connection with
69836900C<die>. Even if C<die> won't do what you want (say, in a CGI script,
69846901where you want to make a nicely formatted error message (but there are
69856902modules that can help with that problem)) you should always check
69866903the return value from opening a file. The infrequent exception is when
69876904working with an unopened filehandle is actually what you want to do.
69886905
69896906=end original
69906907
69916908ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは
69926909普通は悪い考えですので、C<open> はしばしば C<die> と結び付けられて
69936910使われます。
69946911望むものが C<die> でない場合(例えば、CGI スクリプト のように
69956912きれいにフォーマットされたエラーメッセージを作りたい場合
69966913(但しこの問題を助けるモジュールがあります))でも、
69976914ファイルを開いた時の帰り値を常にチェックするべきです。
69986915めったにない例外は、開いていないファイルハンドルを使うのが
69996916本当にやりたいことの場合です。
70006917
70016918=begin original
70026919
70036920As a special case the 3-arg form with a read/write mode and the third
70046921argument being C<undef>:
70056922
70066923=end original
70076924
70086925特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が
70096926C<undef> の場合:
70106927
7011 open(my $tmp, "+>", undef) or die ...
6928 open(TMP, "+>", undef) or die ...
70126929
70136930=begin original
70146931
70156932opens a filehandle to an anonymous temporary file. Also using "+<"
70166933works for symmetry, but you really should consider writing something
70176934to the temporary file first. You will need to seek() to do the
70186935reading.
70196936
70206937=end original
70216938
70226939無名一時ファイルとしてファイルハンドルを開きます。
70236940また "+<" も対称性のために動作しますが、
70246941一時ファイルにはまず何かを書き込みたいはずです。
70256942読み込みを行うためには seek() が必要です。
70266943
70276944=begin original
70286945
70296946Since v5.8.0, perl has built using PerlIO by default. Unless you've
70306947changed this (i.e. Configure -Uuseperlio), you can open file handles to
70316948"in memory" files held in Perl scalars via:
70326949
70336950=end original
70346951
70356952v5.8.0 から、perl はデフォルトで PerlIO を使ってビルドされています。
70366953これ(Configure -Uuseperlio)を変更していない限り、
70376954以下のようにして、Perl スカラに保持されている「オンメモリの」
70386955ファイルをファイルハンドルを開くことができます:
70396956
70406957 open($fh, '>', \$variable) || ..
70416958
70426959=begin original
70436960
70446961Though if you try to re-open C<STDOUT> or C<STDERR> as an "in memory"
70456962file, you have to close it first:
70466963
70476964=end original
70486965
70496966しかし、もし C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして
70506967再び開きたい場合は、先にそれを閉じる必要があります:
70516968
70526969 close STDOUT;
70536970 open STDOUT, '>', \$variable or die "Can't open STDOUT: $!";
70546971
70556972=begin original
70566973
70576974Examples:
70586975
70596976=end original
70606977
70616978例:
70626979
70636980 $ARTICLE = 100;
70646981 open ARTICLE or die "Can't find article $ARTICLE: $!\n";
70656982 while (<ARTICLE>) {...
70666983
70676984 open(LOG, '>>/usr/spool/news/twitlog'); # (log is reserved)
70686985 # if the open fails, output is discarded
70696986
7070 open(my $dbase, '+<', 'dbase.mine') # open for update
6987 open(DBASE, '+<', 'dbase.mine') # open for update
70716988 or die "Can't open 'dbase.mine' for update: $!";
70726989
7073 open(my $dbase, '+<dbase.mine') # ditto
6990 open(DBASE, '+<dbase.mine') # ditto
70746991 or die "Can't open 'dbase.mine' for update: $!";
70756992
70766993 open(ARTICLE, '-|', "caesar <$article") # decrypt article
70776994 or die "Can't start caesar: $!";
70786995
70796996 open(ARTICLE, "caesar <$article |") # ditto
70806997 or die "Can't start caesar: $!";
70816998
70826999 open(EXTRACT, "|sort >Tmp$$") # $$ is our process id
70837000 or die "Can't start sort: $!";
70847001
70857002 # in memory files
70867003 open(MEMORY,'>', \$var)
70877004 or die "Can't open memory file: $!";
70887005 print MEMORY "foo!\n"; # output will end up in $var
70897006
70907007 # process argument list of files along with any includes
70917008
70927009 foreach $file (@ARGV) {
70937010 process($file, 'fh00');
70947011 }
70957012
70967013 sub process {
70977014 my($filename, $input) = @_;
70987015 $input++; # this is a string increment
70997016 unless (open($input, $filename)) {
71007017 print STDERR "Can't open $filename: $!\n";
71017018 return;
71027019 }
71037020
71047021 local $_;
71057022 while (<$input>) { # note use of indirection
71067023 if (/^#include "(.*)"/) {
71077024 process($1, $input);
71087025 next;
71097026 }
71107027 #... # whatever
71117028 }
71127029 }
71137030
71147031=begin original
71157032
71167033See L<perliol> for detailed info on PerlIO.
71177034
71187035=end original
71197036
71207037PerlIO に関する詳しい情報については L<perliol> を参照してください。
71217038
71227039=begin original
71237040
71247041You may also, in the Bourne shell tradition, specify an EXPR beginning
71257042with C<< '>&' >>, in which case the rest of the string is interpreted
71267043as the name of a filehandle (or file descriptor, if numeric) to be
7127duped (as C<dup(2)>) and opened. You may use C<&> after C<< > >>,
7044duped (as L<dup(2)>) and opened. You may use C<&> after C<< > >>,
71287045C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>.
71297046The mode you specify should match the mode of the original filehandle.
71307047(Duping a filehandle does not take into account any existing contents
71317048of IO buffers.) If you use the 3-arg form then you can pass either a
71327049number, the name of a filehandle or the normal "reference to a glob".
71337050
71347051=end original
71357052
71367053Bourne シェルの慣例にしたがって、EXPR の先頭に C<< '>&' >>
71377054を付けると、EXPR の残りの文字列をファイルハンドル名
7138(数字であれば、ファイル記述子) と解釈して、それを (C<dup(2)> によって)
7055(数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によって)
71397056複製してオープンします。
71407057C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>,
71417058C<< +< >>というモード指定に付けることができます。
71427059指定するモード指定は、もとのファイルハンドルのモードと
71437060合っていないといけません。
71447061(ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。)
714570623 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、
71467063通常の「グロブへのリファレンス」を渡します。
71477064
71487065=begin original
71497066
71507067Here is a script that saves, redirects, and restores C<STDOUT> and
71517068C<STDERR> using various methods:
71527069
71537070=end original
71547071
71557072C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します:
71567073
71577074 #!/usr/bin/perl
71587075 open my $oldout, ">&STDOUT" or die "Can't dup STDOUT: $!";
71597076 open OLDERR, ">&", \*STDERR or die "Can't dup STDERR: $!";
71607077
71617078 open STDOUT, '>', "foo.out" or die "Can't redirect STDOUT: $!";
71627079 open STDERR, ">&STDOUT" or die "Can't dup STDOUT: $!";
71637080
71647081 select STDERR; $| = 1; # make unbuffered
71657082 select STDOUT; $| = 1; # make unbuffered
71667083
71677084 print STDOUT "stdout 1\n"; # this works for
71687085 print STDERR "stderr 1\n"; # subprocesses too
71697086
71707087 open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!";
71717088 open STDERR, ">&OLDERR" or die "Can't dup OLDERR: $!";
71727089
71737090 print STDOUT "stdout 2\n";
71747091 print STDERR "stderr 2\n";
71757092
71767093=begin original
71777094
71787095If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
71797096or a filehandle, then Perl will do an equivalent of C's C<fdopen> of
7180that file descriptor (and not call C<dup(2)>); this is more
7097that file descriptor (and not call L<dup(2)>); this is more
71817098parsimonious of file descriptors. For example:
71827099
71837100=end original
71847101
71857102C<X> をファイル記述子の番号かファイルハンドルとして、
71867103C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する
7187C の C<fdopen> と同じことを行ないます(そして C<dup(2)> は呼び出しません);
7104C の C<fdopen> と同じことを行ないます(そして L<dup(2)> は呼び出しません);
71887105これはファイル記述子をより節約します。
71897106例:
71907107
71917108 # open for input, reusing the fileno of $fd
71927109 open(FILEHANDLE, "<&=$fd")
71937110
71947111=begin original
71957112
71967113or
71977114
71987115=end original
71997116
72007117または
72017118
72027119 open(FILEHANDLE, "<&=", $fd)
72037120
72047121=begin original
72057122
72067123or
72077124
72087125=end original
72097126
72107127または
72117128
72127129 # open for append, using the fileno of OLDFH
72137130 open(FH, ">>&=", OLDFH)
72147131
72157132=begin original
72167133
72177134or
72187135
72197136=end original
72207137
72217138または
72227139
72237140 open(FH, ">>&=OLDFH")
72247141
72257142=begin original
72267143
72277144Being parsimonious on filehandles is also useful (besides being
72287145parsimonious) for example when something is dependent on file
72297146descriptors, like for example locking using flock(). If you do just
72307147C<< open(A, '>>&B') >>, the filehandle A will not have the same file
72317148descriptor as B, and therefore flock(A) will not flock(B), and vice
72327149versa. But with C<< open(A, '>>&=B') >> the filehandles will share
72337150the same file descriptor.
72347151
72357152=end original
72367153
72377154ファイルハンドルを倹約することは、何かがファイル記述子に依存している場合、
72387155例えば flock() を使ったファイルロックといった場合に有用です
72397156(しかも倹約できます)。
72407157C<< open(A, '>>&B') >> とすると、ファイルハンドル A は B と同じ
72417158ファイル記述子にはならないので、flock(A) と flock(B) は別々になります。
72427159しかし C<< open(A, '>>&=B') >> ではファイルハンドルは同じファイル記述子を
72437160共有します。
72447161
72457162=begin original
72467163
72477164Note that if you are using Perls older than 5.8.0, Perl will be using
72487165the standard C libraries' fdopen() to implement the "=" functionality.
72497166On many UNIX systems fdopen() fails when file descriptors exceed a
72507167certain value, typically 255. For Perls 5.8.0 and later, PerlIO is
72517168most often the default.
72527169
72537170=end original
72547171
725571725.8.0 より前の Perl を使っている場合、"=" 機能の実装は
72567173標準 C ライブラリの fdopen() を使っています。
72577174多くの UNIX システムでは、fdopen() はファイル記述子がある値
72587175(典型的には 255)を超えた場合に失敗することが知られています。
725971765.8.0 以降の Perl では、ほとんどの場合 PerlIO がデフォルトです。
72607177
72617178=begin original
72627179
72637180You can see whether Perl has been compiled with PerlIO or not by
72647181running C<perl -V> and looking for C<useperlio=> line. If C<useperlio>
72657182is C<define>, you have PerlIO, otherwise you don't.
72667183
72677184=end original
72687185
72697186Perl が PerlIO つきでコンパイルされているかどうかを確認するには、
72707187C<perl -V> として C<useperlio=> の行を見ます。
72717188C<useperlio> が C<define> なら PerlIO を使っています。
72727189そうでなければ使っていません。
72737190
72747191=begin original
72757192
72767193If you open a pipe on the command C<'-'>, i.e., either C<'|-'> or C<'-|'>
72777194with 2-arguments (or 1-argument) form of open(), then
72787195there is an implicit fork done, and the return value of open is the pid
72797196of the child within the parent process, and C<0> within the child
72807197process. (Use C<defined($pid)> to determine whether the open was successful.)
72817198The filehandle behaves normally for the parent, but i/o to that
72827199filehandle is piped from/to the STDOUT/STDIN of the child process.
72837200In the child process the filehandle isn't opened--i/o happens from/to
72847201the new STDOUT or STDIN. Typically this is used like the normal
72857202piped open when you want to exercise more control over just how the
72867203pipe command gets executed, such as when you are running setuid, and
72877204don't want to have to scan shell commands for metacharacters.
72887205The following triples are more or less equivalent:
72897206
72907207=end original
72917208
729272092 引数(または 1 引数)の形の open() で
72937210C<'-|'> や C<'|-'> というふうに、C<'-'> というコマンドに
72947211パイプをオープンすると、fork が行なわれ、open の返り値として、
72957212親プロセスにはチャイルドプロセスの pid が、チャイルドプロセスには
72967213C<0> が返されます。
72977214(open が成功したかどうかは、
72987215C<defined($pid)> のようにして調べることができます。)
72997216親プロセスでは、このファイルハンドルは
73007217通常通りに動作しますが、行なわれる入出力は、
73017218チャイルドプロセスの STDIN/STDOUT にパイプされます。
73027219チャイルドプロセス側では、そのファイルハンドルは
73037220オープンされず、入出力は新しい STDOUT か STDIN に対して行なわれます。
73047221これは、setuid で実行して、シェルコマンドのメタ文字を
73057222検索させたくないような場合に、パイプコマンドの起動の仕方を
73067223制御したいとき、普通のパイプの open と同じように使います。
73077224以下の組み合わせは、だいたい同じものです:
73087225
73097226 open(FOO, "|tr '[a-z]' '[A-Z]'");
73107227 open(FOO, '|-', "tr '[a-z]' '[A-Z]'");
73117228 open(FOO, '|-') || exec 'tr', '[a-z]', '[A-Z]';
73127229 open(FOO, '|-', "tr", '[a-z]', '[A-Z]');
73137230
73147231 open(FOO, "cat -n '$file'|");
73157232 open(FOO, '-|', "cat -n '$file'");
73167233 open(FOO, '-|') || exec 'cat', '-n', $file;
73177234 open(FOO, '-|', "cat", '-n', $file);
73187235
73197236=begin original
73207237
73217238The last example in each block shows the pipe as "list form", which is
73227239not yet supported on all platforms. A good rule of thumb is that if
73237240your platform has true C<fork()> (in other words, if your platform is
73247241UNIX) you can use the list form.
73257242
73267243=end original
73277244
73287245それぞれのブロックの最後の例ではパイプを「リスト形式」にしていますが、
73297246これはまだ全てのプラットフォームで対応しているわけではなりません。
73307247よい経験則としては、もし実行しているプラットフォームで真の C<fork()> が
73317248あれば(言い換えると、プラットフォームが UNIX なら) リスト形式が使えます。
73327249
73337250=begin original
73347251
73357252See L<perlipc/"Safe Pipe Opens"> for more examples of this.
73367253
73377254=end original
73387255
73397256これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を参照して下さい。
73407257
73417258=begin original
73427259
73437260Beginning with v5.6.0, Perl will attempt to flush all files opened for
73447261output before any operation that may do a fork, but this may not be
73457262supported on some platforms (see L<perlport>). To be safe, you may need
73467263to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
73477264of C<IO::Handle> on any open handles.
73487265
73497266=end original
73507267
73517268v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
73527269fork を行う前にフラッシュしようとしますが、これに対応していない
73537270プラットフォームもあります(L<perlport> を参照してください)。
73547271安全のために、C<$|> (English モジュールでは $AUTOFLUSH) をセットするか、
73557272全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
7356呼び出す必要があるかもれません
7273呼び出すようにてください
73577274
73587275=begin original
73597276
73607277On systems that support a close-on-exec flag on files, the flag will
73617278be set for the newly opened file descriptor as determined by the value
73627279of $^F. See L<perlvar/$^F>.
73637280
73647281=end original
73657282
73667283ファイルに対する close-on-exec フラグをサポートしているシステムでは、
73677284フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
73687285セットされます。
73697286L<perlvar/$^F> を参照してください。
73707287
73717288=begin original
73727289
73737290Closing any piped filehandle causes the parent process to wait for the
73747291child to finish, and returns the status value in C<$?> and
73757292C<${^CHILD_ERROR_NATIVE}>.
73767293
73777294=end original
73787295
73797296パイプのファイルハンドルを close することで、
73807297親プロセスは、チャイルドプロセスの終了を待ち、C<$?> と
73817298C<${^CHILD_ERROR_NATIVE}> にステータス値を返します。
73827299
73837300=begin original
73847301
73857302The filename passed to 2-argument (or 1-argument) form of open() will
73867303have leading and trailing whitespace deleted, and the normal
73877304redirection characters honored. This property, known as "magic open",
73887305can often be used to good effect. A user could specify a filename of
73897306F<"rsh cat file |">, or you could change certain filenames as needed:
73907307
73917308=end original
73927309
739373102 引数(と 1 引数)の形の open() に渡されたファイル名は、
73947311はじめと終わりの空白が取り除かれ、
73957312通常のリダイレクト文字列を受け付けます。
73967313この機能は "magic open" として知られていますが、
73977314普通いい効果をもたらします。
73987315ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、
73997316特定のファイル名を必要に応じて変更できます。
74007317
74017318 $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
74027319 open(FH, $filename) or die "Can't open $filename: $!";
74037320
74047321=begin original
74057322
74067323Use 3-argument form to open a file with arbitrary weird characters in it,
74077324
74087325=end original
74097326
74107327妙な文字が含まれているようなファイル名をオープンするには、
741173283 引数の形を使います。
74127329
74137330 open(FOO, '<', $file);
74147331
74157332=begin original
74167333
74177334otherwise it's necessary to protect any leading and trailing whitespace:
74187335
74197336=end original
74207337
74217338あるいは、次のようにして、最初と最後の空白を保護します:
74227339
74237340 $file =~ s#^(\s)#./$1#;
74247341 open(FOO, "< $file\0");
74257342
74267343=begin original
74277344
74287345(this may not work on some bizarre filesystems). One should
74297346conscientiously choose between the I<magic> and 3-arguments form
74307347of open():
74317348
74327349=end original
74337350
74347351(これは奇妙なファイルシステムでは動作しないかもしれません)。
74357352open() の I<magic> と 3 引数形式を誠実に選択するべきです。
74367353
74377354 open IN, $ARGV[0];
74387355
74397356=begin original
74407357
74417358will allow the user to specify an argument of the form C<"rsh cat file |">,
74427359but will not work on a filename which happens to have a trailing space, while
74437360
74447361=end original
74457362
74467363とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、
74477364末尾にスペースがついてしまったファイル名では動作しません。一方:
74487365
74497366 open IN, '<', $ARGV[0];
74507367
74517368=begin original
74527369
74537370will have exactly the opposite restrictions.
74547371
74557372=end original
74567373
74577374はまったく逆の制限があります。
74587375
74597376=begin original
74607377
7461If you want a "real" C C<open> (see C<open(2)> on your system), then you
7378If you want a "real" C C<open> (see L<open(2)> on your system), then you
74627379should use the C<sysopen> function, which involves no such magic (but
74637380may use subtly different filemodes than Perl open(), which is mapped
74647381to C fopen()). This is
74657382another way to protect your filenames from interpretation. For example:
74667383
74677384=end original
74687385
7469もし「本当の」C 言語の C<open> (システムの C<open(2)> を参照してください)が
7386もし「本当の」C 言語の C<open> (システムの L<open(2)> を参照してください)が
74707387必要なら、このような副作用のない C<sysopen> 関数を使うべきです
74717388(ただし、C の fopen() に割り付けられる Perl の open() とは
74727389かすかに違うファイルモードを持ちます)。
74737390これはファイル名を解釈から守るもう一つの方法です。
74747391例えば:
74757392
74767393 use IO::Handle;
74777394 sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL)
74787395 or die "sysopen $path: $!";
74797396 $oldfh = select(HANDLE); $| = 1; select($oldfh);
74807397 print HANDLE "stuff $$\n";
74817398 seek(HANDLE, 0, 0);
74827399 print "File contains: ", <HANDLE>;
74837400
74847401=begin original
74857402
74867403Using the constructor from the C<IO::Handle> package (or one of its
74877404subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous
74887405filehandles that have the scope of whatever variables hold references to
74897406them, and automatically close whenever and however you leave that scope:
74907407
74917408=end original
74927409
74937410C<IO::Handle> パッケージ(または C<IO::File> や C<IO::Socket> といった
74947411サブパッケージ)のコンストラクタを使うことで、
74957412これらへのリファレンスを保持している変数のスコープを持ち、
74967413スコープから離れると自動的に閉じる無名ファイルハンドルを作成できます:
74977414
74987415 use IO::File;
74997416 #...
75007417 sub read_myfile_munged {
75017418 my $ALL = shift;
7502 my $handle = IO::File->new;
7419 my $handle = new IO::File;
75037420 open($handle, "myfile") or die "myfile: $!";
75047421 $first = <$handle>
75057422 or return (); # Automatically closed here.
75067423 mung $first or die "mung failed"; # Or here.
75077424 return $first, <$handle> if $ALL; # Or here.
75087425 $first; # Or here.
75097426 }
75107427
75117428=begin original
75127429
75137430See L</seek> for some details about mixing reading and writing.
75147431
75157432=end original
75167433
75177434読み書きを混ぜる場合の詳細については L</seek> を参照して下さい。
75187435
75197436=item opendir DIRHANDLE,EXPR
75207437X<opendir>
75217438
75227439=begin original
75237440
75247441Opens a directory named EXPR for processing by C<readdir>, C<telldir>,
75257442C<seekdir>, C<rewinddir>, and C<closedir>. Returns true if successful.
75267443DIRHANDLE may be an expression whose value can be used as an indirect
75277444dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined
75287445scalar variable (or array or hash element), the variable is assigned a
75297446reference to a new anonymous dirhandle.
75307447DIRHANDLEs have their own namespace separate from FILEHANDLEs.
75317448
75327449=end original
75337450
75347451C<readdir>、C<telldir>、C<seekdir>、C<rewinddir>、C<closedir> で
75357452処理するために、EXPR で指定された名前のディレクトリをオープンします。
75367453成功時には真を返します。
75377454DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ
75387455ハンドルの名前)となる式でも構いません。
75397456DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は
75407457新しい無名ディレクトリハンドルへのリファレンスが代入されます。
75417458DIRHANDLE は、FILEHANDLE とは別に名前空間を持っています。
75427459
7543=begin original
7544
7545See example at C<readdir>.
7546
7547=end original
7548
7549C<readdir> の例を参照してください。
7550
75517460=item ord EXPR
75527461X<ord> X<encoding>
75537462
75547463=item ord
75557464
75567465=begin original
75577466
75587467Returns the numeric (the native 8-bit encoding, like ASCII or EBCDIC,
75597468or Unicode) value of the first character of EXPR. If EXPR is omitted,
75607469uses C<$_>.
75617470
75627471=end original
75637472
75647473EXPR の最初の文字の数値としての(ASCII, EBCDIC, Unicode のような 8-bit
75657474ネイティブエンコーディングの)値を返します。
75667475EXPR を省略した場合には、C<$_> を使用します。
75677476
75687477=begin original
75697478
75707479For the reverse, see L</chr>.
75717480See L<perlunicode> for more about Unicode.
75727481
75737482=end original
75747483
75757484逆のことをするには L</chr> を参照してください。
75767485Unicode については L<perlunicode> を参照してください。
75777486
75787487=item our EXPR
75797488X<our> X<global>
75807489
75817490=item our TYPE EXPR
75827491
75837492=item our EXPR : ATTRS
75847493
75857494=item our TYPE EXPR : ATTRS
75867495
75877496=begin original
75887497
75897498C<our> associates a simple name with a package variable in the current
75907499package for use within the current scope. When C<use strict 'vars'> is in
75917500effect, C<our> lets you use declared global variables without qualifying
75927501them with package names, within the lexical scope of the C<our> declaration.
75937502In this way C<our> differs from C<use vars>, which is package scoped.
75947503
75957504=end original
75967505
75977506C<our> は単純名を、現在のスコープ内で使うために、現在のパッケージの
75987507パッケージ変数と結び付けます。
75997508C<use strict 'vars'> が有効の場合は、C<our> を使うことで、C<our> 宣言の
76007509レキシカルスコープ内で、宣言されたグローバル変数をパッケージ名で
76017510修飾することなく使うことができます。
76027511この意味では、C<use vars> はパッケージスコープなので、C<our> とは異なります。
76037512
76047513=begin original
76057514
76067515Unlike C<my>, which both allocates storage for a variable and associates
76077516a simple name with that storage for use within the current scope, C<our>
76087517associates a simple name with a package variable in the current package,
76097518for use within the current scope. In other words, C<our> has the same
76107519scoping rules as C<my>, but does not necessarily create a
76117520variable.
76127521
76137522=end original
76147523
76157524記憶領域を変数に割り当て、単純名を現在のスコープ内で使うためにその記憶領域に
76167525割り当てる C<my> と違って、C<our> は単純名を、現在のスコープ内で使うために、
76177526現在のパッケージのパッケージ変数と結び付けます。
76187527言い換えると、C<our> は C<my> と同じスコープルールを持ちますが、
76197528変数を作る必要はありません。
76207529
76217530=begin original
76227531
76237532If more than one value is listed, the list must be placed
76247533in parentheses.
76257534
76267535=end original
76277536
76287537二つ以上の値をリストする場合は、リストはかっこでくくる必要があります。
76297538
76307539 our $foo;
76317540 our($bar, $baz);
76327541
76337542=begin original
76347543
76357544An C<our> declaration declares a global variable that will be visible
76367545across its entire lexical scope, even across package boundaries. The
76377546package in which the variable is entered is determined at the point
76387547of the declaration, not at the point of use. This means the following
76397548behavior holds:
76407549
76417550=end original
76427551
76437552C<our> 宣言はレキシカルスコープ全体に対して(たとえパッケージ境界を
76447553越えていても)見えるグローバル変数を宣言します。
76457554この変数が入るパッケージは宣言した時点で定義され、
76467555使用した時点ではありません。
76477556これにより、以下のような振る舞いになります:
76487557
76497558 package Foo;
76507559 our $bar; # declares $Foo::bar for rest of lexical scope
76517560 $bar = 20;
76527561
76537562 package Bar;
76547563 print $bar; # prints 20, as it refers to $Foo::bar
76557564
76567565=begin original
76577566
76587567Multiple C<our> declarations with the same name in the same lexical
76597568scope are allowed if they are in different packages. If they happen
76607569to be in the same package, Perl will emit warnings if you have asked
76617570for them, just like multiple C<my> declarations. Unlike a second
76627571C<my> declaration, which will bind the name to a fresh variable, a
76637572second C<our> declaration in the same package, in the same scope, is
76647573merely redundant.
76657574
76667575=end original
76677576
76687577同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の
76697578C<our> 宣言ができます。
76707579同じパッケージになっていると、警告が出力されるようになっていれば
76717580複数の C<my> 宣言がある場合と同じように警告が出力されます。
76727581新しい変数を名前に割り当てることになる 2 回目の C<my> 宣言と違って、
76737582同じパッケージの同じスコープで 2 回 C<our> 宣言するのは単に冗長です。
76747583
76757584 use warnings;
76767585 package Foo;
76777586 our $bar; # declares $Foo::bar for rest of lexical scope
76787587 $bar = 20;
76797588
76807589 package Bar;
76817590 our $bar = 30; # declares $Bar::bar for rest of lexical scope
76827591 print $bar; # prints 30
76837592
76847593 our $bar; # emits warning but has no other effect
76857594 print $bar; # still prints 30
76867595
76877596=begin original
76887597
76897598An C<our> declaration may also have a list of attributes associated
76907599with it.
76917600
76927601=end original
76937602
76947603C<our> 宣言には、それと結び付けられる属性のリストを持つこともあります。
76957604
76967605=begin original
76977606
76987607The exact semantics and interface of TYPE and ATTRS are still
76997608evolving. TYPE is currently bound to the use of C<fields> pragma,
77007609and attributes are handled using the C<attributes> pragma, or starting
77017610from Perl 5.8.0 also via the C<Attribute::Handlers> module. See
77027611L<perlsub/"Private Variables via my()"> for details, and L<fields>,
77037612L<attributes>, and L<Attribute::Handlers>.
77047613
77057614=end original
77067615
77077616TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
77087617現在のところ、TYPE は C<fields> プラグマの使用と結び付けられていて、
77097618属性は C<attributes> プラグマか、Perl 5.8.0 からは
77107619C<Attribute::Handlers> モジュールと結び付けられています。
77117620詳しくはL<perlsub/"Private Variables via my()">, L<fields>,
77127621L<attributes>, L<Attribute::Handlers> を参照してください。
77137622
77147623=item pack TEMPLATE,LIST
77157624X<pack>
77167625
77177626=begin original
77187627
77197628Takes a LIST of values and converts it into a string using the rules
77207629given by the TEMPLATE. The resulting string is the concatenation of
77217630the converted values. Typically, each converted value looks
77227631like its machine-level representation. For example, on 32-bit machines
77237632an integer may be represented by a sequence of 4 bytes that will be
77247633converted to a sequence of 4 characters.
77257634
77267635=end original
77277636
77287637LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。
77297638結果の文字列は変換した値を連結したものです。
77307639典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。
77317640例えば、32-bit マシンでは、4 バイトで表現される整数を変換すると
773276414 文字の文字列に変換されます。
77337642
77347643=begin original
77357644
77367645The TEMPLATE is a sequence of characters that give the order and type
77377646of values, as follows:
77387647
77397648=end original
77407649
77417650TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです:
77427651
77437652=begin original
77447653
77457654 a A string with arbitrary binary data, will be null padded.
77467655 A A text (ASCII) string, will be space padded.
77477656 Z A null terminated (ASCIZ) string, will be null padded.
77487657
77497658=end original
77507659
77517660 a 任意のバイナリデータを含む文字列、ヌル文字で埋める
77527661 A テキスト (ASCII) 文字列、スペース文字で埋める
77537662 Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める
77547663
77557664=begin original
77567665
77577666 b A bit string (ascending bit order inside each byte, like vec()).
77587667 B A bit string (descending bit order inside each byte).
77597668 h A hex string (low nybble first).
77607669 H A hex string (high nybble first).
77617670
77627671=end original
77637672
77647673 b ビット列 (バイトごとに昇ビット順、vec() と同じ)
77657674 B ビット列 (バイトごとに降ビット順)
77667675 h 16 進数文字列 (低位ニブルが先)
77677676 H 16 進数文字列 (高位ニブルが先)
77687677
77697678=begin original
77707679
77717680 c A signed char (8-bit) value.
77727681 C An unsigned char (octet) value.
77737682 W An unsigned char value (can be greater than 255).
77747683
77757684=end original
77767685
77777686 c signed char (8 ビット) 値
77787687 C unsigned char (オクテット) 値
77797688 W unsigned char 値 (255 より大きいかもしれません)
77807689
77817690=begin original
77827691
77837692 s A signed short (16-bit) value.
77847693 S An unsigned short value.
77857694
77867695=end original
77877696
77887697 s signed short (16 ビット) 値
77897698 S unsigned short 値
77907699
77917700=begin original
77927701
77937702 l A signed long (32-bit) value.
77947703 L An unsigned long value.
77957704
77967705=end original
77977706
77987707 l signed long (32 ビット) 値
77997708 L unsigned long 値
78007709
78017710=begin original
78027711
78037712 q A signed quad (64-bit) value.
78047713 Q An unsigned quad value.
78057714 (Quads are available only if your system supports 64-bit
78067715 integer values _and_ if Perl has been compiled to support those.
78077716 Causes a fatal error otherwise.)
78087717
78097718=end original
78107719
78117720 q 符号付き 64 ビット整数
78127721 Q 符号なし 64 ビット整数
78137722 (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が
78147723 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。
78157724 それ以外の場合は致命的エラーが発生します。)
78167725
78177726=begin original
78187727
78197728 i A signed integer value.
78207729 I A unsigned integer value.
78217730 (This 'integer' is _at_least_ 32 bits wide. Its exact
78227731 size depends on what a local C compiler calls 'int'.)
78237732
78247733=end original
78257734
78267735 i signed int 値
78277736 I unsigned int 値
78287737 (ここでの 'integer' は 「最低」 32 bits 幅です。
78297738 正確なサイズはローカルの C コンパイラの
78307739 'int'のサイズに依存します)
78317740
78327741=begin original
78337742
78347743 n An unsigned short (16-bit) in "network" (big-endian) order.
78357744 N An unsigned long (32-bit) in "network" (big-endian) order.
78367745 v An unsigned short (16-bit) in "VAX" (little-endian) order.
78377746 V An unsigned long (32-bit) in "VAX" (little-endian) order.
78387747
78397748=end original
78407749
78417750 n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)
78427751 N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)
78437752 v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)
78447753 V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)
78457754
78467755=begin original
78477756
78487757 j A Perl internal signed integer value (IV).
78497758 J A Perl internal unsigned integer value (UV).
78507759
78517760=end original
78527761
78537762 j Perl 内部符号付き整数 (IV)
78547763 J Perl 内部符号なし整数 (UV)
78557764
78567765=begin original
78577766
78587767 f A single-precision float in the native format.
78597768 d A double-precision float in the native format.
78607769
78617770=end original
78627771
78637772 f 機種依存の単精度浮動小数点数
78647773 d 機種依存の倍精度浮動小数点数
78657774
78667775=begin original
78677776
78687777 F A Perl internal floating point value (NV) in the native format
78697778 D A long double-precision float in the native format.
78707779 (Long doubles are available only if your system supports long
78717780 double values _and_ if Perl has been compiled to support those.
78727781 Causes a fatal error otherwise.)
78737782
78747783=end original
78757784
78767785 F ネイティブフォーマットの Perl 内部浮動小数点数 (NV)
78777786 D ネイティブフォーマットの長い倍精度浮動小数点数(long double)
78787787 (long double は、システムが long double に対応していて、かつ Perl が
78797788 long double 対応としてコンパイルされている場合にのみ使用可能です。
78807789 それ以外の場合は致命的エラーが発生します。)
78817790
78827791=begin original
78837792
78847793 p A pointer to a null-terminated string.
78857794 P A pointer to a structure (fixed-length string).
78867795
78877796=end original
78887797
78897798 p ヌル文字で終端する文字列へのポインタ
78907799 P 構造体 (固定長文字列) へのポインタ
78917800
78927801=begin original
78937802
78947803 u A uuencoded string.
78957804 U A Unicode character number. Encodes to a character in character mode
78967805 and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in byte mode.
78977806
78987807=end original
78997808
79007809 u uuencode 文字列
79017810 U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に
79027811 (EBCDIC システムでは UTF-EBCDIC に)エンコードされます
79037812
79047813=begin original
79057814
79067815 w A BER compressed integer (not an ASN.1 BER, see perlpacktut for
79077816 details). Its bytes represent an unsigned integer in base 128,
79087817 most significant digit first, with as few digits as possible. Bit
79097818 eight (the high bit) is set on each byte except the last.
79107819
79117820=end original
79127821
79137822 w A BER 圧縮変数(ASN.1 BER ではありません。詳細については perlpacktut を
79147823 参照してください)。このバイト列はできるだけ少ない桁数で表現された
79157824 128 を基とした符号なし整数で、最上位ビットから順に並びます。
79167825 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。
79177826
79187827=begin original
79197828
79207829 x A null byte.
79217830 X Back up a byte.
79227831 @ Null fill or truncate to absolute position, counted from the
79237832 start of the innermost ()-group.
79247833 . Null fill or truncate to absolute position specified by value.
79257834 ( Start of a ()-group.
79267835
79277836=end original
79287837
79297838 x ヌル文字
79307839 X 1 文字後退
79317840 @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で
79327841 埋めるか切り詰める
79337842 . 値で指定した絶対位置までヌル文字で埋めるか切り詰める
79347843 ( () の組の開始
79357844
79367845=begin original
79377846
79387847One or more of the modifiers below may optionally follow some letters in the
79397848TEMPLATE (the second column lists the letters for which the modifier is
79407849valid):
79417850
79427851=end original
79437852
79447853以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで
79457854付けることができます(表の 2 列目は、その修飾子が有効な文字です):
79467855
79477856=begin original
79487857
79497858 ! sSlLiI Forces native (short, long, int) sizes instead
79507859 of fixed (16-/32-bit) sizes.
79517860
79527861=end original
79537862
79547863 ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな
79557864 (short, long, int)サイズを強制する。
79567865
79577866=begin original
79587867
79597868 xX Make x and X act as alignment commands.
79607869
79617870=end original
79627871
79637872 xX x と X をアライメントコマンドとして振舞わせる。
79647873
79657874=begin original
79667875
79677876 nNvV Treat integers as signed instead of unsigned.
79687877
79697878=end original
79707879
79717880 nNvV 整数を符号なしではなく符号付きとして扱わせる。
79727881
79737882=begin original
79747883
79757884 @. Specify position as byte offset in the internal
79767885 representation of the packed string. Efficient but
79777886 dangerous.
79787887
79797888=end original
79807889
79817890 @. pack された内部表現のバイトオフセットとして位置を指定する。
79827891 効率的ですが危険です。
79837892
79847893=begin original
79857894
79867895 > sSiIlLqQ Force big-endian byte-order on the type.
79877896 jJfFdDpP (The "big end" touches the construct.)
79887897
79897898=end original
79907899
79917900 > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します
79927901 jJfFdDpP (「大きい端」が構造に触れています)
79937902
79947903=begin original
79957904
79967905 < sSiIlLqQ Force little-endian byte-order on the type.
79977906 jJfFdDpP (The "little end" touches the construct.)
79987907
79997908=end original
80007909
80017910 < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します
80027911 jJfFdDpP (「小さい端」が構造に触れています)
80037912
80047913=begin original
80057914
80067915The C<E<gt>> and C<E<lt>> modifiers can also be used on C<()>-groups,
80077916in which case they force a certain byte-order on all components of
80087917that group, including subgroups.
80097918
80107919=end original
80117920
80127921C<E<gt>> と C<E<lt>> の修飾子は C<()>-グループでも使えます;
80137922この場合はそのグループと副グループ内の全ての要素を特定のバイト順に
80147923強制します。
80157924
80167925=begin original
80177926
80187927The following rules apply:
80197928
80207929=end original
80217930
80227931以下の条件が適用されます:
80237932
80247933=over 8
80257934
80267935=item *
80277936
80287937=begin original
80297938
80307939Each letter may optionally be followed by a number giving a repeat
80317940count. With all types except C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>,
80327941C<H>, C<@>, C<.>, C<x>, C<X> and C<P> the pack function will gobble up
80337942that many values from the LIST. A C<*> for the repeat count means to
80347943use however many items are left, except for C<@>, C<x>, C<X>, where it
80357944is equivalent to C<0>, for <.> where it means relative to string start
80367945and C<u>, where it is equivalent to 1 (or 45, which is the same).
80377946A numeric repeat count may optionally be enclosed in brackets, as in
80387947C<pack 'C[80]', @arr>.
80397948
80407949=end original
80417950
80427951これらの文字の後には、繰り返し数を示す数字を付けることができます。
80437952C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P>
80447953以外の全ての型では、LIST からその数の値を取り出して使います。
80457954繰り返し数に C<*> を指定すると、その時点で残っているすべての要素を意味します。
80467955ただし、C<@>, C<x>, C<X> では C<0> と等価で、
80477956C<.> では文字列の開始からの相対位置を意味し、
80487957C<u> では 1 (あるいは 45 でも同じ) と等価です。
80497958数値の繰り返し数は C<pack 'C[80]', @arr> のように大かっこで囲むこともできます。
80507959
80517960=begin original
80527961
80537962One can replace the numeric repeat count by a template enclosed in brackets;
80547963then the packed length of this template in bytes is used as a count.
80557964For example, C<x[L]> skips a long (it skips the number of bytes in a long);
80567965the template C<$t X[$t] $t> unpack()s twice what $t unpacks.
80577966If the template in brackets contains alignment commands (such as C<x![d]>),
80587967its packed length is calculated as if the start of the template has the maximal
80597968possible alignment.
80607969
80617970=end original
80627971
80637972大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることができます;
80647973このテンプレートでパックされたバイト長が繰り返し数として使われます。
80657974例えば、C<x[L]> は long をスキップします(long のバイト数だけスキップします);
80667975テンプレート C<$t X[$t] $t> は $t を unpack したものの 2 倍を
80677976unpack() します。
80687977(C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、
80697978パックされた長さは、テンプレートの先頭で最大限可能なアライメントを
80707979持っているものとして計算されます。
80717980
80727981=begin original
80737982
80747983When used with C<Z>, C<*> results in the addition of a trailing null
80757984byte (so the packed result will be one longer than the byte C<length>
80767985of the item).
80777986
80787987=end original
80797988
80807989C<*> が C<Z> と共に使われた場合、末尾にヌルバイトをつけます
80817990(従ってパックされた結果は要素の C<length> の値より 1 大きくなります)。
80827991
80837992=begin original
80847993
80857994When used with C<@>, the repeat count represents an offset from the start
80867995of the innermost () group.
80877996
80887997=end original
80897998
80907999C<@> を使うと、繰り返し数は一番内側の () グループの先頭からのオフセットを
80918000表現します。
80928001
80938002=begin original
80948003
80958004When used with C<.>, the repeat count is used to determine the starting
80968005position from where the value offset is calculated. If the repeat count
80978006is 0, it's relative to the current position. If the repeat count is C<*>,
80988007the offset is relative to the start of the packed string. And if its an
80998008integer C<n> the offset is relative to the start of the n-th innermost
81008009() group (or the start of the string if C<n> is bigger then the group
81018010level).
81028011
81038012=end original
81048013
81058014C<.> で使われると、繰り返し数は値のオフセットを計算するための開始位置を
81068015決定するために使われます。
81078016繰り返し数が 0 なら、現在位置からの相対位置となります。
81088017繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの相対位置です。
81098018そして整数 C<n> なら、オフセットは一番内側から n 番目の () グループの先頭
81108019(または C<n> がグループレベルより大きい場合は文字列の先頭)からの
81118020相対位置です。
81128021
81138022=begin original
81148023
81158024The repeat count for C<u> is interpreted as the maximal number of bytes
81168025to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
81178026count should not be more than 65.
81188027
81198028=end original
81208029
81218030C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを
81228031示します。0, 1, 2 は 45 として扱われます。
81238032繰り返し数は 65 を超えてはなりません。
81248033
81258034=item *
81268035
81278036=begin original
81288037
81298038The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a
81308039string of length count, padding with nulls or spaces as necessary. When
81318040unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything
81328041after the first null, and C<a> returns data verbatim.
81338042
81348043=end original
81358044
81368045C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、
81378046繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か
81388047スペース文字を付け足します。
81398048unpack するとき、C<A> は後続の空白やヌル文字を取り除きます。
81408049C<Z>は最初のヌル文字以降の全てを取り除きます。
81418050C<a>はデータをそのまま返します。
81428051
81438052=begin original
81448053
81458054If the value-to-pack is too long, it is truncated. If too long and an
81468055explicit count is provided, C<Z> packs only C<$count-1> bytes, followed
81478056by a null byte. Thus C<Z> always packs a trailing null (except when the
81488057count is 0).
81498058
81508059=end original
81518060
81528061pack する値が長すぎる場合、切り詰められます。
81538062長すぎてかつ明示的に個数が指定されている場合、
81548063C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。
81558064従って、C<Z> は(繰り返し数が 0 の場合を除いて)常に末尾にヌルバイトが
81568065つきます。
81578066
81588067=item *
81598068
81608069=begin original
81618070
81628071Likewise, the C<b> and C<B> fields pack a string that many bits long.
81638072Each character of the input field of pack() generates 1 bit of the result.
81648073Each result bit is based on the least-significant bit of the corresponding
81658074input character, i.e., on C<ord($char)%2>. In particular, characters C<"0">
81668075and C<"1"> generate bits 0 and 1, as do characters C<"\0"> and C<"\1">.
81678076
81688077=end original
81698078
81708079同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。
81718080pack() の入力フィールドの各文字は結果の 1 ビットを生成します。
81728081結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします
81738082(つまり C<ord($char)%2>)。
81748083特に、文字 C<"0"> と C<"1"> は文字 C<"\0"> と C<"\1"> と同様に、
81758084ビット 0 と 1 を生成します。
81768085
81778086=begin original
81788087
81798088Starting from the beginning of the input string of pack(), each 8-tuple
81808089of characters is converted to 1 character of output. With format C<b>
81818090the first character of the 8-tuple determines the least-significant bit of a
81828091character, and with format C<B> it determines the most-significant bit of
81838092a character.
81848093
81858094=end original
81868095
81878096pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に
81888097変換されます。
81898098C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなり、
81908099C<B> フォーマットでは出力の最上位ビットとなります。
81918100
81928101=begin original
81938102
81948103If the length of the input string is not exactly divisible by 8, the
81958104remainder is packed as if the input string were padded by null characters
81968105at the end. Similarly, during unpack()ing the "extra" bits are ignored.
81978106
81988107=end original
81998108
82008109もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の
82018110最後にヌル文字がパッディングされているものとしてパックされます。
82028111同様に、unpack() 中は「余分な」ビットは無視されます。
82038112
82048113=begin original
82058114
82068115If the input string of pack() is longer than needed, extra characters are
82078116ignored. A C<*> for the repeat count of pack() means to use all the
82088117characters of the input field. On unpack()ing the bits are converted to a
82098118string of C<"0">s and C<"1">s.
82108119
82118120=end original
82128121
82138122pack() の入力文字列が必要な分よりも長い場合、余分な文字は無視されます。
82148123pack() の繰り返し数として C<*> が指定されると、入力フィールドの全ての
82158124文字が使われます。
82168125unpack() 時にはビット列は C<"0"> と C<"1"> の文字列に変換されます。
82178126
82188127=item *
82198128
82208129=begin original
82218130
82228131The C<h> and C<H> fields pack a string that many nybbles (4-bit groups,
82238132representable as hexadecimal digits, 0-9a-f) long.
82248133
82258134=end original
82268135
82278136C<h> や C<H> は、多ニブル長(16 進文字である 0-9a-f で表現可能な
822881374 ビットグループ)のニブル列に pack します。
82298138
82308139=begin original
82318140
82328141Each character of the input field of pack() generates 4 bits of the result.
82338142For non-alphabetical characters the result is based on the 4 least-significant
82348143bits of the input character, i.e., on C<ord($char)%16>. In particular,
82358144characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
82368145C<"\0"> and C<"\1">. For characters C<"a".."f"> and C<"A".."F"> the result
82378146is compatible with the usual hexadecimal digits, so that C<"a"> and
82388147C<"A"> both generate the nybble C<0xa==10>. The result for characters
82398148C<"g".."z"> and C<"G".."Z"> is not well-defined.
82408149
82418150=end original
82428151
82438152pack() の入力フィールドの各文字は結果の 4 ビットを生成します。
82448153英字でない文字の場合、結果は入力文字の下位 4 ビットを
82458154基にします(つまり C<ord($char)%16>)。
82468155特に、文字 C<"0"> と C<"1"> はバイト C<"\0"> と C<"\1"> と同様に
82478156ニブル 0 と 1 を生成します。
82488157文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の
8249815816 進数と同じ結果になりますので、C<"a"> と C<"A"> はどちらも
82508159ニブル C<0xa==10> を生成します。
82518160文字 C<"g".."z"> と C<"G".."Z"> に対する結果は未定義です。
82528161
82538162=begin original
82548163
82558164Starting from the beginning of the input string of pack(), each pair
82568165of characters is converted to 1 character of output. With format C<h> the
82578166first character of the pair determines the least-significant nybble of the
82588167output character, and with format C<H> it determines the most-significant
82598168nybble.
82608169
82618170=end original
82628171
82638172pack() の入力文字列の先頭から始めて、2 文字毎に 1 文字の出力に
82648173変換されます。
82658174C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、
82668175C<H> フォーマットでは出力の最上位ニブルとなります。
82678176
82688177=begin original
82698178
82708179If the length of the input string is not even, it behaves as if padded
82718180by a null character at the end. Similarly, during unpack()ing the "extra"
82728181nybbles are ignored.
82738182
82748183=end original
82758184
82768185入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて
82778186いるかのように振る舞います。
82788187同様に、unpack() 中は「余分な」ニブルは無視されます。
82798188
82808189=begin original
82818190
82828191If the input string of pack() is longer than needed, extra characters are
82838192ignored.
82848193A C<*> for the repeat count of pack() means to use all the characters of
82858194the input field. On unpack()ing the nybbles are converted to a string
82868195of hexadecimal digits.
82878196
82888197=end original
82898198
82908199pack() の入力文字列が必要な分より長い場合、余分な部分は無視されます。
82918200pack() の繰り返し数として C<*> が指定されると、入力フィールドの全ての
82928201文字が使われます。
82938202unpack() 時にはニブルは 16 進数の文字列に変換されます。
82948203
82958204=item *
82968205
82978206=begin original
82988207
82998208The C<p> type packs a pointer to a null-terminated string. You are
83008209responsible for ensuring the string is not a temporary value (which can
83018210potentially get deallocated before you get around to using the packed result).
83028211The C<P> type packs a pointer to a structure of the size indicated by the
83038212length. A NULL pointer is created if the corresponding value for C<p> or
83048213C<P> is C<undef>, similarly for unpack().
83058214
83068215=end original
83078216
83088217C<p>は、ヌル文字終端文字列へのポインタを pack します。
83098218文字列が一時的な値でない(つまり pack された結果を使う前に文字列が
83108219解放されない) ことに責任を持つ必要があります
83118220C<P> は、指定した長さの構造体へのポインタを pack します。
83128221C<p>またはC<P>に対応する値が C<undef> だった場合、
83138222unpack() と同様にヌルポインタが作成されます。
83148223
83158224=begin original
83168225
83178226If your system has a strange pointer size (i.e. a pointer is neither as
83188227big as an int nor as big as a long), it may not be possible to pack or
83198228unpack pointers in big- or little-endian byte order. Attempting to do
83208229so will result in a fatal error.
83218230
83228231=end original
83238232
83248233システムのポインタが変わったサイズの場合(つまり、int の大きさでも
83258234long の大きさでもない場合) ポインタをビッグエンディアンやリトルエンディアンの
83268235バイト順で pack や unpack することはできません。
83278236そうしようとすると致命的エラーになります。
83288237
83298238=item *
83308239
83318240=begin original
83328241
83338242The C</> template character allows packing and unpacking of a sequence of
83348243items where the packed structure contains a packed item count followed by
83358244the packed items themselves.
83368245
83378246=end original
83388247
83398248C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の
83408249アイテム列を pack 及び unpack します。
83418250
83428251=begin original
83438252
83448253For C<pack> you write I<length-item>C</>I<sequence-item> and the
83458254I<length-item> describes how the length value is packed. The ones likely
83468255to be of most use are integer-packing ones like C<n> (for Java strings),
83478256C<w> (for ASN.1 or SNMP) and C<N> (for Sun XDR).
83488257
83498258=end original
83508259
83518260C<pack> では I<length-item>C</>I<string-item> の形になり、
83528261I<length-item> は長さの値がどのように pack されているかを指定します。
83538262もっともよく使われるのは C<n>(Java 文字列), C<w>(SNMP), C<N>(Sun XDR) と
83548263いった整数型です。
83558264
83568265=begin original
83578266
83588267For C<pack>, the I<sequence-item> may have a repeat count, in which case
83598268the minimum of that and the number of available items is used as argument
83608269for the I<length-item>. If it has no repeat count or uses a '*', the number
83618270of available items is used.
83628271
83638272=end original
83648273
83658274C<pack> では、I<sequence-item> は繰り返し数を持つことがあり、その場合は
83668275その最小値と利用可能なアイテムの数は I<length-item> のための引数として
83678276使われます。
83688277繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。
83698278
83708279=begin original
83718280
83728281For C<unpack> an internal stack of integer arguments unpacked so far is
83738282used. You write C</>I<sequence-item> and the repeat count is obtained by
83748283popping off the last element from the stack. The I<sequence-item> must not
83758284have a repeat count.
83768285
83778286=end original
83788287
83798288C<unpack> では、今まで unpack した数値引数の内部スタックが使われます。
83808289C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を
83818290取り出すことで得ます。
83828291I<sequence-item> は繰り返し数を持っていてはいけません。
83838292
83848293=begin original
83858294
83868295If the I<sequence-item> refers to a string type (C<"A">, C<"a"> or C<"Z">),
83878296the I<length-item> is a string length, not a number of strings. If there is
83888297an explicit repeat count for pack, the packed string will be adjusted to that
83898298given length.
83908299
83918300=end original
83928301
83938302I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、
83948303I<length-item> は文字列の数ではなく、文字列の長さです。
83958304pack で明示的な繰り返し数があると、pack された文字列は与えられた
83968305長さに調整されます。
83978306
83988307 unpack 'W/a', "\04Gurusamy"; gives ('Guru')
83998308 unpack 'a3/A A*', '007 Bond J '; gives (' Bond', 'J')
84008309 unpack 'a3 x2 /A A*', '007: Bond, J.'; gives ('Bond, J', '.')
84018310 pack 'n/a* w/a','hello,','world'; gives "\000\006hello,\005world"
84028311 pack 'a/W2', ord('a') .. ord('z'); gives '2ab'
84038312
84048313=begin original
84058314
84068315The I<length-item> is not returned explicitly from C<unpack>.
84078316
84088317=end original
84098318
84108319I<length-item> は C<unpack> から明示的には返されません。
84118320
84128321=begin original
84138322
84148323Adding a count to the I<length-item> letter is unlikely to do anything
84158324useful, unless that letter is C<A>, C<a> or C<Z>. Packing with a
84168325I<length-item> of C<a> or C<Z> may introduce C<"\000"> characters,
84178326which Perl does not regard as legal in numeric strings.
84188327
84198328=end original
84208329
84218330I<length-item> 文字に繰り返し数をつけるのは
84228331文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。
84238332C<a> や C<Z> を I<length-item> としてパックすると C<"\000"> 文字が
84248333出力されることがあり、Perl はこれを有効な数値文字列として認識しません。
84258334
84268335=item *
84278336
84288337=begin original
84298338
84308339The integer types C<s>, C<S>, C<l>, and C<L> may be
84318340followed by a C<!> modifier to signify native shorts or
84328341longs--as you can see from above for example a bare C<l> does mean
84338342exactly 32 bits, the native C<long> (as seen by the local C compiler)
84348343may be larger. This is an issue mainly in 64-bit platforms. You can
84358344see whether using C<!> makes any difference by
84368345
84378346=end original
84388347
84398348C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を
84408349つけることで、ネイティブの short や long を指定できます --
84418350上述のように、例えば C<l> は正確に 32 ビットであり、ネイティブな
84428351(ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。
84438352これは主に 64 ビットプラットフォームで意味があります。
84448353C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます:
84458354
84468355 print length(pack("s")), " ", length(pack("s!")), "\n";
84478356 print length(pack("l")), " ", length(pack("l!")), "\n";
84488357
84498358=begin original
84508359
84518360C<i!> and C<I!> also work but only because of completeness;
84528361they are identical to C<i> and C<I>.
84538362
84548363=end original
84558364
84568365C<i!> と C<I!> も動作しますが、単に完全性のためだけです;
84578366これは C<i> 及び C<I> と同じです。
84588367
84598368=begin original
84608369
84618370The actual sizes (in bytes) of native shorts, ints, longs, and long
84628371longs on the platform where Perl was built are also available via
84638372L<Config>:
84648373
84658374=end original
84668375
84678376Perl がビルドされたプラットフォームでの short, int, long, long long の
84688377実際の(バイト数での)サイズは L<Config> でも得られます。
84698378
84708379 use Config;
84718380 print $Config{shortsize}, "\n";
84728381 print $Config{intsize}, "\n";
84738382 print $Config{longsize}, "\n";
84748383 print $Config{longlongsize}, "\n";
84758384
84768385=begin original
84778386
84788387(The C<$Config{longlongsize}> will be undefined if your system does
84798388not support long longs.)
84808389
84818390=end original
84828391
84838392(システムが long long に対応していない場合は C<$Config{longlongsize}> は
84848393未定義値になります。)
84858394
84868395=item *
84878396
84888397=begin original
84898398
84908399The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J>
84918400are inherently non-portable between processors and operating systems
84928401because they obey the native byteorder and endianness. For example a
849384024-byte integer 0x12345678 (305419896 decimal) would be ordered natively
84948403(arranged in and handled by the CPU registers) into bytes as
84958404
84968405=end original
84978406
84988407整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は
84998408ネイティブなバイト順序とエンディアンに従っているため、
85008409本質的にプロセッサ間や OS 間で移植性がありません。
85018410例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は
85028411内部では(CPU レジスタによって変換され扱われる形では)
85038412以下のようなバイト列に並べられます:
85048413
85058414 0x12 0x34 0x56 0x78 # big-endian
85068415 0x78 0x56 0x34 0x12 # little-endian
85078416
85088417=begin original
85098418
85108419Basically, the Intel and VAX CPUs are little-endian, while everybody
85118420else, for example Motorola m68k/88k, PPC, Sparc, HP PA, Power, and
85128421Cray are big-endian. Alpha and MIPS can be either: Digital/Compaq
85138422used/uses them in little-endian mode; SGI/Cray uses them in big-endian
85148423mode.
85158424
85168425=end original
85178426
85188427基本的に、Intel と VAX の CPU はリトルエンディアンです。
85198428一方それ以外、例えば Motorola m68k/88k, PPC, Sparc, HP PA, Power,
85208429Cray などはビッグエンディアンです。
85218430Alpha と MIPS は両方ともあります:
85228431Digital/Compaq はリトルエンディアンモードで使っています(いました);
85238432SGI/Cray はビッグエンディアンモードで使っています。
85248433
85258434=begin original
85268435
85278436The names `big-endian' and `little-endian' are comic references to
85288437the classic "Gulliver's Travels" (via the paper "On Holy Wars and a
85298438Plea for Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980) and
85308439the egg-eating habits of the Lilliputians.
85318440
85328441=end original
85338442
85348443「ビッグエンディアン」と「リトルエンディアン」の名前は
85358444古典である「ガリバー旅行記」とリリパット族の卵を食べる習慣から
85368445取られています。
85378446
85388447=begin original
85398448
85408449Some systems may have even weirder byte orders such as
85418450
85428451=end original
85438452
85448453以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません:
85458454
85468455 0x56 0x78 0x12 0x34
85478456 0x34 0x12 0x78 0x56
85488457
85498458=begin original
85508459
85518460You can see your system's preference with
85528461
85538462=end original
85548463
85558464システムの設定は以下のようにして見ることができます:
85568465
85578466 print join(" ", map { sprintf "%#02x", $_ }
85588467 unpack("W*",pack("L",0x12345678))), "\n";
85598468
85608469=begin original
85618470
85628471The byteorder on the platform where Perl was built is also available
85638472via L<Config>:
85648473
85658474=end original
85668475
85678476Perl がビルドされたプラットフォームでのバイト順序は
85688477L<Config> でも知ることができます:
85698478
85708479 use Config;
85718480 print $Config{byteorder}, "\n";
85728481
85738482=begin original
85748483
85758484Byteorders C<'1234'> and C<'12345678'> are little-endian, C<'4321'>
85768485and C<'87654321'> are big-endian.
85778486
85788487=end original
85798488
85808489C<'1234'> と C<'12345678'> はリトルエンディアン、
85818490C<'4321'> と C<'87654321'> はビッグエンディアンです。
85828491
85838492=begin original
85848493
85858494If you want portable packed integers you can either use the formats
85868495C<n>, C<N>, C<v>, and C<V>, or you can use the C<E<gt>> and C<E<lt>>
85878496modifiers. These modifiers are only available as of perl 5.9.2.
85888497See also L<perlport>.
85898498
85908499=end original
85918500
85928501移植性のあるパック化された整数がほしい場合は、
85938502C<n>, C<N>, C<v>, C<V> フォーマットを使うか、C<E<gt>> と C<E<lt>> の
85948503修飾子が使えます。
85958504これらの修飾子は perl 5.9.2 以降でのみ使えます。
85968505L<perlport> も参照して下さい。
85978506
85988507=item *
85998508
86008509=begin original
86018510
86028511All integer and floating point formats as well as C<p> and C<P> and
86038512C<()>-groups may be followed by the C<E<gt>> or C<E<lt>> modifiers
86048513to force big- or little- endian byte-order, respectively.
86058514This is especially useful, since C<n>, C<N>, C<v> and C<V> don't cover
86068515signed integers, 64-bit integers and floating point values. However,
86078516there are some things to keep in mind.
86088517
86098518=end original
86108519
86118520C<p> と C<P> と C<()> グループと同様、全ての整数と浮動小数点数の
86128521フォーマットは C<E<gt>> や C<E<lt>> の修飾子をつけることで、それぞれ
86138522ビッグエンディアンとリトルエンディアンに強制させることができます。
86148523C<n>, C<N>, C<v> and C<V> は符号付き整数、64 ビット整数、浮動小数点数に
86158524対応していないので、これは特に有用です。
86168525しかし、心に留めておくべきことがいくつかあります。
86178526
86188527=begin original
86198528
86208529Exchanging signed integers between different platforms only works
86218530if all platforms store them in the same format. Most platforms store
86228531signed integers in two's complement, so usually this is not an issue.
86238532
86248533=end original
86258534
86268535異なったプラットフォームで符号付き整数を交換することは、全ての
86278536プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。
86288537ほとんどのプラットフォームでは符号付き整数は 2 の補数で保存するので、
86298538普通はこれは問題になりません。
86308539
86318540=begin original
86328541
86338542The C<E<gt>> or C<E<lt>> modifiers can only be used on floating point
86348543formats on big- or little-endian machines. Otherwise, attempting to
86358544do so will result in a fatal error.
86368545
86378546=end original
86388547
86398548C<E<gt>> や C<E<lt>> の修飾子はビッグエンディアンやリトルエンディアンの
86408549マシンでの浮動小数点フォーマットでのみ使えます。
86418550それ以外では、そのような試みは致命的エラーとなります。
86428551
86438552=begin original
86448553
86458554Forcing big- or little-endian byte-order on floating point values for
86468555data exchange can only work if all platforms are using the same
86478556binary representation (e.g. IEEE floating point format). Even if all
86488557platforms are using IEEE, there may be subtle differences. Being able
86498558to use C<E<gt>> or C<E<lt>> on floating point values can be very useful,
86508559but also very dangerous if you don't know exactly what you're doing.
86518560It is definitely not a general way to portably store floating point
86528561values.
86538562
86548563=end original
86558564
86568565データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル
86578566エンディアンに強制することは、全てのプラットフォームが同じバイナリ
86588567表現(例えば IEEE 浮動小数点フォーマット)の場合にのみうまくいきます。
86598568たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが
86608569あるかもしれません。
86618570浮動小数点数に C<E<gt>> や C<E<lt>> が使えることはとても便利な場合が
86628571ありますが、もし自分が何をしているかを正確に理解していなければ、
86638572とても危険です。
86648573移植性のある浮動小数点数の保存のための一般的な方法がないことは確実です。
86658574
86668575=begin original
86678576
86688577When using C<E<gt>> or C<E<lt>> on an C<()>-group, this will affect
86698578all types inside the group that accept the byte-order modifiers,
86708579including all subgroups. It will silently be ignored for all other
86718580types. You are not allowed to override the byte-order within a group
86728581that already has a byte-order modifier suffix.
86738582
86748583=end original
86758584
86768585C<()> グループで C<E<gt>> や C<E<lt>> を使うと、これは、副グループを
86778586含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。
86788587その他の型については沈黙のうちに無視されます。
86798588既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは
86808589できません。
86818590
86828591=item *
86838592
86848593=begin original
86858594
86868595Real numbers (floats and doubles) are in the native machine format only;
86878596due to the multiplicity of floating formats around, and the lack of a
86888597standard "network" representation, no facility for interchange has been
86898598made. This means that packed floating point data written on one machine
86908599may not be readable on another - even if both use IEEE floating point
86918600arithmetic (as the endian-ness of the memory representation is not part
86928601of the IEEE spec). See also L<perlport>.
86938602
86948603=end original
86958604
86968605実数 (float と double) は、機種依存のフォーマットしかありません。
86978606いろんな浮動小数点数のフォーマットが在り、標準的な
86988607"network" 表現といったものがないため、データ交換のための機能は
86998608用意してありません。
87008609つまり、あるマシンで pack した浮動小数点数は、別のマシンでは
87018610読めないかもしれないということです。
87028611たとえ双方で IEEE フォーマットの浮動小数点数演算を行なっていてもです
87038612(IEEE の仕様では、メモリ表現上のバイト順序までは、
87048613規定されていないからです)。
87058614L<perlport> も参照してください。
87068615
87078616=begin original
87088617
87098618If you know exactly what you're doing, you can use the C<E<gt>> or C<E<lt>>
87108619modifiers to force big- or little-endian byte-order on floating point values.
87118620
87128621=end original
87138622
87148623もし何をしようとしているのかを正確に理解しているなら、浮動小数点数の
87158624バイト順をビッグエンディアンやリトルエンディアンに強制するために、
87168625C<E<gt>> と C<E<lt>> の修飾子が使えます。
87178626
87188627=begin original
87198628
87208629Note that Perl uses doubles (or long doubles, if configured) internally for
87218630all numeric calculation, and converting from double into float and thence back
87228631to double again will lose precision (i.e., C<unpack("f", pack("f", $foo)>)
87238632will not in general equal $foo).
87248633
87258634=end original
87268635
87278636Perl では、すべての数値演算のために、内部的に double (または
87288637設定によっては long double) を使用しています。
87298638double から float へ変換し、それから再び double に戻すと
87308639精度が落ちることになります (つまり、C<unpack("f", pack("f", $foo)>) は、
87318640一般には $foo と同じではないということです)。
87328641
87338642=item *
87348643
87358644=begin original
87368645
87378646Pack and unpack can operate in two modes, character mode (C<C0> mode) where
87388647the packed string is processed per character and UTF-8 mode (C<U0> mode)
87398648where the packed string is processed in its UTF-8-encoded Unicode form on
87408649a byte by byte basis. Character mode is the default unless the format string
87418650starts with an C<U>. You can switch mode at any moment with an explicit
87428651C<C0> or C<U0> in the format. A mode is in effect until the next mode switch
87438652or until the end of the ()-group in which it was entered.
87448653
87458654=end original
87468655
87478656pack と unpack は二つのモードで操作します; pack された文字列を文字単位で
87488657処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、
87498658その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。
87508659文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。
87518660モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも
87528661切り替えられます。
87538662モードは次のモードに切り替えられるか、現在の () グループが終了するまで
87548663有効です。
87558664
87568665=item *
87578666
87588667=begin original
87598668
87608669You must yourself do any alignment or padding by inserting for example
87618670enough C<'x'>es while packing. There is no way to pack() and unpack()
87628671could know where the characters are going to or coming from. Therefore
87638672C<pack> (and C<unpack>) handle their output and input as flat
87648673sequences of characters.
87658674
87668675=end original
87678676
87688677pack するときに、例えば十分な数の C<'x'> を挿入することによって
87698678アライメントやパッディングを行うのは全て自分でしなければなりません。
87708679文字列がどこへ行くか・どこから来たかを pack() や unpack() が
87718680知る方法はありません。
87728681従って C<pack> (と C<unpack>) は出力と入力をフラットな文字列として
87738682扱います。
87748683
87758684=item *
87768685
87778686=begin original
87788687
87798688A ()-group is a sub-TEMPLATE enclosed in parentheses. A group may
87808689take a repeat count, both as postfix, and for unpack() also via the C</>
87818690template character. Within each repetition of a group, positioning with
87828691C<@> starts again at 0. Therefore, the result of
87838692
87848693=end original
87858694
87868695() のグループはかっこで囲われた副テンプレートです。
87878696グループは繰り返し数を取ることができます; 接尾辞によるか、unpack() の場合は
87888697C</> テンプレート文字によります。
87898698グループの繰り返し毎に、C<@> の位置は 0 になります。
87908699従って、以下の結果は:
87918700
87928701 pack( '@1A((@2A)@3A)', 'a', 'b', 'c' )
87938702
87948703=begin original
87958704
87968705is the string "\0a\0\0bc".
87978706
87988707=end original
87998708
88008709文字列 "\0a\0\0bc" です。
88018710
88028711=item *
88038712
88048713=begin original
88058714
88068715C<x> and C<X> accept C<!> modifier. In this case they act as
88078716alignment commands: they jump forward/back to the closest position
88088717aligned at a multiple of C<count> characters. For example, to pack() or
88098718unpack() C's C<struct {char c; double d; char cc[2]}> one may need to
88108719use the template C<W x![d] d W[2]>; this assumes that doubles must be
88118720aligned on the double's size.
88128721
88138722=end original
88148723
88158724C<x> と C<X> には C<!> 修飾子を付けることができます。
88168725この場合、これらはアライメントコマンドとして働きます:
88178726C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。
88188727例えば、C の C<struct {char c; double d; char cc[2]}> を pack() または
88198728unpack() するためには、C<W x![d] d W[2]> というテンプレートを使う必要が
88208729あるかもしれません;
88218730これは double が double のサイズでアライメントされていることを
88228731仮定しています。
88238732
88248733=begin original
88258734
88268735For alignment commands C<count> of 0 is equivalent to C<count> of 1;
88278736both result in no-ops.
88288737
88298738=end original
88308739
88318740アライメントコマンドに対しては、C<count> に 0 を指定するのは 1 を
88328741指定するのと等価です; どちらも何もしません。
88338742
88348743=item *
88358744
88368745=begin original
88378746
88388747C<n>, C<N>, C<v> and C<V> accept the C<!> modifier. In this case they
88398748will represent signed 16-/32-bit integers in big-/little-endian order.
88408749This is only portable if all platforms sharing the packed data use the
88418750same binary representation for signed integers (e.g. all platforms are
88428751using two's complement representation).
88438752
88448753=end original
88458754
88468755C<n>, C<N>, C<v>, C<V> は C<!> 修飾子を受け入れます。
88478756この場合、これらはビッグ/リトルエンディアンの順序で符号付き 16 または
8848875732 ビット整数で表現されます。
88498758これは pack されたデータを共有する全てのプラットフォームが
88508759符号付き整数について同じバイナリ表現を使う(つまり、全ての
88518760プラットフォームで 2 の補数表現を使う)場合にのみ移植性があります。
88528761
88538762=item *
88548763
88558764=begin original
88568765
88578766A comment in a TEMPLATE starts with C<#> and goes to the end of line.
88588767White space may be used to separate pack codes from each other, but
88598768modifiers and a repeat count must follow immediately.
88608769
88618770=end original
88628771
88638772TEMPLATE の中の C<#> から行末まではコメントです。
88648773空白は pack コードをそれぞれ分けるために使えますが、修飾子と
88658774繰り返し数は直後に置かなければなりません。
88668775
88678776=item *
88688777
88698778=begin original
88708779
88718780If TEMPLATE requires more arguments to pack() than actually given, pack()
88728781assumes additional C<""> arguments. If TEMPLATE requires fewer arguments
88738782to pack() than actually given, extra arguments are ignored.
88748783
88758784=end original
88768785
88778786TEMPLATE が要求する引数の数が pack() が実際に与えている数より多い場合、
88788787追加の C<""> 引数があるものと仮定します。
88798788TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。
88808789
88818790=back
88828791
88838792=begin original
88848793
88858794Examples:
88868795
88878796=end original
88888797
88898798例:
88908799
88918800 $foo = pack("WWWW",65,66,67,68);
88928801 # foo eq "ABCD"
88938802 $foo = pack("W4",65,66,67,68);
88948803 # same thing
88958804 $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9);
88968805 # same thing with Unicode circled letters.
88978806 $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9);
88988807 # same thing with Unicode circled letters. You don't get the UTF-8
88998808 # bytes because the U at the start of the format caused a switch to
89008809 # U0-mode, so the UTF-8 bytes get joined into characters
89018810 $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9);
89028811 # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9"
89038812 # This is the UTF-8 encoding of the string in the previous example
89048813
89058814 $foo = pack("ccxxcc",65,66,67,68);
89068815 # foo eq "AB\0\0CD"
89078816
89088817 # note: the above examples featuring "W" and "c" are true
89098818 # only on ASCII and ASCII-derived systems such as ISO Latin 1
89108819 # and UTF-8. In EBCDIC the first example would be
89118820 # $foo = pack("WWWW",193,194,195,196);
89128821
89138822 $foo = pack("s2",1,2);
89148823 # "\1\0\2\0" on little-endian
89158824 # "\0\1\0\2" on big-endian
89168825
89178826 $foo = pack("a4","abcd","x","y","z");
89188827 # "abcd"
89198828
89208829 $foo = pack("aaaa","abcd","x","y","z");
89218830 # "axyz"
89228831
89238832 $foo = pack("a14","abcdefg");
89248833 # "abcdefg\0\0\0\0\0\0\0"
89258834
89268835 $foo = pack("i9pl", gmtime);
89278836 # a real struct tm (on my system anyway)
89288837
89298838 $utmp_template = "Z8 Z8 Z16 L";
89308839 $utmp = pack($utmp_template, @utmp1);
89318840 # a struct utmp (BSDish)
89328841
89338842 @utmp2 = unpack($utmp_template, $utmp);
89348843 # "@utmp1" eq "@utmp2"
89358844
89368845 sub bintodec {
89378846 unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
89388847 }
89398848
89408849 $foo = pack('sx2l', 12, 34);
89418850 # short 12, two zero bytes padding, long 34
89428851 $bar = pack('s@4l', 12, 34);
89438852 # short 12, zero fill to position 4, long 34
89448853 # $foo eq $bar
89458854 $baz = pack('s.l', 12, 4, 34);
89468855 # short 12, zero fill to position 4, long 34
89478856
89488857 $foo = pack('nN', 42, 4711);
89498858 # pack big-endian 16- and 32-bit unsigned integers
89508859 $foo = pack('S>L>', 42, 4711);
89518860 # exactly the same
89528861 $foo = pack('s<l<', -42, 4711);
89538862 # pack little-endian 16- and 32-bit signed integers
89548863 $foo = pack('(sl)<', -42, 4711);
89558864 # exactly the same
89568865
89578866=begin original
89588867
89598868The same template may generally also be used in unpack().
89608869
89618870=end original
89628871
89638872一般には、pack で使用したものと同じテンプレートが、
89648873unpack() 関数でも使用できます。
89658874
89668875=item package NAMESPACE
89678876X<package> X<module> X<namespace>
89688877
89698878=item package
89708879
89718880=begin original
89728881
89738882Declares the compilation unit as being in the given namespace. The scope
89748883of the package declaration is from the declaration itself through the end
89758884of the enclosing block, file, or eval (the same as the C<my> operator).
89768885All further unqualified dynamic identifiers will be in this namespace.
89778886A package statement affects only dynamic variables--including those
89788887you've used C<local> on--but I<not> lexical variables, which are created
89798888with C<my>. Typically it would be the first declaration in a file to
89808889be included by the C<require> or C<use> operator. You can switch into a
89818890package in more than one place; it merely influences which symbol table
89828891is used by the compiler for the rest of that block. You can refer to
89838892variables and filehandles in other packages by prefixing the identifier
89848893with the package name and a double colon: C<$Package::Variable>.
89858894If the package name is null, the C<main> package as assumed. That is,
89868895C<$::sail> is equivalent to C<$main::sail> (as well as to C<$main'sail>,
89878896still seen in older code).
89888897
89898898=end original
89908899
89918900与えられた名前空間でのコンパイル単位を宣言します。
89928901パッケージ宣言のスコープは、宣言自体から、閉じたブロック、ファイル、
89938902eval の終わりまでです(C<my> 演算子と同じです)。
89948903全てのさらなる修飾されてない動的識別子はこの名前空間になります。
89958904package 文は動的変数にのみ影響します -- C<local> で使ったものも
89968905含みます -- が、C<my> で作成されたレキシカル変数には I<影響しません>。
89978906典型的にはこれは C<require> や C<use> 演算子でインクルードされるファイルの
89988907最初に宣言されます。
89998908パッケージを複数の場所で切り替えることができます;
90008909これは単にコンパイラがこのブロックの残りに対してどのシンボルテーブルを
90018910使うかにのみ影響します。
90028911他のパッケージの変数やファイルハンドルは、識別子にパッケージ名と
90038912コロン 2 つをつけることで参照できます(C<$Package::Variable>)。
90048913パッケージ名が空文字列の場合、C<main> パッケージが仮定されます。
90058914つまり、C<$::sail> は C<$main::sail> と等価です(C<$main'sail> も
90068915古いコードではまだ見られます)。
90078916
90088917=begin original
90098918
8919If NAMESPACE is omitted, then there is no current package, and all
8920identifiers must be fully qualified or lexicals. However, you are
8921strongly advised not to make use of this feature. Its use can cause
8922unexpected behaviour, even crashing some versions of Perl. It is
8923deprecated, and will be removed from a future release.
8924
8925=end original
8926
8927NAMESPACE が省略されると、カレントパッケージはなくなるので、
8928全ての識別子は完全修飾されるかレキシカルでなければなりません。
8929しかし、この機能を使わないことを強く勧めます。
8930この使用は予想外の振る舞いを引きおこすことがあり、Perl のバージョンに
8931よってはクラッシュするかもしれません。
8932これは非推奨であり、将来のリリースでは削除されます。
8933
8934=begin original
8935
90108936See L<perlmod/"Packages"> for more information about packages, modules,
90118937and classes. See L<perlsub> for other scoping issues.
90128938
90138939=end original
90148940
90158941パッケージ、モジュール、クラスに関するさらなる情報については
90168942L<perlmod/"Packages"> を参照してください。
90178943その他のスコープに関する話題については L<perlsub> を参照してください。
90188944
90198945=item pipe READHANDLE,WRITEHANDLE
90208946X<pipe>
90218947
90228948=begin original
90238949
90248950Opens a pair of connected pipes like the corresponding system call.
90258951Note that if you set up a loop of piped processes, deadlock can occur
90268952unless you are very careful. In addition, note that Perl's pipes use
90278953IO buffering, so you may need to set C<$|> to flush your WRITEHANDLE
90288954after each command, depending on the application.
90298955
90308956=end original
90318957
90328958対応するシステムコールと同じように、
90338959接続されたパイプのペアをオープンします。
90348960パイプでプロセスをループにするときには、よほど気を付けないと、
90358961デッドロックが起こり得ます。
90368962さらに、Perl のパイプでは、IO のバッファリングを使いますから、
90378963アプリケーションによっては、コマンドごとに WRITEHANDLE を
90388964フラッシュするように、C<$|> を設定することが必要になるかもしれません。
90398965
90408966=begin original
90418967
90428968See L<IPC::Open2>, L<IPC::Open3>, and L<perlipc/"Bidirectional Communication">
90438969for examples of such things.
90448970
90458971=end original
90468972
90478973これらに関する例については、L<IPC::Open2>, L<IPC::Open3>,
90488974L<perlipc/"Bidirectional Communication"> を参照して下さい。
90498975
90508976=begin original
90518977
90528978On systems that support a close-on-exec flag on files, the flag will be set
90538979for the newly opened file descriptors as determined by the value of $^F.
90548980See L<perlvar/$^F>.
90558981
90568982=end original
90578983
90588984ファイルに対する close-on-exec フラグをサポートしているシステムでは、
90598985フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
90608986セットされます。
90618987L<perlvar/$^F> を参照してください。
90628988
90638989=item pop ARRAY
90648990X<pop> X<stack>
90658991
90668992=item pop
90678993
90688994=begin original
90698995
90708996Pops and returns the last value of the array, shortening the array by
90718997one element.
90728998
90738999=end original
90749000
90759001配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。
90769002
90779003=begin original
90789004
90799005If there are no elements in the array, returns the undefined value
90809006(although this may happen at other times as well). If ARRAY is
90819007omitted, pops the C<@ARGV> array in the main program, and the C<@_>
90829008array in subroutines, just like C<shift>.
90839009
90849010=end original
90859011
90869012指定された配列に要素がなければ、未定義値が返されます
90879013(しかしこれは他の場合にも起こり得ます)。
90889014ARRAY が省略されると、C<shift> と同様に、メインプログラムでは C<@ARGV>が、
90899015サブルーチンでは C<@_> が使われます。
90909016
90919017=item pos SCALAR
90929018X<pos> X<match, position>
90939019
90949020=item pos
90959021
90969022=begin original
90979023
90989024Returns the offset of where the last C<m//g> search left off for the variable
90999025in question (C<$_> is used when the variable is not specified). Note that
910090260 is a valid match offset. C<undef> indicates that the search position
91019027is reset (usually due to match failure, but can also be because no match has
91029028yet been performed on the scalar). C<pos> directly accesses the location used
91039029by the regexp engine to store the offset, so assigning to C<pos> will change
91049030that offset, and so will also influence the C<\G> zero-width assertion in
91059031regular expressions. Because a failed C<m//gc> match doesn't reset the offset,
91069032the return from C<pos> won't change either in this case. See L<perlre> and
91079033L<perlop>.
91089034
91099035=end original
91109036
91119037対象の変数に対して、前回の C<m//g> が終了した場所の
91129038オフセットを返します(変数が指定されなかった場合は C<$_> が使われます)。
911390390 は有効なマッチオフセットであることに注意してください。
91149040C<undef> は検索位置がリセットされることを意味します (通常はマッチ失敗が
91159041原因ですが、このスカラ値にまだマッチングが行われていないためかもしれません)。
91169042C<pos> は正規表現エンジンがオフセットを保存するために使う場所を直接
91179043アクセスするので、C<pos> への代入はオフセットを変更し、そのような変更は
91189044正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
91199045C<m//gc> マッチに失敗してもオフセットはリセットしないので、
91209046C<pos> からの返り値はどちらの場合も変更されません。
91219047L<perlre> と L<perlop> を参照してください。
91229048
91239049=item print FILEHANDLE LIST
91249050X<print>
91259051
91269052=item print LIST
91279053
91289054=item print
91299055
91309056=begin original
91319057
91329058Prints a string or a list of strings. Returns true if successful.
91339059FILEHANDLE may be a scalar variable name, in which case the variable
91349060contains the name of or a reference to the filehandle, thus introducing
91359061one level of indirection. (NOTE: If FILEHANDLE is a variable and
91369062the next token is a term, it may be misinterpreted as an operator
91379063unless you interpose a C<+> or put parentheses around the arguments.)
91389064If FILEHANDLE is omitted, prints by default to standard output (or
91399065to the last selected output channel--see L</select>). If LIST is
91409066also omitted, prints C<$_> to the currently selected output channel.
91419067To set the default output channel to something other than STDOUT
91429068use the select operation. The current value of C<$,> (if any) is
91439069printed between each LIST item. The current value of C<$\> (if
91449070any) is printed after the entire LIST has been printed. Because
91459071print takes a LIST, anything in the LIST is evaluated in list
91469072context, and any subroutine that you call will have one or more of
91479073its expressions evaluated in list context. Also be careful not to
91489074follow the print keyword with a left parenthesis unless you want
91499075the corresponding right parenthesis to terminate the arguments to
91509076the print--interpose a C<+> or put parentheses around all the
91519077arguments.
91529078
91539079=end original
91549080
91559081文字列か文字列のリストを出力します。
91569082成功時には、真を返します。FILEHANDLE は、スカラ変数名でもよく、
91579083その場合には、その変数にファイルハンドル名またはそのリファレンスが
91589084入っているものとして扱われますから、一段階の間接指定が行なえます。
91599085(注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、
91609086間に C<+> を置くか、引数の前後を括弧で括らなければ、
91619087誤って解釈されることがあります。)
91629088FILEHANDLE を省略した場合には、標準出力 (か、最後に選択された出力チャネル
91639089-- L</select>を参照) に出力します。
91649090LIST も省略すると、C<$_> を現在選択されている出力チャネルに
91659091出力することになります。
91669092デフォルトの出力チャネルを STDOUT 以外にしたければ、select 演算子を
91679093使ってください。
91689094C<$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
91699095print の引数は LIST なので、LISTの中のものは、
91709096すべてリストコンテキストで評価されます。
91719097サブルーチンの呼び出しがあれば、リストコンテキストでは、
91729098複数の値を返すかもしれません。
91739099また、すべての引数を括弧で括るのでなければ、print というキーワードの
91749100次に開き括弧を書いてはいけません。
91759101"print" と引数の間に C<+> を書くか、すべての引数を括弧で括ってください。
91769102
91779103=begin original
91789104
91799105Note that if you're storing FILEHANDLEs in an array, or if you're using
91809106any other expression more complex than a scalar variable to retrieve it,
91819107you will have to use a block returning the filehandle value instead:
91829108
91839109=end original
91849110
91859111もし FILESHANDLE を配列に保存していたり、それを得るためにスカラ変数より
91869112複雑な表現を使っている場合、
91879113代わりにその値を返すブロックを使う必要があります:
91889114
91899115 print { $files[$i] } "stuff\n";
91909116 print { $OK ? STDOUT : STDERR } "stuff\n";
91919117
91929118=item printf FILEHANDLE FORMAT, LIST
91939119X<printf>
91949120
91959121=item printf FORMAT, LIST
91969122
91979123=begin original
91989124
91999125Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that C<$\>
92009126(the output record separator) is not appended. The first argument
92019127of the list will be interpreted as the C<printf> format. See C<sprintf>
92029128for an explanation of the format argument. If C<use locale> is in effect,
92039129and POSIX::setlocale() has been called, the character used for the decimal
92049130separator in formatted floating point numbers is affected by the LC_NUMERIC
92059131locale. See L<perllocale> and L<POSIX>.
92069132
92079133=end original
92089134
92099135C<$\>(出力レコードセパレータ)を追加しないことを除けば、
92109136C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。
92119137リストの最初の要素は、C<printf> フォーマットと解釈されます。
92129138フォーマット引数の説明については C<sprintf> を参照してください。
92139139C<use locale> が効力をもっていて、POSIX::setlocale() が呼び出されていれば、
92149140小数点に使われる文字は LC_NUMERIC ロケールの影響を受けます。
92159141L<perllocale> と L<POSIX> を参照してください。
92169142
92179143=begin original
92189144
92199145Don't fall into the trap of using a C<printf> when a simple
92209146C<print> would do. The C<print> is more efficient and less
92219147error prone.
92229148
92239149=end original
92249150
92259151単純な C<print> を使うべきところで C<printf> を使ってしまう
92269152罠にかからないようにしてください。
92279153C<print> はより効率的で、間違いが起こりにくいです。
92289154
92299155=item prototype FUNCTION
92309156X<prototype>
92319157
92329158=begin original
92339159
92349160Returns the prototype of a function as a string (or C<undef> if the
92359161function has no prototype). FUNCTION is a reference to, or the name of,
92369162the function whose prototype you want to retrieve.
92379163
92389164=end original
92399165
92409166関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は
92419167C<undef> を返します)。
92429168FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。
92439169
92449170=begin original
92459171
92469172If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
92479173name for Perl builtin. If the builtin is not I<overridable> (such as
92489174C<qw//>) or if its arguments cannot be adequately expressed by a prototype
92499175(such as C<system>), prototype() returns C<undef>, because the builtin
92509176does not really behave like a Perl function. Otherwise, the string
92519177describing the equivalent prototype is returned.
92529178
92539179=end original
92549180
92559181FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として
92569182扱われます。
92579183このビルドインが(C<qw//> のように) I<オーバーライド可能> でない、
92589184またはこの引数が(C<system> のように)プロトタイプとして適切に記述できない場合、
92599185prototype() は C<undef> を返します;
92609186なぜならビルドインは実際に Perl 関数のように振舞わないからです。
92619187それ以外では、等価なプロトタイプを表現した文字列が返されます。
92629188
92639189=item push ARRAY,LIST
92649190X<push> X<stack>
92659191
92669192=begin original
92679193
92689194Treats ARRAY as a stack, and pushes the values of LIST
92699195onto the end of ARRAY. The length of ARRAY increases by the length of
92709196LIST. Has the same effect as
92719197
92729198=end original
92739199
92749200ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりにプッシュします。
92759201ARRAY の大きさは、LIST の長さ分だけ大きくなります。
92769202これは、
92779203
92789204 for $value (LIST) {
92799205 $ARRAY[++$#ARRAY] = $value;
92809206 }
92819207
92829208=begin original
92839209
92849210but is more efficient. Returns the number of elements in the array following
92859211the completed C<push>.
92869212
92879213=end original
92889214
92899215とするのと同じ効果がありますが、より効率的です。
92909216C<push> の処理終了後の配列の要素数を返します。
92919217
92929218=item q/STRING/
92939219
92949220=item qq/STRING/
92959221
9222=item qr/STRING/
9223
92969224=item qx/STRING/
92979225
92989226=item qw/STRING/
92999227
93009228=begin original
93019229
9302Generalized quotes. See L<perlop/"Quote-Like Operators">.
9230Generalized quotes. See L<perlop/"Regexp Quote-Like Operators">.
93039231
93049232=end original
93059233
93069234汎用のクォートです。
9307L<perlop/"Quote-Like Operators"> を参照してください。
9308
9309=item qr/STRING/
9310
9311=begin original
9312
9313Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">.
9314
9315=end original
9316
9317正規表現風のクォートです。
93189235L<perlop/"Regexp Quote-Like Operators"> を参照してください。
93199236
93209237=item quotemeta EXPR
93219238X<quotemeta> X<metacharacter>
93229239
93239240=item quotemeta
93249241
93259242=begin original
93269243
93279244Returns the value of EXPR with all non-"word"
93289245characters backslashed. (That is, all characters not matching
93299246C</[A-Za-z_0-9]/> will be preceded by a backslash in the
93309247returned string, regardless of any locale settings.)
93319248This is the internal function implementing
93329249the C<\Q> escape in double-quoted strings.
93339250
93349251=end original
93359252
93369253EXPR の中のすべての非英数字キャラクタをバックスラッシュで
93379254エスケープしたものを返します
93389255(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての文字の前には
93399256ロケールに関わらずバックスラッシュが前置されます)。
93409257これは、ダブルクォート文字列での C<\Q> エスケープを
93419258実装するための内部関数です。
93429259
93439260=begin original
93449261
93459262If EXPR is omitted, uses C<$_>.
93469263
93479264=end original
93489265
93499266EXPR が省略されると、C<$_> を使います。
93509267
93519268=item rand EXPR
93529269X<rand> X<random>
93539270
93549271=item rand
93559272
93569273=begin original
93579274
93589275Returns a random fractional number greater than or equal to C<0> and less
93599276than the value of EXPR. (EXPR should be positive.) If EXPR is
93609277omitted, the value C<1> is used. Currently EXPR with the value C<0> is
93619278also special-cased as C<1> - this has not been documented before perl 5.8.0
93629279and is subject to change in future versions of perl. Automatically calls
93639280C<srand> unless C<srand> has already been called. See also C<srand>.
93649281
93659282=end original
93669283
93679284C<0> 以上 EXPR の値未満の小数の乱数値を返します。
93689285(EXPR は正の数である必要があります。)
93699286EXPR を省略すると、C<1> とみなします。
93709287現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます -
93719288これは perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では
93729289変更される可能性があります。
93739290C<srand> が既に呼ばれている場合以外は、自動的に C<srand> 関数を
93749291呼び出します。
93759292C<srand> も参照してください。
93769293
93779294=begin original
93789295
93799296Apply C<int()> to the value returned by C<rand()> if you want random
93809297integers instead of random fractional numbers. For example,
93819298
93829299=end original
93839300
93849301ランダムな小数ではなく、ランダムな整数がほしい場合は、C<rand()> から
93859302返された値に C<int()> を適用してください。
93869303
93879304 int(rand(10))
93889305
93899306=begin original
93909307
93919308returns a random integer between C<0> and C<9>, inclusive.
93929309
93939310=end original
93949311
93959312これは C<0> から C<9> の値をランダムに返します。
93969313
93979314=begin original
93989315
93999316(Note: If your rand function consistently returns numbers that are too
94009317large or too small, then your version of Perl was probably compiled
94019318with the wrong number of RANDBITS.)
94029319
94039320=end original
94049321
94059322(注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを
94069323返すようなら、お使いになっている Perl が、
94079324良くない RANDBITS を使ってコンパイルされている可能性があります。)
94089325
94099326=item read FILEHANDLE,SCALAR,LENGTH,OFFSET
94109327X<read> X<file, read>
94119328
94129329=item read FILEHANDLE,SCALAR,LENGTH
94139330
94149331=begin original
94159332
94169333Attempts to read LENGTH I<characters> of data into variable SCALAR
94179334from the specified FILEHANDLE. Returns the number of characters
94189335actually read, C<0> at end of file, or undef if there was an error (in
94199336the latter case C<$!> is also set). SCALAR will be grown or shrunk
94209337so that the last character actually read is the last character of the
94219338scalar after the read.
94229339
94239340=end original
94249341
94259342指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> の
94269343データを読み込みます。
94279344実際に読み込まれた文字数、
94289345ファイル終端の場合は C<0>、エラーの場合は undef のいずれかを返します
94299346(後者の場合、C<$!> もセットされます)。
94309347SCALAR は伸び縮みするので、
94319348読み込み後は、実際に読み込んだ最後の文字がスカラの最後の文字になります。
94329349
94339350=begin original
94349351
94359352An OFFSET may be specified to place the read data at some place in the
94369353string other than the beginning. A negative OFFSET specifies
94379354placement at that many characters counting backwards from the end of
94389355the string. A positive OFFSET greater than the length of SCALAR
94399356results in the string being padded to the required size with C<"\0">
94409357bytes before the result of the read is appended.
94419358
94429359=end original
94439360
9444OFFSET を指定すると、SCALAR の先頭以外の場所から、読み込みを行なうことが
9361OFFSET を指定すると、文字列の先頭以外の場所から、
9445できます。
9362読み込みを行なうことができます。
9446OFFSET に負の値を指定すると、文字列の最後から逆向に何文字目か
9363負の数の OFFSET を指定すると、文字列の最後から逆向に何文字目かを数えます。
9447位置を指定しま
9364SCALAR の長さよりも大きい、正の数の OFFSET を指定すると、文字列は
9448OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は
94499365読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイトで
94509366パッディングされます。
94519367
94529368=begin original
94539369
94549370The call is actually implemented in terms of either Perl's or system's
94559371fread() call. To get a true read(2) system call, see C<sysread>.
94569372
94579373=end original
94589374
94599375この関数は、Perl か システムの fread() 関数を使って実装しています。
94609376本当の read(2) システムコールを利用するには、C<sysread> を参照してください。
94619377
94629378=begin original
94639379
94649380Note the I<characters>: depending on the status of the filehandle,
94659381either (8-bit) bytes or characters are read. By default all
94669382filehandles operate on bytes, but for example if the filehandle has
94679383been opened with the C<:utf8> I/O layer (see L</open>, and the C<open>
94689384pragma, L<open>), the I/O will operate on UTF-8 encoded Unicode
94699385characters, not bytes. Similarly for the C<:encoding> pragma:
94709386in that case pretty much any characters can be read.
94719387
94729388=end original
94739389
94749390I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか
94759391文字が読み込まれます。
94769392デフォルトでは全てのファイルハンドルはバイトを処理しますが、
94779393例えばファイルハンドルが C<:utf8> I/O 層(L</open>, C<open> プラグマ、
94789394L<open> を参照してください) で開かれた場合、I/O はバイトではなく、
94799395UTF-8 エンコードされた Unicode 文字を操作します。
94809396C<:encoding> プラグマも同様です:
94819397この場合、ほとんど大体全ての文字が読み込めます。
94829398
94839399=item readdir DIRHANDLE
94849400X<readdir>
94859401
94869402=begin original
94879403
94889404Returns the next directory entry for a directory opened by C<opendir>.
94899405If used in list context, returns all the rest of the entries in the
94909406directory. If there are no more entries, returns an undefined value in
94919407scalar context or a null list in list context.
94929408
94939409=end original
94949410
94959411C<opendir> でオープンしたディレクトリで、
94969412次のディレクトリエントリを返します。
94979413リストコンテキストで用いると、
94989414そのディレクトリの残りのエントリを、すべて返します。
94999415エントリが残っていない場合には、スカラコンテキストでは未定義値を、
95009416リストコンテキストでは空リストを返します。
95019417
95029418=begin original
95039419
95049420If you're planning to filetest the return values out of a C<readdir>, you'd
95059421better prepend the directory in question. Otherwise, because we didn't
95069422C<chdir> there, it would have been testing the wrong file.
95079423
95089424=end original
95099425
95109426C<readdir> の返り値をファイルテストに使おうと計画しているなら、
95119427頭にディレクトリをつける必要があります。
95129428さもなければ、ここでは C<chdir> はしないので、
95139429間違ったファイルをテストしてしまうことになるでしょう。
95149430
9515 opendir(my $dh, $some_dir) || die "can't opendir $some_dir: $!";
9431 opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
9516 @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
9432 @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR);
9517 closedir $dh;
9433 closedir DIR;
95189434
95199435=item readline EXPR
95209436
95219437=item readline
95229438X<readline> X<gets> X<fgets>
95239439
95249440=begin original
95259441
95269442Reads from the filehandle whose typeglob is contained in EXPR (or from
95279443*ARGV if EXPR is not provided). In scalar context, each call reads and
95289444returns the next line, until end-of-file is reached, whereupon the
95299445subsequent call returns undef. In list context, reads until end-of-file
95309446is reached and returns a list of lines. Note that the notion of "line"
95319447used here is however you may have defined it with C<$/> or
95329448C<$INPUT_RECORD_SEPARATOR>). See L<perlvar/"$/">.
95339449
95349450=end original
95359451
95369452型グロブが EXPR (EXPR がない場合は *ARGV) に含まれている
95379453ファイルハンドルから読み込みます。
95389454スカラコンテキストでは、呼び出し毎に一行読み込んで返します。
95399455ファイルの最後まで読み込んだら、以後の呼び出しでは undef を返します。
95409456リストコンテキストでは、ファイルの最後まで読み込んで、
95419457行のリストを返します。
95429458ここでの「行」とは、C<$/> または C<$INPUT_RECORD_SEPARATOR> で
95439459定義されることに注意してください。L<perlvar/"$/"> も参照して下さい。
95449460
95459461=begin original
95469462
95479463When C<$/> is set to C<undef>, when readline() is in scalar
95489464context (i.e. file slurp mode), and when an empty file is read, it
95499465returns C<''> the first time, followed by C<undef> subsequently.
95509466
95519467=end original
95529468
95539469C<$/> に C<undef> を設定した場合は、readline() はスカラコンテキスト
95549470(つまりファイル吸い込みモード)となり、
95559471空のファイルを読み込んだ場合は、最初は C<''> を返し、
95569472それ以降は C<undef> を返します。
95579473
95589474=begin original
95599475
95609476This is the internal function implementing the C<< <EXPR> >>
95619477operator, but you can use it directly. The C<< <EXPR> >>
95629478operator is discussed in more detail in L<perlop/"I/O Operators">.
95639479
95649480=end original
95659481
95669482これは C<< <EXPR> >> 演算子を実装している内部関数ですが、
95679483直接使うこともできます。
95689484C<< <EXPR> >> 演算子についてのさらなる詳細については
95699485L<perlop/"I/O Operators"> で議論されています。
95709486
95719487 $line = <STDIN>;
95729488 $line = readline(*STDIN); # same thing
95739489
95749490=begin original
95759491
95769492If readline encounters an operating system error, C<$!> will be set with the
95779493corresponding error message. It can be helpful to check C<$!> when you are
95789494reading from filehandles you don't trust, such as a tty or a socket. The
95799495following example uses the operator form of C<readline>, and takes the necessary
95809496steps to ensure that C<readline> was successful.
95819497
95829498=end original
95839499
95849500readline が OS のシステムエラーになると、C<$!> に対応するエラーメッセージが
95859501セットされます。
95869502tty やソケットといった、信頼できないファイルハンドルから読み込む時には
95879503C<$!> をチェックするのが助けになります。
95889504以下の例は演算子の形の C<readline> を使っており、C<readline> が
95899505成功したことを確実にするために必要なステップを実行しています。
95909506
95919507 for (;;) {
95929508 undef $!;
95939509 unless (defined( $line = <> )) {
9594 last if eof;
95959510 die $! if $!;
9511 last; # reached EOF
95969512 }
95979513 # ...
95989514 }
95999515
96009516=item readlink EXPR
96019517X<readlink>
96029518
96039519=item readlink
96049520
96059521=begin original
96069522
96079523Returns the value of a symbolic link, if symbolic links are
96089524implemented. If not, gives a fatal error. If there is some system
96099525error, returns the undefined value and sets C<$!> (errno). If EXPR is
96109526omitted, uses C<$_>.
96119527
96129528=end original
96139529
96149530シンボリックリンクが実装されていれば、
96159531シンボリックリンクの値を返します。
96169532実装されていないときには、致命的エラーとなります。
96179533何らかのシステムエラーが検出されると、
96189534未定義値を返し、C<$!> (errno)を設定します。
96199535EXPR を省略すると、C<$_> を使用します。
96209536
96219537=item readpipe EXPR
96229538
96239539=item readpipe
96249540X<readpipe>
96259541
96269542=begin original
96279543
96289544EXPR is executed as a system command.
96299545The collected standard output of the command is returned.
96309546In scalar context, it comes back as a single (potentially
96319547multi-line) string. In list context, returns a list of lines
96329548(however you've defined lines with C<$/> or C<$INPUT_RECORD_SEPARATOR>).
96339549This is the internal function implementing the C<qx/EXPR/>
96349550operator, but you can use it directly. The C<qx/EXPR/>
96359551operator is discussed in more detail in L<perlop/"I/O Operators">.
96369552If EXPR is omitted, uses C<$_>.
96379553
96389554=end original
96399555
96409556EXPR がシステムコマンドとして実行されます。
96419557コマンドの標準出力の内容が返されます。
96429558スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。
96439559リストコンテキストでは、行のリストを返します
96449560(但し、行は C<$/> または C<$INPUT_RECORD_SEPARATOR> で定義されます)。
96459561これは C<qx/EXPR/> 演算子を実装する内部関数ですが、
96469562直接使うことも出来ます。
96479563C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に
96489564述べられています。
9649EXPR 省略されると、C<$_> を使ます。
9565EXPR 省略ると、C<$_> を使用します。
96509566
96519567=item recv SOCKET,SCALAR,LENGTH,FLAGS
96529568X<recv>
96539569
96549570=begin original
96559571
96569572Receives a message on a socket. Attempts to receive LENGTH characters
96579573of data into variable SCALAR from the specified SOCKET filehandle.
96589574SCALAR will be grown or shrunk to the length actually read. Takes the
96599575same flags as the system call of the same name. Returns the address
96609576of the sender if SOCKET's protocol supports this; returns an empty
96619577string otherwise. If there's an error, returns the undefined value.
96629578This call is actually implemented in terms of recvfrom(2) system call.
96639579See L<perlipc/"UDP: Message Passing"> for examples.
96649580
96659581=end original
96669582
96679583ソケット上のメッセージを受信します。
96689584指定されたファイルハンドル SOCKET から、変数 SCALAR に
96699585LENGTH 文字のデータを読み込もうとします。
96709586SCALAR は、実際に読まれた長さによって、大きくなったり、
96719587小さくなったりします。
96729588同名のシステムコールと同じ FLAGS を使います。
96739589SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。
96749590エラー発生時には、未定義値を返します。
96759591実際には、C のrecvfrom(2) を呼びます。
96769592例についてはL<perlipc/"UDP: Message Passing">を参照してください。
96779593
96789594=begin original
96799595
96809596Note the I<characters>: depending on the status of the socket, either
96819597(8-bit) bytes or characters are received. By default all sockets
96829598operate on bytes, but for example if the socket has been changed using
96839599binmode() to operate with the C<:encoding(utf8)> I/O layer (see the
96849600C<open> pragma, L<open>), the I/O will operate on UTF-8 encoded Unicode
96859601characters, not bytes. Similarly for the C<:encoding> pragma: in that
96869602case pretty much any characters can be read.
96879603
96889604=end original
96899605
96909606I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
96919607文字を受信します。
96929608デフォルトでは全てのソケットはバイトを処理しますが、
96939609例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(C<open> プラグマ、
96949610L<open> を参照してください) を使うように指定された場合、I/O はバイトではなく、
96959611UTF-8 エンコードされた Unicode 文字を操作します。
96969612C<:encoding> プラグマも同様です:
96979613この場合、ほとんど大体全ての文字が読み込めます。
96989614
96999615=item redo LABEL
97009616X<redo>
97019617
97029618=item redo
97039619
97049620=begin original
97059621
97069622The C<redo> command restarts the loop block without evaluating the
97079623conditional again. The C<continue> block, if any, is not executed. If
97089624the LABEL is omitted, the command refers to the innermost enclosing
97099625loop. Programs that want to lie to themselves about what was just input
97109626normally use this command:
97119627
97129628=end original
97139629
97149630C<redo> コマンドは、条件を再評価しないで、ループブロックの始めからもう一度
97159631実行を開始します。
97169632C<continue> ブロックがあっても、実行されません。
97179633LABEL が省略されると、このコマンドは、もっとも内側のループを参照します。
97189634このコマンドは通常、自分への入力を欺くために使用します:
97199635
97209636 # a simpleminded Pascal comment stripper
97219637 # (warning: assumes no { or } in strings)
97229638 LINE: while (<STDIN>) {
97239639 while (s|({.*}.*){.*}|$1 |) {}
97249640 s|{.*}| |;
97259641 if (s|{.*| |) {
97269642 $front = $_;
97279643 while (<STDIN>) {
97289644 if (/}/) { # end of comment?
97299645 s|^|$front\{|;
97309646 redo LINE;
97319647 }
97329648 }
97339649 }
97349650 print;
97359651 }
97369652
97379653=begin original
97389654
97399655C<redo> cannot be used to retry a block which returns a value such as
97409656C<eval {}>, C<sub {}> or C<do {}>, and should not be used to exit
97419657a grep() or map() operation.
97429658
97439659=end original
97449660
97459661C<redo> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
97469662ブロックを繰り返すのには使えません。
97479663また、grep() や map() 操作から抜けるのに使うべきではありません。
97489664
97499665=begin original
97509666
97519667Note that a block by itself is semantically identical to a loop
97529668that executes once. Thus C<redo> inside such a block will effectively
97539669turn it into a looping construct.
97549670
97559671=end original
97569672
97579673ブロック自身は一回だけ実行されるループと文法的に同一であることに
97589674注意してください。
97599675従って、ブロックの中で C<redo> を使うことで効果的に
97609676ループ構造に変換します。
97619677
97629678=begin original
97639679
97649680See also L</continue> for an illustration of how C<last>, C<next>, and
97659681C<redo> work.
97669682
97679683=end original
97689684
97699685C<last>, C<next>, C<redo> がどのように働くかについては
9770L</continue> 参照して下さい。
9686L</continue> 参照して下さい。
97719687
97729688=item ref EXPR
97739689X<ref> X<reference>
97749690
97759691=item ref
97769692
97779693=begin original
97789694
97799695Returns a non-empty string if EXPR is a reference, the empty
97809696string otherwise. If EXPR
97819697is not specified, C<$_> will be used. The value returned depends on the
97829698type of thing the reference is a reference to.
97839699Builtin types include:
97849700
97859701=end original
97869702
97879703EXPR がリファレンスであれば、空でない文字列を返し、さもなくば、
97889704空文字列を返します。
97899705EXPR が指定されなければ、C<$_> が使われます。
97909706返される値は、リファレンスが参照するものの型に依存します。
97919707組み込みの型には、以下のものがあります。
97929708
97939709 SCALAR
97949710 ARRAY
97959711 HASH
97969712 CODE
97979713 REF
97989714 GLOB
97999715 LVALUE
98009716 FORMAT
98019717 IO
98029718 VSTRING
98039719 Regexp
98049720
98059721=begin original
98069722
98079723If the referenced object has been blessed into a package, then that package
98089724name is returned instead. You can think of C<ref> as a C<typeof> operator.
98099725
98109726=end original
98119727
98129728参照されるオブジェクトが、何らかのパッケージに
98139729bless されたものであれば、これらの代わりに、
98149730そのパッケージ名が返されます。
98159731C<ref> は、C<typeof> 演算子のように考えることができます。
98169732
98179733 if (ref($r) eq "HASH") {
98189734 print "r is a reference to a hash.\n";
98199735 }
98209736 unless (ref($r)) {
98219737 print "r is not a reference at all.\n";
98229738 }
98239739
98249740=begin original
98259741
98269742The return value C<LVALUE> indicates a reference to an lvalue that is not
98279743a variable. You get this from taking the reference of function calls like
98289744C<pos()> or C<substr()>. C<VSTRING> is returned if the reference points
98299745to a L<version string|perldata/"Version Strings">.
98309746
98319747=end original
98329748
98339749返り値 C<LVALUE> は、変数ではない左辺値へのリファレンスを示します。
98349750これは、C<pos()> や C<substr()> のようの関数呼び出しのリファレンスから
98359751得られます。
98369752C<VSTRING> は、リファレンスが L<version string|perldata/"Version Strings"> を
98379753指している場合に返されます。
98389754
98399755=begin original
98409756
98419757The result C<Regexp> indicates that the argument is a regular expression
98429758resulting from C<qr//>.
98439759
98449760=end original
98459761
98469762C<Regexp> という結果は、引数が C<qr//> からの結果である
98479763正規表現であることを意味します。
98489764
98499765=begin original
98509766
98519767See also L<perlref>.
98529768
98539769=end original
98549770
98559771L<perlref> も参照してください。
98569772
98579773=item rename OLDNAME,NEWNAME
98589774X<rename> X<move> X<mv> X<ren>
98599775
98609776=begin original
98619777
98629778Changes the name of a file; an existing file NEWNAME will be
98639779clobbered. Returns true for success, false otherwise.
98649780
98659781=end original
98669782
98679783ファイルの名前を変更します。
98689784NEWNAME というファイルが既に存在した場合、上書きされるかもしれません。
98699785成功時には真、失敗時には偽を返します。
98709786
98719787=begin original
98729788
98739789Behavior of this function varies wildly depending on your system
98749790implementation. For example, it will usually not work across file system
98759791boundaries, even though the system I<mv> command sometimes compensates
98769792for this. Other restrictions include whether it works on directories,
98779793open files, or pre-existing files. Check L<perlport> and either the
98789794rename(2) manpage or equivalent system documentation for details.
98799795
98809796=end original
98819797
98829798この関数の振る舞いはシステムの実装に大きく依存して異なります。
98839799普通はファイルシステムにまたがってパス名を付け替えることはできません。
98849800システムの I<mv> がこれを補完している場合でもそうです。
98859801その他の制限には、ディレクトリ、オープンしているファイル、既に存在している
98869802ファイルに対して使えるか、といったことを含みます。
98879803詳しくは、L<perlport> および rename(2) man ページあるいは同様の
98889804システムドキュメントを参照してください。
98899805
98909806=begin original
98919807
98929808For a platform independent C<move> function look at the L<File::Copy>
98939809module.
98949810
98959811=end original
98969812
98979813プラットフォームに依存しない C<move> 関数については L<File::Copy> モジュールを
98989814参照してください。
98999815
99009816=item require VERSION
99019817X<require>
99029818
99039819=item require EXPR
99049820
99059821=item require
99069822
99079823=begin original
99089824
99099825Demands a version of Perl specified by VERSION, or demands some semantics
99109826specified by EXPR or by C<$_> if EXPR is not supplied.
99119827
99129828=end original
99139829
99149830VERSION で指定される Perl のバージョンを要求するか、
99159831EXPR (省略時には C<$_>) によって指定されるいくつかの動作を要求します。
99169832
99179833=begin original
99189834
99199835VERSION may be either a numeric argument such as 5.006, which will be
99209836compared to C<$]>, or a literal of the form v5.6.1, which will be compared
99219837to C<$^V> (aka $PERL_VERSION). A fatal error is produced at run time if
99229838VERSION is greater than the version of the current Perl interpreter.
99239839Compare with L</use>, which can do a similar check at compile time.
99249840
99259841=end original
99269842
99279843VERSION は 5.006 のような数値(C<$]> と比較されます)か、v5.6.1 の形
99289844(C<$^V> (またの名を $PERL_VERSION) と比較されます)で指定します。
99299845VERSION が Perl の現在のバージョンより大きいと、実行時に致命的エラーが
99309846発生します。
99319847L</use> と似ていますが、これはコンパイル時にチェックされます。
99329848
99339849=begin original
99349850
99359851Specifying VERSION as a literal of the form v5.6.1 should generally be
99369852avoided, because it leads to misleading error messages under earlier
99379853versions of Perl that do not support this syntax. The equivalent numeric
99389854version should be used instead.
99399855
99409856=end original
99419857
99429858VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
99439859なぜなら、この文法に対応していない Perl の初期のバージョンでは
99449860誤解させるようなエラーメッセージが出るからです。
99459861代わりに等価な数値表現を使うべきです。
99469862
99479863 require v5.6.1; # run time version check
99489864 require 5.6.1; # ditto
99499865 require 5.006_001; # ditto; preferred for backwards compatibility
99509866
99519867=begin original
99529868
99539869Otherwise, C<require> demands that a library file be included if it
99549870hasn't already been included. The file is included via the do-FILE
99559871mechanism, which is essentially just a variety of C<eval> with the
99569872caveat that lexical variables in the invoking script will be invisible
99579873to the included code. Has semantics similar to the following subroutine:
99589874
99599875=end original
99609876
99619877それ以外の場合には、C<require> は、既に読み込まれていないときに読み込む
99629878ライブラリファイルを要求するものとなります。
99639879そのファイルは、基本的には C<eval> の一種である、do-FILE によって
99649880読み込まれますが、起動したスクリプトのレキシカル変数は読み込まれたコードから
99659881見えないという欠点があります。
99669882意味的には、次のようなサブルーチンと同じようなものです:
99679883
99689884 sub require {
99699885 my ($filename) = @_;
99709886 if (exists $INC{$filename}) {
99719887 return 1 if $INC{$filename};
99729888 die "Compilation failed in require";
99739889 }
99749890 my ($realfilename,$result);
99759891 ITER: {
99769892 foreach $prefix (@INC) {
99779893 $realfilename = "$prefix/$filename";
99789894 if (-f $realfilename) {
99799895 $INC{$filename} = $realfilename;
99809896 $result = do $realfilename;
99819897 last ITER;
99829898 }
99839899 }
99849900 die "Can't find $filename in \@INC";
99859901 }
99869902 if ($@) {
99879903 $INC{$filename} = undef;
99889904 die $@;
99899905 } elsif (!$result) {
99909906 delete $INC{$filename};
99919907 die "$filename did not return true value";
99929908 } else {
99939909 return $result;
99949910 }
99959911 }
99969912
99979913=begin original
99989914
99999915Note that the file will not be included twice under the same specified
100009916name.
100019917
100029918=end original
100039919
100049920ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。
100059921
100069922=begin original
100079923
100089924The file must return true as the last statement to indicate
100099925successful execution of any initialization code, so it's customary to
100109926end such a file with C<1;> unless you're sure it'll return true
100119927otherwise. But it's better just to put the C<1;>, in case you add more
100129928statements.
100139929
100149930=end original
100159931
100169932初期化コードの実行がうまくいったことを示すために、
100179933ファイルは真を返さなければなりませんから、
100189934真を返すようになっている自信がある場合を除いては、
100199935ファイルの最後に C<1;> と書くのが習慣です。
100209936実行文を追加するような場合に備えて、C<1;> と書いておいた方が
100219937良いでしょう。
100229938
100239939=begin original
100249940
100259941If EXPR is a bareword, the require assumes a "F<.pm>" extension and
100269942replaces "F<::>" with "F</>" in the filename for you,
100279943to make it easy to load standard modules. This form of loading of
100289944modules does not risk altering your namespace.
100299945
100309946=end original
100319947
100329948EXPR が裸の単語であるときには、標準モジュールのロードを
100339949簡単にするように、require は拡張子が "F<.pm>" であり、
100349950"F<::>" を "F</>" に変えたものがファイル名であると仮定します。
100359951この形式のモジュールロードは、
100369952名前空間を変更してしまう危険はありません。
100379953
100389954=begin original
100399955
100409956In other words, if you try this:
100419957
100429958=end original
100439959
100449960言い換えると、以下のようにすると:
100459961
100469962 require Foo::Bar; # a splendid bareword
100479963
100489964=begin original
100499965
100509966The require function will actually look for the "F<Foo/Bar.pm>" file in the
100519967directories specified in the C<@INC> array.
100529968
100539969=end original
100549970
100559971require 関数は C<@INC> 配列で指定されたディレクトリにある
100569972"F<Foo/Bar.pm>" ファイルを探します。
100579973
100589974=begin original
100599975
100609976But if you try this:
100619977
100629978=end original
100639979
100649980しかし、以下のようにすると:
100659981
100669982 $class = 'Foo::Bar';
100679983 require $class; # $class is not a bareword
100689984 #or
100699985 require "Foo::Bar"; # not a bareword because of the ""
100709986
100719987=begin original
100729988
100739989The require function will look for the "F<Foo::Bar>" file in the @INC array and
100749990will complain about not finding "F<Foo::Bar>" there. In this case you can do:
100759991
100769992=end original
100779993
100789994require 関数は @INC 配列の "F<Foo::Bar>" ファイルを探し、
100799995おそらくそこに "F<Foo::Bar>" がないと文句をいうことになるでしょう。
100809996このような場合には、以下のようにします:
100819997
100829998 eval "require $class";
100839999
1008410000=begin original
1008510001
1008610002Now that you understand how C<require> looks for files in the case of a
1008710003bareword argument, there is a little extra functionality going on behind
1008810004the scenes. Before C<require> looks for a "F<.pm>" extension, it will
1008910005first look for a similar filename with a "F<.pmc>" extension. If this file
1009010006is found, it will be loaded in place of any file ending in a "F<.pm>"
1009110007extension.
1009210008
1009310009=end original
1009410010
1009510011引数が裸の単語の場合、C<require> がどのようにファイルを探すかを
1009610012理解してください; 水面下でちょっとした追加の機能があります。
1009710013C<require> が拡張子 "F<.pm>" のファイルを探す前に、まず拡張子 "F<.pmc>" を
1009810014持つファイルを探します。
1009910015このファイルが見つかると、このファイルが拡張子 "F<.pm>" の代わりに
1010010016読み込まれます。
1010110017
1010210018=begin original
1010310019
1010410020You can also insert hooks into the import facility, by putting directly
1010510021Perl code into the @INC array. There are three forms of hooks: subroutine
1010610022references, array references and blessed objects.
1010710023
1010810024=end original
1010910025
1011010026@INC 配列に直接 Perl コードを入れることで、インポート機能にフックを
1011110027挿入できます。
10112100283 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、
1011310029bless されたオブジェクトです。
1011410030
1011510031=begin original
1011610032
1011710033Subroutine references are the simplest case. When the inclusion system
1011810034walks through @INC and encounters a subroutine, this subroutine gets
1011910035called with two parameters, the first being a reference to itself, and the
1012010036second the name of the file to be included (e.g. "F<Foo/Bar.pm>"). The
1012110037subroutine should return nothing, or a list of up to three values in the
1012210038following order:
1012310039
1012410040=end original
1012510041
1012610042サブルーチンへのリファレンスは一番単純な場合です。
1012710043インクルード機能が @INC を走査してサブルーチンに出会った場合、この
1012810044サブルーチンは二つの引数と共に呼び出されます;
1012910045一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名
1013010046("F<Foo/Bar.pm>" など)です。
1013110047サブルーチンは C<undef> か、インクルードするファイルが読み込まれる
1013210048ファイルハンドルを返します。
1013310049サブルーチンは何も返さないか、以下の順で最大 3 つの値のリストを
1013410050返します。
1013510051
1013610052=over
1013710053
1013810054=item 1
1013910055
1014010056=begin original
1014110057
1014210058A filehandle, from which the file will be read.
1014310059
1014410060=end original
1014510061
1014610062ファイルが読み込まれるファイルハンドル。
1014710063
1014810064=item 2
1014910065
1015010066=begin original
1015110067
1015210068A reference to a subroutine. If there is no filehandle (previous item),
1015310069then this subroutine is expected to generate one line of source code per
1015410070call, writing the line into C<$_> and returning 1, then returning 0 at
1015510071"end of file". If there is a filehandle, then the subroutine will be
10156called to act as a simple source filter, with the line as read in C<$_>.
10072called to act a simple source filter, with the line as read in C<$_>.
1015710073Again, return 1 for each valid line, and 0 after all lines have been
1015810074returned.
1015910075
1016010076=end original
1016110077
1016210078サブルーチンへのリファレンス。
1016310079(一つ前のアイテムである)ファイルハンドルがない場合、
1016410080サブルーチンは呼び出し毎に一行のソースコードを生成し、その行を C<$_> に
1016510081書き込んで 1 を返し、それから「ファイル終端」で 0 を返すものと想定されます。
1016610082ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして
1016710083振舞うように呼び出され、行は C<$_> から読み込まれます。
1016810084再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。
1016910085
1017010086=item 3
1017110087
1017210088=begin original
1017310089
1017410090Optional state for the subroutine. The state is passed in as C<$_[1]>. A
1017510091reference to the subroutine itself is passed in as C<$_[0]>.
1017610092
1017710093=end original
1017810094
1017910095サブルーチンのための状態(オプション)。
1018010096状態は C<$_[1]> として渡されます。
1018110097サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。
1018210098
1018310099=back
1018410100
1018510101=begin original
1018610102
1018710103If an empty list, C<undef>, or nothing that matches the first 3 values above
1018810104is returned then C<require> will look at the remaining elements of @INC.
1018910105Note that this file handle must be a real file handle (strictly a typeglob,
1019010106or reference to a typeglob, blessed or unblessed) - tied file handles will be
1019110107ignored and return value processing will stop there.
1019210108
1019310109=end original
1019410110
1019510111空リスト、C<undef>、または上記の最初の 3 つの値のどれとも一致しないものが
1019610112返されると、C<require> は @INC の残りの要素を見ます。
1019710113このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの
1019810114リファレンス、bless されているかされていないか)である必要があります -
1019910115tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。
1020010116
1020110117=begin original
1020210118
1020310119If the hook is an array reference, its first element must be a subroutine
1020410120reference. This subroutine is called as above, but the first parameter is
1020510121the array reference. This enables to pass indirectly some arguments to
1020610122the subroutine.
1020710123
1020810124=end original
1020910125
1021010126フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの
1021110127リファレンスでなければなりません。
1021210128このサブルーチンは上述のように呼び出されますが、その最初の引数は
1021310129配列のリファレンスです。
1021410130これによって、間接的にサブルーチンに引数を渡すことが出来ます。
1021510131
1021610132=begin original
1021710133
1021810134In other words, you can write:
1021910135
1022010136=end original
1022110137
1022210138言い換えると、以下のように書いたり:
1022310139
1022410140 push @INC, \&my_sub;
1022510141 sub my_sub {
1022610142 my ($coderef, $filename) = @_; # $coderef is \&my_sub
1022710143 ...
1022810144 }
1022910145
1023010146=begin original
1023110147
1023210148or:
1023310149
1023410150=end original
1023510151
1023610152または以下のように書けます:
1023710153
1023810154 push @INC, [ \&my_sub, $x, $y, ... ];
1023910155 sub my_sub {
1024010156 my ($arrayref, $filename) = @_;
1024110157 # Retrieve $x, $y, ...
1024210158 my @parameters = @$arrayref[1..$#$arrayref];
1024310159 ...
1024410160 }
1024510161
1024610162=begin original
1024710163
1024810164If the hook is an object, it must provide an INC method that will be
1024910165called as above, the first parameter being the object itself. (Note that
1025010166you must fully qualify the sub's name, as unqualified C<INC> is always forced
1025110167into package C<main>.) Here is a typical code layout:
1025210168
1025310169=end original
1025410170
1025510171フックがオブジェクトの場合、INC メソッドを提供している必要があります;
1025610172それが、最初の引数をオブジェクト自身として上述のように呼び出されます。
1025710173(修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、
1025810174サブルーチン名は完全修飾する必要があることに注意してください。)
1025910175以下は典型的なコードレイアウトです:
1026010176
1026110177 # In Foo.pm
1026210178 package Foo;
1026310179 sub new { ... }
1026410180 sub Foo::INC {
1026510181 my ($self, $filename) = @_;
1026610182 ...
1026710183 }
1026810184
1026910185 # In the main program
10270 push @INC, Foo->new(...);
10186 push @INC, new Foo(...);
1027110187
1027210188=begin original
1027310189
1027410190Note that these hooks are also permitted to set the %INC entry
1027510191corresponding to the files they have loaded. See L<perlvar/%INC>.
1027610192
1027710193=end original
1027810194
1027910195これらのフックは、読み込まれるファイルに対応する %INC エントリを
1028010196セットすることも許可することに注意してください。
1028110197L<perlvar/%INC> を参照してください。
1028210198
1028310199=begin original
1028410200
1028510201For a yet-more-powerful import facility, see L</use> and L<perlmod>.
1028610202
1028710203=end original
1028810204
1028910205より強力な import 機能については、このドキュメントの
1029010206L</use> の項と、L<perlmod> を参照してください。
1029110207
1029210208=item reset EXPR
1029310209X<reset>
1029410210
1029510211=item reset
1029610212
1029710213=begin original
1029810214
1029910215Generally used in a C<continue> block at the end of a loop to clear
1030010216variables and reset C<??> searches so that they work again. The
1030110217expression is interpreted as a list of single characters (hyphens
1030210218allowed for ranges). All variables and arrays beginning with one of
1030310219those letters are reset to their pristine state. If the expression is
1030410220omitted, one-match searches (C<?pattern?>) are reset to match again. Resets
1030510221only variables or searches in the current package. Always returns
10306102221. Examples:
1030710223
1030810224=end original
1030910225
1031010226通常、ループの最後に、変数をクリアし、C<??> 検索を再び
1031110227動作するようにリセットするため、C<continue> ブロックで使われます。
1031210228EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と
1031310229解釈されます。
1031410230名前がその文字のいずれかで始まる変数や配列は、
1031510231最初の状態にリセットされます。
1031610232EXPR を省略すると、1 回検索 (C<?PATTERN?>) を再びマッチするように
1031710233リセットできます。
1031810234カレントパッケージの変数もしくは検索だけがリセットされます。
1031910235常に 1 を返します。
1032010236例:
1032110237
1032210238 reset 'X'; # reset all X variables
1032310239 reset 'a-z'; # reset lower case variables
1032410240 reset; # just reset ?one-time? searches
1032510241
1032610242=begin original
1032710243
1032810244Resetting C<"A-Z"> is not recommended because you'll wipe out your
1032910245C<@ARGV> and C<@INC> arrays and your C<%ENV> hash. Resets only package
1033010246variables--lexical variables are unaffected, but they clean themselves
1033110247up on scope exit anyway, so you'll probably want to use them instead.
1033210248See L</my>.
1033310249
1033410250=end original
1033510251
1033610252reset C<"A-Z"> とすると、C<@ARGV>, C<@INC> 配列や C<%ENV> ハッシュも
1033710253なくなってしまいますから、止めた方が良いでしょう。
1033810254パッケージ変数だけがリセットされます。
1033910255レキシカル変数は、影響を受けませんが、スコープから外れれば、
1034010256自動的に綺麗になりますので、これからは、こちらを使うようにした方が
1034110257よいでしょう。
1034210258L</my> を参照してください。
1034310259
1034410260=item return EXPR
1034510261X<return>
1034610262
1034710263=item return
1034810264
1034910265=begin original
1035010266
1035110267Returns from a subroutine, C<eval>, or C<do FILE> with the value
1035210268given in EXPR. Evaluation of EXPR may be in list, scalar, or void
1035310269context, depending on how the return value will be used, and the context
1035410270may vary from one execution to the next (see C<wantarray>). If no EXPR
1035510271is given, returns an empty list in list context, the undefined value in
1035610272scalar context, and (of course) nothing at all in a void context.
1035710273
1035810274=end original
1035910275
1036010276サブルーチン, C<eval>, C<do FILE> から EXPR で与えられた値をもって、
1036110277リターンします。
1036210278EXPR の評価は、返り値がどのように使われるかによって
1036310279リスト、スカラ、無効コンテキストになります。
1036410280またコンテキストは実行毎に変わります(C<wantarray> を参照してください)。
1036510281EXPR が指定されなかった場合は、リストコンテキストでは空リストを、
1036610282スカラコンテキストでは未定義値を返します。
1036710283そして(もちろん)無効コンテキストでは何も返しません。
1036810284
1036910285=begin original
1037010286
1037110287(Note that in the absence of an explicit C<return>, a subroutine, eval,
1037210288or do FILE will automatically return the value of the last expression
1037310289evaluated.)
1037410290
1037510291=end original
1037610292
1037710293(サブルーチン, eval, do FILE に明示的に C<return> が
1037810294なければ、最後に評価された値で、自動的にリターンします。)
1037910295
1038010296=item reverse LIST
1038110297X<reverse> X<rev> X<invert>
1038210298
1038310299=begin original
1038410300
1038510301In list context, returns a list value consisting of the elements
1038610302of LIST in the opposite order. In scalar context, concatenates the
1038710303elements of LIST and returns a string value with all characters
1038810304in the opposite order.
1038910305
1039010306=end original
1039110307
1039210308リストコンテキストでは、LIST を構成する要素を逆順に並べた
1039310309リスト値を返します。
1039410310スカラコンテキストでは、LIST の要素を連結して、
1039510311全ての文字を逆順にした文字列を返します。
1039610312
10397 print join(", ", reverse "world", "Hello"); # Hello, world
10313 print reverse <>; # line tac, last line first
1039810314
10399 print scalar reverse "dlrow ,", "olleH"; # Hello, world
10315 undef $/; # for efficiency of <>
10316 print scalar reverse <>; # character tac, last line tsrif
1040010317
1040110318=begin original
1040210319
1040310320Used without arguments in scalar context, reverse() reverses C<$_>.
1040410321
1040510322=end original
1040610323
1040710324スカラコンテキストで引数なしで使うと、reverse() は C<$_> を逆順にします。
1040810325
10409 $_ = "dlrow ,olleH";
10410 print reverse; # No output, list context
10411 print scalar reverse; # Hello, world
10412
1041310326=begin original
1041410327
1041510328This operator is also handy for inverting a hash, although there are some
1041610329caveats. If a value is duplicated in the original hash, only one of those
1041710330can be represented as a key in the inverted hash. Also, this has to
1041810331unwind one hash and build a whole new one, which may take some time
1041910332on a large hash, such as from a DBM file.
1042010333
1042110334=end original
1042210335
1042310336この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。
1042410337元のハッシュで値が重複していると、それらのうち一つだけが
1042510338逆順になったハッシュのキーとして表現されます。
1042610339また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、
1042710340DBM ファイルからのような大きなハッシュでは少し時間がかかります。
1042810341
1042910342 %by_name = reverse %by_address; # Invert the hash
1043010343
1043110344=item rewinddir DIRHANDLE
1043210345X<rewinddir>
1043310346
1043410347=begin original
1043510348
1043610349Sets the current position to the beginning of the directory for the
1043710350C<readdir> routine on DIRHANDLE.
1043810351
1043910352=end original
1044010353
1044110354DIRHANDLE に対する C<readdir> ルーチンの現在位置を
1044210355ディレクトリの最初に設定します。
1044310356
1044410357=item rindex STR,SUBSTR,POSITION
1044510358X<rindex>
1044610359
1044710360=item rindex STR,SUBSTR
1044810361
1044910362=begin original
1045010363
1045110364Works just like index() except that it returns the position of the I<last>
1045210365occurrence of SUBSTR in STR. If POSITION is specified, returns the
1045310366last occurrence beginning at or before that position.
1045410367
1045510368=end original
1045610369
1045710370STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、
1045810371index() と同じように動作します。
1045910372POSITION を指定すると、その位置から始まるか、その位置より前の、
1046010373最後の位置を返します。
1046110374
1046210375=item rmdir FILENAME
1046310376X<rmdir> X<rd> X<directory, remove>
1046410377
1046510378=item rmdir
1046610379
1046710380=begin original
1046810381
1046910382Deletes the directory specified by FILENAME if that directory is
1047010383empty. If it succeeds it returns true, otherwise it returns false and
1047110384sets C<$!> (errno). If FILENAME is omitted, uses C<$_>.
1047210385
1047310386=end original
1047410387
1047510388FILENAME で指定したディレクトリが空であれば、
1047610389そのディレクトリを削除します。
1047710390成功時には真を返し、失敗時には偽を返し、C<$!> (errno) を設定します。
1047810391FILENAMEを省略した場合には、C<$_> を使用します。
1047910392
1048010393=begin original
1048110394
1048210395To remove a directory tree recursively (C<rm -rf> on unix) look at
1048310396the C<rmtree> function of the L<File::Path> module.
1048410397
1048510398=end original
1048610399
1048710400ディレクトリツリーを再帰的に削除したい (unix での C<rm -rf>) 場合、
1048810401L<File::Path> モジュールの C<rmtree> 関数を参照してください。
1048910402
1049010403=item s///
1049110404
1049210405=begin original
1049310406
10494The substitution operator. See L<perlop/"Regexp Quote-Like Operators">.
10407The substitution operator. See L<perlop>.
1049510408
1049610409=end original
1049710410
1049810411置換演算子。
10499L<perlop/"Regexp Quote-Like Operators"> を参照してください。
10412L<perlop> を参照してください。
1050010413
1050110414=item say FILEHANDLE LIST
1050210415X<say>
1050310416
1050410417=item say LIST
1050510418
1050610419=item say
1050710420
1050810421=begin original
1050910422
1051010423Just like C<print>, but implicitly appends a newline.
1051110424C<say LIST> is simply an abbreviation for C<{ local $\ = "\n"; print
1051210425LIST }>.
1051310426
1051410427=end original
1051510428
1051610429C<print> と同様ですが、暗黙に改行が追加されます。
1051710430C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> の省略形です。
1051810431
1051910432=begin original
1052010433
1052110434This keyword is only available when the "say" feature is
1052210435enabled: see L<feature>.
1052310436
1052410437=end original
1052510438
1052610439このキーワードは、"say" 機能が有効の場合にのみ利用可能です:
1052710440L<feature> を参照してください。
1052810441
1052910442=item scalar EXPR
1053010443X<scalar> X<context>
1053110444
1053210445=begin original
1053310446
1053410447Forces EXPR to be interpreted in scalar context and returns the value
1053510448of EXPR.
1053610449
1053710450=end original
1053810451
1053910452EXPR を強制的にスカラコンテキストで解釈されるようにして、
1054010453EXPR の値を返します。
1054110454
1054210455 @counts = ( scalar @a, scalar @b, scalar @c );
1054310456
1054410457=begin original
1054510458
1054610459There is no equivalent operator to force an expression to
1054710460be interpolated in list context because in practice, this is never
1054810461needed. If you really wanted to do so, however, you could use
1054910462the construction C<@{[ (some expression) ]}>, but usually a simple
1055010463C<(some expression)> suffices.
1055110464
1055210465=end original
1055310466
1055410467式を強制的にリストコンテキストで解釈させるようにする演算子はありません。
1055510468理論的には不要だからです。
1055610469それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を
1055710470使えます。
1055810471しかし、普通は単に C<(some expression)> とすれば十分です。
1055910472
1056010473=begin original
1056110474
1056210475Because C<scalar> is unary operator, if you accidentally use for EXPR a
1056310476parenthesized list, this behaves as a scalar comma expression, evaluating
1056410477all but the last element in void context and returning the final element
1056510478evaluated in scalar context. This is seldom what you want.
1056610479
1056710480=end original
1056810481
1056910482C<scalar> は単項演算子なので、EXPR として括弧でくくったリストを使った場合、
1057010483これはスカラカンマ表現として振舞い、最後以外の全ては無効コンテキストとして
1057110484扱われ、最後の要素をスカラコンテキストとして扱った結果が返されます。
1057210485これがあなたの望むものであることはめったにないでしょう。
1057310486
1057410487=begin original
1057510488
1057610489The following single statement:
1057710490
1057810491=end original
1057910492
1058010493以下の 1 つの文は:
1058110494
1058210495 print uc(scalar(&foo,$bar)),$baz;
1058310496
1058410497=begin original
1058510498
1058610499is the moral equivalent of these two:
1058710500
1058810501=end original
1058910502
1059010503以下の 2 つの文と等価です。
1059110504
1059210505 &foo;
1059310506 print(uc($bar),$baz);
1059410507
1059510508=begin original
1059610509
1059710510See L<perlop> for more details on unary operators and the comma operator.
1059810511
1059910512=end original
1060010513
1060110514単項演算子とカンマ演算子に関する詳細については L<perlop> を参照して下さい。
1060210515
1060310516=item seek FILEHANDLE,POSITION,WHENCE
1060410517X<seek> X<fseek> X<filehandle, position>
1060510518
1060610519=begin original
1060710520
1060810521Sets FILEHANDLE's position, just like the C<fseek> call of C<stdio>.
1060910522FILEHANDLE may be an expression whose value gives the name of the
1061010523filehandle. The values for WHENCE are C<0> to set the new position
1061110524I<in bytes> to POSITION, C<1> to set it to the current position plus
1061210525POSITION, and C<2> to set it to EOF plus POSITION (typically
1061310526negative). For WHENCE you may use the constants C<SEEK_SET>,
1061410527C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end
1061510528of the file) from the Fcntl module. Returns C<1> upon success, C<0>
1061610529otherwise.
1061710530
1061810531=end original
1061910532
1062010533C<stdio> ライブラリの C<fseek> 関数のように、FILEHANDLE の
1062110534ファイルポインタを任意の位置に設定します。
1062210535FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1062310536WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ、C<1> ならば、
1062410537現在位置から I<バイト数で> POSITION 加えた位置へ、C<2> ならば、EOF から
1062510538POSITION だけ加えた位置へ、新しい位置を設定します。
1062610539この値には、Fcntl モジュールで使われている C<SEEK_SET>、
1062710540C<SEEK_CUR>、C<SEEK_END>
1062810541(ファイルの先頭、現在位置、ファイルの最後)という定数を使うこともできます。
1062910542成功時には、C<1> を、失敗時には C<0> を返します。
1063010543
1063110544=begin original
1063210545
1063310546Note the I<in bytes>: even if the filehandle has been set to
1063410547operate on characters (for example by using the C<:encoding(utf8)> open
1063510548layer), tell() will return byte offsets, not character offsets
1063610549(because implementing that would render seek() and tell() rather slow).
1063710550
1063810551=end original
1063910552
1064010553I<バイト単位> に関する注意: ファイルハンドルが (例えば C<:encoding(utf8)> 層を
1064110554使って)文字を操作するように設定されていたとしても、tell() は文字の
1064210555オフセットではなくバイトのオフセットを返すことに注意してください
1064310556(なぜならこれを実装すると seek() と tell() が遅くなってしまうからです)。
1064410557
1064510558=begin original
1064610559
1064710560If you want to position file for C<sysread> or C<syswrite>, don't use
1064810561C<seek>--buffering makes its effect on the file's system position
1064910562unpredictable and non-portable. Use C<sysseek> instead.
1065010563
1065110564=end original
1065210565
1065310566C<sysread> や C<syswrite> のためにファイルの位置を指定したい場合は、
1065410567C<seek> は使えません -- バッファリングのために動作は予測不能で
1065510568移植性のないものになってしまいます。
1065610569代わりに C<sysseek> を使ってください。
1065710570
1065810571=begin original
1065910572
1066010573Due to the rules and rigors of ANSI C, on some systems you have to do a
1066110574seek whenever you switch between reading and writing. Amongst other
1066210575things, this may have the effect of calling stdio's clearerr(3).
1066310576A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position:
1066410577
1066510578=end original
1066610579
1066710580ANSI C の規則と困難により、システムによっては読み込みと書き込みを
1066810581切り替える度にシークしなければならない場合があります。
1066910582その他のことの中で、これは stdio の clearerr(3) を呼び出す効果があります。
1067010583WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です:
1067110584
1067210585 seek(TEST,0,1);
1067310586
1067410587=begin original
1067510588
1067610589This is also useful for applications emulating C<tail -f>. Once you hit
1067710590EOF on your read, and then sleep for a while, you might have to stick in a
1067810591seek() to reset things. The C<seek> doesn't change the current position,
1067910592but it I<does> clear the end-of-file condition on the handle, so that the
1068010593next C<< <FILE> >> makes Perl try again to read something. We hope.
1068110594
1068210595=end original
1068310596
1068410597これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。
1068510598一度読み込み時に EOF に到達すると、しばらくスリープし、
1068610599seek() することでリセットする必要があります。
1068710600C<seek> は現在の位置を変更しませんが、ハンドルの EOF 状態を
1068810601I<クリアします> ので、次の C<< <FILE> >> で Perl は再び何かを
1068910602読み込もうとします。
1069010603そのはずです。
1069110604
1069210605=begin original
1069310606
1069410607If that doesn't work (some IO implementations are particularly
1069510608cantankerous), then you may need something more like this:
1069610609
1069710610=end original
1069810611
1069910612これが動かない場合(特に意地の悪い IO 実装もあります)、
1070010613以下のようなことをする必要があります:
1070110614
1070210615 for (;;) {
1070310616 for ($curpos = tell(FILE); $_ = <FILE>;
1070410617 $curpos = tell(FILE)) {
1070510618 # search for some stuff and put it into files
1070610619 }
1070710620 sleep($for_a_while);
1070810621 seek(FILE, $curpos, 0);
1070910622 }
1071010623
1071110624=item seekdir DIRHANDLE,POS
1071210625X<seekdir>
1071310626
1071410627=begin original
1071510628
1071610629Sets the current position for the C<readdir> routine on DIRHANDLE. POS
1071710630must be a value returned by C<telldir>. C<seekdir> also has the same caveats
1071810631about possible directory compaction as the corresponding system library
1071910632routine.
1072010633
1072110634=end original
1072210635
1072310636DIRHANDLE での C<readdir> ルーチンの現在位置を設定します。
1072410637POS は、C<telldir> が返す値でなければなりません。
1072510638C<seekdir> は同名のシステムライブラリルーチンと同じく、
1072610639ディレクトリ縮小時の問題が考えられます。
1072710640
1072810641=item select FILEHANDLE
1072910642X<select> X<filehandle, default>
1073010643
1073110644=item select
1073210645
1073310646=begin original
1073410647
1073510648Returns the currently selected filehandle. If FILEHANDLE is supplied,
1073610649sets the new current default filehandle for output. This has two
1073710650effects: first, a C<write> or a C<print> without a filehandle will
1073810651default to this FILEHANDLE. Second, references to variables related to
1073910652output will refer to this output channel. For example, if you have to
1074010653set the top of form format for more than one output channel, you might
1074110654do the following:
1074210655
1074310656=end original
1074410657
1074510658その時点で、選択されていたファイルハンドルを返します。
1074610659FILEHANDLE を指定した場合には、その値を出力のデフォルト
1074710660ファイルハンドルに設定します。
1074810661これには、2 つの効果があります。
1074910662まず、ファイルハンドルを指定しないで
1075010663C<write> や C<print> を行なった場合のデフォルトが、
1075110664この FILEHANDLE になります。
1075210665もう一つは、出力関連の変数への参照は、
1075310666この出力チャネルを参照するようになります。
1075410667たとえば、複数の出力チャネルに対して、ページ先頭フォーマットを
1075510668設定しなければならないのであれば、
1075610669以下のようにしなければならないでしょう。
1075710670
1075810671 select(REPORT1);
1075910672 $^ = 'report1_top';
1076010673 select(REPORT2);
1076110674 $^ = 'report2_top';
1076210675
1076310676=begin original
1076410677
1076510678FILEHANDLE may be an expression whose value gives the name of the
1076610679actual filehandle. Thus:
1076710680
1076810681=end original
1076910682
1077010683FILEHANDLE は、実際のファイルハンドルの名前を示す式でもかまいません。
1077110684つまり、以下のようなものです:
1077210685
1077310686 $oldfh = select(STDERR); $| = 1; select($oldfh);
1077410687
1077510688=begin original
1077610689
1077710690Some programmers may prefer to think of filehandles as objects with
1077810691methods, preferring to write the last example as:
1077910692
1078010693=end original
1078110694
1078210695ファイルハンドルはメソッドを持ったオブジェクトであると
1078310696考えることを好むプログラマもいるかもしれません。
1078410697そのような場合のための最後の例は以下のようなものです。
1078510698
1078610699 use IO::Handle;
1078710700 STDERR->autoflush(1);
1078810701
1078910702=item select RBITS,WBITS,EBITS,TIMEOUT
1079010703X<select>
1079110704
1079210705=begin original
1079310706
1079410707This calls the select(2) system call with the bit masks specified, which
1079510708can be constructed using C<fileno> and C<vec>, along these lines:
1079610709
1079710710=end original
1079810711
1079910712これは、select(2) システムコールを、指定したビットマスクで呼び出します。
1080010713ビットマスクは、C<fileno> と
1080110714C<vec> を使って、以下のようにして作成できます。
1080210715
1080310716 $rin = $win = $ein = '';
1080410717 vec($rin,fileno(STDIN),1) = 1;
1080510718 vec($win,fileno(STDOUT),1) = 1;
1080610719 $ein = $rin | $win;
1080710720
1080810721=begin original
1080910722
1081010723If you want to select on many filehandles you might wish to write a
1081110724subroutine:
1081210725
1081310726=end original
1081410727
1081510728複数のファイルハンドルに select を行ないたいのであれば、
1081610729以下のようにします。
1081710730
1081810731 sub fhbits {
1081910732 my(@fhlist) = split(' ',$_[0]);
1082010733 my($bits);
1082110734 for (@fhlist) {
1082210735 vec($bits,fileno($_),1) = 1;
1082310736 }
1082410737 $bits;
1082510738 }
1082610739 $rin = fhbits('STDIN TTY SOCK');
1082710740
1082810741=begin original
1082910742
1083010743The usual idiom is:
1083110744
1083210745=end original
1083310746
1083410747通常は、
1083510748
1083610749 ($nfound,$timeleft) =
1083710750 select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
1083810751
1083910752=begin original
1084010753
1084110754or to block until something becomes ready just do this
1084210755
1084310756=end original
1084410757
1084510758のように使い、いずれかの準備が整うまでブロックするには、
1084610759以下のようにします。
1084710760
1084810761 $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
1084910762
1085010763=begin original
1085110764
1085210765Most systems do not bother to return anything useful in $timeleft, so
1085310766calling select() in scalar context just returns $nfound.
1085410767
1085510768=end original
1085610769
1085710770ほとんどのシステムではわざわざ意味のある値を $timeleft に返さないので、
1085810771select() をスカラコンテキストで呼び出すと、単に $nfound を返します。
1085910772
1086010773=begin original
1086110774
1086210775Any of the bit masks can also be undef. The timeout, if specified, is
1086310776in seconds, which may be fractional. Note: not all implementations are
1086410777capable of returning the $timeleft. If not, they always return
1086510778$timeleft equal to the supplied $timeout.
1086610779
1086710780=end original
1086810781
1086910782どのビットマスクにも undef を設定することができます。
1087010783TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。
1087110784注: すべての実装で、$timeleft が返せるものではありません。
1087210785その場合、$timeleft には、常に指定した TIMEOUT と同じ値が返されます。
1087310786
1087410787=begin original
1087510788
1087610789You can effect a sleep of 250 milliseconds this way:
1087710790
1087810791=end original
1087910792
1088010793250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。
1088110794
1088210795 select(undef, undef, undef, 0.25);
1088310796
1088410797=begin original
1088510798
1088610799Note that whether C<select> gets restarted after signals (say, SIGALRM)
1088710800is implementation-dependent. See also L<perlport> for notes on the
1088810801portability of C<select>.
1088910802
1089010803=end original
1089110804
1089210805C<select> がシグナル (例えば、SIGALRM) の後に再起動するかどうかは
1089310806実装依存であることに注意してください。
1089410807C<select> の移植性に関する注意については L<perlport> も参照してください。
1089510808
1089610809=begin original
1089710810
1089810811On error, C<select> behaves like the select(2) system call : it returns
1089910812-1 and sets C<$!>.
1090010813
1090110814=end original
1090210815
1090310816エラー時は、C<select> は select(2) システムコールのように振舞います:
1090410817-1 を返し、C<$!> をセットします。
1090510818
1090610819=begin original
1090710820
1090810821Note: on some Unixes, the select(2) system call may report a socket file
1090910822descriptor as "ready for reading", when actually no data is available,
1091010823thus a subsequent read blocks. It can be avoided using always the
1091110824O_NONBLOCK flag on the socket. See select(2) and fcntl(2) for further
1091210825details.
1091310826
1091410827=end original
1091510828
1091610829注意: Unix の中には、実際に利用可能なデータがないために引き続く読み込みが
1091710830ブロックされる場合、select(2) システムコールが、ソケットファイル記述子が
1091810831「読み込み準備中」であると報告するものもあります。
1091910832これは、ソケットに対して常に O_NONBLOCK フラグを使うことで回避できます。
1092010833さらなる詳細については select(2) と fcntl(2) を参照してください。
1092110834
1092210835=begin original
1092310836
1092410837B<WARNING>: One should not attempt to mix buffered I/O (like C<read>
1092510838or <FH>) with C<select>, except as permitted by POSIX, and even
1092610839then only on POSIX systems. You have to use C<sysread> instead.
1092710840
1092810841=end original
1092910842
1093010843B<警告>: バッファ付き I/O (C<read> や <FH>) と C<select> を
1093110844混ぜて使ってはいけません(例外: POSIX で認められている形で使い、
1093210845POSIX システムでだけ動かす場合を除きます)。
1093310846代わりに C<sysread> を使わなければなりません。
1093410847
1093510848=item semctl ID,SEMNUM,CMD,ARG
1093610849X<semctl>
1093710850
1093810851=begin original
1093910852
1094010853Calls the System V IPC function C<semctl>. You'll probably have to say
1094110854
1094210855=end original
1094310856
1094410857System V IPC 関数 C<semctl> を呼び出します。
1094510858正しい定数定義を得るために、まず
1094610859
1094710860 use IPC::SysV;
1094810861
1094910862=begin original
1095010863
1095110864first to get the correct constant definitions. If CMD is IPC_STAT or
1095210865GETALL, then ARG must be a variable that will hold the returned
1095310866semid_ds structure or semaphore value array. Returns like C<ioctl>:
1095410867the undefined value for error, "C<0 but true>" for zero, or the actual
1095510868return value otherwise. The ARG must consist of a vector of native
1095610869short integers, which may be created with C<pack("s!",(0)x$nsem)>.
1095710870See also L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore>
1095810871documentation.
1095910872
1096010873=end original
1096110874
1096210875と宣言する必要があるでしょう。
1096310876CMD が、IPC_STAT か GETALL のときには、ARG は、返される
1096410877semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。
1096510878C<ioctl> と同じように、エラー時には未定義値、
1096610879ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
1096710880ARG はネイティブな short int のベクターから成っていなければなりません。
1096810881これは C<pack("s!",(0)x$nsem)> で作成できます。
1096910882L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::Semaphore> も参照してください。
1097010883
1097110884=item semget KEY,NSEMS,FLAGS
1097210885X<semget>
1097310886
1097410887=begin original
1097510888
1097610889Calls the System V IPC function semget. Returns the semaphore id, or
1097710890the undefined value if there is an error. See also
1097810891L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore>
1097910892documentation.
1098010893
1098110894=end original
1098210895
1098310896System V IPC 関数 semget を呼び出します。
1098410897セマフォ ID か、エラー時には未定義値を返します。
1098510898L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> も
1098610899参照してください。
1098710900
1098810901=item semop KEY,OPSTRING
1098910902X<semop>
1099010903
1099110904=begin original
1099210905
1099310906Calls the System V IPC function semop to perform semaphore operations
1099410907such as signalling and waiting. OPSTRING must be a packed array of
1099510908semop structures. Each semop structure can be generated with
1099610909C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
1099710910implies the number of semaphore operations. Returns true if
1099810911successful, or false if there is an error. As an example, the
1099910912following code waits on semaphore $semnum of semaphore id $semid:
1100010913
1100110914=end original
1100210915
1100310916シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、
1100410917System V IPC 関数 semop を呼び出します。
1100510918OPSTRING は、semop 構造体の pack された配列でなければなりません。
1100610919semop 構造体は、それぞれ、
1100710920C<pack("s!3", $semnum, $semop, $semflag)> のように作ることができます。
1100810921セマフォ操作の数は、OPSTRING の長さからわかります。
1100910922成功時には真を、エラー時には偽を返します。
1101010923以下の例は、セマフォ ID $semid のセマフォ $semnum で
1101110924待ち合わせを行ないます。
1101210925
1101310926 $semop = pack("s!3", $semnum, -1, 0);
1101410927 die "Semaphore trouble: $!\n" unless semop($semid, $semop);
1101510928
1101610929=begin original
1101710930
1101810931To signal the semaphore, replace C<-1> with C<1>. See also
1101910932L<perlipc/"SysV IPC">, C<IPC::SysV>, and C<IPC::SysV::Semaphore>
1102010933documentation.
1102110934
1102210935=end original
1102310936
1102410937セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。
1102510938L<perlipc/"SysV IPC">, C<IPC::SysV>, C<IPC::SysV::Semaphore> も
1102610939参照してください。
1102710940
1102810941=item send SOCKET,MSG,FLAGS,TO
1102910942X<send>
1103010943
1103110944=item send SOCKET,MSG,FLAGS
1103210945
1103310946=begin original
1103410947
1103510948Sends a message on a socket. Attempts to send the scalar MSG to the
1103610949SOCKET filehandle. Takes the same flags as the system call of the
1103710950same name. On unconnected sockets you must specify a destination to
1103810951send TO, in which case it does a C C<sendto>. Returns the number of
1103910952characters sent, or the undefined value if there is an error. The C
1104010953system call sendmsg(2) is currently unimplemented. See
1104110954L<perlipc/"UDP: Message Passing"> for examples.
1104210955
1104310956=end original
1104410957
1104510958ソケットにメッセージを送ります。
1104610959スカラ MSG を ファイルハンドル SOCKET に送ろうとします。
1104710960同名のシステムコールと同じフラグが指定できます。
1104810961接続していないソケットには、送信先 TO を指定しなければならず、
1104910962この場合、C の C<sendto> を実行します。
1105010963送信した文字数か、エラー時には、未定義値を返します。
1105110964C の システムコール sendmsg(2) は現在実装されていません。
1105210965例については L<perlipc/"UDP: Message Passing"> を参照してください。
1105310966
1105410967=begin original
1105510968
1105610969Note the I<characters>: depending on the status of the socket, either
1105710970(8-bit) bytes or characters are sent. By default all sockets operate
1105810971on bytes, but for example if the socket has been changed using
1105910972binmode() to operate with the C<:encoding(utf8)> I/O layer (see
1106010973L</open>, or the C<open> pragma, L<open>), the I/O will operate on UTF-8
1106110974encoded Unicode characters, not bytes. Similarly for the C<:encoding>
1106210975pragma: in that case pretty much any characters can be sent.
1106310976
1106410977=end original
1106510978
1106610979I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
1106710980文字を送信します。
1106810981デフォルトでは全てのソケットはバイトを処理しますが、
1106910982例えばソケットが binmode() で C<:encoding(utf8)> I/O 層(L</open>、
1107010983C<open> プラグマ、L<open> を参照してください) を使うように指定された場合、
1107110984I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。
1107210985C<:encoding> プラグマも同様です:
1107310986この場合、ほとんど大体全ての文字が書き込めます。
1107410987
1107510988=item setpgrp PID,PGRP
1107610989X<setpgrp> X<group>
1107710990
1107810991=begin original
1107910992
1108010993Sets the current process group for the specified PID, C<0> for the current
1108110994process. Will produce a fatal error if used on a machine that doesn't
1108210995implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments are omitted,
1108310996it defaults to C<0,0>. Note that the BSD 4.2 version of C<setpgrp> does not
1108410997accept any arguments, so only C<setpgrp(0,0)> is portable. See also
1108510998C<POSIX::setsid()>.
1108610999
1108711000=end original
1108811001
1108911002指定した PID (C<0> を指定するとカレントプロセス) に
1109011003対するプロセスグループを設定します。
1109111004POSIX setpgrp(2) または BSD setpgrp(2) が実装されていないマシンでは、
1109211005致命的エラーが発生します。
1109311006引数が省略された場合は、C<0,0>が使われます。
1109411007BSD 4.2 版の C<setpgrp> は引数を取ることができないので、
1109511008C<setpgrp(0,0)> のみが移植性があることに注意してください。
1109611009C<POSIX::setsid()> も参照してください。
1109711010
1109811011=item setpriority WHICH,WHO,PRIORITY
1109911012X<setpriority> X<priority> X<nice> X<renice>
1110011013
1110111014=begin original
1110211015
1110311016Sets the current priority for a process, a process group, or a user.
1110411017(See setpriority(2).) Will produce a fatal error if used on a machine
1110511018that doesn't implement setpriority(2).
1110611019
1110711020=end original
1110811021
1110911022プロセス、プロセスグループ、ユーザに対する優先順位を設定します。
1111011023(setpriority(2) を参照してください。)
1111111024setpriority(2) が実装されていないマシンでは、
1111211025致命的エラーが発生します。
1111311026
1111411027=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1111511028X<setsockopt>
1111611029
1111711030=begin original
1111811031
1111911032Sets the socket option requested. Returns undefined if there is an
1112011033error. Use integer constants provided by the C<Socket> module for
1112111034LEVEL and OPNAME. Values for LEVEL can also be obtained from
1112211035getprotobyname. OPTVAL might either be a packed string or an integer.
1112311036An integer OPTVAL is shorthand for pack("i", OPTVAL).
1112411037
1112511038=end original
1112611039
1112711040要求したソケットオプションを設定します。
1112811041エラー時には、未定義値が返されます。
1112911042LEVEL と OPNAME には C<Socket> モジュールが提供する整数定数を使います。
1113011043LEVEL の値は getprotobyname から得ることもできます。
1113111044OPTVAL は pack された文字列か整数です。
1113211045整数の OPTVAL は pack("i", OPTVAL) の省略表現です。
1113311046
1113411047=begin original
1113511048
1113611049An example disabling the Nagle's algorithm for a socket:
1113711050
1113811051=end original
1113911052
1114011053ソケットに対する Nagle のアルゴリズムを無効にする例です:
1114111054
1114211055 use Socket qw(IPPROTO_TCP TCP_NODELAY);
1114311056 setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1);
1114411057
1114511058=item shift ARRAY
1114611059X<shift>
1114711060
1114811061=item shift
1114911062
1115011063=begin original
1115111064
1115211065Shifts the first value of the array off and returns it, shortening the
1115311066array by 1 and moving everything down. If there are no elements in the
1115411067array, returns the undefined value. If ARRAY is omitted, shifts the
1115511068C<@_> array within the lexical scope of subroutines and formats, and the
1115611069C<@ARGV> array outside of a subroutine and also within the lexical scopes
1115711070established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
1115811071C<UNITCHECK {}> and C<END {}> constructs.
1115911072
1116011073=end original
1116111074
1116211075配列の最初の値を取り出して、その値を返し、配列を一つ
1116311076短くして、すべての要素を前へずらします。
1116411077配列に要素がなければ、未定義値を返します。
1116511078ARRAY を省略すると、
1116611079サブルーチンやフォーマットのレキシカルスコープでは C<@_> を、
1116711080サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
1116811081C<UNITCHECK {}>, C<END {}> で作成されたレキシカルスコープでは
1116911082C<@ARGV> が用いられます。
1117011083
1117111084=begin original
1117211085
1117311086See also C<unshift>, C<push>, and C<pop>. C<shift> and C<unshift> do the
1117411087same thing to the left end of an array that C<pop> and C<push> do to the
1117511088right end.
1117611089
1117711090=end original
1117811091
1117911092C<unshift>、C<push>、C<pop> も参照してください。
1118011093C<shift> と C<unshift> は、C<pop> と
1118111094C<push> が配列の右端で行なうことを、左端で行ないます。
1118211095
1118311096=item shmctl ID,CMD,ARG
1118411097X<shmctl>
1118511098
1118611099=begin original
1118711100
1118811101Calls the System V IPC function shmctl. You'll probably have to say
1118911102
1119011103=end original
1119111104
1119211105System V IPC 関数 shmctl を呼び出します。正しい定数定義を得るために、まず
1119311106
1119411107 use IPC::SysV;
1119511108
1119611109=begin original
1119711110
1119811111first to get the correct constant definitions. If CMD is C<IPC_STAT>,
1119911112then ARG must be a variable that will hold the returned C<shmid_ds>
1120011113structure. Returns like ioctl: the undefined value for error, "C<0> but
1120111114true" for zero, or the actual return value otherwise.
1120211115See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
1120311116
1120411117=end original
1120511118
1120611119と宣言する必要があるでしょう。
1120711120CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を
1120811121納める変数でなければなりません。
1120911122ioctl と同じように、エラー時には未定義値、ゼロのときは "C<0> だが真"、
1121011123それ以外なら、その値そのものを返します。
1121111124L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。
1121211125
1121311126=item shmget KEY,SIZE,FLAGS
1121411127X<shmget>
1121511128
1121611129=begin original
1121711130
1121811131Calls the System V IPC function shmget. Returns the shared memory
1121911132segment id, or the undefined value if there is an error.
1122011133See also L<perlipc/"SysV IPC"> and C<IPC::SysV> documentation.
1122111134
1122211135=end original
1122311136
1122411137System V IPC 関数 shmget を呼び出します。
1122511138共有メモリのセグメント ID か、エラー時には未定義値を返します。
1122611139L<perlipc/"SysV IPC"> と C<IPC::SysV> も参照してください。
1122711140
1122811141=item shmread ID,VAR,POS,SIZE
1122911142X<shmread>
1123011143X<shmwrite>
1123111144
1123211145=item shmwrite ID,STRING,POS,SIZE
1123311146
1123411147=begin original
1123511148
1123611149Reads or writes the System V shared memory segment ID starting at
1123711150position POS for size SIZE by attaching to it, copying in/out, and
1123811151detaching from it. When reading, VAR must be a variable that will
1123911152hold the data read. When writing, if STRING is too long, only SIZE
1124011153bytes are used; if STRING is too short, nulls are written to fill out
1124111154SIZE bytes. Return true if successful, or false if there is an error.
1124211155shmread() taints the variable. See also L<perlipc/"SysV IPC">,
1124311156C<IPC::SysV> documentation, and the C<IPC::Shareable> module from CPAN.
1124411157
1124511158=end original
1124611159
1124711160System V 共有メモリセグメント ID に対し、アタッチして、
1124811161コピーを行ない、デタッチするという形で、位置 POS から、
1124911162サイズ SIZE だけ、読み込みか書き込みを行ないます。
1125011163読み込み時には、VAR は読み込んだデータを納める
1125111164変数でなければなりません。
1125211165書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます。
1125311166STRING が短すぎる場合には、SIZE バイトを埋めるために、
1125411167ヌル文字が書き込まれます。
1125511168成功時には真を、エラー時には偽を返します。
1125611169shmread() は変数を汚染します。
1125711170L<perlipc/"SysV IPC"> と C<IPC::SysV> の文章と、
1125811171CPAN の C<IPC::Shareable> も参照してください。
1125911172
1126011173=item shutdown SOCKET,HOW
1126111174X<shutdown>
1126211175
1126311176=begin original
1126411177
1126511178Shuts down a socket connection in the manner indicated by HOW, which
1126611179has the same interpretation as in the system call of the same name.
1126711180
1126811181=end original
1126911182
1127011183同名のシステムコールと同じように解釈される HOW によって、
1127111184指定された方法でソケット接続のシャットダウンを行ないます。
1127211185
1127311186 shutdown(SOCKET, 0); # I/we have stopped reading data
1127411187 shutdown(SOCKET, 1); # I/we have stopped writing data
1127511188 shutdown(SOCKET, 2); # I/we have stopped using this socket
1127611189
1127711190=begin original
1127811191
1127911192This is useful with sockets when you want to tell the other
1128011193side you're done writing but not done reading, or vice versa.
1128111194It's also a more insistent form of close because it also
1128211195disables the file descriptor in any forked copies in other
1128311196processes.
1128411197
1128511198=end original
1128611199
1128711200これは、こちらがソケットを書き終わったが読み終わっていない、
1128811201またはその逆を相手側に伝えたいときに便利です。
1128911202これはその他のプロセスでフォークしたファイル記述子のコピーも
1129011203無効にするので、よりしつこい閉じ方です。
1129111204
11292=begin original
11293
11294Returns C<1> for success. In the case of error, returns C<undef> if
11295the first argument is not a valid filehandle, or returns C<0> and sets
11296C<$!> for any other failure.
11297
11298=end original
11299
11300成功時には C<1> を返します。
11301エラーの場合、最初の引数が有効なファイルハンドルでない場合は C<undef> を
11302返し、その他のエラーの場合は C<0> を返してC<$!> をセットします。
11303
1130411205=item sin EXPR
1130511206X<sin> X<sine> X<asin> X<arcsine>
1130611207
1130711208=item sin
1130811209
1130911210=begin original
1131011211
1131111212Returns the sine of EXPR (expressed in radians). If EXPR is omitted,
1131211213returns sine of C<$_>.
1131311214
1131411215=end original
1131511216
1131611217(ラジアンで示した) EXPR の正弦を返します。
1131711218EXPR が省略されたときには、C<$_> の正弦を返します。
1131811219
1131911220=begin original
1132011221
1132111222For the inverse sine operation, you may use the C<Math::Trig::asin>
1132211223function, or use this relation:
1132311224
1132411225=end original
1132511226
1132611227逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、
1132711228以下の関係を使ってください:
1132811229
1132911230 sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
1133011231
1133111232=item sleep EXPR
1133211233X<sleep> X<pause>
1133311234
1133411235=item sleep
1133511236
1133611237=begin original
1133711238
1133811239Causes the script to sleep for EXPR seconds, or forever if no EXPR.
11339Returns the number of seconds actually slept.
11240May be interrupted if the process receives a signal such as C<SIGALRM>.
11241Returns the number of seconds actually slept. You probably cannot
11242mix C<alarm> and C<sleep> calls, because C<sleep> is often implemented
11243using C<alarm>.
1134011244
1134111245=end original
1134211246
1134311247スクリプトを EXPR で指定した秒数 (省略時には、永久に)
1134411248スリープさせます。
11345実際にスリーした秒数返します。
11249そのロセスには、C<SIGALRM>のようなシグナル
11250受信すると、割り込みがかかります。
11251実際にスリープした秒数を返します。C<sleep> は、C<alarm> を
11252使って実装されることが多いので、C<alarm> と
11253C<sleep> は、おそらく混ぜて使用することはできません。
1134611254
1134711255=begin original
1134811256
11349May be interrupted if the process receives a signal such as C<SIGALRM>.
11350
11351=end original
11352
11353そのプロセスが C<SIGALRM>のようなシグナルを受信すると、
11354割り込みがかかります。
11355
11356 eval {
11357 local $SIG{ALARM} = sub { die "Alarm!\n" };
11358 sleep;
11359 };
11360 die $@ unless $@ eq "Alarm!\n";
11361
11362=begin original
11363
11364You probably cannot mix C<alarm> and C<sleep> calls, because C<sleep>
11365is often implemented using C<alarm>.
11366
11367=end original
11368
11369C<sleep> は、C<alarm> を使って実装されることが多いので、C<alarm> と
11370C<sleep> は、混ぜて使用することはおそらくできません。
11371
11372=begin original
11373
1137411257On some older systems, it may sleep up to a full second less than what
1137511258you requested, depending on how it counts seconds. Most modern systems
1137611259always sleep the full amount. They may appear to sleep longer than that,
1137711260however, because your process might not be scheduled right away in a
1137811261busy multitasking system.
1137911262
1138011263=end original
1138111264
1138211265古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に
1138311266満たないうちに、スリープから抜ける場合があります。
1138411267最近のシステムでは、常に完全にスリープします。
1138511268しかし、負荷の高いマルチタスクシステムでは
1138611269正しくスケジューリングされないがために
1138711270より長い時間スリープすることがあります。
1138811271
1138911272=begin original
1139011273
1139111274For delays of finer granularity than one second, the Time::HiRes module
1139211275(from CPAN, and starting from Perl 5.8 part of the standard
1139311276distribution) provides usleep(). You may also use Perl's four-argument
1139411277version of select() leaving the first three arguments undefined, or you
1139511278might be able to use the C<syscall> interface to access setitimer(2) if
1139611279your system supports it. See L<perlfaq8> for details.
1139711280
1139811281=end original
1139911282
11400112831 秒より精度の高いスリープを行なうには、
1140111284Time::HiRes モジュール(CPAN から、また Perl 5.8 からは
1140211285標準配布されています) が usleep() を提供します。
1140311286Perl の 4 引数版 select() を最初の 3 引数を未定義にして使うか、
1140411287setitimer(2) をサポートしているシステムでは、Perl の
1140511288C<syscall> インタフェースを使ってアクセスすることもできます。
1140611289詳しくは L<perlfaq8> を参照してください。
1140711290
1140811291=begin original
1140911292
1141011293See also the POSIX module's C<pause> function.
1141111294
1141211295=end original
1141311296
1141411297POSIX モジュールの C<pause> 関数も参照して下さい。
1141511298
1141611299=item socket SOCKET,DOMAIN,TYPE,PROTOCOL
1141711300X<socket>
1141811301
1141911302=begin original
1142011303
1142111304Opens a socket of the specified kind and attaches it to filehandle
1142211305SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for
1142311306the system call of the same name. You should C<use Socket> first
1142411307to get the proper definitions imported. See the examples in
1142511308L<perlipc/"Sockets: Client/Server Communication">.
1142611309
1142711310=end original
1142811311
1142911312指定した種類のソケットをオープンし、ファイルハンドル
1143011313SOCKET にアタッチします。
1143111314DOMAIN、TYPE、PROTOCOL は、
1143211315同名のシステムコールと同じように指定します。
1143311316適切な定義を import するために、まず、C<use Socket> と
1143411317するとよいでしょう。
1143511318例については L<perlipc/"Sockets: Client/Server Communication"> を
1143611319参照してください。
1143711320
1143811321=begin original
1143911322
1144011323On systems that support a close-on-exec flag on files, the flag will
1144111324be set for the newly opened file descriptor, as determined by the
1144211325value of $^F. See L<perlvar/$^F>.
1144311326
1144411327=end original
1144511328
1144611329ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1144711330フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
1144811331セットされます。
1144911332L<perlvar/$^F> を参照してください。
1145011333
1145111334=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1145211335X<socketpair>
1145311336
1145411337=begin original
1145511338
1145611339Creates an unnamed pair of sockets in the specified domain, of the
1145711340specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as
1145811341for the system call of the same name. If unimplemented, yields a fatal
1145911342error. Returns true if successful.
1146011343
1146111344=end original
1146211345
1146311346指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。
1146411347DOMAIN、TYPE、PROTOCOL は、同名のシステムコールと同じように指定します。
1146511348実装されていない場合には、致命的エラーとなります。
1146611349成功時には真を返します。
1146711350
1146811351=begin original
1146911352
1147011353On systems that support a close-on-exec flag on files, the flag will
1147111354be set for the newly opened file descriptors, as determined by the value
1147211355of $^F. See L<perlvar/$^F>.
1147311356
1147411357=end original
1147511358
1147611359ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1147711360フラグは $^F の値で決定される、新しくオープンされたファイル記述子に対して
1147811361セットされます。
1147911362L<perlvar/$^F> を参照してください。
1148011363
1148111364=begin original
1148211365
1148311366Some systems defined C<pipe> in terms of C<socketpair>, in which a call
1148411367to C<pipe(Rdr, Wtr)> is essentially:
1148511368
1148611369=end original
1148711370
1148811371C<pipe> を C<socketpair> を使って定義しているシステムもあります;
1148911372C<pipe(Rdr, Wtr)> は本質的には以下のようになります:
1149011373
1149111374 use Socket;
1149211375 socketpair(Rdr, Wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
1149311376 shutdown(Rdr, 1); # no more writing for reader
1149411377 shutdown(Wtr, 0); # no more reading for writer
1149511378
1149611379=begin original
1149711380
1149811381See L<perlipc> for an example of socketpair use. Perl 5.8 and later will
1149911382emulate socketpair using IP sockets to localhost if your system implements
1150011383sockets but not socketpair.
1150111384
1150211385=end original
1150311386
1150411387socketpair の使用例については L<perlipc> を参照してください。
1150511388Perl 5.8 以降では、システムがソケットを実装しているが socketpair を
1150611389実装していない場合、localhost に対して IP ソケットを使うことで
1150711390socketpair をエミュレートします。
1150811391
1150911392=item sort SUBNAME LIST
1151011393X<sort> X<qsort> X<quicksort> X<mergesort>
1151111394
1151211395=item sort BLOCK LIST
1151311396
1151411397=item sort LIST
1151511398
1151611399=begin original
1151711400
1151811401In list context, this sorts the LIST and returns the sorted list value.
1151911402In scalar context, the behaviour of C<sort()> is undefined.
1152011403
1152111404=end original
1152211405
1152311406リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。
1152411407スカラコンテキストでは、C<sort()> の振る舞いは未定義です。
1152511408
1152611409=begin original
1152711410
1152811411If SUBNAME or BLOCK is omitted, C<sort>s in standard string comparison
1152911412order. If SUBNAME is specified, it gives the name of a subroutine
1153011413that returns an integer less than, equal to, or greater than C<0>,
1153111414depending on how the elements of the list are to be ordered. (The C<<
1153211415<=> >> and C<cmp> operators are extremely useful in such routines.)
1153311416SUBNAME may be a scalar variable name (unsubscripted), in which case
1153411417the value provides the name of (or a reference to) the actual
1153511418subroutine to use. In place of a SUBNAME, you can provide a BLOCK as
1153611419an anonymous, in-line sort subroutine.
1153711420
1153811421=end original
1153911422
1154011423SUBNAME や BLOCK を省略すると、標準の文字列比較の順番でソートが
1154111424行なわれます。
1154211425SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに
1154311426応じて、負、ゼロ、正の整数を返すサブルーチンの名前であると解釈されます。
1154411427(このようなルーチンには、C<< <=> >> 演算子や cmp 演算子が、
1154511428たいへん便利です。)
1154611429SUBNAME は、スカラ変数名(添字なし)でもよく、
1154711430その場合には、その値が使用する実際のサブルーチンの
1154811431名前(またはそのリファレンス)と解釈されます。
1154911432SUBNAME の代わりに、無名のインライン
1155011433ソートルーチンとして、BLOCK を書くことができます。
1155111434
1155211435=begin original
1155311436
1155411437If the subroutine's prototype is C<($$)>, the elements to be compared
1155511438are passed by reference in C<@_>, as for a normal subroutine. This is
1155611439slower than unprototyped subroutines, where the elements to be
1155711440compared are passed into the subroutine
1155811441as the package global variables $a and $b (see example below). Note that
1155911442in the latter case, it is usually counter-productive to declare $a and
1156011443$b as lexicals.
1156111444
1156211445=end original
1156311446
1156411447サブルーチンのプロトタイプが C<($$)>の場合、
1156511448比較する要素は通常のサブルーチンと同じように C<@_> の中に
1156611449リファレンスとして渡されます。
1156711450これはプロトタイプなしのサブルーチンより遅いです。
1156811451この場合は比較のためサブルーチンに渡される 2 つの
1156911452要素は、パッケージのグローバル変数 $a と $b で渡されます
1157011453(次の例を参照してください)。
1157111454後者の場合、レキシカルに $a と $b を宣言するのは普通逆効果になります。
1157211455
1157311456=begin original
1157411457
1157511458The values to be compared are always passed by reference and should not
1157611459be modified.
1157711460
1157811461=end original
1157911462
1158011463$a や $b はリファレンスによって渡されるので、変更するべきではありません。
1158111464
1158211465=begin original
1158311466
1158411467You also cannot exit out of the sort block or subroutine using any of the
1158511468loop control operators described in L<perlsyn> or with C<goto>.
1158611469
1158711470=end original
1158811471
1158911472また、ソートブロックやサブルーチンから L<perlsyn> で説明されている
1159011473ループ制御子や C<goto> を使って抜けてはいけません。
1159111474
1159211475=begin original
1159311476
1159411477When C<use locale> is in effect, C<sort LIST> sorts LIST according to the
1159511478current collation locale. See L<perllocale>.
1159611479
1159711480=end original
1159811481
1159911482C<use locale> が有効の場合、C<sort LIST> は LIST を現在の比較ロケールに
1160011483従ってソートします。L<perllocale> を参照して下さい。
1160111484
1160211485=begin original
1160311486
1160411487sort() returns aliases into the original list, much as a for loop's index
1160511488variable aliases the list elements. That is, modifying an element of a
1160611489list returned by sort() (for example, in a C<foreach>, C<map> or C<grep>)
1160711490actually modifies the element in the original list. This is usually
1160811491something to be avoided when writing clear code.
1160911492
1161011493=end original
1161111494
1161211495sort() は元のリストへのエイリアスを返します; for ループのインデックス変数が
1161311496リスト要素へのエイリアスと同様です。
1161411497つまり、sort() で返されるリストの要素を(例えば、C<foreach> や C<map> や
1161511498C<grep> で)変更すると、実際に元のリストの要素が変更されます。
1161611499これはきれいなコードを書くことで普通は回避できます。
1161711500
1161811501=begin original
1161911502
1162011503Perl 5.6 and earlier used a quicksort algorithm to implement sort.
1162111504That algorithm was not stable, and I<could> go quadratic. (A I<stable> sort
1162211505preserves the input order of elements that compare equal. Although
1162311506quicksort's run time is O(NlogN) when averaged over all arrays of
1162411507length N, the time can be O(N**2), I<quadratic> behavior, for some
1162511508inputs.) In 5.7, the quicksort implementation was replaced with
1162611509a stable mergesort algorithm whose worst-case behavior is O(NlogN).
1162711510But benchmarks indicated that for some inputs, on some platforms,
1162811511the original quicksort was faster. 5.8 has a sort pragma for
1162911512limited control of the sort. Its rather blunt control of the
1163011513underlying algorithm may not persist into future Perls, but the
1163111514ability to characterize the input or output in implementation
11632independent ways quite probably will. See L<the sort pragma|sort>.
11515independent ways quite probably will. See L<sort>.
1163311516
1163411517=end original
1163511518
1163611519Perl 5.6 以前ではソートの実装にクイックソートアルゴリズムを使っていました。
1163711520このアルゴリズムは安定せず、2 乗の時間が掛かる I<可能性があります> 。
1163811521(I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。
1163911522クイックソートの実行時間は、長さ N の全ての配列の平均では
1164011523O(NlogN) ですが、入力によっては O(N**2) という I<2 乗の> 振る舞いを
1164111524することがあります。)
11642115255.7 では、クイックソートによる実装は、最悪の場合の振る舞いも
1164311526O(NlogN) である、安定したマージソートアルゴリズムに置き換えられました。
1164411527しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの
1164511528方が速くなります。
11646115295.8 ではソートを限定的に制御できる sort プラグマがあります。
1164711530この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも
1164811531しれませんが、実装に依存しない形で入力や出力を性格付ける機能は
1164911532おそらくあります。
11650L<the sort pragma|sort> を参照してください。
11533L<sort> を参照してください。
1165111534
1165211535=begin original
1165311536
1165411537Examples:
1165511538
1165611539=end original
1165711540
1165811541例:
1165911542
1166011543 # sort lexically
1166111544 @articles = sort @files;
1166211545
1166311546 # same thing, but with explicit sort routine
1166411547 @articles = sort {$a cmp $b} @files;
1166511548
1166611549 # now case-insensitively
1166711550 @articles = sort {uc($a) cmp uc($b)} @files;
1166811551
1166911552 # same thing in reversed order
1167011553 @articles = sort {$b cmp $a} @files;
1167111554
1167211555 # sort numerically ascending
1167311556 @articles = sort {$a <=> $b} @files;
1167411557
1167511558 # sort numerically descending
1167611559 @articles = sort {$b <=> $a} @files;
1167711560
1167811561 # this sorts the %age hash by value instead of key
1167911562 # using an in-line function
1168011563 @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
1168111564
1168211565 # sort using explicit subroutine name
1168311566 sub byage {
1168411567 $age{$a} <=> $age{$b}; # presuming numeric
1168511568 }
1168611569 @sortedclass = sort byage @class;
1168711570
1168811571 sub backwards { $b cmp $a }
1168911572 @harry = qw(dog cat x Cain Abel);
1169011573 @george = qw(gone chased yz Punished Axed);
1169111574 print sort @harry;
1169211575 # prints AbelCaincatdogx
1169311576 print sort backwards @harry;
1169411577 # prints xdogcatCainAbel
1169511578 print sort @george, 'to', @harry;
1169611579 # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
1169711580
1169811581 # inefficiently sort by descending numeric compare using
1169911582 # the first integer after the first = sign, or the
1170011583 # whole record case-insensitively otherwise
1170111584
1170211585 @new = sort {
1170311586 ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
1170411587 ||
1170511588 uc($a) cmp uc($b)
1170611589 } @old;
1170711590
1170811591 # same thing, but much more efficiently;
1170911592 # we'll build auxiliary indices instead
1171011593 # for speed
1171111594 @nums = @caps = ();
1171211595 for (@old) {
1171311596 push @nums, /=(\d+)/;
1171411597 push @caps, uc($_);
1171511598 }
1171611599
1171711600 @new = @old[ sort {
1171811601 $nums[$b] <=> $nums[$a]
1171911602 ||
1172011603 $caps[$a] cmp $caps[$b]
1172111604 } 0..$#old
1172211605 ];
1172311606
1172411607 # same thing, but without any temps
1172511608 @new = map { $_->[0] }
1172611609 sort { $b->[1] <=> $a->[1]
1172711610 ||
1172811611 $a->[2] cmp $b->[2]
1172911612 } map { [$_, /=(\d+)/, uc($_)] } @old;
1173011613
1173111614 # using a prototype allows you to use any comparison subroutine
1173211615 # as a sort subroutine (including other package's subroutines)
1173311616 package other;
1173411617 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are not set here
1173511618
1173611619 package main;
1173711620 @new = sort other::backwards @old;
1173811621
1173911622 # guarantee stability, regardless of algorithm
1174011623 use sort 'stable';
1174111624 @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
1174211625
1174311626 # force use of mergesort (not portable outside Perl 5.8)
1174411627 use sort '_mergesort'; # note discouraging _
1174511628 @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
1174611629
1174711630=begin original
1174811631
11749Warning: syntactical care is required when sorting the list returned from
11750a function. If you want to sort the list returned by the function call
11751C<find_records(@key)>, you can use:
11752
11753=end original
11754
11755警告: 関数からかえされたリストをソートするときには文法上の注意が必要です。
11756関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、
11757以下のように出来ます:
11758
11759 @contact = sort { $a cmp $b } find_records @key;
11760 @contact = sort +find_records(@key);
11761 @contact = sort &find_records(@key);
11762 @contact = sort(find_records(@key));
11763
11764=begin original
11765
11766If instead you want to sort the array @key with the comparison routine
11767C<find_records()> then you can use:
11768
11769=end original
11770
11771一方、配列 @key を比較ルーチン C<find_records()> でソートしたい場合は、
11772以下のように出来ます:
11773
11774 @contact = sort { find_records() } @key;
11775 @contact = sort find_records(@key);
11776 @contact = sort(find_records @key);
11777 @contact = sort(find_records (@key));
11778
11779=begin original
11780
1178111632If you're using strict, you I<must not> declare $a
1178211633and $b as lexicals. They are package globals. That means
11783that if you're in the C<main> package and type
11634if you're in the C<main> package and type
1178411635
1178511636=end original
1178611637
1178711638use strict している場合、$a と $b をレキシカルとして
1178811639宣言しては I<いけません>。
1178911640これはパッケージグローバルです。
1179011641つまり、C<main> パッケージで以下のように書いた場合:
1179111642
1179211643 @articles = sort {$b <=> $a} @files;
1179311644
1179411645=begin original
1179511646
1179611647then C<$a> and C<$b> are C<$main::a> and C<$main::b> (or C<$::a> and C<$::b>),
1179711648but if you're in the C<FooPack> package, it's the same as typing
1179811649
1179911650=end original
1180011651
1180111652C<$a> と C<$b> は C<$main::a> と C<$main::b> (または C<$::a> と C<$::b>) を
1180211653意味しますが、C<FooPack> パッケージ内の場合、これは以下と同じになります:
1180311654
1180411655 @articles = sort {$FooPack::b <=> $FooPack::a} @files;
1180511656
1180611657=begin original
1180711658
1180811659The comparison function is required to behave. If it returns
1180911660inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and
1181011661sometimes saying the opposite, for example) the results are not
1181111662well-defined.
1181211663
1181311664=end original
1181411665
1181511666比較関数は一貫した振る舞いをすることが求められます。
1181611667一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より
1181711668小さいと返し、またあるときは逆を返す)場合、結果は未定義です。
1181811669
1181911670=begin original
1182011671
1182111672Because C<< <=> >> returns C<undef> when either operand is C<NaN>
1182211673(not-a-number), and because C<sort> will trigger a fatal error unless the
1182311674result of a comparison is defined, when sorting with a comparison function
1182411675like C<< $a <=> $b >>, be careful about lists that might contain a C<NaN>.
1182511676The following example takes advantage of the fact that C<NaN != NaN> to
1182611677eliminate any C<NaN>s from the input.
1182711678
1182811679=end original
1182911680
1183011681C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに
1183111682C<undef> を返し、C<sort> は比較の結果が未定義値だと致命的エラーになるので、
1183211683C<< $a <=> $b >> といった比較関数でソートする場合はリストに C<NaN> が
1183311684含まれないように注意してください。
1183411685以下の例は 入力から C<NaN> を取り除くために C<NaN != NaN> という性質を
1183511686利用しています。
1183611687
1183711688 @result = sort { $a <=> $b } grep { $_ == $_ } @input;
1183811689
1183911690=item splice ARRAY,OFFSET,LENGTH,LIST
1184011691X<splice>
1184111692
1184211693=item splice ARRAY,OFFSET,LENGTH
1184311694
1184411695=item splice ARRAY,OFFSET
1184511696
1184611697=item splice ARRAY
1184711698
1184811699=begin original
1184911700
1185011701Removes the elements designated by OFFSET and LENGTH from an array, and
1185111702replaces them with the elements of LIST, if any. In list context,
1185211703returns the elements removed from the array. In scalar context,
1185311704returns the last element removed, or C<undef> if no elements are
1185411705removed. The array grows or shrinks as necessary.
1185511706If OFFSET is negative then it starts that far from the end of the array.
1185611707If LENGTH is omitted, removes everything from OFFSET onward.
1185711708If LENGTH is negative, removes the elements from OFFSET onward
1185811709except for -LENGTH elements at the end of the array.
1185911710If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
1186011711past the end of the array, perl issues a warning, and splices at the
1186111712end of the array.
1186211713
1186311714=end original
1186411715
1186511716ARRAY から OFFSET、LENGTH で指定される要素を取り除き、
1186611717LIST があれば、それを代わりに挿入します。
1186711718リストコンテキストでは、配列から取り除かれた要素を返します。
1186811719スカラコンテキストでは、取り除かれた最後の要素を返します。
1186911720要素が取り除かれなかった場合は C<undef> を返します。
1187011721配列は、必要に応じて、大きくなったり、小さくなったりします。
1187111722OFFSET が負の数の場合は、配列の最後からの距離を示します。
1187211723LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。
1187311724LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を
1187411725除いて取り除きます。
1187511726OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。
1187611727OFFSET が配列の最後より後ろの場合、perl は警告を出し、配列の最後に対して
1187711728処理します。
1187811729
1187911730=begin original
1188011731
1188111732The following equivalences hold (assuming C<< $[ == 0 and $#a >= $i >> )
1188211733
1188311734=end original
1188411735
1188511736以下は、(C<< $[ == 0 と $#a >= $i >> と仮定すると) それぞれ、等価です。
1188611737
1188711738 push(@a,$x,$y) splice(@a,@a,0,$x,$y)
1188811739 pop(@a) splice(@a,-1)
1188911740 shift(@a) splice(@a,0,1)
1189011741 unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
1189111742 $a[$i] = $y splice(@a,$i,1,$y)
1189211743
1189311744=begin original
1189411745
1189511746Example, assuming array lengths are passed before arrays:
1189611747
1189711748=end original
1189811749
1189911750次の例では、配列の前に、それぞれの配列の大きさが渡されるものとしています:
1190011751
1190111752 sub aeq { # compare two list values
1190211753 my(@a) = splice(@_,0,shift);
1190311754 my(@b) = splice(@_,0,shift);
1190411755 return 0 unless @a == @b; # same len?
1190511756 while (@a) {
1190611757 return 0 if pop(@a) ne pop(@b);
1190711758 }
1190811759 return 1;
1190911760 }
1191011761 if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
1191111762
1191211763=item split /PATTERN/,EXPR,LIMIT
1191311764X<split>
1191411765
1191511766=item split /PATTERN/,EXPR
1191611767
1191711768=item split /PATTERN/
1191811769
1191911770=item split
1192011771
1192111772=begin original
1192211773
1192311774Splits the string EXPR into a list of strings and returns that list. By
1192411775default, empty leading fields are preserved, and empty trailing ones are
1192511776deleted. (If all fields are empty, they are considered to be trailing.)
1192611777
1192711778=end original
1192811779
1192911780文字列 EXPR を文字列のリストに分割して、リストを返します。
1193011781デフォルトでは、行頭の空白は保存され、末尾の空白は削除されます。
1193111782(全てのフィールドが空の場合、これらは末尾であるとして扱われます。)
1193211783
1193311784=begin original
1193411785
11935In scalar context, returns the number of fields found. In scalar and void
11786In scalar context, returns the number of fields found and splits into
11936context it splits into the C<@_> array. Use of split in scalar and void
11787the C<@_> array. Use of split in scalar context is deprecated, however,
11937context is deprecated, however, because it clobbers your subroutine
11788because it clobbers your subroutine arguments.
11938arguments.
1193911789
1194011790=end original
1194111791
11942スカラコンテキストは、見つかったフィールドの数を返します。
11792スカラコンテキストの場合には、見つかったフィールドの数を返し
11943スカラコンテキストと無効コンテキストでは、配列 C<@_> に分割結果を
11793配列 C<@_> に分割結果を設定します。
11944設定しま
11794かし、スカラコンテキストでの split の使用は推奨されせん
11945、スカラコンテキストや無効コンテキストの split の使用は
11795サブルーチンの引数を上書きまうからす。
11946推奨されません; サブルーチンの引数を上書きしてしまうからです。
1194711796
1194811797=begin original
1194911798
1195011799If EXPR is omitted, splits the C<$_> string. If PATTERN is also omitted,
1195111800splits on whitespace (after skipping any leading whitespace). Anything
1195211801matching PATTERN is taken to be a delimiter separating the fields. (Note
1195311802that the delimiter may be longer than one character.)
1195411803
1195511804=end original
1195611805
1195711806EXPR を省略すると、文字列 C<$_> を split します。
1195811807もし、PATTERN も省略すると、
1195911808(先頭の空白文字をスキップした後) 空白で split します。
1196011809PATTERN にマッチするものは、フィールドを分割するデリミタとして扱われます。
1196111810(デリミタは、1 文字とは限りません。)
1196211811
1196311812=begin original
1196411813
1196511814If LIMIT is specified and positive, it represents the maximum number
1196611815of fields the EXPR will be split into, though the actual number of
1196711816fields returned depends on the number of times PATTERN matches within
1196811817EXPR. If LIMIT is unspecified or zero, trailing null fields are
1196911818stripped (which potential users of C<pop> would do well to remember).
1197011819If LIMIT is negative, it is treated as if an arbitrarily large LIMIT
1197111820had been specified. Note that splitting an EXPR that evaluates to the
1197211821empty string always returns the empty list, regardless of the LIMIT
1197311822specified.
1197411823
1197511824=end original
1197611825
1197711826正の数の LIMIT を指定した場合には、EXPR が分割されるフィールドの最大数を
1197811827表しますが、実際に返されるフィールドの数は EXPR の中で何回 PATTERN が
1197911828マッチするかに依存します。
1198011829LIMIT を指定しないかゼロなら、末尾の空フィールドを捨ててしまいます
1198111830(C<pop> を行なうときには気を付けないといけません)。
1198211831LIMIT が負ならば、LIMIT に任意の大きな数を指定したのと同じことになります。
1198311832空文字列に評価される EXPR を分割する場合、LIMIT での指定に関わらず
1198411833常に空のリストが返ることに注意してください。
1198511834
1198611835=begin original
1198711836
1198811837A pattern matching the null string (not to be confused with
1198911838a null pattern C<//>, which is just one member of the set of patterns
1199011839matching a null string) will split the value of EXPR into separate
1199111840characters at each point it matches that way. For example:
1199211841
1199311842=end original
1199411843
1199511844空文字列にマッチするパターン (ヌルパターン C<//> と混同しないでください。
1199611845これは、空文字列にマッチするパターンの一つでしかありません) は、
1199711846どの場所にもマッチし、EXPR の値を1 文字ずつに分割します。
1199811847例えば:
1199911848
12000 print join(':', split(/ */, 'hi there')), "\n";
11849 print join(':', split(/ */, 'hi there'));
1200111850
1200211851=begin original
1200311852
1200411853produces the output 'h:i:t:h:e:r:e'.
1200511854
1200611855=end original
1200711856
1200811857は、'h:i:t:h:e:r:e' という出力になります。
1200911858
1201011859=begin original
1201111860
1201211861As a special case for C<split>, using the empty pattern C<//> specifically
1201311862matches only the null string, and is not be confused with the regular use
1201411863of C<//> to mean "the last successful pattern match". So, for C<split>,
1201511864the following:
1201611865
1201711866=end original
1201811867
1201911868C<split> に関する特別な場合として、特に空パターン C<//> は空文字列に
1202011869マッチするので、「最後に成功したパターンマッチ」を意味する通常の C<//> の
1202111870使用法と混乱しないようにしてください。
1202211871それで、C<split> の場合は、以下のようにすると:
1202311872
12024 print join(':', split(//, 'hi there')), "\n";
11873 print join(':', split(//, 'hi there'));
1202511874
1202611875=begin original
1202711876
1202811877produces the output 'h:i: :t:h:e:r:e'.
1202911878
1203011879=end original
1203111880
1203211881'h:i: :t:h:e:r:e' という出力になります。
1203311882
1203411883=begin original
1203511884
1203611885Empty leading fields are produced when there are positive-width matches at
1203711886the beginning of the string; a zero-width match at the beginning of
1203811887the string does not produce an empty field. For example:
1203911888
1204011889=end original
1204111890
1204211891先頭の空フィールドは、文字列の先頭で 0 でない幅でマッチした場合は
1204311892生成されます。
1204411893幅 0 でマッチした場合は生成されません。
1204511894例えば:
1204611895
1204711896 print join(':', split(/(?=\w)/, 'hi there!'));
1204811897
1204911898=begin original
1205011899
1205111900produces the output 'h:i :t:h:e:r:e!'. Empty trailing fields, on the other
1205211901hand, are produced when there is a match at the end of the string (and
1205311902when LIMIT is given and is not 0), regardless of the length of the match.
1205411903For example:
1205511904
1205611905=end original
1205711906
1205811907これの出力は 'h:i :t:h:e:r:e!' となります。
1205911908一方、末尾の空フィールドは、マッチングの長さに関わらず、文字列の最後に
1206011909マッチングした(そして LIMIT が与えられてそれが 0 でなかった)場合に
1206111910生成されます。
1206211911例えば:
1206311912
12064 print join(':', split(//, 'hi there!', -1)), "\n";
11913 print join(':', split(//, 'hi there!', -1));
12065 print join(':', split(/\W/, 'hi there!', -1)), "\n";
11914 print join(':', split(/\W/, 'hi there!', -1));
1206611915
1206711916=begin original
1206811917
1206911918produce the output 'h:i: :t:h:e:r:e:!:' and 'hi:there:', respectively,
1207011919both with an empty trailing field.
1207111920
1207211921=end original
1207311922
1207411923これの出力はそれぞれ 'h:i :t:h:e:r:e:!:' および 'hi:there:' となり、
1207511924両方とも末尾に空フィールドが付きます。
1207611925
1207711926=begin original
1207811927
1207911928The LIMIT parameter can be used to split a line partially
1208011929
1208111930=end original
1208211931
1208311932LIMIT を使うと、行を部分的に split することができます。
1208411933
1208511934 ($login, $passwd, $remainder) = split(/:/, $_, 3);
1208611935
1208711936=begin original
1208811937
1208911938When assigning to a list, if LIMIT is omitted, or zero, Perl supplies
1209011939a LIMIT one larger than the number of variables in the list, to avoid
1209111940unnecessary work. For the list above LIMIT would have been 4 by
1209211941default. In time critical applications it behooves you not to split
1209311942into more fields than you really need.
1209411943
1209511944=end original
1209611945
1209711946リストへ代入するとき、LIMIT を省略するか 0 の場合、Perl は、
1209811947無駄な仕事を避けるため、そのリストの変数の数より、1 つだけ大きい
1209911948LIMIT が与えられたものとして処理を行ないます。
1210011949上のリストの場合には、LIMIT はデフォルトで 4 になります。
1210111950時間が問題となるアプリケーションでは、
1210211951必要以上のフィールドに分けないようにする必要があります。
1210311952
1210411953=begin original
1210511954
1210611955If the PATTERN contains parentheses, additional list elements are
1210711956created from each matching substring in the delimiter.
1210811957
1210911958=end original
1211011959
1211111960PATTERN に括弧が含まれていると、デリミタ内の部分文字列にマッチするものも、
1211211961リスト要素に含まれるようになります。
1211311962
1211411963 split(/([,-])/, "1-10,20", 3);
1211511964
1211611965=begin original
1211711966
1211811967produces the list value
1211911968
1212011969=end original
1212111970
1212211971は、以下のリスト値を生成します。
1212311972
1212411973 (1, '-', 10, ',', 20)
1212511974
1212611975=begin original
1212711976
1212811977If you had the entire header of a normal Unix email message in $header,
1212911978you could split it up into fields and their values this way:
1213011979
1213111980=end original
1213211981
1213311982$header に Unix E メールメッセージヘッダ全体が入っているとすると、
1213411983以下のようにしてフィールドとその値に分割できます:
1213511984
12136 $header =~ s/\n(?=\s)//g; # fix continuation lines
11985 $header =~ s/\n\s+/ /g; # fix continuation lines
1213711986 %hdrs = (UNIX_FROM => split /^(\S*?):\s*/m, $header);
1213811987
1213911988=begin original
1214011989
1214111990The pattern C</PATTERN/> may be replaced with an expression to specify
1214211991patterns that vary at runtime. (To do runtime compilation only once,
1214311992use C</$variable/o>.)
1214411993
1214511994=end original
1214611995
1214711996/PATTERN/ は、実行時に変わるパターンを指定する式で置き換えることができます。
1214811997(実行時のコンパイルを 1 度にするために、/$variable/o を使ってください。)
1214911998
1215011999=begin original
1215112000
1215212001As a special case, specifying a PATTERN of space (S<C<' '>>) will split on
1215312002white space just as C<split> with no arguments does. Thus, S<C<split(' ')>> can
1215412003be used to emulate B<awk>'s default behavior, whereas S<C<split(/ /)>>
1215512004will give you as many null initial fields as there are leading spaces.
1215612005A C<split> on C</\s+/> is like a S<C<split(' ')>> except that any leading
1215712006whitespace produces a null first field. A C<split> with no arguments
1215812007really does a S<C<split(' ', $_)>> internally.
1215912008
1216012009=end original
1216112010
1216212011特別な場合として、PATTERN にスペース (S<C<' '>>) を指定すると、
1216312012引数なしの C<split> のように空白で split を行ないます。
1216412013つまり、S<C<split(' ')>> は B<awk> のデフォルトの動作をエミュレートするために
1216512014使うことができ、S<C<split(/ /)>> は行頭のスペースの数に応じた空フィールドが
1216612015できます。
1216712016C<split /\s+/> は S<C<split(' ')>> と同様ですが、
1216812017先頭の空白は先頭の空フィールドとなります。
1216912018引数なしの C<split> は内部的には S<C<split(' ', $_)>> を実行します。
1217012019
1217112020=begin original
1217212021
1217312022A PATTERN of C</^/> is treated as if it were C</^/m>, since it isn't
1217412023much use otherwise.
1217512024
1217612025=end original
1217712026
1217812027PATTERN に C</^/> を指定すると C</^/m> として扱われます。
1217912028他の意味に使われることはまずないからです。
1218012029
1218112030=begin original
1218212031
1218312032Example:
1218412033
1218512034=end original
1218612035
1218712036例:
1218812037
1218912038 open(PASSWD, '/etc/passwd');
1219012039 while (<PASSWD>) {
1219112040 chomp;
1219212041 ($login, $passwd, $uid, $gid,
1219312042 $gcos, $home, $shell) = split(/:/);
1219412043 #...
1219512044 }
1219612045
1219712046=begin original
1219812047
1219912048As with regular pattern matching, any capturing parentheses that are not
1220012049matched in a C<split()> will be set to C<undef> when returned:
1220112050
1220212051=end original
1220312052
1220412053通常のパターンマッチングで、C<split()> でマッチしない全てのかっこは
1220512054返される時には C<undef> がセットされます。
1220612055
1220712056 @fields = split /(A)|B/, "1A2B3";
1220812057 # @fields is (1, 'A', 2, undef, 3)
1220912058
1221012059=item sprintf FORMAT, LIST
1221112060X<sprintf>
1221212061
1221312062=begin original
1221412063
1221512064Returns a string formatted by the usual C<printf> conventions of the C
1221612065library function C<sprintf>. See below for more details
12217and see C<sprintf(3)> or C<printf(3)> on your system for an explanation of
12066and see L<sprintf(3)> or L<printf(3)> on your system for an explanation of
1221812067the general principles.
1221912068
1222012069=end original
1222112070
1222212071普通の C 言語の C<printf> 記法のフォーマットで、整形された文字列を返します。
1222312072一般的な原則の説明については以下の説明と、システムの
12224C<sprintf(3)> または C<printf(3)> の説明を参照してください。
12073L<sprintf(3)> または L<printf(3)> の説明を参照してください。
1222512074
1222612075=begin original
1222712076
1222812077For example:
1222912078
1223012079=end original
1223112080
1223212081例:
1223312082
1223412083 # Format number with up to 8 leading zeroes
1223512084 $result = sprintf("%08d", $number);
1223612085
1223712086 # Round number to 3 digits after decimal point
1223812087 $rounded = sprintf("%.3f", $number);
1223912088
1224012089=begin original
1224112090
1224212091Perl does its own C<sprintf> formatting--it emulates the C
1224312092function C<sprintf>, but it doesn't use it (except for floating-point
1224412093numbers, and even then only the standard modifiers are allowed). As a
1224512094result, any non-standard extensions in your local C<sprintf> are not
1224612095available from Perl.
1224712096
1224812097=end original
1224912098
1225012099Perl は C<sprintf> フォーマット処理を自力で行います。
1225112100これは C の C<sprintf> 関数をエミュレートしますが、
1225212101C の関数は使いません(浮動小数点を除きますが、それでも標準の
1225312102記述子のみが利用できます)。
1225412103従って、ローカルな非標準の C<sprintf> 拡張機能は Perl では使えません。
1225512104
1225612105=begin original
1225712106
1225812107Unlike C<printf>, C<sprintf> does not do what you probably mean when you
1225912108pass it an array as your first argument. The array is given scalar context,
1226012109and instead of using the 0th element of the array as the format, Perl will
1226112110use the count of elements in the array as the format, which is almost never
1226212111useful.
1226312112
1226412113=end original
1226512114
1226612115C<printf> と違って、 C<sprintf> の最初の引数に配列を渡しても
1226712116あなたが多分望むとおりには動作しません。
1226812117配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、
1226912118配列の要素数をフォーマットとして扱います。
1227012119これはほとんど役に立ちません。
1227112120
1227212121=begin original
1227312122
1227412123Perl's C<sprintf> permits the following universally-known conversions:
1227512124
1227612125=end original
1227712126
1227812127Perl の C<sprintf> は以下の一般に知られている変換に対応しています:
1227912128
1228012129 %% a percent sign
1228112130 %c a character with the given number
1228212131 %s a string
1228312132 %d a signed integer, in decimal
1228412133 %u an unsigned integer, in decimal
1228512134 %o an unsigned integer, in octal
1228612135 %x an unsigned integer, in hexadecimal
1228712136 %e a floating-point number, in scientific notation
1228812137 %f a floating-point number, in fixed decimal notation
1228912138 %g a floating-point number, in %e or %f notation
1229012139
1229112140=begin original
1229212141
1229312142In addition, Perl permits the following widely-supported conversions:
1229412143
1229512144=end original
1229612145
1229712146さらに、Perl では以下のよく使われている変換に対応しています:
1229812147
1229912148 %X like %x, but using upper-case letters
1230012149 %E like %e, but using an upper-case "E"
1230112150 %G like %g, but with an upper-case "E" (if applicable)
1230212151 %b an unsigned integer, in binary
1230312152 %B like %b, but using an upper-case "B" with the # flag
1230412153 %p a pointer (outputs the Perl value's address in hexadecimal)
1230512154 %n special: *stores* the number of characters output so far
1230612155 into the next variable in the parameter list
1230712156
1230812157=begin original
1230912158
1231012159Finally, for backward (and we do mean "backward") compatibility, Perl
1231112160permits these unnecessary but widely-supported conversions:
1231212161
1231312162=end original
1231412163
1231512164最後に、過去との互換性(これは「過去」だと考えています)のために、
1231612165Perl は以下の不要ではあるけれども広く使われている変換に対応しています。
1231712166
1231812167 %i a synonym for %d
1231912168 %D a synonym for %ld
1232012169 %U a synonym for %lu
1232112170 %O a synonym for %lo
1232212171 %F a synonym for %f
1232312172
1232412173=begin original
1232512174
1232612175Note that the number of exponent digits in the scientific notation produced
1232712176by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
1232812177exponent less than 100 is system-dependent: it may be three or less
1232912178(zero-padded as necessary). In other words, 1.23 times ten to the
123301217999th may be either "1.23e99" or "1.23e099".
1233112180
1233212181=end original
1233312182
1233412183C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の
1233512184指数部の科学的な表記法はシステム依存であることに注意してください:
12336121853 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で
1233712186パッディングされます)。
1233812187言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし
1233912188"1.23e099" かもしれません。
1234012189
1234112190=begin original
1234212191
1234312192Between the C<%> and the format letter, you may specify a number of
1234412193additional attributes controlling the interpretation of the format.
1234512194In order, these are:
1234612195
1234712196=end original
1234812197
1234912198C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、
1235012199任意の数の追加の属性を指定できます。
1235112200順番に、以下のものがあります:
1235212201
1235312202=over 4
1235412203
1235512204=item format parameter index
1235612205
1235712206=begin original
1235812207
1235912208An explicit format parameter index, such as C<2$>. By default sprintf
1236012209will format the next unused argument in the list, but this allows you
1236112210to take the arguments out of order, e.g.:
1236212211
1236312212=end original
1236412213
1236512214
1236612215 printf '%2$d %1$d', 12, 34; # prints "34 12"
1236712216 printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1"
1236812217
1236912218=item flags
1237012219
1237112220=begin original
1237212221
1237312222one or more of:
1237412223
1237512224=end original
1237612225
1237712226以下のうちの一つまたは複数指定できます:
1237812227
12379 space prefix non-negative number with a space
12228 space prefix positive number with a space
12380 + prefix non-negative number with a plus sign
12229 + prefix positive number with a plus sign
1238112230 - left-justify within the field
1238212231 0 use zeros, not spaces, to right-justify
1238312232 # ensure the leading "0" for any octal,
1238412233 prefix non-zero hexadecimal with "0x" or "0X",
1238512234 prefix non-zero binary with "0b" or "0B"
1238612235
1238712236=begin original
1238812237
1238912238For example:
1239012239
1239112240=end original
1239212241
1239312242例:
1239412243
1239512244 printf '<% d>', 12; # prints "< 12>"
1239612245 printf '<%+d>', 12; # prints "<+12>"
1239712246 printf '<%6s>', 12; # prints "< 12>"
1239812247 printf '<%-6s>', 12; # prints "<12 >"
1239912248 printf '<%06s>', 12; # prints "<000012>"
1240012249 printf '<%#o>', 12; # prints "<014>"
1240112250 printf '<%#x>', 12; # prints "<0xc>"
1240212251 printf '<%#X>', 12; # prints "<0XC>"
1240312252 printf '<%#b>', 12; # prints "<0b1100>"
1240412253 printf '<%#B>', 12; # prints "<0B1100>"
1240512254
1240612255=begin original
1240712256
1240812257When a space and a plus sign are given as the flags at once,
1240912258a plus sign is used to prefix a positive number.
1241012259
1241112260=end original
1241212261
1241312262空白とプラス記号がフラグとして同時に与えられると、プラス記号は正の数に
1241412263前置するために使われます。
1241512264
1241612265 printf '<%+ d>', 12; # prints "<+12>"
1241712266 printf '<% +d>', 12; # prints "<+12>"
1241812267
1241912268=begin original
1242012269
1242112270When the # flag and a precision are given in the %o conversion,
1242212271the precision is incremented if it's necessary for the leading "0".
1242312272
1242412273=end original
1242512274
1242612275%o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は
1242712276精度に 1 が加えられます。
1242812277
1242912278 printf '<%#.5o>', 012; # prints "<00012>"
1243012279 printf '<%#.5o>', 012345; # prints "<012345>"
1243112280 printf '<%#.0o>', 0; # prints "<0>"
1243212281
1243312282=item vector flag
1243412283
1243512284=begin original
1243612285
1243712286This flag tells perl to interpret the supplied string as a vector of
1243812287integers, one for each character in the string. Perl applies the format to
1243912288each integer in turn, then joins the resulting strings with a separator (a
1244012289dot C<.> by default). This can be useful for displaying ordinal values of
1244112290characters in arbitrary strings:
1244212291
1244312292=end original
1244412293
1244512294このフラグは perl に、与えられた文字列を、文字毎に一つの整数のベクタとして
1244612295解釈させます。
1244712296Perl は各数値をフォーマットし、それから結果の文字列をセパレータ
1244812297(デフォルトでは C<.>)で連結します。
1244912298これは任意の文字列の文字を順序付きの値として表示するのに便利です:
1245012299
1245112300 printf "%vd", "AB\x{100}"; # prints "65.66.256"
1245212301 printf "version is v%vd\n", $^V; # Perl's version
1245312302
1245412303=begin original
1245512304
1245612305Put an asterisk C<*> before the C<v> to override the string to
1245712306use to separate the numbers:
1245812307
1245912308=end original
1246012309
1246112310アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を
1246212311上書きします:
1246312312
1246412313 printf "address is %*vX\n", ":", $addr; # IPv6 address
1246512314 printf "bits are %0*v8b\n", " ", $bits; # random bitstring
1246612315
1246712316=begin original
1246812317
1246912318You can also explicitly specify the argument number to use for
1247012319the join string using e.g. C<*2$v>:
1247112320
1247212321=end original
1247312322
1247412323また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に
1247512324指定できます。
1247612325
1247712326 printf '%*4$vX %*4$vX %*4$vX', @addr[1..3], ":"; # 3 IPv6 addresses
1247812327
1247912328=item (minimum) width
1248012329
1248112330=begin original
1248212331
1248312332Arguments are usually formatted to be only as wide as required to
1248412333display the given value. You can override the width by putting
1248512334a number here, or get the width from the next argument (with C<*>)
1248612335or from a specified argument (with e.g. C<*2$>):
1248712336
1248812337=end original
1248912338
1249012339引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。
1249112340ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で
1249212341幅を上書きできます。
1249312342
1249412343 printf '<%s>', "a"; # prints "<a>"
1249512344 printf '<%6s>', "a"; # prints "< a>"
1249612345 printf '<%*s>', 6, "a"; # prints "< a>"
1249712346 printf '<%*2$s>', "a", 6; # prints "< a>"
1249812347 printf '<%2s>', "long"; # prints "<long>" (does not truncate)
1249912348
1250012349=begin original
1250112350
1250212351If a field width obtained through C<*> is negative, it has the same
1250312352effect as the C<-> flag: left-justification.
1250412353
1250512354=end original
1250612355
1250712356C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと
1250812357同様の効果 (左詰め) があります。
1250912358
1251012359=item precision, or maximum width
1251112360X<precision>
1251212361
1251312362=begin original
1251412363
1251512364You can specify a precision (for numeric conversions) or a maximum
1251612365width (for string conversions) by specifying a C<.> followed by a number.
1251712366For floating point formats, with the exception of 'g' and 'G', this specifies
1251812367the number of decimal places to show (the default being 6), e.g.:
1251912368
1252012369=end original
1252112370
1252212371C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合)
1252312372最大幅を指定できます。
1252412373小数点数フォーマットの場合、'g' と 'G' を除いて、表示する小数点以下の
1252512374桁数を指定します(デフォルトは 6 です)。
1252612375例:
1252712376
1252812377 # these examples are subject to system-specific variation
1252912378 printf '<%f>', 1; # prints "<1.000000>"
1253012379 printf '<%.1f>', 1; # prints "<1.0>"
1253112380 printf '<%.0f>', 1; # prints "<1>"
1253212381 printf '<%e>', 10; # prints "<1.000000e+01>"
1253312382 printf '<%.1e>', 10; # prints "<1.0e+01>"
1253412383
1253512384=begin original
1253612385
1253712386For 'g' and 'G', this specifies the maximum number of digits to show,
1253812387including prior to the decimal point as well as after it, e.g.:
1253912388
1254012389=end original
1254112390
1254212391'g' と 'G' の場合、これは表示する数値の数を指定します;
1254312392これには小数点の前の数値と後の数値を含みます。
1254412393例:
1254512394
1254612395 # these examples are subject to system-specific variation
1254712396 printf '<%g>', 1; # prints "<1>"
1254812397 printf '<%.10g>', 1; # prints "<1>"
1254912398 printf '<%g>', 100; # prints "<100>"
1255012399 printf '<%.1g>', 100; # prints "<1e+02>"
1255112400 printf '<%.2g>', 100.01; # prints "<1e+02>"
1255212401 printf '<%.5g>', 100.01; # prints "<100.01>"
1255312402 printf '<%.4g>', 100.01; # prints "<100>"
1255412403
1255512404=begin original
1255612405
1255712406For integer conversions, specifying a precision implies that the
1255812407output of the number itself should be zero-padded to this width,
1255912408where the 0 flag is ignored:
1256012409
1256112410=end original
1256212411
1256312412整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で
1256412413パッディングするべきであることを暗に示すことになり、0 フラグは
1256512414無視されます:
1256612415
1256712416 printf '<%.6d>', 1; # prints "<000001>"
1256812417 printf '<%+.6d>', 1; # prints "<+000001>"
1256912418 printf '<%-10.6d>', 1; # prints "<000001 >"
1257012419 printf '<%10.6d>', 1; # prints "< 000001>"
1257112420 printf '<%010.6d>', 1; # prints "< 000001>"
1257212421 printf '<%+10.6d>', 1; # prints "< +000001>"
1257312422
1257412423 printf '<%.6x>', 1; # prints "<000001>"
1257512424 printf '<%#.6x>', 1; # prints "<0x000001>"
1257612425 printf '<%-10.6x>', 1; # prints "<000001 >"
1257712426 printf '<%10.6x>', 1; # prints "< 000001>"
1257812427 printf '<%010.6x>', 1; # prints "< 000001>"
1257912428 printf '<%#10.6x>', 1; # prints "< 0x000001>"
1258012429
1258112430=begin original
1258212431
1258312432For string conversions, specifying a precision truncates the string
1258412433to fit in the specified width:
1258512434
1258612435=end original
1258712436
1258812437文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を
1258912438切り詰めます:
1259012439
1259112440 printf '<%.5s>', "truncated"; # prints "<trunc>"
1259212441 printf '<%10.5s>', "truncated"; # prints "< trunc>"
1259312442
1259412443=begin original
1259512444
1259612445You can also get the precision from the next argument using C<.*>:
1259712446
1259812447=end original
1259912448
1260012449C<.*> を使って精度を次の引数から取ることも出来ます:
1260112450
1260212451 printf '<%.6x>', 1; # prints "<000001>"
1260312452 printf '<%.*x>', 6, 1; # prints "<000001>"
1260412453
1260512454=begin original
1260612455
1260712456If a precision obtained through C<*> is negative, it has the same
1260812457effect as no precision.
1260912458
1261012459=end original
1261112460
1261212461C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と
1261312462同じ効果となります。
1261412463
1261512464 printf '<%.*s>', 7, "string"; # prints "<string>"
1261612465 printf '<%.*s>', 3, "string"; # prints "<str>"
1261712466 printf '<%.*s>', 0, "string"; # prints "<>"
1261812467 printf '<%.*s>', -1, "string"; # prints "<string>"
1261912468
1262012469 printf '<%.*d>', 1, 0; # prints "<0>"
1262112470 printf '<%.*d>', 0, 0; # prints "<>"
1262212471 printf '<%.*d>', -1, 0; # prints "<0>"
1262312472
1262412473=begin original
1262512474
1262612475You cannot currently get the precision from a specified number,
1262712476but it is intended that this will be possible in the future using
1262812477e.g. C<.*2$>:
1262912478
1263012479=end original
1263112480
1263212481現在のところ精度を指定した数値から得ることはできませんが、
1263312482将来は C<.*2$> のようにして可能にしようとしています:
1263412483
1263512484 printf '<%.*2$x>', 1, 6; # INVALID, but in future will print "<000001>"
1263612485
1263712486=item size
1263812487
1263912488=begin original
1264012489
1264112490For numeric conversions, you can specify the size to interpret the
1264212491number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer
1264312492conversions (C<d u o x X b i D U O>), numbers are usually assumed to be
1264412493whatever the default integer size is on your platform (usually 32 or 64
1264512494bits), but you can override this to use instead one of the standard C types,
1264612495as supported by the compiler used to build Perl:
1264712496
1264812497=end original
1264912498
1265012499数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の
1265112500大きさを指定できます。
1265212501整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの
1265312502デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、
1265412503これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで
1265512504上書きできます:
1265612505
1265712506=begin original
1265812507
1265912508 l interpret integer as C type "long" or "unsigned long"
1266012509 h interpret integer as C type "short" or "unsigned short"
1266112510 q, L or ll interpret integer as C type "long long", "unsigned long long".
1266212511 or "quads" (typically 64-bit integers)
1266312512
1266412513=end original
1266512514
1266612515 l 整数を C の "long" または "unsigned long" と解釈する
1266712516 h 整数を C の "short" または "unsigned short" と解釈する
1266812517 q, L or ll 整数を C の "long long", "unsigned long long",
1266912518 "quads"(典型的には 64 ビット整数) のどれかと解釈する
1267012519
1267112520=begin original
1267212521
1267312522The last will produce errors if Perl does not understand "quads" in your
1267412523installation. (This requires that either the platform natively supports quads
1267512524or Perl was specifically compiled to support quads.) You can find out
1267612525whether your Perl supports quads via L<Config>:
1267712526
1267812527=end original
1267912528
1268012529最後の例では、Perl が 64 ビット整数を理解しない場合はエラーになります。
1268112530(このためにはプラットフォームがネイティブに 64 ビット整数に対応しているか、
1268212531Perl が特に 64 ビット整数に対応するようにコンパイルされている
1268312532必要があります。)
1268412533Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って
1268512534調べられます:
1268612535
1268712536 use Config;
1268812537 ($Config{use64bitint} eq 'define' || $Config{longsize} >= 8) &&
1268912538 print "quads\n";
1269012539
1269112540=begin original
1269212541
1269312542For floating point conversions (C<e f g E F G>), numbers are usually assumed
1269412543to be the default floating point size on your platform (double or long double),
1269512544but you can force 'long double' with C<q>, C<L>, or C<ll> if your
1269612545platform supports them. You can find out whether your Perl supports long
1269712546doubles via L<Config>:
1269812547
1269912548=end original
1270012549
1270112550浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの
1270212551不動小数点数のサイズ (double か long double) を仮定します。
1270312552Perl が long double に対応しているかどうかは L<Config> を使って
1270412553調べられます:
1270512554
1270612555 use Config;
1270712556 $Config{d_longdbl} eq 'define' && print "long doubles\n";
1270812557
1270912558=begin original
1271012559
1271112560You can find out whether Perl considers 'long double' to be the default
1271212561floating point size to use on your platform via L<Config>:
1271312562
1271412563=end original
1271512564
1271612565Perl が 'long double' をデフォルトの浮動小数点数として扱っているかどうかは
1271712566L<Config> を使って調べられます:
1271812567
1271912568 use Config;
1272012569 ($Config{uselongdouble} eq 'define') &&
1272112570 print "long doubles by default\n";
1272212571
1272312572=begin original
1272412573
1272512574It can also be the case that long doubles and doubles are the same thing:
1272612575
1272712576=end original
1272812577
1272912578long double と double が同じ場合もあります:
1273012579
1273112580 use Config;
1273212581 ($Config{doublesize} == $Config{longdblsize}) &&
1273312582 print "doubles are long doubles\n";
1273412583
1273512584=begin original
1273612585
1273712586The size specifier C<V> has no effect for Perl code, but it is supported
1273812587for compatibility with XS code; it means 'use the standard size for
1273912588a Perl integer (or floating-point number)', which is already the
1274012589default for Perl code.
1274112590
1274212591=end original
1274312592
1274412593サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは
1274512594XS コードとの互換性のために対応しています; これは「Perl 整数 (または
1274612595浮動小数点数) として標準的なサイズを使う」ことを意味し、これは Perl の
1274712596コードでは既にデフォルトです。
1274812597
1274912598=item order of arguments
1275012599
1275112600=begin original
1275212601
1275312602Normally, sprintf takes the next unused argument as the value to
1275412603format for each format specification. If the format specification
1275512604uses C<*> to require additional arguments, these are consumed from
1275612605the argument list in the order in which they appear in the format
1275712606specification I<before> the value to format. Where an argument is
1275812607specified using an explicit index, this does not affect the normal
1275912608order for the arguments (even when the explicitly specified index
1276012609would have been the next argument in any case).
1276112610
1276212611=end original
1276312612
1276412613通常、sprintf は各フォーマット指定について、使われていない次の引数を
1276512614フォーマットする値として使います。
1276612615追加の引数を要求するためにフォーマット指定 C<*> を使うと、
1276712616これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に
1276812617引数リストから消費されます。
1276912618引数の位置が明示的なインデックスを使って指定された場合、
1277012619(明示的に指定したインデックスが次の引数の場合でも)
1277112620これは通常の引数の順番に影響を与えません。
1277212621
1277312622=begin original
1277412623
1277512624So:
1277612625
1277712626=end original
1277812627
1277912628それで:
1278012629
1278112630 printf '<%*.*s>', $a, $b, $c;
1278212631
1278312632=begin original
1278412633
1278512634would use C<$a> for the width, C<$b> for the precision and C<$c>
1278612635as the value to format, while:
1278712636
1278812637=end original
1278912638
1279012639とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に
1279112640使いますが、一方:
1279212641
1279312642 printf '<%*1$.*s>', $a, $b;
1279412643
1279512644=begin original
1279612645
1279712646would use C<$a> for the width and the precision, and C<$b> as the
1279812647value to format.
1279912648
1280012649=end original
1280112650
1280212651とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。
1280312652
1280412653=begin original
1280512654
1280612655Here are some more examples - beware that when using an explicit
1280712656index, the C<$> may need to be escaped:
1280812657
1280912658=end original
1281012659
1281112660以下にさらなる例を示します - 明示的にインデックスを使う場合、C<$> は
1281212661エスケープする必要があることに注意してください。
1281312662
1281412663 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
1281512664 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
1281612665 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
1281712666 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
1281812667
1281912668=back
1282012669
1282112670=begin original
1282212671
1282312672If C<use locale> is in effect, and POSIX::setlocale() has been called,
1282412673the character used for the decimal separator in formatted floating
1282512674point numbers is affected by the LC_NUMERIC locale. See L<perllocale>
1282612675and L<POSIX>.
1282712676
1282812677=end original
1282912678
1283012679C<use locale> が有効で、POSIX::setlocale() が呼び出されている場合、
1283112680フォーマットされた浮動小数点数の小数点として使われる文字は
1283212681LC_NUMERIC ロケールの影響を受けます。
1283312682L<perllocale> と L<POSIX> を参照してください。
1283412683
1283512684=item sqrt EXPR
1283612685X<sqrt> X<root> X<square root>
1283712686
1283812687=item sqrt
1283912688
1284012689=begin original
1284112690
1284212691Return the square root of EXPR. If EXPR is omitted, returns square
1284312692root of C<$_>. Only works on non-negative operands, unless you've
1284412693loaded the standard Math::Complex module.
1284512694
1284612695=end original
1284712696
1284812697EXPR の平方根を返します。
1284912698EXPR を省略すると、C<$_> の平方根を返します。
1285012699標準の Math::Complex モジュールを使わない場合は、
1285112700負の数の引数は扱えません。
1285212701
1285312702 use Math::Complex;
1285412703 print sqrt(-2); # prints 1.4142135623731i
1285512704
1285612705=item srand EXPR
1285712706X<srand> X<seed> X<randseed>
1285812707
1285912708=item srand
1286012709
1286112710=begin original
1286212711
1286312712Sets the random number seed for the C<rand> operator.
1286412713
1286512714=end original
1286612715
1286712716rand 演算子のためのシード値を設定します。
1286812717
1286912718=begin original
1287012719
1287112720The point of the function is to "seed" the C<rand> function so that
1287212721C<rand> can produce a different sequence each time you run your
1287312722program.
1287412723
1287512724=end original
1287612725
1287712726この関数のポイントは、プログラムを実行するごとに C<rand> 関数が
1287812727異なる乱数列を生成できるように C<rand> 関数の「種」を設定することです。
1287912728
1288012729=begin original
1288112730
1288212731If srand() is not called explicitly, it is called implicitly at the
1288312732first use of the C<rand> operator. However, this was not the case in
1288412733versions of Perl before 5.004, so if your script will run under older
1288512734Perl versions, it should call C<srand>.
1288612735
1288712736=end original
1288812737
1288912738srand() が明示的に呼び出されなかった場合、最初に C<rand> 演算子を使った
1289012739時点で暗黙に呼び出されます。
1289112740しかし、これは Perl のバージョンが 5.004 より前では行われませんので、
1289212741プログラムが古い Perl で実行される場合は、C<srand> を呼ぶべきです。
1289312742
1289412743=begin original
1289512744
1289612745Most programs won't even call srand() at all, except those that
1289712746need a cryptographically-strong starting point rather than the
1289812747generally acceptable default, which is based on time of day,
1289912748process ID, and memory allocation, or the F</dev/urandom> device,
1290012749if available.
1290112750
1290212751=end original
1290312752
1290412753ほとんどのプログラムはそもそも srand() を呼ぶ必要すらありません;
1290512754例外は、時刻、プロセス ID、メモリ配置、(利用可能なら) F</dev/urandom>
1290612755デバイスといった、一般的に受け入れられるデフォルトよりも暗号学的に
1290712756強力な開始点が必要な場合です。
1290812757
1290912758=begin original
1291012759
1291112760You can call srand($seed) with the same $seed to reproduce the
1291212761I<same> sequence from rand(), but this is usually reserved for
1291312762generating predictable results for testing or debugging.
1291412763Otherwise, don't call srand() more than once in your program.
1291512764
1291612765=end original
1291712766
1291812767同じ $seed を使って srand($seed) を呼び出すことで、rand() から I<同じ>
1291912768乱数列を再現できますが、これは普通テストやデバッグのために予測された
1292012769結果を生成するために使われます。
1292112770それ以外では、srand() をプログラム内で 2 回以上呼び出さないでください。
1292212771
1292312772=begin original
1292412773
1292512774Do B<not> call srand() (i.e. without an argument) more than once in
1292612775a script. The internal state of the random number generator should
1292712776contain more entropy than can be provided by any seed, so calling
1292812777srand() again actually I<loses> randomness.
1292912778
1293012779=end original
1293112780
1293212781srand() (引数なし)をプログラム中でI<複数回呼び出してはいけません>。
1293312782乱数生成器の内部状態はどのような種によって提供されるものよりも
1293412783高いエントロピーを持っているので、srand() を再び呼び出すと
1293512784ランダム性が I<失われます>。
1293612785
1293712786=begin original
1293812787
1293912788Most implementations of C<srand> take an integer and will silently
1294012789truncate decimal numbers. This means C<srand(42)> will usually
1294112790produce the same results as C<srand(42.1)>. To be safe, always pass
1294212791C<srand> an integer.
1294312792
1294412793=end original
1294512794
1294612795C<srand> のほとんどの実装では整数を取り、小数を暗黙に切り捨てます。
1294712796これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを
1294812797意味します。
1294912798安全のために、C<srand> には常に整数を渡しましょう。
1295012799
1295112800=begin original
1295212801
1295312802In versions of Perl prior to 5.004 the default seed was just the
1295412803current C<time>. This isn't a particularly good seed, so many old
1295512804programs supply their own seed value (often C<time ^ $$> or C<time ^
1295612805($$ + ($$ << 15))>), but that isn't necessary any more.
1295712806
1295812807=end original
1295912808
12960128095.004 以前の Perl では、デフォルトのシード値は現在の C<time> でした。
1296112810これは特によいシード値ではありませんでしたので、
1296212811多くの古いプログラムは自力でシード値を指定しています
1296312812(C<time ^ $$> または C<time ^ ($$ + ($$ << 15))> がよく使われました)が、
1296412813もはやこれは必要ありません。
1296512814
1296612815=begin original
1296712816
1296812817For cryptographic purposes, however, you need something much more random
1296912818than the default seed. Checksumming the compressed output of one or more
1297012819rapidly changing operating system status programs is the usual method. For
1297112820example:
1297212821
1297312822=end original
1297412823
1297512824しかし、暗号処理にはもっとランダムな値を使う必要があります。
1297612825急激に変化するOS のステータス値プログラムの出力をひとつまたは複数用い、
1297712826圧縮してチェックサムをとる、というようなことが普通行なわれます。
1297812827例えば:
1297912828
1298012829 srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip -f`);
1298112830
1298212831=begin original
1298312832
1298412833If you're particularly concerned with this, see the C<Math::TrulyRandom>
1298512834module in CPAN.
1298612835
1298712836=end original
1298812837
1298912838特にこのようなことに関心がある場合は、
1299012839CPAN の C<Math::TrulyRandom> モジュールを参照して下さい。
1299112840
1299212841=begin original
1299312842
1299412843Frequently called programs (like CGI scripts) that simply use
1299512844
1299612845=end original
1299712846
1299812847(CGI スクリプトのような)頻繁に呼び出されるプログラムで単純に
1299912848
1300012849 time ^ $$
1300112850
1300212851=begin original
1300312852
1300412853for a seed can fall prey to the mathematical property that
1300512854
1300612855=end original
1300712856
1300812857を種として使うと、3 回に 1 回は以下の数学特性
1300912858
1301012859 a^b == (a+1)^(b+1)
1301112860
1301212861=begin original
1301312862
1301412863one-third of the time. So don't do that.
1301512864
1301612865=end original
1301712866
1301812867の餌食になります。
1301912868従ってこのようなことはしてはいけません。
1302012869
1302112870=item stat FILEHANDLE
1302212871X<stat> X<file, status> X<ctime>
1302312872
1302412873=item stat EXPR
1302512874
1302612875=item stat DIRHANDLE
1302712876
1302812877=item stat
1302912878
1303012879=begin original
1303112880
1303212881Returns a 13-element list giving the status info for a file, either
1303312882the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
1303412883omitted, it stats C<$_>. Returns a null list if the stat fails. Typically
1303512884used as follows:
1303612885
1303712886=end original
1303812887
1303912888FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、
1304012889EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。
1304112890EXPR が省略されると、 C<$_> が用いられます。
1304212891stat に失敗した場合には、空リストを返します。
1304312892普通は、以下のようにして使います:
1304412893
1304512894 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1304612895 $atime,$mtime,$ctime,$blksize,$blocks)
1304712896 = stat($filename);
1304812897
1304912898=begin original
1305012899
1305112900Not all fields are supported on all filesystem types. Here are the
1305212901meanings of the fields:
1305312902
1305412903=end original
1305512904
1305612905全てのファイルシステムで全てのフィールドに対応しているわけではありません。
1305712906フィールドの意味は以下の通りです。
1305812907
1305912908=begin original
1306012909
1306112910 0 dev device number of filesystem
1306212911 1 ino inode number
1306312912 2 mode file mode (type and permissions)
1306412913 3 nlink number of (hard) links to the file
1306512914 4 uid numeric user ID of file's owner
1306612915 5 gid numeric group ID of file's owner
1306712916 6 rdev the device identifier (special files only)
1306812917 7 size total size of file, in bytes
1306912918 8 atime last access time in seconds since the epoch
1307012919 9 mtime last modify time in seconds since the epoch
1307112920 10 ctime inode change time in seconds since the epoch (*)
1307212921 11 blksize preferred block size for file system I/O
1307312922 12 blocks actual number of blocks allocated
1307412923
1307512924=end original
1307612925
1307712926 0 dev ファイルシステムのデバイス番号
1307812927 1 ino inode 番号
1307912928 2 mode ファイルモード (タイプとパーミッション)
1308012929 3 nlink ファイルへの(ハード)リンクの数
1308112930 4 uid ファイル所有者のユーザー ID の数値
1308212931 5 gid ファイル所有者のグループ ID の数値
1308312932 6 rdev デバイス識別子(特殊ファイルのみ)
1308412933 7 size ファイルサイズ(バイト単位)
1308512934 8 atime 紀元から、最後にアクセスされた時刻までの秒数
1308612935 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数
1308712936 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*)
1308812937 11 blksize ファイルシステム I/O に適したブロックサイズ
1308912938 12 blocks 実際に割り当てられているブロックの数
1309012939
1309112940=begin original
1309212941
1309312942(The epoch was at 00:00 January 1, 1970 GMT.)
1309412943
1309512944=end original
1309612945
1309712946(紀元は GMT で 1970/01/01 00:00:00)
1309812947
1309912948=begin original
1310012949
1310112950(*) Not all fields are supported on all filesystem types. Notably, the
1310212951ctime field is non-portable. In particular, you cannot expect it to be a
1310312952"creation time", see L<perlport/"Files and Filesystems"> for details.
1310412953
1310512954=end original
1310612955
1310712956(*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは
1310812957ありません。
1310912958明らかに、ctime のフィールドは移植性がありません。
1311012959特に、これから「作成時刻」を想定することは出来ません。
1311112960詳細については L<perlport/"Files and Filesystems"> を参照してください。
1311212961
1311312962=begin original
1311412963
1311512964If C<stat> is passed the special filehandle consisting of an underline, no
1311612965stat is done, but the current contents of the stat structure from the
1311712966last C<stat>, C<lstat>, or filetest are returned. Example:
1311812967
1311912968=end original
1312012969
1312112970下線だけの _ という特別なファイルハンドルを C<stat> に渡すと、
1312212971実際には stat を行なわず、stat 構造体に残っている
1312312972前回の stat やファイルテストの情報が返されます。
1312412973例:
1312512974
1312612975 if (-x $file && (($d) = stat(_)) && $d < 0) {
1312712976 print "$file is executable NFS file\n";
1312812977 }
1312912978
1313012979=begin original
1313112980
1313212981(This works on machines only for which the device number is negative
1313312982under NFS.)
1313412983
1313512984=end original
1313612985
1313712986(これは、NFS のもとでデバイス番号が負になるマシンで
1313812987のみ動作します。)
1313912988
1314012989=begin original
1314112990
1314212991Because the mode contains both the file type and its permissions, you
1314312992should mask off the file type portion and (s)printf using a C<"%o">
1314412993if you want to see the real permissions.
1314512994
1314612995=end original
1314712996
1314812997モードにはファイルタイプとその権限の両方が含まれているので、
1314912998本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで
1315012999ファイルタイプをマスクするべきです。
1315113000
1315213001 $mode = (stat($filename))[2];
1315313002 printf "Permissions are %04o\n", $mode & 07777;
1315413003
1315513004=begin original
1315613005
1315713006In scalar context, C<stat> returns a boolean value indicating success
1315813007or failure, and, if successful, sets the information associated with
1315913008the special filehandle C<_>.
1316013009
1316113010=end original
1316213011
1316313012スカラコンテキストでは、C<stat> は成功か失敗を表す真偽値を返し、
1316413013成功した場合は、特別なファイルハンドル C<_> に結び付けられた
1316513014情報をセットします。
1316613015
1316713016=begin original
1316813017
1316913018The L<File::stat> module provides a convenient, by-name access mechanism:
1317013019
1317113020=end original
1317213021
1317313022L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。
1317413023
1317513024 use File::stat;
1317613025 $sb = stat($filename);
1317713026 printf "File is %s, size is %s, perm %04o, mtime %s\n",
1317813027 $filename, $sb->size, $sb->mode & 07777,
1317913028 scalar localtime $sb->mtime;
1318013029
1318113030=begin original
1318213031
1318313032You can import symbolic mode constants (C<S_IF*>) and functions
1318413033(C<S_IS*>) from the Fcntl module:
1318513034
1318613035=end original
1318713036
1318813037モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を Fcntl モジュールから
1318913038インポートできます。
1319013039
1319113040 use Fcntl ':mode';
1319213041
1319313042 $mode = (stat($filename))[2];
1319413043
1319513044 $user_rwx = ($mode & S_IRWXU) >> 6;
1319613045 $group_read = ($mode & S_IRGRP) >> 3;
1319713046 $other_execute = $mode & S_IXOTH;
1319813047
1319913048 printf "Permissions are %04o\n", S_IMODE($mode), "\n";
1320013049
1320113050 $is_setuid = $mode & S_ISUID;
1320213051 $is_directory = S_ISDIR($mode);
1320313052
1320413053=begin original
1320513054
1320613055You could write the last two using the C<-u> and C<-d> operators.
1320713056The commonly available C<S_IF*> constants are
1320813057
1320913058=end original
1321013059
1321113060最後の二つは C<-u> と C<-d> 演算子を使っても書けます。
1321213061一般に利用可能な C<S_IF*> 定数は以下のものです。
1321313062
1321413063 # Permissions: read, write, execute, for user, group, others.
1321513064
1321613065 S_IRWXU S_IRUSR S_IWUSR S_IXUSR
1321713066 S_IRWXG S_IRGRP S_IWGRP S_IXGRP
1321813067 S_IRWXO S_IROTH S_IWOTH S_IXOTH
1321913068
1322013069 # Setuid/Setgid/Stickiness/SaveText.
1322113070 # Note that the exact meaning of these is system dependent.
1322213071
1322313072 S_ISUID S_ISGID S_ISVTX S_ISTXT
1322413073
1322513074 # File types. Not necessarily all are available on your system.
1322613075
1322713076 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
1322813077
1322913078 # The following are compatibility aliases for S_IRUSR, S_IWUSR, S_IXUSR.
1323013079
1323113080 S_IREAD S_IWRITE S_IEXEC
1323213081
1323313082=begin original
1323413083
1323513084and the C<S_IF*> functions are
1323613085
1323713086=end original
1323813087
1323913088一般に利用可能な C<S_IF*> 関数は以下のものです。
1324013089
1324113090 S_IMODE($mode) the part of $mode containing the permission bits
1324213091 and the setuid/setgid/sticky bits
1324313092
1324413093 S_IFMT($mode) the part of $mode containing the file type
1324513094 which can be bit-anded with e.g. S_IFREG
1324613095 or with the following functions
1324713096
1324813097 # The operators -f, -d, -l, -b, -c, -p, and -S.
1324913098
1325013099 S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
1325113100 S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)
1325213101
1325313102 # No direct -X operator counterpart, but for the first one
1325413103 # the -g operator is often equivalent. The ENFMT stands for
1325513104 # record flocking enforcement, a platform-dependent feature.
1325613105
1325713106 S_ISENFMT($mode) S_ISWHT($mode)
1325813107
1325913108=begin original
1326013109
1326113110See your native chmod(2) and stat(2) documentation for more details
1326213111about the C<S_*> constants. To get status info for a symbolic link
1326313112instead of the target file behind the link, use the C<lstat> function.
1326413113
1326513114=end original
1326613115
1326713116C<S_*> 定数に関する詳細についてはネイティブの chmod(2) と stat(2) の
1326813117ドキュメントを参照して下さい。
1326913118リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を
1327013119得たい場合は、C<lstat> 関数を使ってください。
1327113120
1327213121=item state EXPR
1327313122X<state>
1327413123
1327513124=item state TYPE EXPR
1327613125
1327713126=item state EXPR : ATTRS
1327813127
1327913128=item state TYPE EXPR : ATTRS
1328013129
1328113130=begin original
1328213131
1328313132C<state> declares a lexically scoped variable, just like C<my> does.
1328413133However, those variables will never be reinitialized, contrary to
1328513134lexical variables that are reinitialized each time their enclosing block
1328613135is entered.
1328713136
1328813137=end original
1328913138
1329013139C<state> は C<my> と同様に、レキシカルスコープの変数を宣言します。
1329113140しかし、ブロックに入る毎に再初期化されるレキシカル変数と違って、
1329213141これらの変数は決して再初期化されません。
1329313142
1329413143=begin original
1329513144
1329613145C<state> variables are only enabled when the C<feature 'state'> pragma is
1329713146in effect. See L<feature>.
1329813147
1329913148=end original
1330013149
1330113150C<state> 変数は C<feature 'state'> プラグマが有効の場合のみ有効です。
1330213151L<feature> を参照してください。
1330313152
1330413153=item study SCALAR
1330513154X<study>
1330613155
1330713156=item study
1330813157
1330913158=begin original
1331013159
1331113160Takes extra time to study SCALAR (C<$_> if unspecified) in anticipation of
1331213161doing many pattern matches on the string before it is next modified.
1331313162This may or may not save time, depending on the nature and number of
1331413163patterns you are searching on, and on the distribution of character
1331513164frequencies in the string to be searched--you probably want to compare
1331613165run times with and without it to see which runs faster. Those loops
1331713166that scan for many short constant strings (including the constant
1331813167parts of more complex patterns) will benefit most. You may have only
1331913168one C<study> active at a time--if you study a different scalar the first
1332013169is "unstudied". (The way C<study> works is this: a linked list of every
1332113170character in the string to be searched is made, so we know, for
1332213171example, where all the C<'k'> characters are. From each search string,
1332313172the rarest character is selected, based on some static frequency tables
1332413173constructed from some C programs and English text. Only those places
1332513174that contain this "rarest" character are examined.)
1332613175
1332713176=end original
1332813177
1332913178次に変更される前に、何回も文字列に対するパターンマッチを
1333013179行なうアプリケーションで、
1333113180そのような文字列 SCALAR(省略時には C<$_>) を予め学習しておきます。
1333213181これは、検索のために、どのようなパターンを何回使うかによって、
1333313182また、検索される文字列内の文字頻度の分布によって、
1333413183時間を節約することになるかもしれませんし、逆に浪費する
1333513184ことになるかもしれません。
1333613185予習をした場合と、しない場合の実行時間を比較して、
1333713186どちらが速いか調べることが、必要でしょう。
1333813187短い固定文字列 (複雑なパターンの固定部分を含みます) をたくさん
1333913188検索するループで、もっとも効果があるでしょう。
1334013189同時には、一つの C<study>だけが有効です。
1334113190別のスカラを study した場合には、以前に学習した内容は
1334213191「忘却」されてしまいます。
1334313192(この C<study> の仕組みは、まず、検索される文字列内の
1334413193すべての文字のリンクされたリストが作られ、たとえば、
1334513194すべての C<'k'> がどこにあるかがわかるようになります。
1334613195各々の検索文字列から、C プログラムや英語のテキストから作られた
1334713196頻度の統計情報に基づいて、もっとも珍しい文字が選ばれます。
1334813197この「珍しい」文字を含む場所だけが調べられるのです。)
1334913198
1335013199=begin original
1335113200
1335213201For example, here is a loop that inserts index producing entries
1335313202before any line containing a certain pattern:
1335413203
1335513204=end original
1335613205
1335713206たとえば、特定のパターンを含む行の前にインデックスを
1335813207付けるエントリを入れる例を示します。
1335913208
1336013209 while (<>) {
1336113210 study;
1336213211 print ".IX foo\n" if /\bfoo\b/;
1336313212 print ".IX bar\n" if /\bbar\b/;
1336413213 print ".IX blurfl\n" if /\bblurfl\b/;
1336513214 # ...
1336613215 print;
1336713216 }
1336813217
1336913218=begin original
1337013219
1337113220In searching for C</\bfoo\b/>, only those locations in C<$_> that contain C<f>
1337213221will be looked at, because C<f> is rarer than C<o>. In general, this is
1337313222a big win except in pathological cases. The only question is whether
1337413223it saves you more time than it took to build the linked list in the
1337513224first place.
1337613225
1337713226=end original
1337813227
1337913228C<f> は C<o> よりも珍しいので、C</\bfoo\b/> を探すとき、C<$_> で C<f> を
1338013229含む場所だけが探されます。
1338113230一般に、病的な場合を除いて、かなりの結果が得られます。
1338213231唯一の問題は、節約できる時間が、最初にリンクリストを作る
1338313232時間よりも多いかどうかです、
1338413233
1338513234=begin original
1338613235
1338713236Note that if you have to look for strings that you don't know till
1338813237runtime, you can build an entire loop as a string and C<eval> that to
1338913238avoid recompiling all your patterns all the time. Together with
1339013239undefining C<$/> to input entire files as one record, this can be very
1339113240fast, often faster than specialized programs like fgrep(1). The following
1339213241scans a list of files (C<@files>) for a list of words (C<@words>), and prints
1339313242out the names of those files that contain a match:
1339413243
1339513244=end original
1339613245
1339713246実行時まで、探そうとする文字列がわからないときには、
1339813247ループ全体を文字列として組み立てて、C<eval> すれば、
1339913248いつも、すべてのパターンを再コンパイルするという事態は避けられます。
1340013249ファイル全体を一つのレコードとして入力するために、
1340113250C<$/> を未定義にすれば、かなり速くなり、
1340213251多くの場合 fgrep(1) のような専用のプログラムより速くなります。
1340313252以下の例は、ファイルのリスト (C<@files>) から単語のリスト (C<@words>) を
1340413253探して、マッチするものがあったファイル名を出力します。
1340513254
1340613255 $search = 'while (<>) { study;';
1340713256 foreach $word (@words) {
1340813257 $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
1340913258 }
1341013259 $search .= "}";
1341113260 @ARGV = @files;
1341213261 undef $/;
1341313262 eval $search; # this screams
1341413263 $/ = "\n"; # put back to normal input delimiter
1341513264 foreach $file (sort keys(%seen)) {
1341613265 print $file, "\n";
1341713266 }
1341813267
1341913268=item sub NAME BLOCK
1342013269X<sub>
1342113270
1342213271=item sub NAME (PROTO) BLOCK
1342313272
1342413273=item sub NAME : ATTRS BLOCK
1342513274
1342613275=item sub NAME (PROTO) : ATTRS BLOCK
1342713276
1342813277=begin original
1342913278
1343013279This is subroutine definition, not a real function I<per se>.
1343113280Without a BLOCK it's just a forward declaration. Without a NAME,
1343213281it's an anonymous function declaration, and does actually return
1343313282a value: the CODE ref of the closure you just created.
1343413283
1343513284=end original
1343613285
1343713286これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。
1343813287NAME なしの場合は、無名関数定義であり、実際には値(作成したブロックの
1343913288コードリファレンス)を返します。
1344013289
1344113290=begin original
1344213291
1344313292See L<perlsub> and L<perlref> for details about subroutines and
1344413293references, and L<attributes> and L<Attribute::Handlers> for more
1344513294information about attributes.
1344613295
1344713296=end original
1344813297
1344913298サブルーチンとリファレンスに関する詳細については、L<perlsub> と
1345013299L<perlref> を、属性に関する更なる情報については L<attributes> と
1345113300L<Attribute::Handlers> を参照してください。
1345213301
1345313302=item substr EXPR,OFFSET,LENGTH,REPLACEMENT
1345413303X<substr> X<substring> X<mid> X<left> X<right>
1345513304
1345613305=item substr EXPR,OFFSET,LENGTH
1345713306
1345813307=item substr EXPR,OFFSET
1345913308
1346013309=begin original
1346113310
1346213311Extracts a substring out of EXPR and returns it. First character is at
1346313312offset C<0>, or whatever you've set C<$[> to (but don't do that).
1346413313If OFFSET is negative (or more precisely, less than C<$[>), starts
1346513314that far from the end of the string. If LENGTH is omitted, returns
1346613315everything to the end of the string. If LENGTH is negative, leaves that
1346713316many characters off the end of the string.
1346813317
1346913318=end original
1347013319
1347113320EXPR から、部分文字列を取り出して返します。
1347213321最初の文字がオフセット C<0> もしくは、C<$[> に設定した値
1347313322(しかしこれを使ってはいけません)となります。
1347413323OFFSET に負の値(より厳密には、C<$[>より小さい値)を設定すると、
1347513324EXPR の終わりからのオフセットとなります。
1347613325LENGTH を省略すると、EXPR の最後まですべてが返されます。
1347713326LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。
1347813327
1347913328 my $s = "The black cat climbed the green tree";
1348013329 my $color = substr $s, 4, 5; # black
1348113330 my $middle = substr $s, 4, -11; # black cat climbed the
1348213331 my $end = substr $s, 14; # climbed the green tree
1348313332 my $tail = substr $s, -4; # tree
1348413333 my $z = substr $s, -4, 2; # tr
1348513334
1348613335=begin original
1348713336
1348813337You can use the substr() function as an lvalue, in which case EXPR
1348913338must itself be an lvalue. If you assign something shorter than LENGTH,
1349013339the string will shrink, and if you assign something longer than LENGTH,
1349113340the string will grow to accommodate it. To keep the string the same
1349213341length you may need to pad or chop your value using C<sprintf>.
1349313342
1349413343=end original
1349513344
1349613345substr() を左辺値として使用することも可能で、その場合には、
1349713346EXPR が自身左辺値でなければなりません。
1349813347LENGTH より短いものを代入したときには、
1349913348EXPR は短くなり、LENGTH より長いものを代入したときには、
1350013349EXPR はそれに合わせて伸びることになります。
1350113350EXPR の長さを一定に保つためには、C<sprintf> を使って、
1350213351代入する値の長さを調整することが、必要になるかもしれません。
1350313352
1350413353=begin original
1350513354
1350613355If OFFSET and LENGTH specify a substring that is partly outside the
1350713356string, only the part within the string is returned. If the substring
1350813357is beyond either end of the string, substr() returns the undefined
1350913358value and produces a warning. When used as an lvalue, specifying a
1351013359substring that is entirely outside the string is a fatal error.
1351113360Here's an example showing the behavior for boundary cases:
1351213361
1351313362=end original
1351413363
1351513364OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、
1351613365文字列の内側の部分だけが返されます。
1351713366部分文字列が文字列の両端の外側の場合、substr() は未定義値を返し、
1351813367警告が出力されます。
1351913368左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると
1352013369致命的エラーになります。
1352113370以下は境界条件の振る舞いを示す例です:
1352213371
1352313372 my $name = 'fred';
1352413373 substr($name, 4) = 'dy'; # $name is now 'freddy'
1352513374 my $null = substr $name, 6, 2; # returns '' (no warning)
1352613375 my $oops = substr $name, 7; # returns undef, with warning
1352713376 substr($name, 7) = 'gap'; # fatal error
1352813377
1352913378=begin original
1353013379
1353113380An alternative to using substr() as an lvalue is to specify the
1353213381replacement string as the 4th argument. This allows you to replace
1353313382parts of the EXPR and return what was there before in one operation,
1353413383just as you can with splice().
1353513384
1353613385=end original
1353713386
1353813387substr() を左辺値として使う代わりの方法は、置き換える文字列を 4 番目の
1353913388引数として指定することです。
1354013389これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、
1354113390ということを(splice() と同様) 1 動作で行えます。
1354213391
1354313392 my $s = "The black cat climbed the green tree";
1354413393 my $z = substr $s, 14, 7, "jumped from"; # climbed
1354513394 # $s is now "The black cat jumped from the green tree"
1354613395
1354713396=begin original
1354813397
1354913398Note that the lvalue returned by the 3-arg version of substr() acts as
1355013399a 'magic bullet'; each time it is assigned to, it remembers which part
1355113400of the original string is being modified; for example:
1355213401
1355313402=end original
1355413403
13555134043 引数の substr() によって返された左辺値は「魔法の弾丸」のように振舞うことに
1355613405注意してください; これが代入される毎に、元の文字列のどの部分が変更されたかが
1355713406思い出されます; 例えば:
1355813407
1355913408 $x = '1234';
1356013409 for (substr($x,1,2)) {
1356113410 $_ = 'a'; print $x,"\n"; # prints 1a4
1356213411 $_ = 'xyz'; print $x,"\n"; # prints 1xyz4
1356313412 $x = '56789';
1356413413 $_ = 'pq'; print $x,"\n"; # prints 5pq9
1356513414 }
1356613415
1356713416=begin original
1356813417
1356913418Prior to Perl version 5.9.1, the result of using an lvalue multiple times was
1357013419unspecified.
1357113420
1357213421=end original
1357313422
1357413423バージョン 5.9.1 以前の Perl では、複数回左辺値を使った場合の結果は
1357513424未定義でした。
1357613425
1357713426=item symlink OLDFILE,NEWFILE
1357813427X<symlink> X<link> X<symbolic link> X<link, symbolic>
1357913428
1358013429=begin original
1358113430
1358213431Creates a new filename symbolically linked to the old filename.
1358313432Returns C<1> for success, C<0> otherwise. On systems that don't support
1358413433symbolic links, produces a fatal error at run time. To check for that,
1358513434use eval:
1358613435
1358713436=end original
1358813437
1358913438NEWFILE として、OLDFILE へのシンボリックリンクを生成します。
1359013439成功時には C<1> を返し、失敗時には C<0> を返します。
1359113440シンボリックリンクをサポートしていないシステムでは、
1359213441実行時に致命的エラーが発生します。
1359313442これをチェックするには、eval を使用します:
1359413443
1359513444 $symlink_exists = eval { symlink("",""); 1 };
1359613445
1359713446=item syscall NUMBER, LIST
1359813447X<syscall> X<system call>
1359913448
1360013449=begin original
1360113450
1360213451Calls the system call specified as the first element of the list,
1360313452passing the remaining elements as arguments to the system call. If
1360413453unimplemented, produces a fatal error. The arguments are interpreted
1360513454as follows: if a given argument is numeric, the argument is passed as
1360613455an int. If not, the pointer to the string value is passed. You are
1360713456responsible to make sure a string is pre-extended long enough to
1360813457receive any result that might be written into a string. You can't use a
1360913458string literal (or other read-only string) as an argument to C<syscall>
1361013459because Perl has to assume that any string pointer might be written
1361113460through. If your
1361213461integer arguments are not literals and have never been interpreted in a
1361313462numeric context, you may need to add C<0> to them to force them to look
1361413463like numbers. This emulates the C<syswrite> function (or vice versa):
1361513464
1361613465=end original
1361713466
1361813467LIST の最初の要素で指定するシステムコールを、残りの要素をその
1361913468システムコールの引数として呼び出します。
1362013469実装されていないときには、致命的エラーとなります。
1362113470引数は、以下のように解釈されます: 引数が数字であれば、int として
1362213471引数を渡します。
1362313472そうでなければ、文字列値へのポインタが渡されます。
1362413473文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、
1362513474文字列を予め伸ばしておく必要があります。
1362613475文字列リテラル(あるいはその他の読み込み専用の文字列)を C<syscall> の
1362713476引数として使うことはできません。
1362813477Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。
1362913478整数引数が、リテラルでなく、数値コンテキストで評価されたことの
1363013479ないものであれば、数値として解釈されるように、
1363113480C<0> を足しておく必要があるかもしれません。
1363213481以下は C<syswrite> 関数(あるいはその逆)をエミュレートします。
1363313482
1363413483 require 'syscall.ph'; # may need to run h2ph
1363513484 $s = "hi there\n";
1363613485 syscall(&SYS_write, fileno(STDOUT), $s, length $s);
1363713486
1363813487=begin original
1363913488
1364013489Note that Perl supports passing of up to only 14 arguments to your system call,
1364113490which in practice should usually suffice.
1364213491
1364313492=end original
1364413493
1364513494Perl は、システムコールに最大 14 個の引数しか渡せませんが、
1364613495実用上問題はないでしょう。
1364713496
1364813497=begin original
1364913498
1365013499Syscall returns whatever value returned by the system call it calls.
1365113500If the system call fails, C<syscall> returns C<-1> and sets C<$!> (errno).
1365213501Note that some system calls can legitimately return C<-1>. The proper
1365313502way to handle such calls is to assign C<$!=0;> before the call and
1365413503check the value of C<$!> if syscall returns C<-1>.
1365513504
1365613505=end original
1365713506
1365813507syscall は、呼び出したシステムコールが返した値を返します。
1365913508システムコールが失敗すると、C<syscall> は C<-1> を返し、
1366013509C<$!>(errno) を設定します。
1366113510システムコールが正常に C<-1> を返す場合があることに注意してください。
1366213511このようなシステムコールを正しく扱うには、
1366313512C<$!=0;> をシステムコールの前に実行し、
1366413513syscall が C<-1> を返した時には C<$!> の値を調べてください。
1366513514
1366613515=begin original
1366713516
1366813517There's a problem with C<syscall(&SYS_pipe)>: it returns the file
1366913518number of the read end of the pipe it creates. There is no way
1367013519to retrieve the file number of the other end. You can avoid this
1367113520problem by using C<pipe> instead.
1367213521
1367313522=end original
1367413523
1367513524C<syscall(&SYS_pipe)> には問題があり、
1367613525作ったパイプの、読み出し側のファイル番号を返しますが、
1367713526もう一方のファイル番号を得る方法がありません。
1367813527この問題を避けるためには、代わりに C<pipe> を使ってください。
1367913528
1368013529=item sysopen FILEHANDLE,FILENAME,MODE
1368113530X<sysopen>
1368213531
1368313532=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
1368413533
1368513534=begin original
1368613535
1368713536Opens the file whose filename is given by FILENAME, and associates it
1368813537with FILEHANDLE. If FILEHANDLE is an expression, its value is used as
1368913538the name of the real filehandle wanted. This function calls the
1369013539underlying operating system's C<open> function with the parameters
1369113540FILENAME, MODE, PERMS.
1369213541
1369313542=end original
1369413543
1369513544FILENAME で与えられたファイル名のファイルをオープンし、
1369613545FILEHANDLE と結び付けます。
1369713546FILEHANDLE が式の場合、その値は実際に求めているファイルハンドルの名前として
1369813547扱われます。
1369913548この関数呼び出しはシステムの C<open> 関数を FILENAME, MODE, PERMS の
1370013549引数で呼び出すことを基礎としています。
1370113550
1370213551=begin original
1370313552
1370413553The possible values and flag bits of the MODE parameter are
1370513554system-dependent; they are available via the standard module C<Fcntl>.
1370613555See the documentation of your operating system's C<open> to see which
1370713556values and flag bits are available. You may combine several flags
1370813557using the C<|>-operator.
1370913558
1371013559=end original
1371113560
1371213561MODE パラメータに指定できるフラグビットと値はシステム依存です;
1371313562これは標準モジュール C<Fcntl> 経由で利用可能です。
1371413563どのようなフラグビットと値が利用可能であるかについては、
1371513564OS の C<open> に関する文書を参照してください。
1371613565C<|> 演算子を使って複数のフラグを結合することができます。
1371713566
1371813567=begin original
1371913568
1372013569Some of the most common values are C<O_RDONLY> for opening the file in
1372113570read-only mode, C<O_WRONLY> for opening the file in write-only mode,
1372213571and C<O_RDWR> for opening the file in read-write mode.
1372313572X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1372413573
1372513574=end original
1372613575
1372713576もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、
1372813577ファイルを書き込み専用で開く C<O_WRONLY>、
1372913578ファイルを読み書き両用で開く C<O_RDWR> です。
1373013579X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1373113580
1373213581=begin original
1373313582
1373413583For historical reasons, some values work on almost every system
1373513584supported by perl: zero means read-only, one means write-only, and two
1373613585means read/write. We know that these values do I<not> work under
1373713586OS/390 & VM/ESA Unix and on the Macintosh; you probably don't want to
1373813587use them in new code.
1373913588
1374013589=end original
1374113590
1374213591歴史的な理由により、perl が対応しているほとんどのシステムで
1374313592使える値があります。
13744135930 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。
1374513594OS/390 & VM/ESA Unix と Macintosh では動作 I<しない> ことが分かっています;
1374613595新しく書くコードではこれらは使わないほうがよいでしょう。
1374713596
1374813597=begin original
1374913598
1375013599If the file named by FILENAME does not exist and the C<open> call creates
1375113600it (typically because MODE includes the C<O_CREAT> flag), then the value of
1375213601PERMS specifies the permissions of the newly created file. If you omit
1375313602the PERMS argument to C<sysopen>, Perl uses the octal value C<0666>.
1375413603These permission values need to be in octal, and are modified by your
1375513604process's current C<umask>.
1375613605X<O_CREAT>
1375713606
1375813607=end original
1375913608
1376013609FILENAME という名前のファイルが存在せず、(典型的には MODE が
1376113610C<O_CREAT> フラグを含んでいたために) C<open> 呼び出しがそれを作った場合、
1376213611PERMS の値は新しく作られたファイルの権限を指定します。
1376313612C<sysopen> の PERMS 引数を省略した場合、Perl は 8 進数 C<0666> を使います。
1376413613これらの権限は 8 進数である必要があり、プロセスの現在の C<umask> で
1376513614修正されます。
1376613615
1376713616=begin original
1376813617
1376913618In many systems the C<O_EXCL> flag is available for opening files in
1377013619exclusive mode. This is B<not> locking: exclusiveness means here that
1377113620if the file already exists, sysopen() fails. C<O_EXCL> may not work
1377213621on network filesystems, and has no effect unless the C<O_CREAT> flag
1377313622is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from
1377413623being opened if it is a symbolic link. It does not protect against
1377513624symbolic links in the file's path.
1377613625X<O_EXCL>
1377713626
1377813627=end original
1377913628
1378013629多くのシステムではファイルを排他モードで開くために C<O_EXCL> が
1378113630利用可能です。
1378213631これはロック B<ではありません>: 排他性というのは既にファイルが
1378313632存在していた場合、sysopen() が失敗することを意味します。
1378413633C<O_EXCL> はネットワークファイルシステムでは動作せず、
1378513634またC<O_CREAT> フラグも有効でない限りは効果がありません。
1378613635C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は
1378713636ファイルを開くことを妨げます。
1378813637これはファイルパス中のシンボリックリンクは守りません。
1378913638X<O_EXCL>
1379013639
1379113640=begin original
1379213641
1379313642Sometimes you may want to truncate an already-existing file. This
1379413643can be done using the C<O_TRUNC> flag. The behavior of
1379513644C<O_TRUNC> with C<O_RDONLY> is undefined.
1379613645X<O_TRUNC>
1379713646
1379813647=end original
1379913648
1380013649既に存在しているファイルを切り詰めたい場合もあるかもしれません。
1380113650これは C<O_TRUNC> フラグを使うことで行えます。
1380213651C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。
1380313652X<O_TRUNC>
1380413653
1380513654=begin original
1380613655
1380713656You should seldom if ever use C<0644> as argument to C<sysopen>, because
1380813657that takes away the user's option to have a more permissive umask.
1380913658Better to omit it. See the perlfunc(1) entry on C<umask> for more
1381013659on this.
1381113660
1381213661=end original
1381313662
1381413663めったなことでは C<sysopen> の引数に C<0644> を指定するべきではないでしょう:
1381513664ユーザーがより寛大な umask を指定する選択肢を奪うからです。
1381613665省略した方がいいです。
1381713666これに関するさらなる情報については perlfunc(1) の C<umask> を
1381813667参照してください。
1381913668
1382013669=begin original
1382113670
1382213671Note that C<sysopen> depends on the fdopen() C library function.
1382313672On many UNIX systems, fdopen() is known to fail when file descriptors
1382413673exceed a certain value, typically 255. If you need more file
1382513674descriptors than that, consider rebuilding Perl to use the C<sfio>
1382613675library, or perhaps using the POSIX::open() function.
1382713676
1382813677=end original
1382913678
1383013679C<sysopen> は C の fdopen() ライブラリ関数に依存していることに注意してください。
1383113680多くの UNIX システムでは、fdopen() はファイル記述子がある値(例えば 255)を超えると
1383213681失敗することが知られています。
1383313682これより多くのファイル記述子が必要な場合は、
1383413683Perl を C<sfio> ライブラリを使って再ビルドするか、
1383513684POSIX::open() 関数を使うことを健闘してください。
1383613685
1383713686=begin original
1383813687
1383913688See L<perlopentut> for a kinder, gentler explanation of opening files.
1384013689
1384113690=end original
1384213691
1384313692ファイル操作に関するより親切な説明については L<perlopentut> を参照して下さい。
1384413693
1384513694=item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
1384613695X<sysread>
1384713696
1384813697=item sysread FILEHANDLE,SCALAR,LENGTH
1384913698
1385013699=begin original
1385113700
1385213701Attempts to read LENGTH bytes of data into variable SCALAR from the
1385313702specified FILEHANDLE, using the system call read(2). It bypasses
1385413703buffered IO, so mixing this with other kinds of reads, C<print>,
1385513704C<write>, C<seek>, C<tell>, or C<eof> can cause confusion because the
1385613705perlio or stdio layers usually buffers data. Returns the number of
1385713706bytes actually read, C<0> at end of file, or undef if there was an
1385813707error (in the latter case C<$!> is also set). SCALAR will be grown or
1385913708shrunk so that the last byte actually read is the last byte of the
1386013709scalar after the read.
1386113710
1386213711=end original
1386313712
1386413713システムコール read(2) を用いて、指定した FILEHANDLE
1386513714から、変数 SCALAR へ、LENGTH バイトのデータの読み込みを試みます。
1386613715これは、バッファ付き IO ルーチンを通りませんから、
1386713716他の入力関数, C<print>, C<write>,
1386813717C<seek>, C<tell>, C<eof> と混ぜて使うと、入力がおかしくなるかも
1386913718しれません。
1387013719perlio 層や stdio 層は普通データをバッファリングするからです。
1387113720ファイルの最後では C<0>が、エラー時には undef が、
1387213721それ以外では実際に読み込まれたデータの長さが返されます
1387313722(後者の場合は C<$!> もセットされます)。
1387413723実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、
1387513724SCALAR は伸び縮みします。
1387613725
1387713726=begin original
1387813727
1387913728An OFFSET may be specified to place the read data at some place in the
1388013729string other than the beginning. A negative OFFSET specifies
1388113730placement at that many characters counting backwards from the end of
1388213731the string. A positive OFFSET greater than the length of SCALAR
1388313732results in the string being padded to the required size with C<"\0">
1388413733bytes before the result of the read is appended.
1388513734
1388613735=end original
1388713736
1388813737OFFSET を指定すると、SCALAR の先頭以外の場所から、読み込みを行なうことが
1388913738できます。
1389013739OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1389113740位置を指定します。
13892OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は
13741OFFSET が正の値で、SCALAR の長さよりも大きかった場合、
13893読み込みの結果が追加される前に、必要なサイズまで C<"\0"> のバイト
13742必要なサイズになるまで C<"\0"> でパッディングされ、その後に
13894パッディングされます。
13743読み込み結果が追加されます。
1389513744
1389613745=begin original
1389713746
1389813747There is no syseof() function, which is ok, since eof() doesn't work
1389913748very well on device files (like ttys) anyway. Use sysread() and check
1390013749for a return value for 0 to decide whether you're done.
1390113750
1390213751=end original
1390313752
1390413753syseof() 関数はありませんが、問題ありません。
1390513754どちらにしろ eof() は(tty のような)デバイスファイルに対しては
1390613755うまく動作しないからです。
1390713756sysread() を使って、 返り値が 0 かどうかで最後まで読んだかを
1390813757判断してください。
1390913758
1391013759=begin original
1391113760
1391213761Note that if the filehandle has been marked as C<:utf8> Unicode
1391313762characters are read instead of bytes (the LENGTH, OFFSET, and the
1391413763return value of sysread() are in Unicode characters).
1391513764The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
1391613765See L</binmode>, L</open>, and the C<open> pragma, L<open>.
1391713766
1391813767=end original
1391913768
1392013769ファイルハンドルが C<:utf8> であるとマークが付けられると、バイトではなく
1392113770Unicode 文字が読み込まれます (sysread() の LENGTH, OFFSET および返り値は
1392213771Unicode 文字になります)。
1392313772C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
1392413773L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。
1392513774
1392613775=item sysseek FILEHANDLE,POSITION,WHENCE
1392713776X<sysseek> X<lseek>
1392813777
1392913778=begin original
1393013779
1393113780Sets FILEHANDLE's system position in bytes using the system call
1393213781lseek(2). FILEHANDLE may be an expression whose value gives the name
1393313782of the filehandle. The values for WHENCE are C<0> to set the new
1393413783position to POSITION, C<1> to set the it to the current position plus
1393513784POSITION, and C<2> to set it to EOF plus POSITION (typically
1393613785negative).
1393713786
1393813787=end original
1393913788
1394013789FILEHANDLE のシステム位置をバイト単位で lseek(2) システムコールを使って
1394113790設定します。
1394213791FILEHANDLE は式でも構いません。
1394313792その場合はその値がファイルハンドルの名前となります。
1394413793WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ、C<1> ならば、
1394513794現在位置から POSITION 加えた位置へ、C<2> ならば、EOF から POSITION だけ
1394613795(普通は負の数です)加えた位置へ、新しい位置を設定します。
1394713796
1394813797=begin original
1394913798
1395013799Note the I<in bytes>: even if the filehandle has been set to operate
1395113800on characters (for example by using the C<:encoding(utf8)> I/O layer),
1395213801tell() will return byte offsets, not character offsets (because
1395313802implementing that would render sysseek() very slow).
1395413803
1395513804=end original
1395613805
1395713806I<バイト単位> に関する注意: 文字単位で扱うようにファイルハンドルが
1395813807設定されている場合(C<:encoding(utf8)> I/O 層を使っている場合など)でも、
1395913808tell() は文字のオフセットではなくバイトのオフセットを返します
1396013809(なぜならこれを実装すると sysseek() がとても遅くなるからです)。
1396113810
1396213811=begin original
1396313812
1396413813sysseek() bypasses normal buffered IO, so mixing this with reads (other
1396513814than C<sysread>, for example C<< <> >> or read()) C<print>, C<write>,
1396613815C<seek>, C<tell>, or C<eof> may cause confusion.
1396713816
1396813817=end original
1396913818
1397013819sysseek() は普通のバッファ付き IO をバイパスしますので、
1397113820(C<sysread> 以外の、例えば C<< <> >> や read() の)読み込み、
1397213821C<print>, C<write>, C<seek>, C<tell>, C<eof> と混ぜて使うと
1397313822混乱を引き起こします。
1397413823
1397513824=begin original
1397613825
1397713826For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>,
1397813827and C<SEEK_END> (start of the file, current position, end of the file)
1397913828from the Fcntl module. Use of the constants is also more portable
1398013829than relying on 0, 1, and 2. For example to define a "systell" function:
1398113830
1398213831=end original
1398313832
1398413833この値には、Fcntl モジュールで使われている C<SEEK_SET>、
1398513834C<SEEK_CUR>、C<SEEK_END>
1398613835(ファイルの先頭、現在位置、ファイルの最後)という定数を使うこともできます。
1398713836
1398813837 use Fcntl 'SEEK_CUR';
1398913838 sub systell { sysseek($_[0], 0, SEEK_CUR) }
1399013839
1399113840=begin original
1399213841
1399313842Returns the new position, or the undefined value on failure. A position
1399413843of zero is returned as the string C<"0 but true">; thus C<sysseek> returns
1399513844true on success and false on failure, yet you can still easily determine
1399613845the new position.
1399713846
1399813847=end original
1399913848
1400013849新しい位置を返します。
1400113850失敗したときは未定義値を返します。
1400213851位置がゼロの場合は、C<"0 but true"> の文字列として返されます。
1400313852従って C<sysseek> は成功時に真を返し、失敗時に偽を返しますが、
1400413853簡単に新しい位置を判定できます。
1400513854
1400613855=item system LIST
1400713856X<system> X<shell>
1400813857
1400913858=item system PROGRAM LIST
1401013859
1401113860=begin original
1401213861
1401313862Does exactly the same thing as C<exec LIST>, except that a fork is
1401413863done first, and the parent process waits for the child process to
1401513864complete. Note that argument processing varies depending on the
1401613865number of arguments. If there is more than one argument in LIST,
1401713866or if LIST is an array with more than one value, starts the program
1401813867given by the first element of the list with arguments given by the
1401913868rest of the list. If there is only one scalar argument, the argument
1402013869is checked for shell metacharacters, and if there are any, the
1402113870entire argument is passed to the system's command shell for parsing
1402213871(this is C</bin/sh -c> on Unix platforms, but varies on other
1402313872platforms). If there are no shell metacharacters in the argument,
1402413873it is split into words and passed directly to C<execvp>, which is
1402513874more efficient.
1402613875
1402713876=end original
1402813877
1402913878C<exec LIST> とほとんど同じですが、まず fork を行ない、
1403013879親プロセスではチャイルドプロセスが終了するのを wait します。
1403113880exec の項で述べたように、引数の処理は、引数の数によって異なることに
1403213881注意してください。
1403313882LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、
1403413883リストの最初の要素で与えられるプログラムを、リストの残りの要素を
1403513884引数として起動します。
1403613885スカラの引数が一つだけの場合、
1403713886引数はシェルのメタ文字をチェックされ、もしあれば
1403813887パーズのために引数全体がシステムコマンドシェル
1403913888(これは Unix プラットフォームでは C</bin/sh -c> ですが、
1404013889他のプラットフォームでは異なります)に渡されます。
1404113890シェルのメタ文字がなかった場合、
1404213891引数は単語に分解されて直接 C<execvp> に渡されます。
1404313892この方がより効率的です。
1404413893
1404513894=begin original
1404613895
1404713896Beginning with v5.6.0, Perl will attempt to flush all files opened for
1404813897output before any operation that may do a fork, but this may not be
1404913898supported on some platforms (see L<perlport>). To be safe, you may need
1405013899to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
1405113900of C<IO::Handle> on any open handles.
1405213901
1405313902=end original
1405413903
14055v5.6.0 から、Perl は書き込み用に開いてい全てファイル対して
13904v5.6.0 から、Perl は fork を行うようなあらゆ動作
14056fork を行う前にフラッシュしようとしますが、これに対応していない
13905出力用オープンしていた全てのァイルをフラッシュしようとします
14057プラットフォームもあります(L<perlport> 参照してください)。
13906しかしこれをサポートしていないプラットフォームもあります(L<perlport> 参照)。
14058安全のために、C<$|> (English モジュールでは $AUTOFLUSH) セットするか、
13907安全のために、C<$l>(English モジュールを使っているなら $AUTOFLUSH)を
14059全ての開いているハンドルに対して C<IO::Handle> の C<autoflush()> メソッドを
13908設定すか、あらゆるオープン済みハンドルにおいて C<IO::Handle> の C<autoflush()>
14060呼び出す必要があるかもしれません。
13909メソッドが必要となるかもしれません。
1406113910
1406213911=begin original
1406313912
1406413913The return value is the exit status of the program as returned by the
1406513914C<wait> call. To get the actual exit value, shift right by eight (see
1406613915below). See also L</exec>. This is I<not> what you want to use to capture
1406713916the output from a command, for that you should use merely backticks or
1406813917C<qx//>, as described in L<perlop/"`STRING`">. Return value of -1
1406913918indicates a failure to start the program or an error of the wait(2) system
1407013919call (inspect $! for the reason).
1407113920
1407213921=end original
1407313922
1407413923返り値は、C<wait> が返すプログラムの exit 状態です。
1407513924実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。
1407613925L</exec> も参照してください。
1407713926これはコマンドからの出力を捕らえるために使うものI<ではありません>。
1407813927そのような用途には、L<perlop/"`STRING`"> に記述されている
1407913928逆クォートや C<qx//> を使用してください。
1408013929-1 の返り値はプログラムを開始させることに失敗したか、wait(2)
1408113930システムコールがエラーを出したことを示します
1408213931(理由は $! を調べてください)。
1408313932
1408413933=begin original
1408513934
14086If you'd like to make C<system> (and many other bits of Perl) die on error,
14087have a look at the L<autodie> pragma.
14088
14089=end original
14090
14091もし C<system> (及び Perl のその他の多くの部分) でエラー時に
14092die したいなら、L<autodie> プラグマを見てみてください。
14093
14094=begin original
14095
1409613935Like C<exec>, C<system> allows you to lie to a program about its name if
1409713936you use the C<system PROGRAM LIST> syntax. Again, see L</exec>.
1409813937
1409913938=end original
1410013939
1410113940C<exec> と同様に、C<system> でも C<system PROGRAM LIST> の文法を
1410213941使うことで、プログラムに対してその名前を嘘をつくことができます。
1410313942再び、L</exec> を参照して下さい。
1410413943
1410513944=begin original
1410613945
1410713946Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of
1410813947C<system>, if you expect your program to terminate on receipt of these
1410913948signals you will need to arrange to do so yourself based on the return
1411013949value.
1411113950
1411213951=end original
1411313952
1411413953C<SIGINT> と C<SIGQUIT> は C<system> の実行中は無視されるので、
1411513954これらのシグナルを受信して終了させることを想定したプログラムの場合、
1411613955返り値を利用するように変更する必要があります。
1411713956
1411813957 @args = ("command", "arg1", "arg2");
1411913958 system(@args) == 0
1412013959 or die "system @args failed: $?"
1412113960
1412213961=begin original
1412313962
14124If you'd like to manually inspect C<system>'s failure, you can check all
13963You can check all the failure possibilities by inspecting
14125possible failure modes by inspecting C<$?> like this:
13964C<$?> like this:
1412613965
1412713966=end original
1412813967
14129C<system> の失敗を手動で検査したいなら、
1413013968以下のように C<$?> を調べることで、全ての失敗の可能性を
14131チェックできます:
13969チェックすることができます:
1413213970
1413313971 if ($? == -1) {
1413413972 print "failed to execute: $!\n";
1413513973 }
1413613974 elsif ($? & 127) {
1413713975 printf "child died with signal %d, %s coredump\n",
1413813976 ($? & 127), ($? & 128) ? 'with' : 'without';
1413913977 }
1414013978 else {
1414113979 printf "child exited with value %d\n", $? >> 8;
1414213980 }
1414313981
1414413982=begin original
1414513983
1414613984Alternatively you might inspect the value of C<${^CHILD_ERROR_NATIVE}>
1414713985with the W*() calls of the POSIX extension.
1414813986
1414913987=end original
1415013988
1415113989または、POSIX 拡張の W*() 呼び出しを使って C<${^CHILD_ERROR_NATIVE}> の
1415213990値を調べることもできます。
1415313991
1415413992=begin original
1415513993
1415613994When the arguments get executed via the system shell, results
1415713995and return codes will be subject to its quirks and capabilities.
1415813996See L<perlop/"`STRING`"> and L</exec> for details.
1415913997
1416013998=end original
1416113999
1416214000引数がシステムシェル経由で実行された場合、
1416314001結果と返り値はシェルの癖と能力によって変更されることがあります。
1416414002詳細については L<perlop/"`STRING`"> と L</exec> を参照して下さい。
1416514003
1416614004=item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
1416714005X<syswrite>
1416814006
1416914007=item syswrite FILEHANDLE,SCALAR,LENGTH
1417014008
1417114009=item syswrite FILEHANDLE,SCALAR
1417214010
1417314011=begin original
1417414012
1417514013Attempts to write LENGTH bytes of data from variable SCALAR to the
1417614014specified FILEHANDLE, using the system call write(2). If LENGTH is
1417714015not specified, writes whole SCALAR. It bypasses buffered IO, so
1417814016mixing this with reads (other than C<sysread())>, C<print>, C<write>,
1417914017C<seek>, C<tell>, or C<eof> may cause confusion because the perlio and
1418014018stdio layers usually buffers data. Returns the number of bytes
1418114019actually written, or C<undef> if there was an error (in this case the
1418214020errno variable C<$!> is also set). If the LENGTH is greater than the
1418314021available data in the SCALAR after the OFFSET, only as much data as is
1418414022available will be written.
1418514023
1418614024=end original
1418714025
1418814026write(2) システムコールを使って、指定した FILEHANDLEへ、
1418914027変数 SCALAR から、LENGTH バイトのデータの書き込みを試みます。
1419014028LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。
1419114029これは、バッファ付き IO ルーチンを通りませんから、
1419214030他の入力関数(C<sysread()> 以外), C<print>, C<write>,
1419314031C<seek>, C<tell>, or C<eof>と混ぜて使うと、
1419414032出力がおかしくなるかもしれません。
1419514033perlio 層と stdio 層は普通データをバッファリングするからです。
1419614034実際に読み込まれたデータの長さか、エラー時には C<undef> が返されます
1419714035(この場合エラー変数 C<$!> もセットされます)。
1419814036LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、
1419914037利用可能なデータのみが書き込まれます。
1420014038
1420114039=begin original
1420214040
1420314041An OFFSET may be specified to write the data from some part of the
1420414042string other than the beginning. A negative OFFSET specifies writing
1420514043that many characters counting backwards from the end of the string.
1420614044In the case the SCALAR is empty you can use OFFSET but only zero offset.
1420714045
1420814046=end original
1420914047
1421014048OFFSET を指定すると、SCALAR の先頭以外の場所から、
1421114049データを取り出して、書き込みを行なうことができます。
1421214050OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて
1421314051何バイト目から書き込むかを示します。
1421414052SCALAR が空の場合、OFFSET はゼロのみ使用できます。
1421514053
1421614054=begin original
1421714055
1421814056Note that if the filehandle has been marked as C<:utf8>, Unicode
1421914057characters are written instead of bytes (the LENGTH, OFFSET, and the
1422014058return value of syswrite() are in UTF-8 encoded Unicode characters).
1422114059The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
1422214060See L</binmode>, L</open>, and the C<open> pragma, L<open>.
1422314061
1422414062=end original
1422514063
1422614064ファイルハンドルが C<:utf8> であるとマークが付けられると、バイトではなく
1422714065Unicode 文字が読み込まれます (syswrite() の LENGTH, OFFSET および返り値は
1422814066Unicode 文字になります)。
1422914067C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
1423014068L</binmode>, L</open>, C<open> プラグマ, L<open> を参照してください。
1423114069
1423214070=item tell FILEHANDLE
1423314071X<tell>
1423414072
1423514073=item tell
1423614074
1423714075=begin original
1423814076
1423914077Returns the current position I<in bytes> for FILEHANDLE, or -1 on
1424014078error. FILEHANDLE may be an expression whose value gives the name of
1424114079the actual filehandle. If FILEHANDLE is omitted, assumes the file
1424214080last read.
1424314081
1424414082=end original
1424514083
1424614084FILEHANDLE の現在の位置を I<バイト数で> 返します。
1424714085エラーの場合は -1 を返します。
1424814086FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
1424914087FILEHANDLE が省略された場合には、
1425014088最後に読み込みを行なったファイルについて調べます。
1425114089
1425214090=begin original
1425314091
1425414092Note the I<in bytes>: even if the filehandle has been set to
1425514093operate on characters (for example by using the C<:encoding(utf8)> open
1425614094layer), tell() will return byte offsets, not character offsets (because
1425714095that would render seek() and tell() rather slow).
1425814096
1425914097=end original
1426014098
1426114099I<バイト単位> に関する注意: ファイルハンドルが (例えば
1426214100C<:encoding(utf8)> 層を使って)
1426314101文字を操作するように設定されていたとしても、tell() は文字の
1426414102オフセットではなくバイトのオフセットを返すことに注意してください
1426514103(なぜならこれは seek() と tell() が遅くなってしまうからです)。
1426614104
1426714105=begin original
1426814106
1426914107The return value of tell() for the standard streams like the STDIN
1427014108depends on the operating system: it may return -1 or something else.
1427114109tell() on pipes, fifos, and sockets usually returns -1.
1427214110
1427314111=end original
1427414112
1427514113STDIN のような標準ストリームに対する tell() の返り値は OS に依存します。
1427614114-1 やその他の値が返ってくるかもしれません。
1427714115パイプ、FIFO、ソケットに対して tell() を使うと、普通は -1 が返ります。
1427814116
1427914117=begin original
1428014118
1428114119There is no C<systell> function. Use C<sysseek(FH, 0, 1)> for that.
1428214120
1428314121=end original
1428414122
1428514123C<systell> 関数はありません。
1428614124代わりに C<sysseek(FH, 0, 1)> を使ってください。
1428714125
1428814126=begin original
1428914127
1429014128Do not use tell() (or other buffered I/O operations) on a file handle
1429114129that has been manipulated by sysread(), syswrite() or sysseek().
1429214130Those functions ignore the buffering, while tell() does not.
1429314131
1429414132=end original
1429514133
1429614134sysread(), syswrite(), sysseek() で操作されたファイルハンドルに tell()
1429714135(またはその他のバッファリング I/O 操作) を使わないでください。
1429814136これらの関数はバッファリングを無視しますが、tell() は違います。
1429914137
1430014138=item telldir DIRHANDLE
1430114139X<telldir>
1430214140
1430314141=begin original
1430414142
1430514143Returns the current position of the C<readdir> routines on DIRHANDLE.
1430614144Value may be given to C<seekdir> to access a particular location in a
1430714145directory. C<telldir> has the same caveats about possible directory
1430814146compaction as the corresponding system library routine.
1430914147
1431014148=end original
1431114149
1431214150DIRHANDLE 上の C<readdir> ルーチンに対する現在位置を返します。
1431314151値は、そのディレクトリで特定の位置をアクセスするため、
1431414152C<seekdir> に渡すことができます。
1431514153C<telldir> は同名のシステムライブラリルーチンと同じく、
1431614154ディレクトリ縮小時の問題が考えられます。
1431714155
1431814156=item tie VARIABLE,CLASSNAME,LIST
1431914157X<tie>
1432014158
1432114159=begin original
1432214160
1432314161This function binds a variable to a package class that will provide the
1432414162implementation for the variable. VARIABLE is the name of the variable
1432514163to be enchanted. CLASSNAME is the name of a class implementing objects
1432614164of correct type. Any additional arguments are passed to the C<new>
1432714165method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>,
1432814166or C<TIEHASH>). Typically these are arguments such as might be passed
1432914167to the C<dbm_open()> function of C. The object returned by the C<new>
1433014168method is also returned by the C<tie> function, which would be useful
1433114169if you want to access other methods in CLASSNAME.
1433214170
1433314171=end original
1433414172
1433514173この関数は、変数を、その変数の実装を行なうクラスと結び付けます。
1433614174VARIABLE は、魔法をかける変数の名前です。
1433714175CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。
1433814176他に引数があれば、そのクラスの C<new> メソッドに渡されます
1433914177(つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。
1434014178通常、これらは、C の C<dbm_open> などの関数に渡す引数となります。
1434114179C<new> メソッドで返されるオブジェクトはまた C<tie> 関数でも返されます。
1434214180これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。
1434314181
1434414182=begin original
1434514183
1434614184Note that functions such as C<keys> and C<values> may return huge lists
1434714185when used on large objects, like DBM files. You may prefer to use the
1434814186C<each> function to iterate over such. Example:
1434914187
1435014188=end original
1435114189
1435214190DBM ファイルのような大きなオブジェクトでは、C<keys> や C<values> のような
1435314191関数は、大きなリストを返す可能性があります。
1435414192そのような場合では、C<each> 関数を使って繰り返しを行なった方が
1435514193よいかもしれません。
1435614194例:
1435714195
1435814196 # print out history file offsets
1435914197 use NDBM_File;
1436014198 tie(%HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
1436114199 while (($key,$val) = each %HIST) {
1436214200 print $key, ' = ', unpack('L',$val), "\n";
1436314201 }
1436414202 untie(%HIST);
1436514203
1436614204=begin original
1436714205
1436814206A class implementing a hash should have the following methods:
1436914207
1437014208=end original
1437114209
1437214210ハッシュを実装するクラスでは、次のようなメソッドを用意します:
1437314211
1437414212 TIEHASH classname, LIST
1437514213 FETCH this, key
1437614214 STORE this, key, value
1437714215 DELETE this, key
1437814216 CLEAR this
1437914217 EXISTS this, key
1438014218 FIRSTKEY this
1438114219 NEXTKEY this, lastkey
1438214220 SCALAR this
1438314221 DESTROY this
1438414222 UNTIE this
1438514223
1438614224=begin original
1438714225
1438814226A class implementing an ordinary array should have the following methods:
1438914227
1439014228=end original
1439114229
1439214230通常の配列を実装するクラスでは、次のようなメソッドを用意します:
1439314231
1439414232 TIEARRAY classname, LIST
1439514233 FETCH this, key
1439614234 STORE this, key, value
1439714235 FETCHSIZE this
1439814236 STORESIZE this, count
1439914237 CLEAR this
1440014238 PUSH this, LIST
1440114239 POP this
1440214240 SHIFT this
1440314241 UNSHIFT this, LIST
1440414242 SPLICE this, offset, length, LIST
1440514243 EXTEND this, count
1440614244 DESTROY this
1440714245 UNTIE this
1440814246
1440914247=begin original
1441014248
1441114249A class implementing a file handle should have the following methods:
1441214250
1441314251=end original
1441414252
1441514253ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します:
1441614254
1441714255 TIEHANDLE classname, LIST
1441814256 READ this, scalar, length, offset
1441914257 READLINE this
1442014258 GETC this
1442114259 WRITE this, scalar, length, offset
1442214260 PRINT this, LIST
1442314261 PRINTF this, format, LIST
1442414262 BINMODE this
1442514263 EOF this
1442614264 FILENO this
1442714265 SEEK this, position, whence
1442814266 TELL this
1442914267 OPEN this, mode, LIST
1443014268 CLOSE this
1443114269 DESTROY this
1443214270 UNTIE this
1443314271
1443414272=begin original
1443514273
1443614274A class implementing a scalar should have the following methods:
1443714275
1443814276=end original
1443914277
1444014278スカラ変数を実装するクラスでは、次のようなメソッドを用意します:
1444114279
1444214280 TIESCALAR classname, LIST
1444314281 FETCH this,
1444414282 STORE this, value
1444514283 DESTROY this
1444614284 UNTIE this
1444714285
1444814286=begin original
1444914287
1445014288Not all methods indicated above need be implemented. See L<perltie>,
1445114289L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>.
1445214290
1445314291=end original
1445414292
1445514293上記の全てのメソッドを実装する必要はありません。
1445614294L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>,
1445714295L<Tie::Handle> を参照して下さい。
1445814296
1445914297=begin original
1446014298
1446114299Unlike C<dbmopen>, the C<tie> function will not use or require a module
1446214300for you--you need to do that explicitly yourself. See L<DB_File>
1446314301or the F<Config> module for interesting C<tie> implementations.
1446414302
1446514303=end original
1446614304
1446714305C<dbmopen> と違い、C<tie> 関数はモジュールを use したり
1446814306require したりしません -- 自分で明示的に行う必要があります。
1446914307C<tie> の興味深い実装については L<DB_File> や F<Config> モジュールを
1447014308参照して下さい。
1447114309
1447214310=begin original
1447314311
1447414312For further details see L<perltie>, L<"tied VARIABLE">.
1447514313
1447614314=end original
1447714315
1447814316更なる詳細については L<perltie> や L<"tied VARIABLE"> を参照して下さい。
1447914317
1448014318=item tied VARIABLE
1448114319X<tied>
1448214320
1448314321=begin original
1448414322
1448514323Returns a reference to the object underlying VARIABLE (the same value
1448614324that was originally returned by the C<tie> call that bound the variable
1448714325to a package.) Returns the undefined value if VARIABLE isn't tied to a
1448814326package.
1448914327
1449014328=end original
1449114329
1449214330VARIABLE の基となるオブジェクトへのリファレンスを返します
1449314331(変数をパッケージに結びつけるために C<tie> 呼び出しをしたときの
1449414332返り値と同じものです)。
1449514333VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。
1449614334
1449714335=item time
1449814336X<time> X<epoch>
1449914337
1450014338=begin original
1450114339
1450214340Returns the number of non-leap seconds since whatever time the system
1450314341considers to be the epoch, suitable for feeding to C<gmtime> and
1450414342C<localtime>. On most systems the epoch is 00:00:00 UTC, January 1, 1970;
1450514343a prominent exception being Mac OS Classic which uses 00:00:00, January 1,
14506143441904 in the current local time zone for its epoch.
1450714345
1450814346=end original
1450914347
1451014348C<gmtime> や C<localtime> への入力形式に合っている、
1451114349システムが紀元と考える時点からの連続秒数を返します。
1451214350ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です;
1451314351特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの
14514143521904 年 1 月 1 日 00:00:00 を紀元として使います。
1451514353
1451614354=begin original
1451714355
1451814356For measuring time in better granularity than one second,
1451914357you may use either the L<Time::HiRes> module (from CPAN, and starting from
1452014358Perl 5.8 part of the standard distribution), or if you have
1452114359gettimeofday(2), you may be able to use the C<syscall> interface of Perl.
1452214360See L<perlfaq8> for details.
1452314361
1452414362=end original
1452514363
14526143641 秒よりも細かい時間を計測するためには、L<Time::HiRes> モジュール(CPAN から、
1452714365また Perl 5.8 からは標準配布の一部です)を使うか、
1452814366gettimeofday(2) があるなら、Perl の C<syscall> インターフェースを
1452914367使った方がよいでしょう。
1453014368詳しくは L<perlfaq8> を参照して下さい。
1453114369
1453214370=begin original
1453314371
1453414372For date and time processing look at the many related modules on CPAN.
1453514373For a comprehensive date and time representation look at the
1453614374L<DateTime> module.
1453714375
1453814376=end original
1453914377
1454014378日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。
1454114379包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
1454214380参照してください。
1454314381
1454414382=item times
1454514383X<times>
1454614384
1454714385=begin original
1454814386
1454914387Returns a four-element list giving the user and system times, in
1455014388seconds, for this process and the children of this process.
1455114389
1455214390=end original
1455314391
1455414392現プロセス及びその子プロセスに対する、ユーザ時間とシステム時間を
1455514393秒で示した、4 要素のリスト値を返します。
1455614394
1455714395 ($user,$system,$cuser,$csystem) = times;
1455814396
1455914397=begin original
1456014398
1456114399In scalar context, C<times> returns C<$user>.
1456214400
1456314401=end original
1456414402
1456514403スカラコンテキストでは、C<times> は C<$user> を返します。
1456614404
1456714405=begin original
1456814406
1456914407Note that times for children are included only after they terminate.
1457014408
1457114409=end original
1457214410
1457314411子プロセスに対する times は、それらが終了した後に含められることに
1457414412注意してください。
1457514413
1457614414=item tr///
1457714415
1457814416=begin original
1457914417
14580The transliteration operator. Same as C<y///>. See
14418The transliteration operator. Same as C<y///>. See L<perlop>.
14581L<perlop/"Quote and Quote-like Operators">.
1458214419
1458314420=end original
1458414421
1458514422変換演算子。
1458614423C<y///> と同じです。
14587L<perlop/"Quote and Quote-like Operators"> を参照してください。
14424L<perlop> を参照してください。
1458814425
1458914426=item truncate FILEHANDLE,LENGTH
1459014427X<truncate>
1459114428
1459214429=item truncate EXPR,LENGTH
1459314430
1459414431=begin original
1459514432
1459614433Truncates the file opened on FILEHANDLE, or named by EXPR, to the
1459714434specified length. Produces a fatal error if truncate isn't implemented
1459814435on your system. Returns true if successful, the undefined value
1459914436otherwise.
1460014437
1460114438=end original
1460214439
1460314440FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、
1460414441指定した長さに切り詰めます。
1460514442システム上に truncate が実装されていなければ、致命的エラーとなります。
1460614443成功すれば真を、さもなければ未定義値を返します。
1460714444
1460814445=begin original
1460914446
1461014447The behavior is undefined if LENGTH is greater than the length of the
1461114448file.
1461214449
1461314450=end original
1461414451
1461514452LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。
1461614453
1461714454=begin original
1461814455
1461914456The position in the file of FILEHANDLE is left unchanged. You may want to
1462014457call L<seek> before writing to the file.
1462114458
1462214459=end original
1462314460
1462414461FILEHANDLE のファイルの位置は変わりません。
1462514462ファイルに書き込む前に L<seek> を呼び出したいかもしれません。
1462614463
1462714464=item uc EXPR
1462814465X<uc> X<uppercase> X<toupper>
1462914466
1463014467=item uc
1463114468
1463214469=begin original
1463314470
1463414471Returns an uppercased version of EXPR. This is the internal function
1463514472implementing the C<\U> escape in double-quoted strings. Respects
1463614473current LC_CTYPE locale if C<use locale> in force. See L<perllocale>
1463714474and L<perlunicode> for more details about locale and Unicode support.
1463814475It does not attempt to do titlecase mapping on initial letters. See
1463914476C<ucfirst> for that.
1464014477
1464114478=end original
1464214479
1464314480EXPR を大文字に変換したものを返します。
1464414481これは、ダブルクォート文字列における、C<\U> エスケープを
1464514482実装する内部関数です。
1464614483C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。
1464714484ロケールと Unicode 対応に関する更なる詳細については L<perllocale> と
1464814485L<perlunicode> を参照してください。
1464914486元の文字の titlecase マッピングは試みません。
1465014487このためには C<ucfirst> を参照してください。
1465114488
1465214489=begin original
1465314490
1465414491If EXPR is omitted, uses C<$_>.
1465514492
1465614493=end original
1465714494
1465814495EXPR が省略されると、C<$_> を使います。
1465914496
1466014497=item ucfirst EXPR
1466114498X<ucfirst> X<uppercase>
1466214499
1466314500=item ucfirst
1466414501
1466514502=begin original
1466614503
1466714504Returns the value of EXPR with the first character in uppercase
1466814505(titlecase in Unicode). This is the internal function implementing
1466914506the C<\u> escape in double-quoted strings. Respects current LC_CTYPE
1467014507locale if C<use locale> in force. See L<perllocale> and L<perlunicode>
1467114508for more details about locale and Unicode support.
1467214509
1467314510=end original
1467414511
1467514512最初の文字だけを大文字にした、EXPR を返します
1467614513(Unicode では titlecase)。
1467714514これは、ダブルクォート文字列における、C<\u> エスケープを
1467814515実装する内部関数です。
1467914516C<use locale> が有効な場合は、現在の LC_CTYPE ロケールを参照します。
1468014517ロケールと Unicode 対応に関する更なる詳細については L<perllocale> と
1468114518L<perlunicode> を参照してください。
1468214519
1468314520=begin original
1468414521
1468514522If EXPR is omitted, uses C<$_>.
1468614523
1468714524=end original
1468814525
1468914526EXPR が省略されると、C<$_> を使います。
1469014527
1469114528=item umask EXPR
1469214529X<umask>
1469314530
1469414531=item umask
1469514532
1469614533=begin original
1469714534
1469814535Sets the umask for the process to EXPR and returns the previous value.
1469914536If EXPR is omitted, merely returns the current umask.
1470014537
1470114538=end original
1470214539
1470314540現在のプロセスの umask を EXPR に設定し、以前の値を返します。
1470414541EXPR が省略されると、単にその時点の umask の値を返します。
1470514542
1470614543=begin original
1470714544
1470814545The Unix permission C<rwxr-x---> is represented as three sets of three
1470914546bits, or three octal digits: C<0750> (the leading 0 indicates octal
1471014547and isn't one of the digits). The C<umask> value is such a number
1471114548representing disabled permissions bits. The permission (or "mode")
1471214549values you pass C<mkdir> or C<sysopen> are modified by your umask, so
1471314550even if you tell C<sysopen> to create a file with permissions C<0777>,
1471414551if your umask is C<0022> then the file will actually be created with
1471514552permissions C<0755>. If your C<umask> were C<0027> (group can't
1471614553write; others can't read, write, or execute), then passing
1471714554C<sysopen> C<0666> would create a file with mode C<0640> (C<0666 &~
1471814555027> is C<0640>).
1471914556
1472014557=end original
1472114558
1472214559Unix パーミッション C<rwxr-x---> は 3 ビットの 3 つの組、
1472314560または 3 桁の 8 進数として表現されます:
1472414561C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。
1472514562C<umask> の値は無効にするパーミッションビットのこのような数値表現です。
1472614563C<mkdir> や C<sysopen> で渡されたパーミッション(または「モード」)の値は
1472714564umask で修正され、たとえ C<sysopen> で C<0777> のパーミッションで
1472814565ファイルを作るように指定しても、umask が C<0022> なら、
1472914566結果としてファイルは C<0755> のパーミッションで作成されます。
1473014567C<umask> が C<0027> (グループは書き込めない; その他は読み込み、書き込み、
1473114568実行できない) のとき、C<sysopen> に C<0666> を渡すと、
1473214569ファイルはモード C<0640> (C<0666 &~ 027> は C<0640>)で作成されます。
1473314570
1473414571=begin original
1473514572
1473614573Here's some advice: supply a creation mode of C<0666> for regular
1473714574files (in C<sysopen>) and one of C<0777> for directories (in
1473814575C<mkdir>) and executable files. This gives users the freedom of
1473914576choice: if they want protected files, they might choose process umasks
1474014577of C<022>, C<027>, or even the particularly antisocial mask of C<077>.
1474114578Programs should rarely if ever make policy decisions better left to
1474214579the user. The exception to this is when writing files that should be
1474314580kept private: mail files, web browser cookies, I<.rhosts> files, and
1474414581so on.
1474514582
1474614583=end original
1474714584
1474814585以下は助言です: 作成モードとして、(C<sysopen> による)通常ファイルでは
1474914586C<0666> を、(C<mkdir> による)ディレクトリでは C<0777> を指定しましょう。
1475014587これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、
1475114588プロセスの umask として C<022>, C<027>, あるいは特に非社交的な
1475214589C<077> を選択できます。
1475314590プログラムがユーザーより適切なポリシー選択ができることは稀です。
1475414591例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、
1475514592I<.rhosts> ファイルなど)を書く場合です。
1475614593
1475714594=begin original
1475814595
1475914596If umask(2) is not implemented on your system and you are trying to
1476014597restrict access for I<yourself> (i.e., (EXPR & 0700) > 0), produces a
1476114598fatal error at run time. If umask(2) is not implemented and you are
1476214599not trying to restrict access for yourself, returns C<undef>.
1476314600
1476414601=end original
1476514602
1476614603umask(2) が実装されていないシステムで、I<自分自身> へのアクセスを
1476714604制限しようとした(つまり (EXPR & 0700) > 0)場合、実行時に致命的エラーが
1476814605発生します。
1476914606umask(2) が実装されていないシステムで、自分自身へのアクセスは
1477014607制限しようとしなかった場合、C<undef> を返します。
1477114608
1477214609=begin original
1477314610
1477414611Remember that a umask is a number, usually given in octal; it is I<not> a
1477514612string of octal digits. See also L</oct>, if all you have is a string.
1477614613
1477714614=end original
1477814615
1477914616umask は通常 8 進数で与えられる数値であることを忘れないでください。
14780146178 進数の文字列 I<ではありません>。
1478114618文字列しかない場合、 L</oct> も参照して下さい。
1478214619
1478314620=item undef EXPR
1478414621X<undef> X<undefine>
1478514622
1478614623=item undef
1478714624
1478814625=begin original
1478914626
1479014627Undefines the value of EXPR, which must be an lvalue. Use only on a
1479114628scalar value, an array (using C<@>), a hash (using C<%>), a subroutine
1479214629(using C<&>), or a typeglob (using C<*>). (Saying C<undef $hash{$key}>
1479314630will probably not do what you expect on most predefined variables or
1479414631DBM list values, so don't do that; see L<delete>.) Always returns the
1479514632undefined value. You can omit the EXPR, in which case nothing is
1479614633undefined, but you still get an undefined value that you could, for
1479714634instance, return from a subroutine, assign to a variable or pass as a
1479814635parameter. Examples:
1479914636
1480014637=end original
1480114638
1480214639左辺値である EXPR の値を未定義にします。
1480314640スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
1480414641サブルーチン、(C<*> を使った)型グロブだけに使用します。
1480514642(特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても
1480614643おそらく期待通りの結果にはなりませんから、しないでください。
1480714644L</delete> を参照してください。)
1480814645常に未定義値を返します。
1480914646EXPR は省略することができ、その場合には何も未定義にされませんが
1481014647未定義値は返されますので、それをたとえば、
1481114648サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。
1481214649例:
1481314650
1481414651 undef $foo;
1481514652 undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};
1481614653 undef @ary;
1481714654 undef %hash;
1481814655 undef &mysub;
1481914656 undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc.
1482014657 return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it;
1482114658 select undef, undef, undef, 0.25;
1482214659 ($a, $b, undef, $c) = &foo; # Ignore third value returned
1482314660
1482414661=begin original
1482514662
1482614663Note that this is a unary operator, not a list operator.
1482714664
1482814665=end original
1482914666
1483014667これはリスト演算子ではなく、単項演算子であることに注意してください。
1483114668
1483214669=item unlink LIST
1483314670X<unlink> X<delete> X<remove> X<rm> X<del>
1483414671
1483514672=item unlink
1483614673
1483714674=begin original
1483814675
1483914676Deletes a list of files. Returns the number of files successfully
1484014677deleted.
1484114678
1484214679=end original
1484314680
1484414681LIST に含まれるファイルを削除します。
1484514682削除に成功したファイルの数を返します。
1484614683
1484714684 $cnt = unlink 'a', 'b', 'c';
1484814685 unlink @goners;
1484914686 unlink <*.bak>;
1485014687
1485114688=begin original
1485214689
1485314690Note: C<unlink> will not attempt to delete directories unless you are superuser
1485414691and the B<-U> flag is supplied to Perl. Even if these conditions are
1485514692met, be warned that unlinking a directory can inflict damage on your
1485614693filesystem. Finally, using C<unlink> on directories is not supported on
1485714694many operating systems. Use C<rmdir> instead.
1485814695
1485914696=end original
1486014697
1486114698注: スーパーユーザ権限で、Perl に -U を付けて実行した場合でなければ、
1486214699C<unlink> はディレクトリを削除しようとすることはありません。
1486314700この条件にあう場合にも、ディレクトリの削除は、
1486414701ファイルシステムに多大な損害を与える可能性があります。
1486514702最後に、C<unlink> をディレクトリに使うのはほとんどの OS では
1486614703対応していません。
1486714704代わりに C<rmdir> を使ってください。
1486814705
1486914706=begin original
1487014707
1487114708If LIST is omitted, uses C<$_>.
1487214709
1487314710=end original
1487414711
1487514712LIST が省略されると、C<$_> を使います。
1487614713
1487714714=item unpack TEMPLATE,EXPR
1487814715X<unpack>
1487914716
1488014717=item unpack TEMPLATE
1488114718
1488214719=begin original
1488314720
1488414721C<unpack> does the reverse of C<pack>: it takes a string
1488514722and expands it out into a list of values.
1488614723(In scalar context, it returns merely the first value produced.)
1488714724
1488814725=end original
1488914726
1489014727C<unpack> は C<pack> の逆を行ないます: 構造体を表わす文字列をとり、
1489114728リスト値に展開し、その配列値を返します。
1489214729(スカラコンテキストでは、単に最初の値を返します。)
1489314730
1489414731=begin original
1489514732
1489614733If EXPR is omitted, unpacks the C<$_> string.
1489714734
1489814735=end original
1489914736
1490014737EXPR が省略されると、C<$_> の文字列を unpack します。
1490114738
1490214739=begin original
1490314740
1490414741The string is broken into chunks described by the TEMPLATE. Each chunk
1490514742is converted separately to a value. Typically, either the string is a result
1490614743of C<pack>, or the characters of the string represent a C structure of some
1490714744kind.
1490814745
1490914746=end original
1491014747
1491114748文字列は TEMPLATE で示された固まりに分割されます。
1491214749それぞれの固まりは別々に値に変換されます。
1491314750典型的には、文字列は C<pack> の結果あるいはある種の C の構造体の
1491414751文字列表現の文字列です。
1491514752
1491614753=begin original
1491714754
1491814755The TEMPLATE has the same format as in the C<pack> function.
1491914756Here's a subroutine that does substring:
1492014757
1492114758=end original
1492214759
1492314760TEMPLATE は、C<pack> 関数と同じフォーマットを使います。
1492414761部分文字列を取り出すうサブルーチンの例を示します:
1492514762
1492614763 sub substr {
1492714764 my($what,$where,$howmuch) = @_;
1492814765 unpack("x$where a$howmuch", $what);
1492914766 }
1493014767
1493114768=begin original
1493214769
1493314770and then there's
1493414771
1493514772=end original
1493614773
1493714774これもそうです。
1493814775
1493914776 sub ordinal { unpack("W",$_[0]); } # same as ord()
1494014777
1494114778=begin original
1494214779
1494314780In addition to fields allowed in pack(), you may prefix a field with
1494414781a %<number> to indicate that
1494514782you want a <number>-bit checksum of the items instead of the items
1494614783themselves. Default is a 16-bit checksum. Checksum is calculated by
1494714784summing numeric values of expanded values (for string fields the sum of
1494814785C<ord($char)> is taken, for bit fields the sum of zeroes and ones).
1494914786
1495014787=end original
1495114788
1495214789pack() で利用可能なフィールドの他に、
1495314790フィールドの前に %<数値> というものを付けて、
1495414791項目自身の代わりに、その項目の <数値>-ビットのチェックサムを
1495514792計算させることができます。
1495614793デフォルトは、16-ビットチェックサムです。
1495714794チェックサムは展開された値の数値としての値の合計
1495814795(文字列フィールドの場合は C<ord($char)> の合計、
1495914796ビットフィールドの場合は 0 と 1 の合計) が用いられます。
1496014797
1496114798=begin original
1496214799
1496314800For example, the following
1496414801computes the same number as the System V sum program:
1496514802
1496614803=end original
1496714804
1496814805たとえば、以下のコードは
1496914806System V の sum プログラムと同じ値を計算します。
1497014807
1497114808 $checksum = do {
1497214809 local $/; # slurp!
1497314810 unpack("%32W*",<>) % 65535;
1497414811 };
1497514812
1497614813=begin original
1497714814
1497814815The following efficiently counts the number of set bits in a bit vector:
1497914816
1498014817=end original
1498114818
1498214819以下は、効率的にビットベクターの設定されているビットを
1498314820数えるものです。
1498414821
1498514822 $setbits = unpack("%32b*", $selectmask);
1498614823
1498714824=begin original
1498814825
1498914826The C<p> and C<P> formats should be used with care. Since Perl
1499014827has no way of checking whether the value passed to C<unpack()>
1499114828corresponds to a valid memory location, passing a pointer value that's
1499214829not known to be valid is likely to have disastrous consequences.
1499314830
1499414831=end original
1499514832
1499614833C<p> と C<P> は注意深く使うべきです。
1499714834Perl は C<unpack()> に渡された値が有効なメモリ位置を指しているかどうかを
1499814835確認する方法がないので、有効かどうかわからないポインタ値を渡すと
1499914836悲惨な結果を引き起こすかもしれません。
1500014837
1500114838=begin original
1500214839
1500314840If there are more pack codes or if the repeat count of a field or a group
1500414841is larger than what the remainder of the input string allows, the result
1500514842is not well defined: in some cases, the repeat count is decreased, or
1500614843C<unpack()> will produce null strings or zeroes, or terminate with an
1500714844error. If the input string is longer than one described by the TEMPLATE,
1500814845the rest is ignored.
1500914846
1501014847=end original
1501114848
1501214849多くの pack コードがある場合や、フィールドやグループの繰り返し回数が
1501314850入力文字列の残りより大きい場合、結果は未定義です:
1501414851繰り返し回数が減らされる場合もありますし、C<unpack()> が空文字列や 0 を
1501514852返すこともありますし、エラーで終了することもあります。
1501614853もし入力文字列が TEMPLATE で表現されているものより大きい場合、残りは
1501714854無視されます。
1501814855
1501914856=begin original
1502014857
1502114858See L</pack> for more examples and notes.
1502214859
1502314860=end original
1502414861
1502514862さらなる例と注意に関しては L</pack> を参照してください。
1502614863
1502714864=item untie VARIABLE
1502814865X<untie>
1502914866
1503014867=begin original
1503114868
1503214869Breaks the binding between a variable and a package. (See C<tie>.)
1503314870Has no effect if the variable is not tied.
1503414871
1503514872=end original
1503614873
1503714874変数とパッケージの間の結合を解きます。
1503814875(L<tie> を参照してください。)
1503914876結合されていない場合は何も起きません。
1504014877
1504114878=item unshift ARRAY,LIST
1504214879X<unshift>
1504314880
1504414881=begin original
1504514882
1504614883Does the opposite of a C<shift>. Or the opposite of a C<push>,
1504714884depending on how you look at it. Prepends list to the front of the
1504814885array, and returns the new number of elements in the array.
1504914886
1505014887=end original
1505114888
1505214889C<shift> の逆操作を行ないます。
1505314890見方を変えれば、C<push>の逆操作とも考えられます。
1505414891LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。
1505514892
1505614893 unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;
1505714894
1505814895=begin original
1505914896
1506014897Note the LIST is prepended whole, not one element at a time, so the
1506114898prepended elements stay in the same order. Use C<reverse> to do the
1506214899reverse.
1506314900
1506414901=end original
1506514902
1506614903LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。
1506714904逆順に登録するには、C<reverse> を使ってください。
1506814905
1506914906=item use Module VERSION LIST
1507014907X<use> X<module> X<import>
1507114908
1507214909=item use Module VERSION
1507314910
1507414911=item use Module LIST
1507514912
1507614913=item use Module
1507714914
1507814915=item use VERSION
1507914916
1508014917=begin original
1508114918
1508214919Imports some semantics into the current package from the named module,
1508314920generally by aliasing certain subroutine or variable names into your
1508414921package. It is exactly equivalent to
1508514922
1508614923=end original
1508714924
1508814925指定したモジュールから、現在のパッケージにさまざまな内容を
1508914926インポートします。
1509014927多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、
1509114928実現されています。これは、
1509214929以下は等価ですが:
1509314930
1509414931 BEGIN { require Module; Module->import( LIST ); }
1509514932
1509614933=begin original
1509714934
1509814935except that Module I<must> be a bareword.
1509914936
1510014937=end original
1510114938
1510214939Module が I<単なる単語でなければならない> ことを除けば、です。
1510314940
1510414941=begin original
1510514942
1510614943In the peculiar C<use VERSION> form, VERSION may be either a numeric
1510714944argument such as 5.006, which will be compared to C<$]>, or a literal of
1510814945the form v5.6.1, which will be compared to C<$^V> (aka $PERL_VERSION). A
1510914946fatal error is produced if VERSION is greater than the version of the
1511014947current Perl interpreter; Perl will not attempt to parse the rest of the
1511114948file. Compare with L</require>, which can do a similar check at run time.
1511214949Symmetrically, C<no VERSION> allows you to specify that you want a version
1511314950of perl older than the specified one.
1511414951
1511514952=end original
1511614953
1511714954特に C<use VERSION> の形式では、
1511814955VERSION は 5.006 のような数値(C<$]> と比較されます)か、v5.6.1 の形
1511914956(C<$^V> (またの名を $PERL_VERSION) と比較されます)で指定します。
1512014957VERSION が Perl の現在のバージョンより大きいと、致命的エラーが
1512114958発生します; Perl はファイルの残りを読み込みません。
1512214959L</require> と似ていますが、これは実行時にチェックされます。
1512314960対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの perl で
1512414961動作させたいことを意味します。
1512514962
1512614963=begin original
1512714964
1512814965Specifying VERSION as a literal of the form v5.6.1 should generally be
1512914966avoided, because it leads to misleading error messages under earlier
15130versions of Perl (that is, prior to 5.6.0) that do not support this
14967versions of Perl that do not support this syntax. The equivalent numeric
15131syntax. The equivalent numeric version should be used instead.
14968version should be used instead.
1513214969
1513314970=end original
1513414971
1513514972VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
15136なぜなら、この文法に対応していない Perl の初期のバージョン
14973なぜなら、この文法に対応していない Perl の初期のバージョンでは
15137(つまり、 5.6.0 以前) では誤解させるようなエラーメッセージが出るからです。
14974誤解させるようなエラーメッセージが出るからです。
1513814975代わりに等価な数値表現を使うべきです。
1513914976
14977=begin original
14978
14979Alternatively, you can use a numeric version C<use 5.006> followed by a
14980v-string version like C<use v5.10.1>, to avoid the unintuitive C<use
149815.010_001>. (older perl versions fail gracefully at the first C<use>,
14982later perl versions understand the v-string syntax in the second).
14983
14984=end original
14985
14986あるいは、直感的ではない C<use 5.010_001> を避けるために、数値のバージョン
14987C<use 5.006> を書いてから v 文字バージョン C<use v5.10.1> を書くという
14988方法もあります。
14989(古いバージョンの perl では最初の C<use> で安全に失敗し、より新しい
14990バージョンの perl は 2 番目の v 文字の文法を理解します)。
14991
1514014992 use v5.6.1; # compile time version check
1514114993 use 5.6.1; # ditto
1514214994 use 5.006_001; # ditto; preferred for backwards compatibility
14995 use 5.006; use 5.6.1; # ditto, for compatibility and readability
1514314996
1514414997=begin original
1514514998
1514614999This is often useful if you need to check the current Perl version before
15147C<use>ing library modules that won't work with older versions of Perl.
15000C<use>ing library modules that have changed in incompatible ways from
15148(We try not to do this more than we have to.)
15001older versions of Perl. (We try not to do this more than we have to.)
1514915002
1515015003=end original
1515115004
15152これは古いバージョンの Perl で動かなくなったライブラリ
15005これは古いバージョンの Perl から互換性のい形で変更されたライブラリ
1515315006モジュール(我々は必要な場合以外にそのようなことがないように
1515415007努力していますが)を C<use> する前に、現在の Perl のバージョンを
1515515008調べたい場合に有用です。
1515615009
1515715010=begin original
1515815011
1515915012Also, if the specified perl version is greater than or equal to 5.9.5,
1516015013C<use VERSION> will also load the C<feature> pragma and enable all
1516115014features available in the requested version. See L<feature>.
1516215015
1516315016=end original
1516415017
1516515018また、指定された perl のバージョンが 5.9.5 以上の場合、C<use VERSION> は
1516615019C<feature> プラグマも読み込み、要求されたバージョンで利用可能な全ての機能を
1516715020有効にします。
1516815021L<feature> を参照してください。
1516915022
1517015023=begin original
1517115024
1517215025The C<BEGIN> forces the C<require> and C<import> to happen at compile time. The
1517315026C<require> makes sure the module is loaded into memory if it hasn't been
1517415027yet. The C<import> is not a builtin--it's just an ordinary static method
1517515028call into the C<Module> package to tell the module to import the list of
1517615029features back into the current package. The module can implement its
1517715030C<import> method any way it likes, though most modules just choose to
1517815031derive their C<import> method via inheritance from the C<Exporter> class that
1517915032is defined in the C<Exporter> module. See L<Exporter>. If no C<import>
1518015033method can be found then the call is skipped, even if there is an AUTOLOAD
1518115034method.
1518215035
1518315036=end original
1518415037
1518515038C<BEGIN> によって、C<require> や C<import> は、コンパイル時に
1518615039実行されることになります。
1518715040C<require> は、モジュールがまだメモリにロードされていなければ、ロードします。
1518815041C<import> は、組込みの関数ではなく、さまざまな機能を現在のパッケージに
1518915042インポートするように C<Module> パッケージに伝えるために呼ばれる、
1519015043通常の静的メソッドです。
1519115044モジュール側では、C<import> メソッドをどのようにでも実装することが
1519215045できますが、多くのモジュールでは、C<Exporter> モジュールで定義された、
1519315046C<Exporter> クラスからの継承によって、C<import> メソッドを行なうように
1519415047しています。
1519515048L<Exporter>モジュールを参照してください。
1519615049C<import>メソッドが見つからなかった場合、AUTOLOAD メソッドがあったとしても
1519715050呼び出しはスキップされます。
1519815051
1519915052=begin original
1520015053
1520115054If you do not want to call the package's C<import> method (for instance,
1520215055to stop your namespace from being altered), explicitly supply the empty list:
1520315056
1520415057=end original
1520515058
1520615059パッケージの C<import> メソッドを呼び出したくない場合(例えば、名前空間を
1520715060変更したくない場合など)は、明示的に空リストを指定してください:
1520815061
1520915062 use Module ();
1521015063
1521115064=begin original
1521215065
1521315066That is exactly equivalent to
1521415067
1521515068=end original
1521615069
1521715070これは以下と完全に等価です:
1521815071
1521915072 BEGIN { require Module }
1522015073
1522115074=begin original
1522215075
1522315076If the VERSION argument is present between Module and LIST, then the
1522415077C<use> will call the VERSION method in class Module with the given
1522515078version as an argument. The default VERSION method, inherited from
1522615079the UNIVERSAL class, croaks if the given version is larger than the
1522715080value of the variable C<$Module::VERSION>.
1522815081
1522915082=end original
1523015083
1523115084Module と LIST の間に VERSION 引数がある場合、C<use> は Module クラスの
1523215085VERSION メソッドを、与えられたバージョンを引数として呼び出します。
1523315086デフォルトの VERSION メソッドは、 UNIVERSAL クラスから継承したもので、
1523415087与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に
1523515088警告を出します。
1523615089
1523715090=begin original
1523815091
1523915092Again, there is a distinction between omitting LIST (C<import> called
1524015093with no arguments) and an explicit empty LIST C<()> (C<import> not
1524115094called). Note that there is no comma after VERSION!
1524215095
1524315096=end original
1524415097
1524515098繰り返すと、LIST を省略する(C<import> が引数なしで呼び出される)ことと
1524615099明示的に空の LIST C<()> を指定する (C<import> は呼び出されない)ことは
1524715100違います。
1524815101VERSION の後ろにカンマが不要なことに注意してください!
1524915102
1525015103=begin original
1525115104
1525215105Because this is a wide-open interface, pragmas (compiler directives)
1525315106are also implemented this way. Currently implemented pragmas are:
1525415107
1525515108=end original
1525615109
1525715110これは、広く公開されているインタフェースですので、
1525815111プラグマ (コンパイラディレクティブ) も、この方法で実装されています。
1525915112現在実装されているプラグマには、以下のものがあります:
1526015113
1526115114 use constant;
1526215115 use diagnostics;
1526315116 use integer;
1526415117 use sigtrap qw(SEGV BUS);
1526515118 use strict qw(subs vars refs);
1526615119 use subs qw(afunc blurfl);
1526715120 use warnings qw(all);
1526815121 use sort qw(stable _quicksort _mergesort);
1526915122
1527015123=begin original
1527115124
1527215125Some of these pseudo-modules import semantics into the current
1527315126block scope (like C<strict> or C<integer>, unlike ordinary modules,
1527415127which import symbols into the current package (which are effective
1527515128through the end of the file).
1527615129
1527715130=end original
1527815131
1527915132通常のモジュールが、現在のパッケージにシンボルをインポートする
1528015133(これは、ファイルの終わりまで有効です) のに対して、
1528115134これらの擬似モジュールの一部(C<strict> や C<integer> など)は、
1528215135現在のブロックスコープにインポートを行ないます。
1528315136
1528415137=begin original
1528515138
1528615139There's a corresponding C<no> command that unimports meanings imported
1528715140by C<use>, i.e., it calls C<unimport Module LIST> instead of C<import>.
1528815141It behaves exactly as C<import> does with respect to VERSION, an
1528915142omitted LIST, empty LIST, or no unimport method being found.
1529015143
1529115144=end original
1529215145
1529315146これに対して、C<no> コマンドという、C<use> によってインポートされたものを、
1529415147インポートされていないことにするものがあります。
1529515148つまり、C<import> の代わりに C<unimport Module LIST> を呼び出します。
1529615149これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない
1529715150場合などの観点では、正確に C<import> と同様に振る舞います。
1529815151
1529915152 no integer;
1530015153 no strict 'refs';
1530115154 no warnings;
1530215155
1530315156=begin original
1530415157
1530515158See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun>
1530615159for the C<-M> and C<-m> command-line options to perl that give C<use>
1530715160functionality from the command-line.
1530815161
1530915162=end original
1531015163
1531115164標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。
1531215165コマンドラインから C<use> 機能を指定するための C<-M> と C<-m> の
1531315166コマンドラインオプションについては L<perlrun> を参照して下さい。
1531415167
1531515168=item utime LIST
1531615169X<utime>
1531715170
1531815171=begin original
1531915172
1532015173Changes the access and modification times on each file of a list of
1532115174files. The first two elements of the list must be the NUMERICAL access
1532215175and modification times, in that order. Returns the number of files
1532315176successfully changed. The inode change time of each file is set
1532415177to the current time. For example, this code has the same effect as the
1532515178Unix touch(1) command when the files I<already exist> and belong to
1532615179the user running the program:
1532715180
1532815181=end original
1532915182
1533015183ファイルのアクセス時刻と修正(modification) 時刻を変更します。
1533115184LIST の最初の 2 つの要素に、数値で表わしたアクセス時刻と修正時刻を
1533215185順に指定します。
1533315186LIST の残りの要素が、変更の対象となるファイルです。
1533415187変更に成功したファイルの数を返します。
1533515188各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。
1533615189例えば、このコードはファイルが I<既に存在して> いて、ユーザーが
1533715190実行しているプログラムに従っているなら、
1533815191Unix の touch(1) コマンドと同じ効果があります。
1533915192
1534015193 #!/usr/bin/perl
1534115194 $atime = $mtime = time;
1534215195 utime $atime, $mtime, @ARGV;
1534315196
1534415197=begin original
1534515198
1534615199Since perl 5.7.2, if the first two elements of the list are C<undef>, then
1534715200the utime(2) function in the C library will be called with a null second
1534815201argument. On most systems, this will set the file's access and
1534915202modification times to the current time (i.e. equivalent to the example
1535015203above) and will even work on other users' files where you have write
1535115204permission:
1535215205
1535315206=end original
1535415207
1535515208perl 5.7.2 から、リストの最初の二つの要素が C<undef> である場合、
1535615209C ライブラリの utime(2) 関数を、秒の引数を null として呼び出します。
1535715210ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を
1535815211現在の時刻にセットし(つまり、上記の例と等価です)、
1535915212書き込み権限があれば他のユーザーのファイルに対しても動作します。
1536015213
1536115214 utime undef, undef, @ARGV;
1536215215
1536315216=begin original
1536415217
1536515218Under NFS this will use the time of the NFS server, not the time of
1536615219the local machine. If there is a time synchronization problem, the
1536715220NFS server and local machine will have different times. The Unix
1536815221touch(1) command will in fact normally use this form instead of the
1536915222one shown in the first example.
1537015223
1537115224=end original
1537215225
1537315226NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が
1537415227使われます。
1537515228時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に
1537615229なっている場合があります。
1537715230実際のところ、Unix の touch(1) コマンドは普通、最初の例ではなく、
1537815231この形を使います。
1537915232
1538015233=begin original
1538115234
1538215235Note that only passing one of the first two elements as C<undef> will
1538315236be equivalent of passing it as 0 and will not have the same effect as
1538415237described when they are both C<undef>. This case will also trigger an
1538515238uninitialized warning.
1538615239
1538715240=end original
1538815241
1538915242最初の二つの要素のうち、一つだけに C<undef> を渡すと、その要素は 0 を
1539015243渡すのと等価となり、上述の、両方に C<undef> を渡した時と同じ
1539115244効果ではないことに注意してください。
1539215245この場合は、未初期化の警告が出ます。
1539315246
1539415247=begin original
1539515248
1539615249On systems that support futimes, you might pass file handles among the
1539715250files. On systems that don't support futimes, passing file handles
1539815251produces a fatal error at run time. The file handles must be passed
1539915252as globs or references to be recognized. Barewords are considered
1540015253file names.
1540115254
1540215255=end original
1540315256
1540415257futimes に対応しているシステムでは、ファイルハンドルを引数として渡せます。
1540515258futimes に対応していないシステムでは、ファイルハンドルを渡すと実行時に
1540615259致命的エラーになります。
1540715260ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
1540815261渡されなければなりません。
1540915262裸の単語はファイル名として扱われます。
1541015263
1541115264=item values HASH
1541215265X<values>
1541315266
1541415267=begin original
1541515268
1541615269Returns a list consisting of all the values of the named hash.
1541715270(In a scalar context, returns the number of values.)
1541815271
1541915272=end original
1542015273
1542115274指定したハッシュのすべての value からなるリストを返します。
1542215275(スカラコンテキストでは、value の数を返します。)
1542315276
1542415277=begin original
1542515278
1542615279The values are returned in an apparently random order. The actual
1542715280random order is subject to change in future versions of perl, but it
1542815281is guaranteed to be the same order as either the C<keys> or C<each>
1542915282function would produce on the same (unmodified) hash. Since Perl
15430152835.8.1 the ordering is different even between different runs of Perl
1543115284for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
1543215285
1543315286=end original
1543415287
1543515288返される value の順序は、見た目にばらばらなものです。
1543615289実際のランダムな順序は将来のバージョンの perl では変わる可能性が
1543715290ありますが、同じ(変更されていない)ハッシュに対して、
1543815291C<keys>関数や C<each>関数が返すものと同じ順序であることは保証されます。
1543915292Perl 5.8.1 以降ではセキュリティ上の理由により、
1544015293実行される毎に順番は変わります
1544115294(L<perlsec/"Algorithmic Complexity Attacks"> を参照してください)。
1544215295
1544315296=begin original
1544415297
1544515298As a side effect, calling values() resets the HASH's internal iterator,
1544615299see L</each>. (In particular, calling values() in void context resets
1544715300the iterator with no other overhead.)
1544815301
1544915302=end original
1545015303
1545115304副作用として、values() を呼び出すと HASH の内部イテレータをリセットします:
1545215305C</each> を参照してください。
1545315306(特に、values() を無効コンテキストで呼び出すとその他のオーバーヘッドなしで
1545415307イテレータをリセットします。)
1545515308
1545615309=begin original
1545715310
1545815311Note that the values are not copied, which means modifying them will
1545915312modify the contents of the hash:
1546015313
1546115314=end original
1546215315
1546315316値はコピーされないので、返されたリストを変更すると
1546415317ハッシュの中身が変更されることに注意してください。
1546515318
1546615319 for (values %hash) { s/foo/bar/g } # modifies %hash values
1546715320 for (@hash{keys %hash}) { s/foo/bar/g } # same
1546815321
1546915322=begin original
1547015323
1547115324See also C<keys>, C<each>, and C<sort>.
1547215325
1547315326=end original
1547415327
1547515328C<keys>, C<each>, C<sort> も参照してください。
1547615329
1547715330=item vec EXPR,OFFSET,BITS
1547815331X<vec> X<bit> X<bit vector>
1547915332
1548015333=begin original
1548115334
1548215335Treats the string in EXPR as a bit vector made up of elements of
1548315336width BITS, and returns the value of the element specified by OFFSET
1548415337as an unsigned integer. BITS therefore specifies the number of bits
1548515338that are reserved for each element in the bit vector. This must
1548615339be a power of two from 1 to 32 (or 64, if your platform supports
1548715340that).
1548815341
1548915342=end original
1549015343
1549115344文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、
1549215345OFFSET で指定される要素の値を返します。
1549315346OFFSET で指定された要素を符号なし整数として返します。
1549415347従って、 BITS はビットベクターの中の各要素について予約されるビット数です。
1549515348BIT は、1 から 32 まで(プラットホームが
1549615349対応していれば 64 まで) の 2 のべき乗でなければなりません。
1549715350
1549815351=begin original
1549915352
1550015353If BITS is 8, "elements" coincide with bytes of the input string.
1550115354
1550215355=end original
1550315356
1550415357BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。
1550515358
1550615359=begin original
1550715360
1550815361If BITS is 16 or more, bytes of the input string are grouped into chunks
1550915362of size BITS/8, and each group is converted to a number as with
1551015363pack()/unpack() with big-endian formats C<n>/C<N> (and analogously
1551115364for BITS==64). See L<"pack"> for details.
1551215365
1551315366=end original
1551415367
1551515368BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに
1551615369グループ化され、各グループは pack()/unpack() のビッグエンディアン
1551715370フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。
1551815371詳細は L<"pack"> を参照してください。
1551915372
1552015373=begin original
1552115374
1552215375If bits is 4 or less, the string is broken into bytes, then the bits
1552315376of each byte are broken into 8/BITS groups. Bits of a byte are
1552415377numbered in a little-endian-ish way, as in C<0x01>, C<0x02>,
1552515378C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example,
1552615379breaking the single input byte C<chr(0x36)> into two groups gives a list
1552715380C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>.
1552815381
1552915382=end original
1553015383
1553115384BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは
15532153858/BITS 個のグループに分割されます。
1553315386ビットはリトルエンディアン風に、C<0x01>, C<0x02>,
1553415387C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。
1553515388例えば、入力バイト C<chr(0x36)> を 2 つのグループに分割すると、
1553615389C<(0x6, 0x3)> になります。
15537153904 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> になります。
1553815391
1553915392=begin original
1554015393
1554115394C<vec> may also be assigned to, in which case parentheses are needed
1554215395to give the expression the correct precedence as in
1554315396
1554415397=end original
1554515398
1554615399左辺値として、代入の対象にすることもできます。
1554715400この場合、式を正しく先行させるために以下のように括弧が必要です。
1554815401
1554915402 vec($image, $max_x * $x + $y, 8) = 3;
1555015403
1555115404=begin original
1555215405
1555315406If the selected element is outside the string, the value 0 is returned.
1555415407If an element off the end of the string is written to, Perl will first
1555515408extend the string with sufficiently many zero bytes. It is an error
1555615409to try to write off the beginning of the string (i.e. negative OFFSET).
1555715410
1555815411=end original
1555915412
1556015413選択された要素が文字列の外側だった場合、値 0 が返されます。
1556115414文字列の最後よりも後ろの要素に書き込もうとした場合、
1556215415Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。
1556315416文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった)
1556415417場合はエラーとなります。
1556515418
1556615419=begin original
1556715420
1556815421If the string happens to be encoded as UTF-8 internally (and thus has
1556915422the UTF8 flag set), this is ignored by C<vec>, and it operates on the
1557015423internal byte string, not the conceptual character string, even if you
1557115424only have characters with values less than 256.
1557215425
1557315426=end original
1557415427
1557515428文字列がなぜか内部で UTF-8 でエンコードされている場合(したがって UTF8 フラグが
1557615429セットされている場合)、これは C<vec> では無視され、たとえ値が 256 未満の
1557715430文字だけであったとしても、概念的な
1557815431文字列ではなく内部バイト文字列で操作されます。
1557915432
1558015433=begin original
1558115434
1558215435Strings created with C<vec> can also be manipulated with the logical
1558315436operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit
1558415437vector operation is desired when both operands are strings.
1558515438See L<perlop/"Bitwise String Operators">.
1558615439
1558715440=end original
1558815441
1558915442vec() で作られた文字列は、論理演算子 C<|>、C<&>、C<^> で扱うこともできます。
1559015443これらの演算子は、両方の被演算子に文字列を使うと、
1559115444ビットベクター演算を行ないます。
1559215445
1559315446=begin original
1559415447
1559515448The following code will build up an ASCII string saying C<'PerlPerlPerl'>.
1559615449The comments show the string after each step. Note that this code works
1559715450in the same way on big-endian or little-endian machines.
1559815451
1559915452=end original
1560015453
1560115454次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。
1560215455コメントは各行の実行後の文字列を示します。
1560315456このコードはビッグエンディアンでもリトルエンディアンでも同じように
1560415457動作することに注意してください。
1560515458
1560615459 my $foo = '';
1560715460 vec($foo, 0, 32) = 0x5065726C; # 'Perl'
1560815461
1560915462 # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits
1561015463 print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P')
1561115464
1561215465 vec($foo, 2, 16) = 0x5065; # 'PerlPe'
1561315466 vec($foo, 3, 16) = 0x726C; # 'PerlPerl'
1561415467 vec($foo, 8, 8) = 0x50; # 'PerlPerlP'
1561515468 vec($foo, 9, 8) = 0x65; # 'PerlPerlPe'
1561615469 vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02"
1561715470 vec($foo, 21, 4) = 7; # 'PerlPerlPer'
1561815471 # 'r' is "\x72"
1561915472 vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c"
1562015473 vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c"
1562115474 vec($foo, 94, 1) = 1; # 'PerlPerlPerl'
1562215475 # 'l' is "\x6c"
1562315476
1562415477=begin original
1562515478
1562615479To transform a bit vector into a string or list of 0's and 1's, use these:
1562715480
1562815481=end original
1562915482
1563015483ビットベクターを、0 と 1 の文字列や配列に変換するには、
1563115484以下のようにします。
1563215485
1563315486 $bits = unpack("b*", $vector);
1563415487 @bits = split(//, unpack("b*", $vector));
1563515488
1563615489=begin original
1563715490
1563815491If you know the exact length in bits, it can be used in place of the C<*>.
1563915492
1564015493=end original
1564115494
1564215495ビット長が分かっていれば、* の代わりにその長さを使うことができます。
1564315496
1564415497=begin original
1564515498
1564615499Here is an example to illustrate how the bits actually fall in place:
1564715500
1564815501=end original
1564915502
1565015503これはビットが実際にどのような位置に入るかを図示する例です。
1565115504
1565215505 #!/usr/bin/perl -wl
1565315506
1565415507 print <<'EOT';
1565515508 0 1 2 3
1565615509 unpack("V",$_) 01234567890123456789012345678901
1565715510 ------------------------------------------------------------------
1565815511 EOT
1565915512
1566015513 for $w (0..3) {
1566115514 $width = 2**$w;
1566215515 for ($shift=0; $shift < $width; ++$shift) {
1566315516 for ($off=0; $off < 32/$width; ++$off) {
1566415517 $str = pack("B*", "0"x32);
1566515518 $bits = (1<<$shift);
1566615519 vec($str, $off, $width) = $bits;
1566715520 $res = unpack("b*",$str);
1566815521 $val = unpack("V", $str);
1566915522 write;
1567015523 }
1567115524 }
1567215525 }
1567315526
1567415527 format STDOUT =
1567515528 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1567615529 $off, $width, $bits, $val, $res
1567715530 .
1567815531 __END__
1567915532
1568015533=begin original
1568115534
1568215535Regardless of the machine architecture on which it is run, the above
1568315536example should print the following table:
1568415537
1568515538=end original
1568615539
1568715540実行するマシンのアーキテクチャに関わらず、
1568815541上記の例は以下の表を出力します。
1568915542
1569015543 0 1 2 3
1569115544 unpack("V",$_) 01234567890123456789012345678901
1569215545 ------------------------------------------------------------------
1569315546 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
1569415547 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
1569515548 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
1569615549 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
1569715550 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
1569815551 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
1569915552 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
1570015553 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
1570115554 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
1570215555 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
1570315556 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
1570415557 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
1570515558 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
1570615559 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
1570715560 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
1570815561 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
1570915562 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
1571015563 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
1571115564 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
1571215565 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
1571315566 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
1571415567 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
1571515568 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
1571615569 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
1571715570 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
1571815571 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
1571915572 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
1572015573 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
1572115574 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
1572215575 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
1572315576 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
1572415577 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
1572515578 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
1572615579 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
1572715580 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
1572815581 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
1572915582 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
1573015583 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
1573115584 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
1573215585 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
1573315586 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
1573415587 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
1573515588 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
1573615589 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
1573715590 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
1573815591 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
1573915592 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
1574015593 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
1574115594 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
1574215595 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
1574315596 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
1574415597 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
1574515598 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
1574615599 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
1574715600 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
1574815601 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
1574915602 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
1575015603 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
1575115604 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
1575215605 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
1575315606 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
1575415607 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
1575515608 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
1575615609 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
1575715610 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
1575815611 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
1575915612 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
1576015613 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
1576115614 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
1576215615 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
1576315616 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
1576415617 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
1576515618 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
1576615619 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
1576715620 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
1576815621 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
1576915622 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
1577015623 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
1577115624 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
1577215625 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
1577315626 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
1577415627 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
1577515628 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
1577615629 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
1577715630 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
1577815631 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
1577915632 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
1578015633 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
1578115634 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
1578215635 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
1578315636 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
1578415637 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
1578515638 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
1578615639 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
1578715640 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
1578815641 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
1578915642 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
1579015643 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
1579115644 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
1579215645 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
1579315646 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
1579415647 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
1579515648 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
1579615649 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
1579715650 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
1579815651 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
1579915652 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
1580015653 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
1580115654 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
1580215655 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
1580315656 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
1580415657 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
1580515658 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
1580615659 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
1580715660 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
1580815661 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
1580915662 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
1581015663 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
1581115664 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
1581215665 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
1581315666 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
1581415667 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
1581515668 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
1581615669 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
1581715670 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
1581815671 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
1581915672 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
1582015673 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
1582115674
1582215675=item wait
1582315676X<wait>
1582415677
1582515678=begin original
1582615679
1582715680Behaves like the wait(2) system call on your system: it waits for a child
1582815681process to terminate and returns the pid of the deceased process, or
1582915682C<-1> if there are no child processes. The status is returned in C<$?>
15830and C<${^CHILD_ERROR_NATIVE}>.
15683and C<{^CHILD_ERROR_NATIVE}>.
1583115684Note that a return value of C<-1> could mean that child processes are
1583215685being automatically reaped, as described in L<perlipc>.
1583315686
1583415687=end original
1583515688
1583615689wait(2) システムコールと同様に振る舞います。
1583715690チャイルドプロセスが終了するのを待ち、消滅したプロセスの pid を返します。
1583815691チャイルドプロセスが存在しないときには、C<-1> を返します。
15839ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されます。
15692ステータスは C<$?> と C<{^CHILD_ERROR_NATIVE}> に返されます。
1584015693L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが
1584115694自動的に刈り取られたことを意味するかもしれないことに注意してください。
1584215695
1584315696=item waitpid PID,FLAGS
1584415697X<waitpid>
1584515698
1584615699=begin original
1584715700
1584815701Waits for a particular child process to terminate and returns the pid of
1584915702the deceased process, or C<-1> if there is no such child process. On some
1585015703systems, a value of 0 indicates that there are processes still running.
15851The status is returned in C<$?> and C<${^CHILD_ERROR_NATIVE}>. If you say
15704The status is returned in C<$?> and C<{^CHILD_ERROR_NATIVE}>. If you say
1585215705
1585315706=end original
1585415707
1585515708特定のチャイルドプロセスが終了するのを待ち、消滅した
1585615709プロセスの pid を返します。
1585715710指定したチャイルドプロセスが存在しないときには、C<-1> を返します。
1585815711値 0 がプロセスがまだ実行中であることを示すシステムもあります。
15859ステータスは C<$?> と C<${^CHILD_ERROR_NATIVE}> に返されます。
15712ステータスは C<$?> と C<{^CHILD_ERROR_NATIVE}> に返されます。
1586015713
1586115714 use POSIX ":sys_wait_h";
1586215715 #...
1586315716 do {
1586415717 $kid = waitpid(-1, WNOHANG);
1586515718 } while $kid > 0;
1586615719
1586715720=begin original
1586815721
1586915722then you can do a non-blocking wait for all pending zombie processes.
1587015723Non-blocking wait is available on machines supporting either the
1587115724waitpid(2) or wait4(2) system calls. However, waiting for a particular
1587215725pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the
1587315726system call by remembering the status values of processes that have
1587415727exited but have not been harvested by the Perl script yet.)
1587515728
1587615729=end original
1587715730
1587815731とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを
1587915732wait します。
1588015733ブロックなしの wait は、システムコール wait_pid(2) か、
1588115734システムコール wait4(2) をサポートしているマシンで利用可能です。
1588215735しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも
1588315736実装されています。
1588415737(exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを
1588515738エミュレートしますが、Perl スクリプトには取り入れられていません。)
1588615739
1588715740=begin original
1588815741
1588915742Note that on some systems, a return value of C<-1> could mean that child
1589015743processes are being automatically reaped. See L<perlipc> for details,
1589115744and for other examples.
1589215745
1589315746=end original
1589415747
1589515748システムによっては、返り値が C<-1> の場合は子プロセスが自動的に
1589615749刈り取られたことを意味するかもしれないことに注意してください。
1589715750詳細やその他の例については L<perlipc> を参照してください。
1589815751
1589915752=item wantarray
1590015753X<wantarray> X<context>
1590115754
1590215755=begin original
1590315756
1590415757Returns true if the context of the currently executing subroutine or
1590515758C<eval> is looking for a list value. Returns false if the context is
1590615759looking for a scalar. Returns the undefined value if the context is
1590715760looking for no value (void context).
1590815761
1590915762=end original
1591015763
1591115764現在実行中のサブルーチンか eval() ブロックのコンテキストが、リスト値を
1591215765要求するものであれば、真を返します。
1591315766スカラを要求するコンテキストであれば、偽を返します。
1591415767何も値を要求しない(無効コンテキスト)場合は未定義値を返します。
1591515768
1591615769 return unless defined wantarray; # don't bother doing more
1591715770 my @a = complex_calculation();
1591815771 return wantarray ? @a : "@a";
1591915772
1592015773=begin original
1592115774
1592215775C<wantarray()>'s result is unspecified in the top level of a file,
1592315776in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or
1592415777in a C<DESTROY> method.
1592515778
1592615779=end original
1592715780
1592815781ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END>
1592915782ブロック内、C<DESTROY> メソッド内では C<wantarray()> の結果は未定義です。
1593015783
1593115784=begin original
1593215785
1593315786This function should have been named wantlist() instead.
1593415787
1593515788=end original
1593615789
1593715790この関数は wantlist() という名前にするべきでした。
1593815791
1593915792=item warn LIST
1594015793X<warn> X<warning> X<STDERR>
1594115794
1594215795=begin original
1594315796
1594415797Prints the value of LIST to STDERR. If the last element of LIST does
1594515798not end in a newline, it appends the same file/line number text as C<die>
1594615799does.
1594715800
1594815801=end original
1594915802
1595015803LIST の値を STDERR に出力します。
1595115804LIST の最後の要素が改行で終わっていない場合、C<die> が行うのと同様の
1595215805ファイル/行番号のテキストが追加されます。
1595315806
1595415807=begin original
1595515808
1595615809If LIST is empty and C<$@> already contains a value (typically from a
1595715810previous eval) that value is used after appending C<"\t...caught">
1595815811to C<$@>. This is useful for staying almost, but not entirely similar to
1595915812C<die>.
1596015813
1596115814=end original
1596215815
1596315816LIST が空かつ、(典型的には以前の eval によって) C<$@> に既に値が入っている
1596415817場合、C<$@> に C<"\t...caught"> を追加した値が用いられます。
1596515818これはほとんどそのままにするときに便利ですが、
1596615819C<die> と全体的に似ているわけではありません。
1596715820
1596815821=begin original
1596915822
1597015823If C<$@> is empty then the string C<"Warning: Something's wrong"> is used.
1597115824
1597215825=end original
1597315826
1597415827C<$@> が空の場合は、C<"Warning: Something's wrong"> という文字列が
1597515828使われます。
1597615829
1597715830=begin original
1597815831
1597915832No message is printed if there is a C<$SIG{__WARN__}> handler
1598015833installed. It is the handler's responsibility to deal with the message
1598115834as it sees fit (like, for instance, converting it into a C<die>). Most
1598215835handlers must therefore make arrangements to actually display the
1598315836warnings that they are not prepared to deal with, by calling C<warn>
1598415837again in the handler. Note that this is quite safe and will not
1598515838produce an endless loop, since C<__WARN__> hooks are not called from
1598615839inside one.
1598715840
1598815841=end original
1598915842
1599015843C<$SIG{__WARN__}> ハンドラが設定されている場合は何のメッセージも
1599115844表示されません。
1599215845メッセージをどう扱うか(例えば C<die> に変換するか)はハンドラの
1599315846責任ということです。
1599415847従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、
1599515848ハンドラの中で C<warn> を再び呼び出します。
1599615849C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、
1599715850無限ループを引き起こすことはないということに注意してください。
1599815851
1599915852=begin original
1600015853
1600115854You will find this behavior is slightly different from that of
1600215855C<$SIG{__DIE__}> handlers (which don't suppress the error text, but can
1600315856instead call C<die> again to change it).
1600415857
1600515858=end original
1600615859
1600715860この振る舞いは C<$SIG{__DIE__}> ハンドラ(エラーテキストは削除しませんが、
1600815861代わりに C<die> をもう一度呼び出すことで変更できます)とは
1600915862少し違うことに気付くことでしょう。
1601015863
1601115864=begin original
1601215865
1601315866Using a C<__WARN__> handler provides a powerful way to silence all
1601415867warnings (even the so-called mandatory ones). An example:
1601515868
1601615869=end original
1601715870
1601815871C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての
1601915872警告を黙らせる強力な手段となります。
1602015873例:
1602115874
1602215875 # wipe out *all* compile-time warnings
1602315876 BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
1602415877 my $foo = 10;
1602515878 my $foo = 20; # no warning about duplicate my $foo,
1602615879 # but hey, you asked for it!
1602715880 # no compile-time or run-time warnings before here
1602815881 $DOWARN = 1;
1602915882
1603015883 # run-time warnings enabled after here
1603115884 warn "\$foo is alive and $foo!"; # does show up
1603215885
1603315886=begin original
1603415887
1603515888See L<perlvar> for details on setting C<%SIG> entries, and for more
1603615889examples. See the Carp module for other kinds of warnings using its
1603715890carp() and cluck() functions.
1603815891
1603915892=end original
1604015893
1604115894C<%SIG> エントリのセットに関する詳細とさらなる例に関しては
1604215895L<perlvar> を参照して下さい。
1604315896carp() 関数と cluck() 関数を用いた警告の方法に関しては
1604415897Carp モジュールを参照して下さい。
1604515898
1604615899=item write FILEHANDLE
1604715900X<write>
1604815901
1604915902=item write EXPR
1605015903
1605115904=item write
1605215905
1605315906=begin original
1605415907
1605515908Writes a formatted record (possibly multi-line) to the specified FILEHANDLE,
1605615909using the format associated with that file. By default the format for
1605715910a file is the one having the same name as the filehandle, but the
1605815911format for the current output channel (see the C<select> function) may be set
1605915912explicitly by assigning the name of the format to the C<$~> variable.
1606015913
1606115914=end original
1606215915
1606315916指定された FILEHANDLE に対して、そのファイルに対応させた
1606415917フォーマットを使って、(複数行の場合もある) 整形された
1606515918レコードを書き出します。
1606615919デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと
1606715920同じ名前のものですが、その時点の出力チャネル (C<select> 関数の項を
1606815921参照してください) のフォーマットは、その名前を明示的に変数 C<$~> に
1606915922代入することで、変更が可能です。 
1607015923
1607115924=begin original
1607215925
1607315926Top of form processing is handled automatically: if there is
1607415927insufficient room on the current page for the formatted record, the
1607515928page is advanced by writing a form feed, a special top-of-page format
1607615929is used to format the new page header, and then the record is written.
1607715930By default the top-of-page format is the name of the filehandle with
1607815931"_TOP" appended, but it may be dynamically set to the format of your
1607915932choice by assigning the name to the C<$^> variable while the filehandle is
1608015933selected. The number of lines remaining on the current page is in
1608115934variable C<$->, which can be set to C<0> to force a new page.
1608215935
1608315936=end original
1608415937
1608515938ページの先頭の処理は、自動的に行なわれます。
1608615939現在のページに整形されたレコードを出力するだけのスペースがない場合には、
1608715940改ページを行なってページを進め、新しいページヘッダを整形するため、
1608815941ページ先頭フォーマットが使われ、その後でレコードが書かれます。
1608915942デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に
1609015943"_TOP" をつなげたものですが、ファイルハンドルが選択されている間に、
1609115944変数 C<$^> に名前を設定すれば、動的にフォーマットを
1609215945変更することができます。
1609315946そのページの残り行数は、変数 C<$-> に入っており、この変数を 0 に
1609415947設定することで、強制的に改ページを行なうことができます。
1609515948
1609615949=begin original
1609715950
1609815951If FILEHANDLE is unspecified, output goes to the current default output
1609915952channel, which starts out as STDOUT but may be changed by the
1610015953C<select> operator. If the FILEHANDLE is an EXPR, then the expression
1610115954is evaluated and the resulting string is used to look up the name of
1610215955the FILEHANDLE at run time. For more on formats, see L<perlform>.
1610315956
1610415957=end original
1610515958
1610615959FILEHANDLE を指定しないと、出力はその時点のデフォルト
1610715960出力チャネルに対して行なわれます。
1610815961これは、スクリプトの開始時点では STDOUT ですが、select() 演算子で
1610915962変更することができます。
1611015963FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が
1611115964実行時に FILEHANDLE の名前として見られます。
1611215965フォーマットについて、さらには、L<perlform> を参照してください。
1611315966
1611415967=begin original
1611515968
1611615969Note that write is I<not> the opposite of C<read>. Unfortunately.
1611715970
1611815971=end original
1611915972
1612015973残念ながら、write は C<read> の反対のことをするもの
1612115974I<ではありません>。
1612215975
1612315976=item y///
1612415977
1612515978=begin original
1612615979
16127The transliteration operator. Same as C<tr///>. See
15980The transliteration operator. Same as C<tr///>. See L<perlop>.
16128L<perlop/"Quote and Quote-like Operators">.
1612915981
1613015982=end original
1613115983
1613215984文字変換演算子です。
1613315985C<tr///> と同じです。
16134L<perlop/"Quote and Quote-like Operators"> を参照してください。
15986L<perlop> を参照してください。
1613515987
1613615988=back
1613715989
1613815990=begin meta
1613915991
1614015992Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp>
16141Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
15993Update: Kentaro Shirakata <argrath@ub32.org>
16142Status: completed
1614315994
1614415995=end meta