perlfunc > 5.32.0 との差分

perlfunc 5.32.0 と 5.36.0 の差分

11
2=encoding euc-jp
2=encoding utf8
33
44=head1 NAME
55X<function>
66
77=begin original
88
99perlfunc - Perl builtin functions
1010
1111=end original
1212
1313perlfunc - Perl 組み込み関数
1414
1515=head1 DESCRIPTION
1616
1717=begin original
1818
1919The functions in this section can serve as terms in an expression.
2020They fall into two major categories: list operators and named unary
2121operators. These differ in their precedence relationship with a
2222following comma. (See the precedence table in L<perlop>.) List
2323operators take more than one argument, while unary operators can never
2424take more than one argument. Thus, a comma terminates the argument of
2525a unary operator, but merely separates the arguments of a list
2626operator. A unary operator generally provides scalar context to its
2727argument, while a list operator may provide either scalar or list
2828contexts for its arguments. If it does both, scalar arguments
2929come first and list argument follow, and there can only ever
3030be one such list argument. For instance,
3131L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> has three scalar arguments
3232followed by a list, whereas L<C<gethostbyname>|/gethostbyname NAME> has
3333four scalar arguments.
3434
3535=end original
3636
3737この節の関数は、式の中で項として使うことができます。
3838これらは、大きく二つに分けられます:
3939リスト演算子と名前付き単項演算子です。
4040これらの違いは、その後に出て来るコンマとの優先順位の関係にあります。
4141(L<perlop> の優先順位の表を参照してください。)
4242リスト演算子は 2 個以上の引数をとるのに対して、単項演算子が複数の引数を
4343とることはありません。
4444つまり、コンマは単項演算子の引数の終わりとなりますが、リスト演算子の
4545場合には、引数の区切りでしかありません。
4646単項演算子は一般に、引数に対してスカラコンテキストを与えるのに対して、
4747スカラ演算子の場合には、引数に対してスカラコンテキストを与える場合も、
4848リストコンテキストを与える場合もあります。
4949一つのリスト演算子が両方のコンテキストを与える場合には、スカラ引数が
5050いくつか並び、最後にリスト引数が一つ続きます;
5151そしてそのようなリスト引数は一つだけしかありません。
5252たとえば、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は三つのスカラ引数に
5353一つのリスト引数が続きます;
5454一方 L<C<gethostbyname>|/gethostbyname NAME> は四つのスカラ引数を持ちます。
5555
5656=begin original
5757
5858In the syntax descriptions that follow, list operators that expect a
5959list (and provide list context for 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 literal elements of the LIST.
6565
6666=end original
6767
6868後に載せる構文記述では、リストをとり (そのリストの要素にリストコンテキストを
6969与える)リスト演算子は、引数として LIST をとるように書いています;
7070そのようなリストには、任意のスカラ引数の組み合わせやリスト値を
7171含めることができ、リスト値はリストの中に、個々の要素が展開されたように
7272埋め込まれます。
73731 次元の長いリスト値が形成されることになります。
7474LIST のリテラルな要素は、コンマで区切られます。
7575
7676=begin original
7777
7878Any function in the list below may be used either with or without
7979parentheses around its arguments. (The syntax descriptions omit the
8080parentheses.) If you use parentheses, the simple but occasionally
8181surprising rule is this: It I<looks> like a function, therefore it I<is> a
8282function, and precedence doesn't matter. Otherwise it's a list
8383operator or unary operator, and precedence does matter. Whitespace
8484between the function and left parenthesis doesn't count, so sometimes
8585you need to be careful:
8686
8787=end original
8888
8989以下のリストの関数はすべて、引数の前後の括弧は省略可能となっています。
9090(構文記述では省略しています。)
9191括弧を使うときには、単純な、(しかし、ときには驚く結果となる規則が
9292適用できます:
9393I<関数に見える>ならば、I<それは関数>で、優先順位は関係ありません。
9494そう見えなければ、それはリスト演算子か単項演算子で、優先順位が関係します。
9595関数と開き括弧の間の空白は関係ありませんので、ときに
9696気を付けなければなりません:
9797
9898 print 1+2+4; # Prints 7.
9999 print(1+2) + 4; # Prints 3.
100100 print (1+2)+4; # Also prints 3!
101101 print +(1+2)+4; # Prints 7.
102102 print ((1+2)+4); # Prints 7.
103103
104104=begin original
105105
106106If you run Perl with the L<C<use warnings>|warnings> pragma, it can warn
107107you about this. For example, the third line above produces:
108108
109109=end original
110110
111111Perl に L<C<use warnings>|warnings> プラグマを付けて実行すれば、
112112こういったものには警告を出してくれます。
113113たとえば、上記の三つめは、以下のような警告が出ます:
114114
115115 print (...) interpreted as function at - line 1.
116116 Useless use of integer addition in void context at - line 1.
117117
118118=begin original
119119
120120A few functions take no arguments at all, and therefore work as neither
121121unary nor list operators. These include such functions as
122122L<C<time>|/time> and L<C<endpwent>|/endpwent>. For example,
123123C<time+86_400> always means C<time() + 86_400>.
124124
125125=end original
126126
127127いくつかの関数は引数を全くとらないので、単項演算子としても
128128リスト演算子としても動作しません。
129129このような関数としては L<C<time>|/time> や L<C<endpwent>|/endpwent> が
130130あります。
131131例えば、C<time+86_400> は常に C<time() + 86_400> として扱われます。
132132
133133=begin original
134134
135135For functions that can be used in either a scalar or list context,
136136nonabortive failure is generally indicated in scalar context by
137137returning the undefined value, and in list context by returning the
138138empty list.
139139
140140=end original
141141
142142スカラコンテキストでも、リストコンテキストでも使える関数は、致命的でない
143143エラーを示すために、スカラコンテキストでは未定義値を返し、
144144リストコンテキストでは空リストを返します。
145145
146146=begin original
147147
148148Remember the following important rule: There is B<no rule> that relates
149149the behavior of an expression in list context to its behavior in scalar
150150context, or vice versa. It might do two totally different things.
151151Each operator and function decides which sort of value would be most
152152appropriate to return in scalar context. Some operators return the
153153length of the list that would have been returned in list context. Some
154154operators return the first value in the list. Some operators return the
155155last value in the list. Some operators return a count of successful
156156operations. In general, they do what you want, unless you want
157157consistency.
158158X<context>
159159
160160=end original
161161
162162以下に述べる重要なルールを忘れないで下さい: リストコンテキストでの
163163振る舞いとスカラコンテキストでの振る舞いの関係、あるいはその逆に
164164B<ルールはありません>。
1651652 つの全く異なったことがあります。
166166それぞれの演算子と関数は、スカラコンテキストでは、もっとも適切と
167167思われる値を返します。
168168リストコンテキストで返す時のリストの長さを返す演算子もあります。
169169リストの最初の値を返す演算子もあります。
170170リストの最後の値を返す演算子もあります。
171171成功した操作の数を返す演算子もあります。
172172一般的には、一貫性を求めない限り、こちらが求めることをします。
173173X<context>
174174
175175=begin original
176176
177177A named array in scalar context is quite different from what would at
178178first glance appear to be a list in scalar context. You can't get a list
179179like C<(1,2,3)> into being in scalar context, because the compiler knows
180180the context at compile time. It would generate the scalar comma operator
181181there, not the list concatenation version of the comma. That means it
182182was never a list to start with.
183183
184184=end original
185185
186186スカラコンテキストでの名前付き配列は、スカラコンテキストでのリストを
187187一目見たものとは全く違います。
188188コンパイラはコンパイル時にコンテキストを知っているので、
189189C<(1,2,3)> のようなリストをスカラコンテキストで得ることはできません。
190190これはスカラコンマ演算子を生成し、コンマのリスト結合版ではありません。
191191これは初めからリストであることはないことを意味します。
192192
193193=begin original
194194
195195In general, functions in Perl that serve as wrappers for system calls
196196("syscalls") of the same name (like L<chown(2)>, L<fork(2)>,
197197L<closedir(2)>, etc.) return true when they succeed and
198198L<C<undef>|/undef EXPR> otherwise, as is usually mentioned in the
199199descriptions below. This is different from the C interfaces, which
200200return C<-1> on failure. Exceptions to this rule include
201201L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>, and
202202L<C<syscall>|/syscall NUMBER, LIST>. System calls also set the special
203203L<C<$!>|perlvar/$!> variable on failure. Other functions do not, except
204204accidentally.
205205
206206=end original
207207
208208一般的に、同じ名前のシステムコールのラッパーとして動作する Perl の関数
209209(L<chown(2)>, L<fork(2)>, L<closedir(2)> など)は、以下に述べるように、
210210成功時に真を返し、そうでなければ L<C<undef>|/undef EXPR> を返します。
211211これは失敗時に C<-1> を返す C のインターフェースとは違います。
212212このルールの例外は L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>,
213213L<C<syscall>|/syscall NUMBER, LIST> です。
214214システムコールは失敗時に特殊変数 L<C<$!>|perlvar/$!> をセットします。
215215その他の関数は、事故を除いて、セットしません。
216216
217217=begin original
218218
219219Extension modules can also hook into the Perl parser to define new
220220kinds of keyword-headed expression. These may look like functions, but
221221may also look completely different. The syntax following the keyword
222222is defined entirely by the extension. If you are an implementor, see
223223L<perlapi/PL_keyword_plugin> for the mechanism. If you are using such
224224a module, see the module's documentation for details of the syntax that
225225it defines.
226226
227227=end original
228228
229229エクステンションモジュールは、新しい種類のキーワードが頭に付いた式を
230230定義するために Perl パーサをフックできます。
231231これらは関数のように見えるかもしれませんが、全く別物かもしれません。
232232キーワード以降の文法は完全にエクステンションによって定義されます。
233233もしあなたが実装者なら、この機構については L<perlapi/PL_keyword_plugin> を
234234参照してください。
235235もしあなたがそのようなモジュールを使っているなら、
236236定義されている文法の詳細についてはモジュールの文書を参照してください。
237237
238238=head2 Perl Functions by Category
239239X<function>
240240
241241(カテゴリ別の Perl 関数)
242242
243243=begin original
244244
245245Here are Perl's functions (including things that look like
246246functions, like some keywords and named operators)
247247arranged by category. Some functions appear in more
248248than one place. Any warnings, including those produced by
249249keywords, are described in L<perldiag> and L<warnings>.
250250
251251=end original
252252
253253以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、
254254関数のように見えるものも含みます)を示します。
255255複数の場所に現れる関数もあります。
256256キーワードによって生成されるものを含む全ての警告は
257257L<perldiag> と L<warnings> に記述されています。
258258
259259=over 4
260260
261261=item Functions for SCALARs or strings
262262X<scalar> X<string> X<character>
263263
264264(スカラや文字列のための関数)
265265
266266=for Pod::Functions =String
267267
268268L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>,
269269L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
270270L<C<fc>|/fc EXPR>, L<C<hex>|/hex EXPR>,
271271L<C<index>|/index STR,SUBSTR,POSITION>, L<C<lc>|/lc EXPR>,
272272L<C<lcfirst>|/lcfirst EXPR>, L<C<length>|/length EXPR>,
273273L<C<oct>|/oct EXPR>, L<C<ord>|/ord EXPR>,
274274L<C<pack>|/pack TEMPLATE,LIST>,
275275L<C<qE<sol>E<sol>>|/qE<sol>STRINGE<sol>>,
276276L<C<qqE<sol>E<sol>>|/qqE<sol>STRINGE<sol>>, L<C<reverse>|/reverse LIST>,
277277L<C<rindex>|/rindex STR,SUBSTR,POSITION>,
278278L<C<sprintf>|/sprintf FORMAT, LIST>,
279279L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>,
280280L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>, L<C<uc>|/uc EXPR>,
281281L<C<ucfirst>|/ucfirst EXPR>,
282282L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>
283283
284284=begin original
285285
286286L<C<fc>|/fc EXPR> is available only if the
287287L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
288288prefixed with C<CORE::>. The
289289L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
290290with a C<use v5.16> (or higher) declaration in the current scope.
291291
292292=end original
293293
294294L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
295295C<CORE::> が前置されたときにのみ利用可能です。
296296L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
297297C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
298298
299299=item Regular expressions and pattern matching
300300X<regular expression> X<regex> X<regexp>
301301
302302(正規表現とパターンマッチング)
303303
304304=for Pod::Functions =Regexp
305305
306306L<C<mE<sol>E<sol>>|/mE<sol>E<sol>>, L<C<pos>|/pos SCALAR>,
307307L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>,
308308L<C<quotemeta>|/quotemeta EXPR>,
309309L<C<sE<sol>E<sol>E<sol>>|/sE<sol>E<sol>E<sol>>,
310310L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
311311L<C<study>|/study SCALAR>
312312
313313=item Numeric functions
314314X<numeric> X<number> X<trigonometric> X<trigonometry>
315315
316316(数値関数)
317317
318318=for Pod::Functions =Math
319319
320320L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>,
321321L<C<exp>|/exp EXPR>, L<C<hex>|/hex EXPR>, L<C<int>|/int EXPR>,
322322L<C<log>|/log EXPR>, L<C<oct>|/oct EXPR>, L<C<rand>|/rand EXPR>,
323323L<C<sin>|/sin EXPR>, L<C<sqrt>|/sqrt EXPR>, L<C<srand>|/srand EXPR>
324324
325325=item Functions for real @ARRAYs
326326X<array>
327327
328328(実配列のための関数)
329329
330330=for Pod::Functions =ARRAY
331331
332332L<C<each>|/each HASH>, L<C<keys>|/keys HASH>, L<C<pop>|/pop ARRAY>,
333333L<C<push>|/push ARRAY,LIST>, L<C<shift>|/shift ARRAY>,
334334L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>,
335335L<C<unshift>|/unshift ARRAY,LIST>, L<C<values>|/values HASH>
336336
337337=item Functions for list data
338338X<list>
339339
340340(リストデータのための関数)
341341
342342=for Pod::Functions =LIST
343343
344344L<C<grep>|/grep BLOCK LIST>, L<C<join>|/join EXPR,LIST>,
345345L<C<map>|/map BLOCK LIST>, L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>>,
346346L<C<reverse>|/reverse LIST>, L<C<sort>|/sort SUBNAME LIST>,
347347L<C<unpack>|/unpack TEMPLATE,EXPR>
348348
349349=item Functions for real %HASHes
350350X<hash>
351351
352352(実ハッシュのための関数)
353353
354354=for Pod::Functions =HASH
355355
356356L<C<delete>|/delete EXPR>, L<C<each>|/each HASH>,
357357L<C<exists>|/exists EXPR>, L<C<keys>|/keys HASH>,
358358L<C<values>|/values HASH>
359359
360360=item Input and output functions
361361X<I/O> X<input> X<output> X<dbm>
362362
363363(入出力関数)
364364
365365=for Pod::Functions =I/O
366366
367367L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<close>|/close FILEHANDLE>,
368368L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>,
369369L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>,
370370L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>,
371371L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<format>|/format>,
372372L<C<getc>|/getc FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>,
373373L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
374374L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
375375L<C<readdir>|/readdir DIRHANDLE>, L<C<readline>|/readline EXPR>,
376376L<C<rewinddir>|/rewinddir DIRHANDLE>, L<C<say>|/say FILEHANDLE LIST>,
377377L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
378378L<C<seekdir>|/seekdir DIRHANDLE,POS>,
379379L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
380380L<C<syscall>|/syscall NUMBER, LIST>,
381381L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
382382L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>,
383383L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
384384L<C<tell>|/tell FILEHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
385385L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<warn>|/warn LIST>,
386386L<C<write>|/write FILEHANDLE>
387387
388388=begin original
389389
390390L<C<say>|/say FILEHANDLE LIST> is available only if the
391391L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
392392prefixed with C<CORE::>. The
393393L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
394394with a C<use v5.10> (or higher) declaration in the current scope.
395395
396396=end original
397397
398398L<C<say>|/say FILEHANDLE LIST> は
399399L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
400400前置されたときにのみ利用可能です。
401401L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
402402C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
403403
404404=item Functions for fixed-length data or records
405405
406406(固定長データやレコードのための関数)
407407
408408=for Pod::Functions =Binary
409409
410410L<C<pack>|/pack TEMPLATE,LIST>,
411411L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
412412L<C<syscall>|/syscall NUMBER, LIST>,
413413L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
414414L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>,
415415L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
416416L<C<unpack>|/unpack TEMPLATE,EXPR>, L<C<vec>|/vec EXPR,OFFSET,BITS>
417417
418418=item Functions for filehandles, files, or directories
419419X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink>
420420
421421(ファイルハンドル、ファイル、ディレクトリのための関数)
422422
423423=for Pod::Functions =File
424424
425425L<C<-I<X>>|/-X FILEHANDLE>, L<C<chdir>|/chdir EXPR>,
426426L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
427427L<C<chroot>|/chroot FILENAME>,
428428L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, L<C<glob>|/glob EXPR>,
429429L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
430430L<C<link>|/link OLDFILE,NEWFILE>, L<C<lstat>|/lstat FILEHANDLE>,
431431L<C<mkdir>|/mkdir FILENAME,MODE>, L<C<open>|/open FILEHANDLE,MODE,EXPR>,
432432L<C<opendir>|/opendir DIRHANDLE,EXPR>, L<C<readlink>|/readlink EXPR>,
433433L<C<rename>|/rename OLDNAME,NEWNAME>, L<C<rmdir>|/rmdir FILENAME>,
434434L<C<select>|/select FILEHANDLE>, L<C<stat>|/stat FILEHANDLE>,
435435L<C<symlink>|/symlink OLDFILE,NEWFILE>,
436436L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
437437L<C<umask>|/umask EXPR>, L<C<unlink>|/unlink LIST>,
438438L<C<utime>|/utime LIST>
439439
440440=item Keywords related to the control flow of your Perl program
441441X<control flow>
442442
443443(プログラムの流れを制御することに関連するキーワード)
444444
445445=for Pod::Functions =Flow
446446
447447L<C<break>|/break>, L<C<caller>|/caller EXPR>,
448448L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>,
449449L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>,
450450L<C<evalbytes>|/evalbytes EXPR>, L<C<exit>|/exit EXPR>,
451451L<C<__FILE__>|/__FILE__>, L<C<goto>|/goto LABEL>,
452452L<C<last>|/last LABEL>, L<C<__LINE__>|/__LINE__>,
453453L<C<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>,
454454L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>,
455455L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>,
456456L<C<wantarray>|/wantarray>
457457
458458=begin original
459459
460460L<C<break>|/break> is available only if you enable the experimental
461461L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::>
462462prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also
463463enables the C<default>, C<given> and C<when> statements, which are
464464documented in L<perlsyn/"Switch Statements">.
465465The L<C<"switch"> feature|feature/The 'switch' feature> is enabled
466466automatically with a C<use v5.10> (or higher) declaration in the current
467467scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK>
468468required the L<C<"switch"> feature|feature/The 'switch' feature>, like
469469the other keywords.
470470
471471=end original
472472
473473L<C<break>|/break> は、実験的な
474474L<C<"switch"> 機能|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を
475475使ったときにのみ利用可能です。
476476L<C<"switch"> 機能|feature/The 'switch' feature> は、
477477L<perlsyn/"Switch Statements"> で文書化されている
478478C<default>, C<given>, C<when> 文も有効にします。
479479L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで
480480C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
481481Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に
482482L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。
483483
484484=begin original
485485
486486L<C<evalbytes>|/evalbytes EXPR> is only available with the
487487L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
488488(see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__>
489489is only available with the
490490L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if
491491prefixed with C<CORE::>. Both the
492492L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features>
493493and L<C<"current_sub">|feature/The 'current_sub' feature> features are
494494enabled automatically with a C<use v5.16> (or higher) declaration in the
495495current scope.
496496
497497=end original
498498
499499L<C<evalbytes>|/evalbytes EXPR> は
500500L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features>
501501(L<feature> 参照) が有効か C<CORE::> が前置されたときにのみ利用可能です。
502502L<C<__SUB__>|/__SUB__> は
503503L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か
504504C<CORE::> が前置されたときにのみ利用可能です。
505505L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と
506506L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は
507507現在のスコープで
508508C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
509509
510510=item Keywords related to scoping
511511
512512(スコープに関するキーワード)
513513
514514=for Pod::Functions =Namespace
515515
516516L<C<caller>|/caller EXPR>, L<C<import>|/import LIST>,
517517L<C<local>|/local EXPR>, L<C<my>|/my VARLIST>, L<C<our>|/our VARLIST>,
518518L<C<package>|/package NAMESPACE>, L<C<state>|/state VARLIST>,
519519L<C<use>|/use Module VERSION LIST>
520520
521521=begin original
522522
523523L<C<state>|/state VARLIST> is available only if the
524524L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
525525prefixed with C<CORE::>. The
526526L<C<"state"> feature|feature/The 'state' feature> is enabled
527527automatically with a C<use v5.10> (or higher) declaration in the current
528528scope.
529529
530530=end original
531531
532532L<C<state>|/state VARLIST> は
533533L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を
534534前置した場合にのみ利用可能です。
535535L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
536536C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
537537
538538=item Miscellaneous functions
539539
540540(さまざまな関数)
541541
542542=for Pod::Functions =Misc
543543
544544L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>,
545545L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>,
546546L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>,
547547L<C<undef>|/undef EXPR>
548548
549549=item Functions for processes and process groups
550550X<process> X<pid> X<process id>
551551
552552(プロセスとプロセスグループのための関数)
553553
554554=for Pod::Functions =Process
555555
556556L<C<alarm>|/alarm SECONDS>, L<C<exec>|/exec LIST>, L<C<fork>|/fork>,
557557L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>,
558558L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>,
559559L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>,
560560L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>,
561561L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>,
562562L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
563563L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>,
564564L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>
565565
566566=item Keywords related to Perl modules
567567X<module>
568568
569569(Perl モジュールに関するキーワード)
570570
571571=for Pod::Functions =Modules
572572
573573L<C<do>|/do EXPR>, L<C<import>|/import LIST>,
574574L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>,
575575L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST>
576576
577577=item Keywords related to classes and object-orientation
578578X<object> X<class> X<package>
579579
580580(クラスとオブジェクト指向に関するキーワード)
581581
582582=for Pod::Functions =Objects
583583
584584L<C<bless>|/bless REF,CLASSNAME>, L<C<dbmclose>|/dbmclose HASH>,
585585L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
586586L<C<package>|/package NAMESPACE>, L<C<ref>|/ref EXPR>,
587587L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>, L<C<tied>|/tied VARIABLE>,
588588L<C<untie>|/untie VARIABLE>, L<C<use>|/use Module VERSION LIST>
589589
590590=item Low-level socket functions
591591X<socket> X<sock>
592592
593593(低レベルソケット関数)
594594
595595=for Pod::Functions =Socket
596596
597597L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>,
598598L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>,
599599L<C<getpeername>|/getpeername SOCKET>,
600600L<C<getsockname>|/getsockname SOCKET>,
601601L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
602602L<C<listen>|/listen SOCKET,QUEUESIZE>,
603603L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>,
604604L<C<send>|/send SOCKET,MSG,FLAGS,TO>,
605605L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
606606L<C<shutdown>|/shutdown SOCKET,HOW>,
607607L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
608608L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>
609609
610610=item System V interprocess communication functions
611611X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message>
612612
613613(System V プロセス間通信関数)
614614
615615=for Pod::Functions =SysV
616616
617617L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>,
618618L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
619619L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>,
620620L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
621621L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
622622L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
623623L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
624624L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>
625625
626626=item Fetching user and group info
627627X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd>
628628
629629(ユーザーとグループの情報取得)
630630
631631=for Pod::Functions =User
632632
633633L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>,
634634L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>,
635635L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
636636L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>,
637637L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>,
638638L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>,
639639L<C<setpwent>|/setpwent>
640640
641641=item Fetching network info
642642X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service>
643643
644644(ネットワーク情報取得)
645645
646646=for Pod::Functions =Network
647647
648648L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>,
649649L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>,
650650L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
651651L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
652652L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
653653L<C<getprotobyname>|/getprotobyname NAME>,
654654L<C<getprotobynumber>|/getprotobynumber NUMBER>,
655655L<C<getprotoent>|/getprotoent>,
656656L<C<getservbyname>|/getservbyname NAME,PROTO>,
657657L<C<getservbyport>|/getservbyport PORT,PROTO>,
658658L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>,
659659L<C<setnetent>|/setnetent STAYOPEN>,
660660L<C<setprotoent>|/setprotoent STAYOPEN>,
661661L<C<setservent>|/setservent STAYOPEN>
662662
663663=item Time-related functions
664664X<time> X<date>
665665
666666(時刻に関する関数)
667667
668668=for Pod::Functions =Time
669669
670670L<C<gmtime>|/gmtime EXPR>, L<C<localtime>|/localtime EXPR>,
671671L<C<time>|/time>, L<C<times>|/times>
672672
673673=item Non-function keywords
674674
675675=for Pod::Functions =!Non-functions
676676
677C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>,
677C<and>,
678C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>,
678C<AUTOLOAD>,
679C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>,
679C<BEGIN>,
680C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>,
680C<catch>,
681C<while>, C<x>, C<xor>
681C<CHECK>,
682C<cmp>,
683C<CORE>,
684C<__DATA__>,
685C<default>,
686C<defer>,
687C<DESTROY>,
688C<else>,
689C<elseif>,
690C<elsif>,
691C<END>,
692C<__END__>,
693C<eq>,
694C<finally>,
695C<for>,
696C<foreach>,
697C<ge>,
698C<given>,
699C<gt>,
700C<if>,
701C<INIT>,
702C<isa>,
703C<le>,
704C<lt>,
705C<ne>,
706C<not>,
707C<or>,
708C<try>,
709C<UNITCHECK>,
710C<unless>,
711C<until>,
712C<when>,
713C<while>,
714C<x>,
715C<xor>
682716
683717=back
684718
685719=head2 Portability
686720X<portability> X<Unix> X<portable>
687721
688722(移植性)
689723
690724=begin original
691725
692726Perl was born in Unix and can therefore access all common Unix
693727system calls. In non-Unix environments, the functionality of some
694728Unix system calls may not be available or details of the available
695729functionality may differ slightly. The Perl functions affected
696730by this are:
697731
698732=end original
699733
700734Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに
701735アクセスします。
702736非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、
703737使える機能の詳細が多少異なったりします。
704738これによる影響を受ける Perl 関数は以下のものです:
705739
706740L<C<-I<X>>|/-X FILEHANDLE>, L<C<binmode>|/binmode FILEHANDLE, LAYER>,
707741L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
708742L<C<chroot>|/chroot FILENAME>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
709743L<C<dbmclose>|/dbmclose HASH>, L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
710744L<C<dump>|/dump LABEL>, L<C<endgrent>|/endgrent>,
711745L<C<endhostent>|/endhostent>, L<C<endnetent>|/endnetent>,
712746L<C<endprotoent>|/endprotoent>, L<C<endpwent>|/endpwent>,
713747L<C<endservent>|/endservent>, L<C<exec>|/exec LIST>,
714748L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>,
715749L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<fork>|/fork>,
716750L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
717751L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
718752L<C<getlogin>|/getlogin>,
719753L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
720754L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
721755L<C<getppid>|/getppid>, L<C<getpgrp>|/getpgrp PID>,
722756L<C<getpriority>|/getpriority WHICH,WHO>,
723757L<C<getprotobynumber>|/getprotobynumber NUMBER>,
724758L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>,
725759L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>,
726760L<C<getservbyport>|/getservbyport PORT,PROTO>,
727761L<C<getservent>|/getservent>,
728762L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
729763L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
730764L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>,
731765L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>,
732766L<C<msgget>|/msgget KEY,FLAGS>,
733767L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
734768L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,MODE,EXPR>,
735769L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>,
736770L<C<rename>|/rename OLDNAME,NEWNAME>,
737771L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
738772L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
739773L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
740774L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>,
741775L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>,
742776L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
743777L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>,
744778L<C<setservent>|/setservent STAYOPEN>,
745779L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
746780L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
747781L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
748782L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>,
749783L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
750784L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>,
751785L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>,
752786L<C<syscall>|/syscall NUMBER, LIST>,
753787L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
754788L<C<system>|/system LIST>, L<C<times>|/times>,
755789L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>,
756790L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>,
757791L<C<waitpid>|/waitpid PID,FLAGS>
758792
759793=begin original
760794
761795For more information about the portability of these functions, see
762796L<perlport> and other available platform-specific documentation.
763797
764798=end original
765799
766800これらの関数の移植性に関するさらなる情報については、
767801L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。
768802
769803=head2 Alphabetical Listing of Perl Functions
770804
771805=over
772806
773807=item -X FILEHANDLE
774808X<-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>
775809X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
776810
777811=item -X EXPR
778812
779813=item -X DIRHANDLE
780814
781815=item -X
782816
783817=for Pod::Functions a file test (-r, -x, etc)
784818
785819=begin original
786820
787821A file test, where X is one of the letters listed below. This unary
788822operator takes one argument, either a filename, a filehandle, or a dirhandle,
789823and tests the associated file to see if something is true about it. If the
790824argument is omitted, tests L<C<$_>|perlvar/$_>, except for C<-t>, which
791825tests STDIN. Unless otherwise documented, it returns C<1> for true and
792826C<''> for false. If the file doesn't exist or can't be examined, it
793827returns L<C<undef>|/undef EXPR> and sets L<C<$!>|perlvar/$!> (errno).
794828With the exception of the C<-l> test they all follow symbolic links
795829because they use C<stat()> and not C<lstat()> (so dangling symlinks can't
796830be examined and will therefore report failure).
797831
798832=end original
799833
800834X は以下にあげる文字で、ファイルテストを行ないます。
801835この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、
802836「あること」について真であるか否かを判定した結果を返します。
803837引数が省略されると、C<-t> では STDIN を調べますが、その他は
804838L<C<$_>|perlvar/$_> を調べます。
805839特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。
806840ファイルが存在しないか、テスト出来なければ、L<C<undef>|/undef EXPR> を返し、
807841L<C<$!>|perlvar/$!> (errno) を設定します。
808842C<-l> テストを例外として、これら全てはシンボリックリンクに従います;
809843C<lstat()> ではなく C<stat()> を使っているからです
810844(従って壊れたシンボリックリンクは検査されず、失敗が報告されます)。
811845
812846=begin original
813847
814848Despite the funny names, precedence is the same as any other named unary
815849operator. The operator may be any of:
816850
817851=end original
818852
819853みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、
820854他の単項演算子と同じく、引数を括弧で括ることもできます。
821855演算子には以下のものがあります:
822856
823857=begin original
824858
825859 -r File is readable by effective uid/gid.
826860 -w File is writable by effective uid/gid.
827861 -x File is executable by effective uid/gid.
828862 -o File is owned by effective uid.
829863
830864=end original
831865
832866 -r ファイルが実効 uid/gid で読み出し可。
833867 -w ファイルが実効 uid/gid で書き込み可。
834868 -x ファイルが実効 uid/gid で実行可。
835869 -o ファイルが実効 uid の所有物。
836870
837871=begin original
838872
839873 -R File is readable by real uid/gid.
840874 -W File is writable by real uid/gid.
841875 -X File is executable by real uid/gid.
842876 -O File is owned by real uid.
843877
844878=end original
845879
846880 -R ファイルが実 uid/gid で読み出し可。
847881 -W ファイルが実 uid/gid で書き込み可。
848882 -X ファイルが実 uid/gid で実行可。
849883 -O ファイルが実 uid の所有物。
850884
851885=begin original
852886
853887 -e File exists.
854888 -z File has zero size (is empty).
855889 -s File has nonzero size (returns size in bytes).
856890
857891=end original
858892
859893 -e ファイルが存在する。
860894 -z ファイルの大きさがゼロ(空)。
861895 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)。
862896
863897=begin original
864898
865899 -f File is a plain file.
866900 -d File is a directory.
867901 -l File is a symbolic link (false if symlinks aren't
868902 supported by the file system).
869903 -p File is a named pipe (FIFO), or Filehandle is a pipe.
870904 -S File is a socket.
871905 -b File is a block special file.
872906 -c File is a character special file.
873907 -t Filehandle is opened to a tty.
874908
875909=end original
876910
877911 -f ファイルは通常ファイル。
878912 -d ファイルはディレクトリ。
879913 -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)。
880914 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ。
881915 -S ファイルはソケット。
882916 -b ファイルはブロック特殊ファイル。
883917 -c ファイルはキャラクタ特殊ファイル。
884918 -t ファイルハンドルは tty にオープンされている。
885919
886920=begin original
887921
888922 -u File has setuid bit set.
889923 -g File has setgid bit set.
890924 -k File has sticky bit set.
891925
892926=end original
893927
894928 -u ファイルの setuid ビットがセットされている。
895929 -g ファイルの setgid ビットがセットされている。
896930 -k ファイルの sticky ビットがセットされている。
897931
898932=begin original
899933
900934 -T File is an ASCII or UTF-8 text file (heuristic guess).
901935 -B File is a "binary" file (opposite of -T).
902936
903937=end original
904938
905939 -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)。
906940 -B ファイルは「バイナリ」ファイル (-T の反対)。
907941
908942=begin original
909943
910944 -M Script start time minus file modification time, in days.
911945 -A Same for access time.
912946 -C Same for inode change time (Unix, may differ for other
913947 platforms)
914948
915949=end original
916950
917951 -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)。
918952 -A 同様にアクセスがあってからの日数。
919953 -C 同様に(Unix では) inode が変更されてからの日数(それ以外の
920954 プラットフォームでは違うかもしれません)。
921955
922956=begin original
923957
924958Example:
925959
926960=end original
927961
928962例:
929963
930964 while (<>) {
931965 chomp;
932966 next unless -f $_; # ignore specials
933967 #...
934968 }
935969
936970=begin original
937971
938972Note that C<-s/a/b/> does not do a negated substitution. Saying
939973C<-exp($foo)> still works as expected, however: only single letters
940974following a minus are interpreted as file tests.
941975
942976=end original
943977
944978C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。
945979しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に
946980英字が 1 字続くときにのみ、ファイルテストと解釈されます。
947981
948982=begin original
949983
950984These operators are exempt from the "looks like a function rule" described
951985above. That is, an opening parenthesis after the operator does not affect
952986how much of the following code constitutes the argument. Put the opening
953987parentheses before the operator to separate it from code that follows (this
954988applies only to operators with higher precedence than unary operators, of
955989course):
956990
957991=end original
958992
959993これらの演算子は上述の「関数のように見えるルール」から免除されます。
960994つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を
961995構成するかに影響を与えません。
962996演算子を引き続くコードから分離するには、演算子の前に開きかっこを
963997置いてください (これはもちろん、単項演算子より高い優先順位を持つ
964998演算子にのみ適用されます):
965999
9661000 -s($file) + 1024 # probably wrong; same as -s($file + 1024)
9671001 (-s $file) + 1024 # correct
9681002
9691003=begin original
9701004
9711005The interpretation of the file permission operators C<-r>, C<-R>,
9721006C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode
9731007of the file and the uids and gids of the user. There may be other
9741008reasons you can't actually read, write, or execute the file: for
9751009example network filesystem access controls, ACLs (access control lists),
9761010read-only filesystems, and unrecognized executable formats. Note
9771011that the use of these six specific operators to verify if some operation
9781012is possible is usually a mistake, because it may be open to race
9791013conditions.
9801014
9811015=end original
9821016
9831017ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>,
9841018C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と
9851019実効/実 gid のみから判断されます。
9861020実際にファイルが読めたり、書けたり、実行できたりするためには、
9871021別の条件が必要かもしれません:
9881022例えば、ネットワークファイルシステムアクセスコントロール、
9891023ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、
9901024認識できない実行ファイルフォーマット、などです。
9911025これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは
9921026通常は誤りであることに注意してください; なぜなら、これらは競合条件を
9931027招きやすいからです。
9941028
9951029=begin original
9961030
9971031Also note that, for the superuser on the local filesystems, the C<-r>,
9981032C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1
9991033if any execute bit is set in the mode. Scripts run by the superuser
10001034may thus need to do a L<C<stat>|/stat FILEHANDLE> to determine the
10011035actual mode of the file, or temporarily set their effective uid to
10021036something else.
10031037
10041038=end original
10051039
10061040ローカルファイルシステムのスーパーユーザには、
10071041C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の
10081042いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が
10091043返ることにも注意してください。
10101044スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、
10111045L<C<stat>|/stat FILEHANDLE> を行なうか、実効 uid を一時的に別のものにする
10121046必要があるでしょう。
10131047
10141048=begin original
10151049
10161050If you are using ACLs, there is a pragma called L<C<filetest>|filetest>
10171051that may produce more accurate results than the bare
10181052L<C<stat>|/stat FILEHANDLE> mode bits.
10191053When under C<use filetest 'access'>, the above-mentioned filetests
10201054test whether the permission can(not) be granted using the L<access(2)>
10211055family of system calls. Also note that the C<-x> and C<-X> tests may
10221056under this pragma return true even if there are no execute permission
10231057bits set (nor any extra execute permission ACLs). This strangeness is
10241058due to the underlying system calls' definitions. Note also that, due to
10251059the implementation of C<use filetest 'access'>, the C<_> special
10261060filehandle won't cache the results of the file tests when this pragma is
10271061in effect. Read the documentation for the L<C<filetest>|filetest>
10281062pragma for more information.
10291063
10301064=end original
10311065
10321066ACL を使っている場合は、生の L<C<stat>|/stat FILEHANDLE> モードビットより
10331067精度の高い結果を作成する L<C<filetest>|filetest> プラグマがあります。
10341068C<use filetest 'access'> とした場合、上述したファイルテストは
10351069システムコールの L<access(2)> ファミリーを使って権限が与えられているか
10361070どうかをテストします。
10371071また、このプラグマが指定されている場合、C<-x> と C<-X> テストは
10381072たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない
10391073場合でも真を返すことに注意してください。
10401074この挙動は使用するシステムコールの定義によるものです。
10411075C<use filetest 'access'> の実装により、このプラグマが有効の場合は
10421076C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに
10431077注意してください。
10441078さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを
10451079参照してください。
10461080
10471081=begin original
10481082
10491083The C<-T> and C<-B> tests work as follows. The first block or so of
10501084the file is examined to see if it is valid UTF-8 that includes non-ASCII
10511085characters. If so, it's a C<-T> file. Otherwise, that same portion of
10521086the file is examined for odd characters such as strange control codes or
10531087characters with the high bit set. If more than a third of the
10541088characters are strange, it's a C<-B> file; otherwise it's a C<-T> file.
10551089Also, any file containing a zero byte in the examined portion is
10561090considered a binary file. (If executed within the scope of a L<S<use
10571091locale>|perllocale> which includes C<LC_CTYPE>, odd characters are
10581092anything that isn't a printable nor space in the current locale.) If
10591093C<-T> or C<-B> is used on a filehandle, the current IO buffer is
10601094examined
10611095rather than the first block. Both C<-T> and C<-B> return true on an empty
10621096file, or a file at EOF when testing a filehandle. Because you have to
10631097read a file to do the C<-T> test, on most occasions you want to use a C<-f>
10641098against the file first, as in C<next unless -f $file && -T $file>.
10651099
10661100=end original
10671101
10681102ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。
10691103ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを
10701104調べます。
10711105もしそうなら、それは C<-T> ファイルです。
10721106さもなければ、ファイルの同じ位置から、変わった制御コードや
10731107上位ビットがセットされているような、通常のテキストには現れない文字を探します。
10741108三分の一以上がおかしな文字なら、それは C<-B> ファイルでです;
10751109さもなければ C<-T> ファイルです。
10761110また、調べた位置にヌル文字が含まれるファイルも、バイナリファイルと
10771111みなされます。
10781112(C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、
10791113おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。)
10801114C<-T> や C<-B> をファイルハンドルに対して用いると、
10811115最初のブロックを調べる代わりに、IO バッファを調べます。
10821116調べたファイルの中身が何もないときや、
10831117ファイルハンドルを調べたときに EOF に達して
10841118いたときには、C<-T> も C<-B> も「真」を返します。
10851119C<-T> テストをするためにはファイルを読み込まないといけないので、
10861120たいていは C<next unless -f $file && -T $file> というような形で
10871121まず調べたいファイルに対して C<-f> を使いたいはずです。
10881122
10891123=begin original
10901124
10911125If any of the file tests (or either the L<C<stat>|/stat FILEHANDLE> or
10921126L<C<lstat>|/lstat FILEHANDLE> operator) is given the special filehandle
10931127consisting of a solitary underline, then the stat structure of the
10941128previous file test (or L<C<stat>|/stat FILEHANDLE> operator) is used,
10951129saving a system call. (This doesn't work with C<-t>, and you need to
10961130remember that L<C<lstat>|/lstat FILEHANDLE> and C<-l> leave values in
10971131the stat structure for the symbolic link, not the real file.) (Also, if
10981132the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call,
10991133C<-T> and C<-B> will reset it with the results of C<stat _>).
11001134Example:
11011135
11021136=end original
11031137
11041138どのファイルテスト (あるいは、L<C<stat>|/stat FILEHANDLE> や
11051139L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、
11061140下線だけから成る特別なファイルハンドルを与えると、
11071141前回のファイルテスト (や L<C<stat>|/stat FILEHANDLE> 演算子) の
11081142stat 構造体が使われ、システムコールを省きます。
11091143(C<-t> には使えませんし、L<C<lstat>|/lstat FILEHANDLE> や C<-l> は
11101144実ファイルではなく、シンボリックリンクの情報を stat 構造体に残すことを
11111145覚えておく必要があります。)
11121146(また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、
11131147C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。
11141148例:
11151149
11161150 print "Can do.\n" if -r $a || -w _ || -x _;
11171151
11181152 stat($filename);
11191153 print "Readable\n" if -r _;
11201154 print "Writable\n" if -w _;
11211155 print "Executable\n" if -x _;
11221156 print "Setuid\n" if -u _;
11231157 print "Setgid\n" if -g _;
11241158 print "Sticky\n" if -k _;
11251159 print "Text\n" if -T _;
11261160 print "Binary\n" if -B _;
11271161
11281162=begin original
11291163
11301164As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file
11311165test operators, in a way that C<-f -w -x $file> is equivalent to
11321166C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use
11331167the return value of C<-f $file> as an argument to another filetest
11341168operator, no special magic will happen.)
11351169
11361170=end original
11371171
11381172Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
11391173スタックさせることができるので、C<-f -w -x $file> は
11401174C<-x $file && -w _ && -f _> と等価です。
11411175(これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト
11421176演算子の引数として使う場合は、何の特別なことも起きません。)
11431177
11441178=begin original
11451179
11461180Portability issues: L<perlport/-X>.
11471181
11481182=end original
11491183
11501184移植性の問題: L<perlport/-X>。
11511185
11521186=begin original
11531187
11541188To avoid confusing would-be users of your code with mysterious
11551189syntax errors, put something like this at the top of your script:
11561190
11571191=end original
11581192
11591193あなたのコードのユーザーが不思議な文法エラーで混乱することを
11601194避けるために、スクリプトの先頭に以下のようなことを書いてください:
11611195
1162 use 5.010; # so filetest ops can stack
1196 use v5.10; # so filetest ops can stack
11631197
11641198=item abs VALUE
11651199X<abs> X<absolute>
11661200
11671201=item abs
11681202
11691203=for Pod::Functions absolute value function
11701204
11711205=begin original
11721206
11731207Returns the absolute value of its argument.
11741208If VALUE is omitted, uses L<C<$_>|perlvar/$_>.
11751209
11761210=end original
11771211
11781212引数の絶対値を返します。
11791213VALUE が省略された場合は、L<C<$_>|perlvar/$_> を使います。
11801214
11811215=item accept NEWSOCKET,GENERICSOCKET
11821216X<accept>
11831217
11841218=for Pod::Functions accept an incoming socket connect
11851219
11861220=begin original
11871221
11881222Accepts an incoming socket connect, just as L<accept(2)>
11891223does. Returns the packed address if it succeeded, false otherwise.
11901224See the example in L<perlipc/"Sockets: Client/Server Communication">.
11911225
11921226=end original
11931227
11941228L<accept(2)> システムコールと同様に、着信するソケットの接続を受け付けます。
11951229成功時にはパックされたアドレスを返し、失敗すれば偽を返します。
11961230L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
11971231
11981232=begin original
11991233
12001234On systems that support a close-on-exec flag on files, the flag will
12011235be set for the newly opened file descriptor, as determined by the
12021236value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
12031237
12041238=end original
12051239
12061240ファイルに対する close-on-exec フラグをサポートしているシステムでは、
12071241フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
12081242ファイル記述子に対してセットされます。
12091243L<perlvar/$^F> を参照してください。
12101244
12111245=item alarm SECONDS
12121246X<alarm>
12131247X<SIGALRM>
12141248X<timer>
12151249
12161250=item alarm
12171251
12181252=for Pod::Functions schedule a SIGALRM
12191253
12201254=begin original
12211255
12221256Arranges to have a SIGALRM delivered to this process after the
12231257specified number of wallclock seconds has elapsed. If SECONDS is not
12241258specified, the value stored in L<C<$_>|perlvar/$_> is used. (On some
12251259machines, unfortunately, the elapsed time may be up to one second less
12261260or more than you specified because of how seconds are counted, and
12271261process scheduling may delay the delivery of the signal even further.)
12281262
12291263=end original
12301264
12311265指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が
12321266送られてくるようにします。
12331267SECONDS が指定されていない場合は、L<C<$_>|perlvar/$_> に格納されている値を
12341268使います。
12351269(マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で
123612701 秒ずれます。)
12371271
12381272=begin original
12391273
12401274Only one timer may be counting at once. Each call disables the
12411275previous timer, and an argument of C<0> may be supplied to cancel the
12421276previous timer without starting a new one. The returned value is the
12431277amount of time remaining on the previous timer.
12441278
12451279=end original
12461280
12471281一度には一つのタイマだけが設定可能です。
12481282呼び出しを行なう度に、以前のタイマを無効にしますし、
12491283新しくタイマを起動しないで以前のタイマをキャンセルするために
12501284引数に C<0> を指定して呼び出すことができます。
12511285以前のタイマの残り時間が、返り値となります。
12521286
12531287=begin original
12541288
12551289For delays of finer granularity than one second, the L<Time::HiRes> module
12561290(from CPAN, and starting from Perl 5.8 part of the standard
12571291distribution) provides
12581292L<C<ualarm>|Time::HiRes/ualarm ( $useconds [, $interval_useconds ] )>.
12591293You may also use Perl's four-argument version of
12601294L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three
12611295arguments undefined, or you might be able to use the
12621296L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
12631297if your system supports it. See L<perlfaq8> for details.
12641298
12651299=end original
12661300
126713011 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
12681302また Perl 5.8 からは標準配布されています) が
12691303L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。
12701304Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
127113053 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、
12721306Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
12731307アクセスすることもできます。
12741308詳しくは L<perlfaq8> を参照してください。
12751309
12761310=begin original
12771311
12781312It is usually a mistake to intermix L<C<alarm>|/alarm SECONDS> and
12791313L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> may be
12801314internally implemented on your system with L<C<alarm>|/alarm SECONDS>.
12811315
12821316=end original
12831317
12841318L<C<alarm>|/alarm SECONDS> と L<C<sleep>|/sleep EXPR> を混ぜて使うのは
12851319普通は間違いです; なぜなら、L<C<sleep>|/sleep EXPR> は内部的に
12861320L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも
12871321しれないからです。
12881322
12891323=begin original
12901324
12911325If you want to use L<C<alarm>|/alarm SECONDS> to time out a system call
12921326you need to use an L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> pair. You
12931327can't rely on the alarm causing the system call to fail with
12941328L<C<$!>|perlvar/$!> set to C<EINTR> because Perl sets up signal handlers
12951329to restart system calls on some systems. Using
12961330L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the
12971331caveats given in L<perlipc/"Signals">.
12981332
12991333=end original
13001334
13011335L<C<alarm>|/alarm SECONDS> をシステムコールの時間切れのために使いたいなら、
13021336L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> のペアで使う必要があります。
13031337システムコールが失敗したときに L<C<$!>|perlvar/$!> に C<EINTR> が
13041338セットされることに頼ってはいけません; なぜならシステムによっては Perl は
13051339システムコールを再開するためにシグナルハンドラを設定するからです。
13061340L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> は常にうまく動きます;
13071341注意点については L<perlipc/"Signals"> を参照してください。
13081342
13091343 eval {
13101344 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
13111345 alarm $timeout;
13121346 my $nread = sysread $socket, $buffer, $size;
13131347 alarm 0;
13141348 };
13151349 if ($@) {
13161350 die unless $@ eq "alarm\n"; # propagate unexpected errors
13171351 # timed out
13181352 }
13191353 else {
13201354 # didn't
13211355 }
13221356
13231357=begin original
13241358
13251359For more information see L<perlipc>.
13261360
13271361=end original
13281362
13291363さらなる情報については L<perlipc> を参照してください。
13301364
13311365=begin original
13321366
13331367Portability issues: L<perlport/alarm>.
13341368
13351369=end original
13361370
13371371移植性の問題: L<perlport/alarm>。
13381372
13391373=item atan2 Y,X
13401374X<atan2> X<arctangent> X<tan> X<tangent>
13411375
13421376=for Pod::Functions arctangent of Y/X in the range -PI to PI
13431377
13441378=begin original
13451379
13461380Returns the arctangent of Y/X in the range -PI to PI.
13471381
13481382=end original
13491383
13501384-πからπの範囲で Y/X の逆正接を返します。
13511385
13521386=begin original
13531387
13541388For the tangent operation, you may use the
13551389L<C<Math::Trig::tan>|Math::Trig/B<tan>> function, or use the familiar
13561390relation:
13571391
13581392=end original
13591393
13601394正接を求めたいときは、L<C<Math::Trig::tan>|Math::Trig/B<tan>> を使うか、
13611395以下のよく知られた関係を使ってください。
13621396
13631397 sub tan { sin($_[0]) / cos($_[0]) }
13641398
13651399=begin original
13661400
13671401The return value for C<atan2(0,0)> is implementation-defined; consult
13681402your L<atan2(3)> manpage for more information.
13691403
13701404=end original
13711405
13721406C<atan2(0,0)> の返り値は実装依存です; さらなる情報については
13731407L<atan2(3)> man ページを参照してください。
13741408
13751409=begin original
13761410
13771411Portability issues: L<perlport/atan2>.
13781412
13791413=end original
13801414
13811415移植性の問題: L<perlport/atan2>。
13821416
13831417=item bind SOCKET,NAME
13841418X<bind>
13851419
13861420=for Pod::Functions binds an address to a socket
13871421
13881422=begin original
13891423
13901424Binds a network address to a socket, just as L<bind(2)>
13911425does. Returns true if it succeeded, false otherwise. NAME should be a
13921426packed address of the appropriate type for the socket. See the examples in
13931427L<perlipc/"Sockets: Client/Server Communication">.
13941428
13951429=end original
13961430
13971431L<bind(2)> システムコールと同様に、ネットワークアドレスをソケットに
13981432結び付けます。
13991433成功時には真を、さもなければ偽を返します。
14001434NAME は、ソケットに対する、適切な型のパックされた
14011435アドレスでなければなりません。
14021436L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
14031437
14041438=item binmode FILEHANDLE, LAYER
14051439X<binmode> X<binary> X<text> X<DOS> X<Windows>
14061440
14071441=item binmode FILEHANDLE
14081442
14091443=for Pod::Functions prepare binary files for I/O
14101444
14111445=begin original
14121446
14131447Arranges for FILEHANDLE to be read or written in "binary" or "text"
14141448mode on systems where the run-time libraries distinguish between
14151449binary and text files. If FILEHANDLE is an expression, the value is
14161450taken as the name of the filehandle. Returns true on success,
14171451otherwise it returns L<C<undef>|/undef EXPR> and sets
14181452L<C<$!>|perlvar/$!> (errno).
14191453
14201454=end original
14211455
14221456バイナリファイルとテキストファイルを区別する OS において、
14231457FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように
14241458指定します。
14251459FILEHANDLE が式である場合には、その式の値がファイルハンドルの
14261460名前として使われます。
14271461成功時には真を返し、失敗時には L<C<undef>|/undef EXPR> を返して
14281462L<C<$!>|perlvar/$!> (errno) を設定します。
14291463
14301464=begin original
14311465
14321466On some systems (in general, DOS- and Windows-based systems)
14331467L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
14341468working with a text file. For the sake of portability it is a good idea
14351469always to use it when appropriate, and never to use it when it isn't
14361470appropriate. Also, people can set their I/O to be by default
14371471UTF8-encoded Unicode, not bytes.
14381472
14391473=end original
14401474
14411475テキストファイルでないものを扱う場合に
14421476L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
14431477システムもあります(一般的には DOS と Windows ベースのシステムです)。
14441478移植性のために、適切なときには常にこれを使い、適切でないときには
14451479決して使わないというのは良い考えです。
14461480また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
14471481Unicode にセットすることも出来ます。
14481482
14491483=begin original
14501484
14511485In other words: regardless of platform, use
14521486L<C<binmode>|/binmode FILEHANDLE, LAYER> on binary data, like images,
14531487for example.
14541488
14551489=end original
14561490
14571491言い換えると: プラットフォームに関わらず、
14581492例えばイメージのようなバイナリファイルに対しては
14591493L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。
14601494
14611495=begin original
14621496
14631497If LAYER is present it is a single string, but may contain multiple
14641498directives. The directives alter the behaviour of the filehandle.
14651499When LAYER is present, using binmode on a text file makes sense.
14661500
14671501=end original
14681502
14691503LAYER が存在すると、それは単一の文字列ですが、複数の指示子を
14701504含むことができます。
14711505指示子はファイルハンドルの振る舞いを変更します。
14721506LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。
14731507
14741508=begin original
14751509
14761510If LAYER is omitted or specified as C<:raw> the filehandle is made
14771511suitable for passing binary data. This includes turning off possible CRLF
14781512translation and marking it as bytes (as opposed to Unicode characters).
14791513Note that, despite what may be implied in I<"Programming Perl"> (the
14801514Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>.
14811515Other layers that would affect the binary nature of the stream are
14821516I<also> disabled. See L<PerlIO>, and the discussion about the PERLIO
14831517environment variable in L<perlrun|perlrun/PERLIO>.
14841518
14851519=end original
14861520
14871521LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ
14881522データの通過に適するように設定されます。
14891523これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく)
14901524バイトであるとマークしたりすることを含みます。
14911525I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、
14921526C<:raw> は単なる C<:crlf> の I<逆ではありません>。
14931527ストリームのバイナリとしての性質に影響を与える
14941528I<その他の層も無効にされます>。
14951529L<PerlIO>, および L<perlrun|perlrun/PERLIO> の PERLIO 環境変数に関する議論を
14961530参照してください。
14971531
14981532=begin original
14991533
15001534The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the
15011535form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to
15021536establish default I/O layers.
15031537
15041538=end original
15051539
15061540C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は
15071541I/O I<層> が呼び出されます。
15081542L<open> プラグマはデフォルト I/O 層を指定するために使われます。
15091543
15101544=begin original
15111545
15121546I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER>
15131547function is described as "DISCIPLINE" in "Programming Perl, 3rd
15141548Edition". However, since the publishing of this book, by many known as
15151549"Camel III", the consensus of the naming of this functionality has moved
15161550from "discipline" to "layer". All documentation of this version of Perl
15171551therefore refers to "layers" rather than to "disciplines". Now back to
15181552the regularly scheduled documentation...>
15191553
15201554=end original
15211555
15221556I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは
15231557「プログラミングPerl 第 3 版」では
15241558「ディシプリン(DISCIPLINE)」と表現されていました。
15251559しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は
15261560「ディシプリン」から「層」に変更することで合意されました。
15271561従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく
15281562「層」と記述されています。では通常の解説に戻ります…>
15291563
15301564=begin original
15311565
15321566To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>.
15331567C<:utf8> just marks the data as UTF-8 without further checking,
15341568while C<:encoding(UTF-8)> checks the data for actually being valid
15351569UTF-8. More details can be found in L<PerlIO::encoding>.
15361570
15371571=end original
15381572
15391573FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か
15401574C<:encoding(UTF-8)> を使ってください。
15411575C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、
15421576C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。
15431577さらなる詳細は L<PerlIO::encoding> にあります。
15441578
15451579=begin original
15461580
15471581In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called
15481582after L<C<open>|/open FILEHANDLE,MODE,EXPR> but before any I/O is done on the
15491583filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally
15501584flushes any pending buffered output data (and perhaps pending input
15511585data) on the handle. An exception to this is the C<:encoding> layer
15521586that changes the default character encoding of the handle.
15531587The C<:encoding> layer sometimes needs to be called in
15541588mid-stream, and it doesn't flush the stream. C<:encoding>
15551589also implicitly pushes on top of itself the C<:utf8> layer because
15561590internally Perl operates on UTF8-encoded Unicode characters.
15571591
15581592=end original
15591593
15601594一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は
15611595L<C<open>|/open FILEHANDLE,MODE,EXPR> を呼び出した後、このファイルハンドルに
15621596対するI/O 操作をする前に呼び出すべきです。
15631597L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼び出すと、普通はこの
15641598ファイルハンドルに対してバッファリングされている全ての出力データ
15651599(およびおそらくは入力データ)をフラッシュします。
15661600例外は、このハンドルに対するデフォルト文字エンコーディングを変更する
15671601C<:encoding> 層です。
15681602C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、
15691603それによってストリームはフラッシュされません。
15701604Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、
15711605C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。
15721606
15731607=begin original
15741608
15751609The operating system, device drivers, C libraries, and Perl run-time
15761610system all conspire to let the programmer treat a single
15771611character (C<\n>) as the line terminator, irrespective of external
15781612representation. On many operating systems, the native text file
15791613representation matches the internal representation, but on some
15801614platforms the external representation of C<\n> is made up of more than
15811615one character.
15821616
15831617=end original
15841618
15851619オペレーティングシステム、デバイスドライバ、C ライブラリ、
15861620Perl ランタイムシステムは全て、プログラマが外部表現に関わらず
158716211 文字 (C<\n>) を行終端として扱えるように協調作業します。
15881622多くのオペレーティングシステムでは、ネイティブテキストファイル表現は
15891623内部表現と同じですが、C<\n> の外部表現が複数文字になる
15901624プラットフォームもあります。
15911625
15921626=begin original
15931627
15941628All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use
15951629a single character to end each line in the external representation of text
15961630(even though that single character is CARRIAGE RETURN on old, pre-Darwin
15971631flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other
15981632systems like OS/2, DOS, and the various flavors of MS-Windows, your program
15991633sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the
16001634two characters C<\cM\cJ>. That means that if you don't use
16011635L<C<binmode>|/binmode FILEHANDLE, LAYER> on these systems, C<\cM\cJ>
16021636sequences on disk will be converted to C<\n> on input, and any C<\n> in
16031637your program will be converted back to C<\cM\cJ> on output. This is
16041638what you want for text files, but it can be disastrous for binary files.
16051639
16061640=end original
16071641
16081642全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは
16091643テキストの外部表現として各行の末尾に一つの文字を
16101644使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、
16111645Unix とほとんどのVMS のファイルでは改行です)。
16121646VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、
16131647プログラムからは C<\n> は単純に C<\cJ> に見えますが、
16141648テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。
16151649つまり、もしこれらのシステムで L<C<binmode>|/binmode FILEHANDLE, LAYER> を
16161650使わないと、ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
16171651プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。
16181652これはテキストファイルの場合は思い通りの結果でしょうが、
16191653バイナリファイルの場合は悲惨です。
16201654
16211655=begin original
16221656
16231657Another consequence of using L<C<binmode>|/binmode FILEHANDLE, LAYER>
16241658(on some systems) is that special end-of-file markers will be seen as
16251659part of the data stream. For systems from the Microsoft family this
16261660means that, if your binary data contain C<\cZ>, the I/O subsystem will
16271661regard it as the end of the file, unless you use
16281662L<C<binmode>|/binmode FILEHANDLE, LAYER>.
16291663
16301664=end original
16311665
16321666L<C<binmode>|/binmode FILEHANDLE, LAYER> を(いくつかのシステムで)
16331667使うことによるその他の作用としては、特別なファイル終端マーカーが
16341668データストリームの一部として見られることです。
16351669Microsoft ファミリーのシステムでは、
16361670L<C<binmode>|/binmode FILEHANDLE, LAYER> を使っていないと、
16371671もしバイナリデータに C<\cZ> が含まれていたときに、
16381672I/O サブシステムがこれをファイル終端とみなすことを意味します。
16391673
16401674=begin original
16411675
16421676L<C<binmode>|/binmode FILEHANDLE, LAYER> is important not only for
16431677L<C<readline>|/readline EXPR> and L<C<print>|/print FILEHANDLE LIST>
16441678operations, but also when using
16451679L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16461680L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
16471681L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16481682L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and
16491683L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the
16501684L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in
16511685L<perlvar> for how to manually set your input and output
16521686line-termination sequences.
16531687
16541688=end original
16551689
16561690L<C<binmode>|/binmode FILEHANDLE, LAYER> は L<C<readline>|/readline EXPR> と
16571691L<C<print>|/print FILEHANDLE LIST> 操作にだけではなく、
16581692L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16591693L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
16601694L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16611695L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16621696L<C<tell>|/tell FILEHANDLE> を使うときにも重要です
16631697(詳細は L<perlport> を参照してください)。
16641698入出力の行端末シーケンスを手動でセットする方法については
16651699L<perlvar> の L<C<$E<sol>>|perlvar/$E<sol>> 変数と
16661700L<C<$\>|perlvar/$\> 変数を参照してください。
16671701
16681702=begin original
16691703
16701704Portability issues: L<perlport/binmode>.
16711705
16721706=end original
16731707
16741708移植性の問題: L<perlport/binmode>。
16751709
16761710=item bless REF,CLASSNAME
16771711X<bless>
16781712
16791713=item bless REF
16801714
16811715=for Pod::Functions create an object
16821716
16831717=begin original
16841718
16851719This function tells the thingy referenced by REF that it is now an object
16861720in the CLASSNAME package. If CLASSNAME is an empty string, it is
16871721interpreted as referring to the C<main> package.
16881722If CLASSNAME is omitted, the current package
16891723is used. Because a L<C<bless>|/bless REF,CLASSNAME> is often the last
16901724thing in a constructor, it returns the reference for convenience.
16911725Always use the two-argument version if a derived class might inherit the
16921726method doing the blessing. See L<perlobj> for more about the blessing
16931727(and blessings) of objects.
16941728
16951729=end original
16961730
16971731この関数は、REF で渡された オブジェクトに対し、
16981732CLASSNAME 内のオブジェクトとなったことを伝えます。
16991733CLASSNAME が空文字列の場合、C<main> パッケージを参照しているものと
17001734解釈されます。
17011735CLASSNAME が省略された場合には、その時点のパッケージとなります。
17021736L<C<bless>|/bless REF,CLASSNAME> は通常、コンストラクタの最後に
17031737置かれますので、簡便のためにそのリファレンスを返します。
17041738派生クラスが bless されるメソッドを継承する場合は、
17051739常に 2 引数版を使ってください。
17061740オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を
17071741参照してください。
17081742
17091743=begin original
17101744
17111745Consider always blessing objects in CLASSNAMEs that are mixed case.
17121746Namespaces with all lowercase names are considered reserved for
17131747Perl pragmas. Builtin types have all uppercase names. To prevent
17141748confusion, you may wish to avoid such package names as well.
17151749It is advised to avoid the class name C<0>, because much code erroneously
17161750uses the result of L<C<ref>|/ref EXPR> as a truth value.
17171751
17181752=end original
17191753
17201754大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを
17211755考慮してください。
17221756全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。
17231757組み込みの型は全て大文字の名前を持ちます。
17241758混乱を避けるために、
17251759パッケージ名としてこのような名前は避けるべきです。
1726CLASSNAME は真の値を持つようにしてください
1760CLASSNAME は真の値を持つようにしてください;
17271761クラス名として C<0> は避けてください; 多くのコードが誤って
17281762L<C<ref>|/ref EXPR> の結果を真の値として使っているからです。
17291763
17301764=begin original
17311765
17321766See L<perlmod/"Perl Modules">.
17331767
17341768=end original
17351769
17361770L<perlmod/"Perl Modules"> を参照してください。
17371771
17381772=item break
17391773
17401774=for Pod::Functions +switch break out of a C<given> block
17411775
17421776=begin original
17431777
17441778Break out of a C<given> block.
17451779
17461780=end original
17471781
17481782C<given> ブロックから脱出します。
17491783
17501784=begin original
17511785
17521786L<C<break>|/break> is available only if the
17531787L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it
17541788is prefixed with C<CORE::>. The
17551789L<C<"switch"> feature|feature/The 'switch' feature> is enabled
17561790automatically with a C<use v5.10> (or higher) declaration in the current
17571791scope.
17581792
17591793=end original
17601794
17611795L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature> が
17621796有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。
17631797L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで
17641798C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
17651799
17661800=item caller EXPR
17671801X<caller> X<call stack> X<stack> X<stack trace>
17681802
17691803=item caller
17701804
17711805=for Pod::Functions get context of the current subroutine call
17721806
17731807=begin original
17741808
17751809Returns the context of the current pure perl subroutine call. In scalar
17761810context, returns the caller's package name if there I<is> a caller (that is, if
17771811we're in a subroutine or L<C<eval>|/eval EXPR> or
17781812L<C<require>|/require VERSION>) and the undefined value otherwise.
17791813caller never returns XS subs and they are skipped. The next pure perl
17801814sub will appear instead of the XS sub in caller's return values. In
17811815list context, caller returns
17821816
17831817=end original
17841818
17851819その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。
17861820スカラコンテキストでは、呼び元が I<ある> 場合
17871821(サブルーチン、L<C<eval>|/eval EXPR>、L<C<require>|/require VERSION> の中に
17881822いるとき) には呼び出し元のパッケージ名を返し、
17891823その他のときには未定義値を返します。
17901824caller は XS サブルーチンを返すことはなく、それらは飛ばされます。
17911825XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に
17921826なります。
17931827リストコンテキストでは、caller は以下を返します:
17941828
17951829 # 0 1 2
17961830 my ($package, $filename, $line) = caller;
17971831
17981832=begin original
17991833
18001834Like L<C<__FILE__>|/__FILE__> and L<C<__LINE__>|/__LINE__>, the filename and
18011835line number returned here may be altered by the mechanism described at
18021836L<perlsyn/"Plain Old Comments (Not!)">.
18031837
18041838=end original
18051839
18061840L<C<__FILE__>|/__FILE__> と L<C<__LINE__>|/__LINE__> 同様、
18071841ここで返されるファイル名と行番号は
18081842L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構によって
18091843置き換えられます。
18101844
18111845=begin original
18121846
18131847With EXPR, it returns some extra information that the debugger uses to
18141848print a stack trace. The value of EXPR indicates how many call frames
18151849to go back before the current one.
18161850
18171851=end original
18181852
18191853EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。
18201854EXPR の値は、現状から数えて、
18211855いくつ前のコールフレームまで戻るかを示します。
18221856
18231857 # 0 1 2 3 4
18241858 my ($package, $filename, $line, $subroutine, $hasargs,
18251859
18261860 # 5 6 7 8 9 10
18271861 $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
18281862 = caller($i);
18291863
18301864=begin original
18311865
18321866Here, $subroutine is the function that the caller called (rather than the
18331867function containing the caller). Note that $subroutine may be C<(eval)> if
18341868the frame is not a subroutine call, but an L<C<eval>|/eval EXPR>. In
18351869such a case additional elements $evaltext and C<$is_require> are set:
18361870C<$is_require> is true if the frame is created by a
18371871L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>
18381872statement, $evaltext contains the text of the C<eval EXPR> statement.
18391873In particular, for an C<eval BLOCK> statement, $subroutine is C<(eval)>,
18401874but $evaltext is undefined. (Note also that each
18411875L<C<use>|/use Module VERSION LIST> statement creates a
18421876L<C<require>|/require VERSION> frame inside an C<eval EXPR> frame.)
18431877$subroutine may also be C<(unknown)> if this particular subroutine
18441878happens to have been deleted from the symbol table. C<$hasargs> is true
18451879if a new instance of L<C<@_>|perlvar/@_> was set up for the frame.
18461880C<$hints> and C<$bitmask> contain pragmatic hints that the caller was
18471881compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and
18481882C<$bitmask> corresponds to
18491883L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and
18501884C<$bitmask> values are subject to change between versions of Perl, and
18511885are not meant for external use.
18521886
18531887=end original
18541888
18551889ここで、$subroutine は、(caller を含む関数ではなく) caller が呼び出した
18561890関数です。
18571891フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この
18581892$subroutine は C<(eval)> になることに注意してください。
18591893この場合、追加の要素である $evaltext と C<$is_require> がセットされます:
18601894C<$is_require> はフレームが L<C<require>|/require VERSION> または
18611895L<C<use>|/use Module VERSION LIST> で作られた場合に真になり、
18621896$evaltext は C<eval EXPR> のテキストが入ります。
18631897特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、
18641898$evaltext は未定義値になります。
18651899(それぞれの L<C<use>|/use Module VERSION LIST> は C<eval EXPR> の中で
18661900L<C<require>|/require VERSION> フレームを作ることに注意してください。)
18671901$subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は
18681902C<(unknown)> になります。
18691903C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が
18701904設定された場合に真となります。
18711905C<$hints> と C<$bitmask> は caller がコンパイルされたときの
18721906実際的なヒントを含みます。
18731907C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は
18741908L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に
18751909対応します。
18761910C<$hints> は C<$bitmask> は Perl のバージョンによって変更される
18771911可能性があるので、外部での使用を想定していません。
18781912
18791913=begin original
18801914
18811915C<$hinthash> is a reference to a hash containing the value of
18821916L<C<%^H>|perlvar/%^H> when the caller was compiled, or
18831917L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not
18841918modify the values of this hash, as they are the actual values stored in
18851919the optree.
18861920
18871921=end original
18881922
18891923C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を
18901924含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は
18911925L<C<undef>|/undef EXPR> です。
18921926このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。
18931927
18941928=begin original
18951929
1930Note that the only types of call frames that are visible are subroutine
1931calls and C<eval>. Other forms of context, such as C<while> or C<foreach>
1932loops or C<try> blocks are not considered interesting to C<caller>, as they
1933do not alter the behaviour of the C<return> expression.
1934
1935=end original
1936
1937見ることができる呼び出しフレームの種類はサブルーチン呼び出しと
1938C<eval> だけであることに注意してください。
1939C<while> や C<foreach> のループや C<try> ブロックのようなその他の構造は、
1940C<caller> の関心外です; これらは C<return> 式の振る舞いを変えないからです。
1941
1942=begin original
1943
18961944Furthermore, when called from within the DB package in
18971945list context, and with an argument, caller returns more
18981946detailed information: it sets the list variable C<@DB::args> to be the
18991947arguments with which the subroutine was invoked.
19001948
19011949=end original
19021950
19031951さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、
19041952caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を
19051953変数 C<@DB::args> に設定します。
19061954
19071955=begin original
19081956
19091957Be aware that the optimizer might have optimized call frames away before
19101958L<C<caller>|/caller EXPR> had a chance to get the information. That
19111959means that C<caller(N)> might not return information about the call
19121960frame you expect it to, for C<< N > 1 >>. In particular, C<@DB::args>
19131961might have information from the previous time L<C<caller>|/caller EXPR>
19141962was called.
19151963
19161964=end original
19171965
19181966L<C<caller>|/caller EXPR> が情報を得る前にオプティマイザが呼び出しフレームを
19191967最適化してしまうかもしれないことに注意してください。
19201968これは、C<caller(N)> が C<< N > 1 >> のとき、
19211969あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。
19221970特に、C<@DB::args> は L<C<caller>|/caller EXPR> が前回呼び出された時の情報を
19231971持っているかもしれません。
19241972
19251973=begin original
19261974
19271975Be aware that setting C<@DB::args> is I<best effort>, intended for
19281976debugging or generating backtraces, and should not be relied upon. In
19291977particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's
19301978arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so
19311979C<@DB::args> will contain modifications the subroutine makes to
19321980L<C<@_>|perlvar/@_> or its contents, not the original values at call
19331981time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit
19341982references to its elements, so under certain cases its elements may have
19351983become freed and reallocated for other variables or temporary values.
19361984Finally, a side effect of the current implementation is that the effects
19371985of C<shift @_> can I<normally> be undone (but not C<pop @_> or other
19381986splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been
19391987taken, I<and> subject to the caveat about reallocated elements), so
19401988C<@DB::args> is actually a hybrid of the current state and initial state
19411989of L<C<@_>|perlvar/@_>. Buyer beware.
19421990
19431991=end original
19441992
19451993C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの
19461994生成を目的としていて、これに依存するべきではないということにも
19471995注意してください。
19481996特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、
19491997Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は
19501998サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、
19511999呼び出し時の元の値ではありません。
19522000C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、その要素への明示的な
19532001リファレンスを保持しないので、ある種の状況では、解放されて他の変数や
19542002一時的な値のために再割り当てされているかもしれません。
19552003最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない
19562004(しかし C<pop @_> やその他の splice は違い、I<そして> もし
19572005L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた
19582006要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の
19592007状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。
19602008ご用心を。
19612009
19622010=item chdir EXPR
19632011X<chdir>
19642012X<cd>
19652013X<directory, change>
19662014
19672015=item chdir FILEHANDLE
19682016
19692017=item chdir DIRHANDLE
19702018
19712019=item chdir
19722020
19732021=for Pod::Functions change your current working directory
19742022
19752023=begin original
19762024
19772025Changes the working directory to EXPR, if possible. If EXPR is omitted,
19782026changes to the directory specified by C<$ENV{HOME}>, if set; if not,
19792027changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the
19802028variable C<$ENV{'SYS$LOGIN'}> is also checked, and used if it is set.) If
19812029neither is set, L<C<chdir>|/chdir EXPR> does nothing and fails. It
19822030returns true on success, false otherwise. See the example under
19832031L<C<die>|/die LIST>.
19842032
19852033=end original
19862034
19872035(可能であれば、) カレントディレクトリを EXPR に移します。
19882036EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに
19892037移ります; そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに
19902038移ります。
19912039(VMS では C<$ENV{'SYS$LOGIN'}> もチェックされ、もしセットされていれば
19922040使われます。)
19932041どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗します。
19942042成功時には真を返し、そうでなければ偽を返します。
19952043L<C<die>|/die LIST> の項の例を参照してください。
19962044
19972045=begin original
19982046
19992047On systems that support L<fchdir(2)>, you may pass a filehandle or
20002048directory handle as the argument. On systems that don't support L<fchdir(2)>,
20012049passing handles raises an exception.
20022050
20032051=end original
20042052
20052053L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや
20062054ディレクトリハンドルを引数として渡せます。
20072055L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。
20082056
20092057=item chmod LIST
20102058X<chmod> X<permission> X<mode>
20112059
20122060=for Pod::Functions changes the permissions on a list of files
20132061
20142062=begin original
20152063
20162064Changes the permissions of a list of files. The first element of the
20172065list must be the numeric mode, which should probably be an octal
20182066number, and which definitely should I<not> be a string of octal digits:
20192067C<0644> is okay, but C<"0644"> is not. Returns the number of files
20202068successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a
20212069string.
20222070
20232071=end original
20242072
20252073LIST に含まれるファイルの、パーミッションを変更します。
20262074LIST の最初の要素は、数値表現のモードでなければなりません;
20272075恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の
20282076文字列では I<いけません>: C<0644> は OK ですが、 C<"0644"> は
20292077だめ、ということです。
20302078変更に成功したファイルの数を返します。
20312079文字列を使いたい場合は、L<C<oct>|/oct EXPR> を参照してください。
20322080
20332081 my $cnt = chmod 0755, "foo", "bar";
20342082 chmod 0755, @executables;
20352083 my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
20362084 # --w----r-T
20372085 my $mode = "0644"; chmod oct($mode), "foo"; # this is better
20382086 my $mode = 0644; chmod $mode, "foo"; # this is best
20392087
20402088=begin original
20412089
20422090On systems that support L<fchmod(2)>, you may pass filehandles among the
20432091files. On systems that don't support L<fchmod(2)>, passing filehandles raises
20442092an exception. Filehandles must be passed as globs or glob references to be
20452093recognized; barewords are considered filenames.
20462094
20472095=end original
20482096
20492097L<fchmod(2)> に対応しているシステムでは、ファイルハンドルを引数として
20502098渡せます。
20512099L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと
20522100例外が発生します。
20532101ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
20542102渡されなければなりません;
20552103裸の単語はファイル名として扱われます。
20562104
20572105 open(my $fh, "<", "foo");
20582106 my $perm = (stat $fh)[2] & 07777;
20592107 chmod($perm | 0600, $fh);
20602108
20612109=begin original
20622110
20632111You can also import the symbolic C<S_I*> constants from the
20642112L<C<Fcntl>|Fcntl> module:
20652113
20662114=end original
20672115
20682116L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を
20692117インポートすることもできます:
20702118
20712119 use Fcntl qw( :mode );
20722120 chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
20732121 # Identical to the chmod 0755 of the example above.
20742122
20752123=begin original
20762124
20772125Portability issues: L<perlport/chmod>.
20782126
20792127=end original
20802128
20812129移植性の問題: L<perlport/chmod>。
20822130
20832131=item chomp VARIABLE
20842132X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol>
20852133
20862134=item chomp( LIST )
20872135
20882136=item chomp
20892137
20902138=for Pod::Functions remove a trailing record separator from a string
20912139
20922140=begin original
20932141
20942142This safer version of L<C<chop>|/chop VARIABLE> removes any trailing
20952143string that corresponds to the current value of
20962144L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR>
20972145in the L<C<English>|English> module). It returns the total
20982146number of characters removed from all its arguments. It's often used to
20992147remove the newline from the end of an input record when you're worried
21002148that the final record may be missing its newline. When in paragraph
21012149mode (C<$/ = ''>), it removes all trailing newlines from the string.
21022150When in slurp mode (C<$/ = undef>) or fixed-length record mode
21032151(L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like;
21042152see L<perlvar>), L<C<chomp>|/chomp VARIABLE> won't remove anything.
21052153If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example:
21062154
21072155=end original
21082156
21092157より安全な L<C<chop>|/chop VARIABLE> (以下を参照してください) です;
21102158L<C<$E<sol>>|perlvar/$E<sol>> (L<C<English>|English> モジュールでは、
21112159C<$INPUT_RECORD_SEPARATOR> とも言う) のその時点の
21122160値に対応する行末文字を削除します。
21132161全ての引数から削除した文字数の合計を返します。
21142162入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が
21152163入っているのかわからないような場合に、使用できます。
21162164段落モード (C<$/ = ''>) では、レコードの最後の改行をすべて取り除きます。
21172165吸い込みモード (C<$/ = undef>) や 固定長レコードモード
21182166(L<C<$E<sol>>|perlvar/$E<sol>> が整数へのリファレンスや類似のものの場合;
21192167L<perlvar>を参照してください)では、L<C<chomp>|/chomp VARIABLE> は
21202168何も取り除きません。
21212169VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。
21222170例:
21232171
21242172 while (<>) {
21252173 chomp; # avoid \n on last field
21262174 my @array = split(/:/);
21272175 # ...
21282176 }
21292177
21302178=begin original
21312179
21322180If VARIABLE is a hash, it chomps the hash's values, but not its keys,
21332181resetting the L<C<each>|/each HASH> iterator in the process.
21342182
21352183=end original
21362184
21372185VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し、
21382186このプロセスの L<C<each>|/each HASH> 反復子をリセットします。
21392187
21402188=begin original
21412189
21422190You can actually chomp anything that's an lvalue, including an assignment:
21432191
21442192=end original
21452193
21462194左辺値であれば、代入を含めて、任意のものを chomp できます:
21472195
21482196 chomp(my $cwd = `pwd`);
21492197 chomp(my $answer = <STDIN>);
21502198
21512199=begin original
21522200
21532201If you chomp a list, each element is chomped, and the total number of
21542202characters removed is returned.
21552203
21562204=end original
21572205
21582206リストを chomp すると、個々の要素が chomp され、
21592207削除された文字数の合計が返されます。
21602208
21612209=begin original
21622210
21632211Note that parentheses are necessary when you're chomping anything
21642212that is not a simple variable. This is because C<chomp $cwd = `pwd`;>
21652213is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as
21662214C<chomp( $cwd = `pwd` )> which you might expect. Similarly,
21672215C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than
21682216as C<chomp($a, $b)>.
21692217
21702218=end original
21712219
21722220単純な変数以外のものを chomp する場合はかっこが必要であることに
21732221注意してください。
21742222これは、C<chomp $cwd = `pwd`;> は、予測している
21752223C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と
21762224解釈されるからです。
21772225同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b>
21782226と解釈されます。
21792227
21802228=item chop VARIABLE
21812229X<chop>
21822230
21832231=item chop( LIST )
21842232
21852233=item chop
21862234
21872235=for Pod::Functions remove the last character from a string
21882236
21892237=begin original
21902238
21912239Chops off the last character of a string and returns the character
21922240chopped. It is much more efficient than C<s/.$//s> because it neither
21932241scans nor copies the string. If VARIABLE is omitted, chops
21942242L<C<$_>|perlvar/$_>.
21952243If VARIABLE is a hash, it chops the hash's values, but not its keys,
21962244resetting the L<C<each>|/each HASH> iterator in the process.
21972245
21982246=end original
21992247
22002248文字列の最後の文字を切り捨てて、その切り取った文字を返します。
22012249文字列の検索もコピーも行ないませんので
22022250C<s/.$//s> よりも、ずっと効率的です。
22032251VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chop します。
22042252VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、
22052253このプロセスの L<C<each>|/each HASH> 反復子をリセットします。
22062254
22072255=begin original
22082256
22092257You can actually chop anything that's an lvalue, including an assignment.
22102258
22112259=end original
22122260
22132261実際のところ、代入を含む左辺値となりうるなんでも chop できます。
22142262
22152263=begin original
22162264
22172265If you chop a list, each element is chopped. Only the value of the
22182266last L<C<chop>|/chop VARIABLE> is returned.
22192267
22202268=end original
22212269
22222270リストを chop すると、個々の要素が chop されます。
22232271最後の L<C<chop>|/chop VARIABLE> の値だけが返されます。
22242272
22252273=begin original
22262274
22272275Note that L<C<chop>|/chop VARIABLE> returns the last character. To
22282276return all but the last character, use C<substr($string, 0, -1)>.
22292277
22302278=end original
22312279
22322280L<C<chop>|/chop VARIABLE> は最後の文字を返すことに注意してください。
22332281最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を
22342282使ってください。
22352283
22362284=begin original
22372285
22382286See also L<C<chomp>|/chomp VARIABLE>.
22392287
22402288=end original
22412289
22422290L<C<chomp>|/chomp VARIABLE> も参照してください。
22432291
22442292=item chown LIST
22452293X<chown> X<owner> X<user> X<group>
22462294
22472295=for Pod::Functions change the ownership on a list of files
22482296
22492297=begin original
22502298
22512299Changes the owner (and group) of a list of files. The first two
22522300elements of the list must be the I<numeric> uid and gid, in that
22532301order. A value of -1 in either position is interpreted by most
22542302systems to leave that value unchanged. Returns the number of files
22552303successfully changed.
22562304
22572305=end original
22582306
22592307LIST に含まれるファイルの所有者 (とグループ) を変更します。
22602308LIST の最初の二つの要素には、I<数値表現> の uid と gid を
22612309この順序で与えなければなりません。
22622310どちらかの値を -1 にすると、ほとんどのシステムではその値は
22632311変更しないと解釈します。
22642312変更に成功したファイルの数を返します。
22652313
22662314 my $cnt = chown $uid, $gid, 'foo', 'bar';
22672315 chown $uid, $gid, @filenames;
22682316
22692317=begin original
22702318
22712319On systems that support L<fchown(2)>, you may pass filehandles among the
22722320files. On systems that don't support L<fchown(2)>, passing filehandles raises
22732321an exception. Filehandles must be passed as globs or glob references to be
22742322recognized; barewords are considered filenames.
22752323
22762324=end original
22772325
22782326L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。
22792327L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと
22802328例外が発生します。
22812329ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
22822330渡されなければなりません; 裸の単語はファイル名として扱われます。
22832331
22842332=begin original
22852333
22862334Here's an example that looks up nonnumeric uids in the passwd file:
22872335
22882336=end original
22892337
22902338passwd ファイルから数値表現でない uid を検索する例を
22912339示します:
22922340
22932341 print "User: ";
22942342 chomp(my $user = <STDIN>);
22952343 print "Files: ";
22962344 chomp(my $pattern = <STDIN>);
22972345
22982346 my ($login,$pass,$uid,$gid) = getpwnam($user)
22992347 or die "$user not in passwd file";
23002348
23012349 my @ary = glob($pattern); # expand filenames
23022350 chown $uid, $gid, @ary;
23032351
23042352=begin original
23052353
23062354On most systems, you are not allowed to change the ownership of the
23072355file unless you're the superuser, although you should be able to change
23082356the group to any of your secondary groups. On insecure systems, these
23092357restrictions may be relaxed, but this is not a portable assumption.
23102358On POSIX systems, you can detect this condition this way:
23112359
23122360=end original
23132361
23142362ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を
23152363変更できますが、グループは実行者の副グループに変更できるべきです。
23162364安全でないシステムでは、この制限はゆるめられています; しかしこれは
23172365移植性のある仮定ではありません。
23182366POSIX システムでは、以下のようにしてこの条件を検出できます:
23192367
23202368 use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
23212369 my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED);
23222370
23232371=begin original
23242372
23252373Portability issues: L<perlport/chown>.
23262374
23272375=end original
23282376
23292377移植性の問題: L<perlport/chown>。
23302378
23312379=item chr NUMBER
23322380X<chr> X<character> X<ASCII> X<Unicode>
23332381
23342382=item chr
23352383
23362384=for Pod::Functions get character this number represents
23372385
23382386=begin original
23392387
23402388Returns the character represented by that NUMBER in the character set.
23412389For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and
23422390chr(0x263a) is a Unicode smiley face.
23432391
23442392=end original
23452393
23462394特定の文字セットでの NUMBER で表わされる文字を返します。
23472395たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります;
23482396chr(0x263a) は Unicode のスマイリーフェイスです。
23492397
23502398=begin original
23512399
23522400Negative values give the Unicode replacement character (chr(0xfffd)),
23532401except under the L<bytes> pragma, where the low eight bits of the value
23542402(truncated to an integer) are used.
23552403
23562404=end original
23572405
23582406負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、
23592407L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが
23602408使われます。
23612409
23622410=begin original
23632411
23642412If NUMBER is omitted, uses L<C<$_>|perlvar/$_>.
23652413
23662414=end original
23672415
23682416NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。
23692417
23702418=begin original
23712419
23722420For the reverse, use L<C<ord>|/ord EXPR>.
23732421
23742422=end original
23752423
23762424逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。
23772425
23782426=begin original
23792427
23802428Note that characters from 128 to 255 (inclusive) are by default
23812429internally not encoded as UTF-8 for backward compatibility reasons.
23822430
23832431=end original
23842432
23852433128 から 255 までの文字は過去との互換性のために
23862434デフォルトでは UTF-8 Unicode にエンコードされません。
23872435
23882436=begin original
23892437
23902438See L<perlunicode> for more about Unicode.
23912439
23922440=end original
23932441
23942442Unicode については L<perlunicode> を参照してください。
23952443
23962444=item chroot FILENAME
23972445X<chroot> X<root>
23982446
23992447=item chroot
24002448
24012449=for Pod::Functions make directory new root for path lookups
24022450
24032451=begin original
24042452
24052453This function works like the system call by the same name: it makes the
24062454named directory the new root directory for all further pathnames that
24072455begin with a C</> by your process and all its children. (It doesn't
24082456change your current working directory, which is unaffected.) For security
24092457reasons, this call is restricted to the superuser. If FILENAME is
24102458omitted, does a L<C<chroot>|/chroot FILENAME> to L<C<$_>|perlvar/$_>.
24112459
24122460=end original
24132461
24142462同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに
24152463対して、C</>で始まるパス名に関して指定されたディレクトリを新しい
24162464ルートディレクトリとして扱います。
24172465(これはカレントディレクトリを変更しません; カレントディレクトリは
24182466そのままです。)
24192467セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。
24202468FILENAME を省略すると、L<C<$_>|perlvar/$_> へ
24212469L<C<chroot>|/chroot FILENAME> します。
24222470
24232471=begin original
24242472
24252473B<NOTE:> It is mandatory for security to C<chdir("/")>
24262474(L<C<chdir>|/chdir EXPR> to the root directory) immediately after a
24272475L<C<chroot>|/chroot FILENAME>, otherwise the current working directory
24282476may be outside of the new root.
24292477
24302478=end original
24312479
24322480B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに
24332481L<C<chdir>|/chdir EXPR> する)
24342482C<chdir("/")> するのはセキュリティ上必須です;
24352483さもなければ現在の作業ディレクトリは新しいルートの外側かもしれません。
24362484
24372485=begin original
24382486
24392487Portability issues: L<perlport/chroot>.
24402488
24412489=end original
24422490
24432491移植性の問題: L<perlport/chroot>。
24442492
24452493=item close FILEHANDLE
24462494X<close>
24472495
24482496=item close
24492497
24502498=for Pod::Functions close file (or pipe or socket) handle
24512499
24522500=begin original
24532501
24542502Closes the file or pipe associated with the filehandle, flushes the IO
24552503buffers, and closes the system file descriptor. Returns true if those
24562504operations succeed and if no error was reported by any PerlIO
24572505layer. Closes the currently selected filehandle if the argument is
24582506omitted.
24592507
24602508=end original
24612509
24622510FILEHANDLE に対応したファイルまたはパイプをクローズして、
24632511IO バッファをフラッシュし、システムファイル記述子をクローズします。
24642512操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。
24652513引数が省略された場合、現在選択されているファイルハンドルをクローズします。
24662514
24672515=begin original
24682516
24692517You don't have to close FILEHANDLE if you are immediately going to do
24702518another L<C<open>|/open FILEHANDLE,MODE,EXPR> on it, because
24712519L<C<open>|/open FILEHANDLE,MODE,EXPR> closes it for you. (See
24722520L<C<open>|/open FILEHANDLE,MODE,EXPR>.) However, an explicit
24732521L<C<close>|/close FILEHANDLE> on an input file resets the line counter
24742522(L<C<$.>|perlvar/$.>), while the implicit close done by
24752523L<C<open>|/open FILEHANDLE,MODE,EXPR> does not.
24762524
24772525=end original
24782526
24792527クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう
24802528場合には、L<C<open>|/open FILEHANDLE,MODE,EXPR> が自動的に
24812529L<C<close>|/close FILEHANDLE> を行ないますので、
24822530close FILEHANDLE する必要はありません。
24832531(L<C<open>|/open FILEHANDLE,MODE,EXPR> を参照してください。)
24842532ただし、明示的にクローズを行なったときにのみ入力ファイルの
24852533行番号 (L<C<$.>|perlvar/$.>) のリセットが行なわれ、
24862534L<C<open>|/open FILEHANDLE,MODE,EXPR> によって行なわれる
24872535暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。
24882536
24892537=begin original
24902538
24912539If the filehandle came from a piped open, L<C<close>|/close FILEHANDLE>
24922540returns false if one of the other syscalls involved fails or if its
24932541program exits with non-zero status. If the only problem was that the
24942542program exited non-zero, L<C<$!>|perlvar/$!> will be set to C<0>.
24952543Closing a pipe also waits for the process executing on the pipe to
24962544exit--in case you wish to look at the output of the pipe afterwards--and
24972545implicitly puts the exit status value of that command into
24982546L<C<$?>|perlvar/$?> and
24992547L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
25002548
25012549=end original
25022550
25032551ファイルハンドルがパイプつきオープンなら、L<C<close>|/close FILEHANDLE> は
25042552その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した
25052553場合にも偽を返します。
25062554プログラムが非ゼロで終了しただけの場合は、L<C<$!>|perlvar/$!> が C<0> に
25072555セットされます。
25082556後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で
25092557実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を
25102558L<C<$?>|perlvar/$?> と
25112559L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。
25122560
25132561=begin original
25142562
25152563If there are multiple threads running, L<C<close>|/close FILEHANDLE> on
25162564a filehandle from a piped open returns true without waiting for the
25172565child process to terminate, if the filehandle is still open in another
25182566thread.
25192567
25202568=end original
25212569
25222570複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する
25232571L<C<close>|/close FILEHANDLE> は、そのファイルハンドルが他のスレッドで
25242572まだ開かれている場合、子プロセスの終了を待たずに真を返します。
25252573
25262574=begin original
25272575
25282576Closing the read end of a pipe before the process writing to it at the
25292577other end is done writing results in the writer receiving a SIGPIPE. If
25302578the other end can't handle that, be sure to read all the data before
25312579closing the pipe.
25322580
25332581=end original
25342582
25352583書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、
25362584書き込み側に SIGPIPE が配送されます。
25372585書き込み側がこれを扱えない場合、パイプを閉じる前に
25382586確実に全てのデータが読み込まれるようにする必要があります。
25392587
25402588=begin original
25412589
25422590Example:
25432591
25442592=end original
25452593
25462594例:
25472595
25482596 open(OUTPUT, '|sort >foo') # pipe to sort
25492597 or die "Can't start sort: $!";
25502598 #... # print stuff to output
25512599 close OUTPUT # wait for sort to finish
25522600 or warn $! ? "Error closing sort pipe: $!"
25532601 : "Exit status $? from sort";
25542602 open(INPUT, 'foo') # get sort's results
25552603 or die "Can't open 'foo' for input: $!";
25562604
25572605=begin original
25582606
25592607FILEHANDLE may be an expression whose value can be used as an indirect
25602608filehandle, usually the real filehandle name or an autovivified handle.
25612609
25622610=end original
25632611
25642612FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと
25652613して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。
25662614
25672615=item closedir DIRHANDLE
25682616X<closedir>
25692617
25702618=for Pod::Functions close directory handle
25712619
25722620=begin original
25732621
25742622Closes a directory opened by L<C<opendir>|/opendir DIRHANDLE,EXPR> and
25752623returns the success of that system call.
25762624
25772625=end original
25782626
25792627L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリをクローズし、
25802628システムコールの返り値を返します。
25812629
25822630=item connect SOCKET,NAME
25832631X<connect>
25842632
25852633=for Pod::Functions connect to a remote socket
25862634
25872635=begin original
25882636
25892637Attempts to connect to a remote socket, just like L<connect(2)>.
25902638Returns true if it succeeded, false otherwise. NAME should be a
25912639packed address of the appropriate type for the socket. See the examples in
25922640L<perlipc/"Sockets: Client/Server Communication">.
25932641
25942642=end original
25952643
25962644L<connect(2)> システムコールと同様に、リモートソケットへの接続を試みます。
25972645成功時には真を、さもなければ偽を返します。
25982646NAME は、ソケットに対する、適切な型のパックされた
25992647アドレスでなければなりません。
26002648L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
26012649
26022650=item continue BLOCK
26032651X<continue>
26042652
26052653=item continue
26062654
26072655=for Pod::Functions optional trailing block in a while or foreach
26082656
26092657=begin original
26102658
26112659When followed by a BLOCK, L<C<continue>|/continue BLOCK> is actually a
26122660flow control statement rather than a function. If there is a
26132661L<C<continue>|/continue BLOCK> BLOCK attached to a BLOCK (typically in a
26142662C<while> or C<foreach>), it is always executed just before the
26152663conditional is about to be evaluated again, just like the third part of
26162664a C<for> loop in C. Thus it can be used to increment a loop variable,
26172665even when the loop has been continued via the L<C<next>|/next LABEL>
26182666statement (which is similar to the C L<C<continue>|/continue BLOCK>
26192667statement).
26202668
26212669=end original
26222670
26232671BLOCK が引き続く場合、L<C<continue>|/continue BLOCK> は実際には関数ではなく、
26242672実行制御文です。
26252673L<C<continue>|/continue BLOCK> BLOCK が BLOCK (典型的には C<while> または
26262674C<foreach> の中)にあると、これは条件文が再評価される直前に常に実行されます;
26272675これは C における C<for> ループの 3 番目の部分と同様です。
26282676従って、これは L<C<next>|/next LABEL> 文 (これは C の
26292677L<C<continue>|/continue BLOCK> 文と似ています) を使って
26302678ループが繰り返されるときでもループ変数を増やしたいときに使えます。
26312679
26322680=begin original
26332681
26342682L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, or
26352683L<C<redo>|/redo LABEL> may appear within a
26362684L<C<continue>|/continue BLOCK> block; L<C<last>|/last LABEL> and
26372685L<C<redo>|/redo LABEL> behave as if they had been executed within the
26382686main block. So will L<C<next>|/next LABEL>, but since it will execute a
26392687L<C<continue>|/continue BLOCK> block, it may be more entertaining.
26402688
26412689=end original
26422690
26432691L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
26442692L<C<continue>|/continue BLOCK> ブロック内に現れる可能性があります;
26452693L<C<last>|/last LABEL> と L<C<redo>|/redo LABEL> はメインブロックの中で
26462694実行されたのと同じように振舞います。
26472695L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを
26482696実行することになるので、より面白いことになります。
26492697
26502698 while (EXPR) {
26512699 ### redo always comes here
26522700 do_something;
26532701 } continue {
26542702 ### next always comes here
26552703 do_something_else;
26562704 # then back the top to re-check EXPR
26572705 }
26582706 ### last always comes here
26592707
26602708=begin original
26612709
26622710Omitting the L<C<continue>|/continue BLOCK> section is equivalent to
26632711using an empty one, logically enough, so L<C<next>|/next LABEL> goes
26642712directly back to check the condition at the top of the loop.
26652713
26662714=end original
26672715
26682716L<C<continue>|/continue BLOCK> 節を省略するのは、空の節を指定したのと同じで、
26692717論理的には十分なので、この場合、L<C<next>|/next LABEL> は直接ループ先頭の
26702718条件チェックに戻ります。
26712719
26722720=begin original
26732721
26742722When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function
26752723that falls through the current C<when> or C<default> block instead of
26762724iterating a dynamically enclosing C<foreach> or exiting a lexically
26772725enclosing C<given>. In Perl 5.14 and earlier, this form of
26782726L<C<continue>|/continue BLOCK> was only available when the
26792727L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See
26802728L<feature> and L<perlsyn/"Switch Statements"> for more information.
26812729
26822730=end original
26832731
26842732BLOCK がなければ、L<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や
26852733レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または
26862734C<default> のブロックを通り抜けるための文です。
26872735Perl 5.14 以前では、この形式の L<C<continue>|/continue BLOCK> は
26882736L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ
26892737利用可能です。
26902738さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を
26912739参照してください。
26922740
26932741=item cos EXPR
26942742X<cos> X<cosine> X<acos> X<arccosine>
26952743
26962744=item cos
26972745
26982746=for Pod::Functions cosine function
26992747
27002748=begin original
27012749
27022750Returns the cosine of EXPR (expressed in radians). If EXPR is omitted,
27032751takes the cosine of L<C<$_>|perlvar/$_>.
27042752
27052753=end original
27062754
27072755(ラジアンで示した) EXPR の余弦を返します。
27082756EXPR が省略されたときには、L<C<$_>|perlvar/$_> の余弦を取ります。
27092757
27102758=begin original
27112759
27122760For the inverse cosine operation, you may use the
27132761L<C<Math::Trig::acos>|Math::Trig> function, or use this relation:
27142762
27152763=end original
27162764
27172765逆余弦を求めるためには、L<C<Math::Trig::acos>|Math::Trig> 関数を使うか、
27182766以下の関係を使ってください。
27192767
27202768 sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
27212769
27222770=item crypt PLAINTEXT,SALT
27232771X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password>
27242772X<decrypt> X<cryptography> X<passwd> X<encrypt>
27252773
27262774=for Pod::Functions one-way passwd-style encryption
27272775
27282776=begin original
27292777
27302778Creates a digest string exactly like the L<crypt(3)> function in the C
27312779library (assuming that you actually have a version there that has not
27322780been extirpated as a potential munition).
27332781
27342782=end original
27352783
27362784C ライブラリの L<crypt(3)> 関数と全く同じように、ダイジェスト文字列を
27372785作成します(一時的な必需品として、まだ絶滅していないバージョンを
27382786持っていると仮定しています)。
27392787
27402788=begin original
27412789
27422790L<C<crypt>|/crypt PLAINTEXT,SALT> is a one-way hash function. The
27432791PLAINTEXT and SALT are turned
27442792into a short string, called a digest, which is returned. The same
27452793PLAINTEXT and SALT will always return the same string, but there is no
27462794(known) way to get the original PLAINTEXT from the hash. Small
27472795changes in the PLAINTEXT or SALT will result in large changes in the
27482796digest.
27492797
27502798=end original
27512799
27522800L<C<crypt>|/crypt PLAINTEXT,SALT> は一方向ハッシュ関数です。
27532801PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、
27542802それが返されます。
27552803PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから
27562804元の PLAINTEXT を得る(既知の)方法はありません。
27572805PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。
27582806
27592807=begin original
27602808
27612809There is no decrypt function. This function isn't all that useful for
27622810cryptography (for that, look for F<Crypt> modules on your nearby CPAN
27632811mirror) and the name "crypt" is a bit of a misnomer. Instead it is
27642812primarily used to check if two pieces of text are the same without
27652813having to transmit or store the text itself. An example is checking
27662814if a correct password is given. The digest of the password is stored,
27672815not the password itself. The user types in a password that is
27682816L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored
27692817digest. If the two digests match, the password is correct.
27702818
27712819=end original
27722820
27732821復号化関数はありません。
27742822この関数は暗号化のためにはまったく役に立ちません(このためには、
27752823お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、
27762824"crypt" という名前は少し間違った名前です。
27772825その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを
27782826転送したり保管したりせずにチェックするために使います。
27792827例としては、正しいパスワードが与えられたかどうかをチェックがあります。
27802828パスワード自身ではなく、パスワードのダイジェストが保管されます。
27812829ユーザーがパスワードを入力すると、保管されているダイジェストと同じ
27822830salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。
27832831二つのダイジェストが同じなら、パスワードは正しいです。
27842832
27852833=begin original
27862834
27872835When verifying an existing digest string you should use the digest as
27882836the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used
27892837to create the digest is visible as part of the digest. This ensures
27902838L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same
27912839salt as the digest. This allows your code to work with the standard
27922840L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations.
27932841In other words, assume nothing about the returned string itself nor
27942842about how many bytes of SALT may matter.
27952843
27962844=end original
27972845
27982846すでにあるダイジェスト文字列を検証するには、ダイジェストを
27992847(C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。
28002848ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。
28012849これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を
28022850ダイジェストとしてハッシュ化できるようにします。
28032851これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな
28042852実装でも動作します。
28052853言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、
28062854どのような仮定もしてはいけません。
28072855
28082856=begin original
28092857
28102858Traditionally the result is a string of 13 bytes: two first bytes of
28112859the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
28122860the first eight bytes of PLAINTEXT mattered. But alternative
28132861hashing schemes (like MD5), higher level security schemes (like C2),
28142862and implementations on non-Unix platforms may produce different
28152863strings.
28162864
28172865=end original
28182866
28192867伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて
28202868集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の
282128698 バイトだけが意味があります。
28222870しかし、(MD5 のように) 異なったハッシュ手法、
28232871(C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの
28242872実装などでは異なった文字列が生成されることがあります。
28252873
28262874=begin original
28272875
28282876When choosing a new salt create a random two character string whose
28292877characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.',
28302878'/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of
28312879characters is just a recommendation; the characters allowed in
28322880the salt depend solely on your system's crypt library, and Perl can't
28332881restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts.
28342882
28352883=end original
28362884
28372885新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から
28382886(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の
28392887ようにして)ランダムに2 つの文字を選びます。
28402888この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化
28412889ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が
28422890どのような salt を受け付けるかについて制限しません。
28432891
28442892=begin original
28452893
28462894Here's an example that makes sure that whoever runs this program knows
28472895their password:
28482896
28492897=end original
28502898
28512899プログラムを実行する人が、
28522900自分のパスワードを知っていることを確認する例です:
28532901
28542902 my $pwd = (getpwuid($<))[1];
28552903
28562904 system "stty -echo";
28572905 print "Password: ";
28582906 chomp(my $word = <STDIN>);
28592907 print "\n";
28602908 system "stty echo";
28612909
28622910 if (crypt($word, $pwd) ne $pwd) {
28632911 die "Sorry...\n";
28642912 } else {
28652913 print "ok\n";
28662914 }
28672915
28682916=begin original
28692917
28702918Of course, typing in your own password to whoever asks you
28712919for it is unwise.
28722920
28732921=end original
28742922
28752923もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。
28762924
28772925=begin original
28782926
28792927The L<C<crypt>|/crypt PLAINTEXT,SALT> function is unsuitable for hashing
28802928large quantities of data, not least of all because you can't get the
28812929information back. Look at the L<Digest> module for more robust
28822930algorithms.
28832931
28842932=end original
28852933
28862934L<C<crypt>|/crypt PLAINTEXT,SALT> 関数は大量のデータのハッシュ化には
28872935向いていません; これは情報を戻せないという理由だけではありません。
28882936より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。
28892937
28902938=begin original
28912939
28922940If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which
28932941I<potentially> has characters with codepoints above 255), Perl tries to
28942942make sense of the situation by trying to downgrade (a copy of) the
28952943string back to an eight-bit byte string before calling
28962944L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good.
28972945If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with
28982946L<C<Wide character in crypt>|perldiag/Wide character in %s>.
28992947
29002948=end original
29012949
29022950Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を
29032951含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は
29042952L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた
29052953文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る)
29062954ことで状況のつじつまを合わせようとします。
29072955うまく動けば、それでよし。
29082956動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT> は
29092957L<C<Wide character in crypt>|perldiag/Wide character in %s> という
29102958メッセージと共に die します。
29112959
29122960=begin original
29132961
29142962Portability issues: L<perlport/crypt>.
29152963
29162964=end original
29172965
29182966移植性の問題: L<perlport/crypt>。
29192967
29202968=item dbmclose HASH
29212969X<dbmclose>
29222970
29232971=for Pod::Functions breaks binding on a tied dbm file
29242972
29252973=begin original
29262974
29272975[This function has been largely superseded by the
29282976L<C<untie>|/untie VARIABLE> function.]
29292977
29302978=end original
29312979
29322980[この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。]
29332981
29342982=begin original
29352983
29362984Breaks the binding between a DBM file and a hash.
29372985
29382986=end original
29392987
29402988DBM ファイルとハッシュの連結をはずします。
29412989
29422990=begin original
29432991
29442992Portability issues: L<perlport/dbmclose>.
29452993
29462994=end original
29472995
29482996移植性の問題: L<perlport/dbmclose>。
29492997
29502998=item dbmopen HASH,DBNAME,MASK
29512999X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm>
29523000
29533001=for Pod::Functions create binding on a tied dbm file
29543002
29553003=begin original
29563004
29573005[This function has been largely superseded by the
29583006L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.]
29593007
29603008=end original
29613009
29623010[この関数は、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数に
29633011大きくとって代わられました。]
29643012
29653013=begin original
29663014
29673015This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley
29683016DB file to a hash. HASH is the name of the hash. (Unlike normal
29693017L<C<open>|/open FILEHANDLE,MODE,EXPR>, the first argument is I<not> a
29703018filehandle, even though it looks like one). DBNAME is the name of the
29713019database (without the F<.dir> or F<.pag> extension if any). If the
29723020database does not exist, it is created with protection specified by MASK
29733021(as modified by the L<C<umask>|/umask EXPR>). To prevent creation of
29743022the database if it doesn't exist, you may specify a MODE of 0, and the
29753023function will return a false value if it can't find an existing
29763024database. If your system supports only the older DBM functions, you may
29773025make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your
29783026program. In older versions of Perl, if your system had neither DBM nor
29793027ndbm, calling L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> produced a fatal
29803028error; it now falls back to L<sdbm(3)>.
29813029
29823030=end original
29833031
29843032L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)> ファイルまたは
29853033Berkeley DB ファイルを連想配列に結び付けます。
29863034HASH は、その連想配列の名前です。
29873035(普通の L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違って、最初の引数は
29883036ファイルハンドル I<ではありません>; まあ、似たようなものですが)。
29893037DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても
29903038つけません)。
29913039データベースが存在しなければ、MODE MASK (を L<C<umask>|/umask EXPR> で
29923040修正したもの) で指定されたモードで作られます。
29933041存在しないときにデータベースを作成しないようにするには、MODE に 0 を
29943042設定でき、データベースを見つけられなかった場合は関数は偽を返します。
29953043古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ
29963044L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を実行することができます。
29973045昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、
29983046L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出すと致命的エラーになります;
29993047現在では L<sdbm(3)> にフォールバックします。
30003048
30013049=begin original
30023050
30033051If you don't have write access to the DBM file, you can only read hash
30043052variables, not set them. If you want to test whether you can write,
30053053either use file tests or try setting a dummy hash entry inside an
30063054L<C<eval>|/eval EXPR> to trap the error.
30073055
30083056=end original
30093057
30103058DBM ファイルに対して、書き込み権が無いときには、ハッシュ
30113059配列を読みだすことだけができ、設定することはできません。
30123060書けるか否かを調べたい場合には、ファイルテスト
30133061演算子を使うか、エラーをトラップするための L<C<eval>|/eval EXPR> の中で、
30143062ダミーのハッシュエントリを設定してみることになります。
30153063
30163064=begin original
30173065
30183066Note that functions such as L<C<keys>|/keys HASH> and
30193067L<C<values>|/values HASH> may return huge lists when used on large DBM
30203068files. You may prefer to use the L<C<each>|/each HASH> function to
30213069iterate over large DBM files. Example:
30223070
30233071=end original
30243072
30253073大きな DBM ファイルを扱うときには、L<C<keys>|/keys HASH> や
30263074L<C<values>|/values HASH> のような関数は、巨大なリストを返します。
30273075大きな DBM ファイルでは、L<C<each>|/each HASH> 関数を使って繰り返しを
30283076行なった方が良いかもしれません。
30293077例:
30303078
30313079 # print out history file offsets
30323080 dbmopen(%HIST,'/usr/lib/news/history',0666);
30333081 while (($key,$val) = each %HIST) {
30343082 print $key, ' = ', unpack('L',$val), "\n";
30353083 }
30363084 dbmclose(%HIST);
30373085
30383086=begin original
30393087
30403088See also L<AnyDBM_File> for a more general description of the pros and
30413089cons of the various dbm approaches, as well as L<DB_File> for a particularly
30423090rich implementation.
30433091
30443092=end original
30453093
30463094様々な dbm 手法に対する利点欠点に関するより一般的な記述および
30473095特にリッチな実装である L<DB_File> に関しては
30483096L<AnyDBM_File> も参照してください。
30493097
30503098=begin original
30513099
30523100You can control which DBM library you use by loading that library
30533101before you call L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>:
30543102
30553103=end original
30563104
30573105L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出す前にライブラリを
30583106読み込むことで、どの DBM ライブラリを使うかを制御できます:
30593107
30603108 use DB_File;
30613109 dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
30623110 or die "Can't open netscape history file: $!";
30633111
30643112=begin original
30653113
30663114Portability issues: L<perlport/dbmopen>.
30673115
30683116=end original
30693117
30703118移植性の問題: L<perlport/dbmopen>。
30713119
30723120=item defined EXPR
30733121X<defined> X<undef> X<undefined>
30743122
30753123=item defined
30763124
30773125=for Pod::Functions test whether a value, variable, or function is defined
30783126
30793127=begin original
30803128
30813129Returns a Boolean value telling whether EXPR has a value other than the
30823130undefined value L<C<undef>|/undef EXPR>. If EXPR is not present,
30833131L<C<$_>|perlvar/$_> is checked.
30843132
30853133=end original
30863134
30873135左辺値 EXPR が未定義値 L<C<undef>|/undef EXPR> 以外の値を持つか否かを示す、
30883136ブール値を返します。
30893137EXPR がない場合は、L<C<$_>|perlvar/$_> がチェックされます。
30903138
30913139=begin original
30923140
30933141Many operations return L<C<undef>|/undef EXPR> to indicate failure, end
30943142of file, system error, uninitialized variable, and other exceptional
30953143conditions. This function allows you to distinguish
30963144L<C<undef>|/undef EXPR> from other values. (A simple Boolean test will
30973145not distinguish among L<C<undef>|/undef EXPR>, zero, the empty string,
30983146and C<"0">, which are all equally false.) Note that since
30993147L<C<undef>|/undef EXPR> is a valid scalar, its presence doesn't
31003148I<necessarily> indicate an exceptional condition: L<C<pop>|/pop ARRAY>
31013149returns L<C<undef>|/undef EXPR> when its argument is an empty array,
31023150I<or> when the element to return happens to be L<C<undef>|/undef EXPR>.
31033151
31043152=end original
31053153
31063154多くの演算子が、EOF や未初期化変数、システムエラーといった、
31073155例外的な条件で L<C<undef>|/undef EXPR> を返すようになっています。
31083156この関数は、他の値と L<C<undef>|/undef EXPR> とを区別するために使えます。
31093157(単純な真偽値テストでは、L<C<undef>|/undef EXPR>、0、C<"0"> のいずれも偽を
31103158返すので、区別することができません。)
31113159L<C<undef>|/undef EXPR> は有効なスカラ値なので、その存在が I<必ずしも>
31123160例外的な状況を表すとは限らないということに注意してください:
31133161L<C<pop>|/pop ARRAY> は引数が空の配列だったときに L<C<undef>|/undef EXPR> を
31143162返しますが、I<あるいは> 返すべき要素がたまたま
31153163L<C<undef>|/undef EXPR> だったのかもしれません。
31163164
31173165=begin original
31183166
31193167You may also use C<defined(&func)> to check whether subroutine C<func>
31203168has ever been defined. The return value is unaffected by any forward
31213169declarations of C<func>. A subroutine that is not defined
31223170may still be callable: its package may have an C<AUTOLOAD> method that
31233171makes it spring into existence the first time that it is called; see
31243172L<perlsub>.
31253173
31263174=end original
31273175
31283176C<defined(&func)> とすることでサブルーチン C<func> の存在を、
31293177確かめることもできます。
31303178返り値は C<func> の前方定義には影響されません。
31313179定義されていないサブルーチンも呼び出し可能です:
31323180最初に呼び出されたときに存在するようにするための
31333181C<AUTOLOAD> メソッドを持ったパッケージかもしれません;
31343182L<perlsub> を参照してください。
31353183
31363184=begin original
31373185
31383186Use of L<C<defined>|/defined EXPR> on aggregates (hashes and arrays) is
31393187no longer supported. It used to report whether memory for that
31403188aggregate had ever been allocated. You should instead use a simple
31413189test for size:
31423190
31433191=end original
31443192
31453193集合(ハッシュや配列)への L<C<defined>|/defined EXPR> の使用は
31463194もはや対応していません。
31473195これはその集合にメモリが割り当てられたかを報告するのに用いられていました。
31483196代わりにサイズに対する簡単なテストを使うべきです。
31493197
31503198 if (@an_array) { print "has array elements\n" }
31513199 if (%a_hash) { print "has hash members\n" }
31523200
31533201=begin original
31543202
31553203When used on a hash element, it tells you whether the value is defined,
31563204not whether the key exists in the hash. Use L<C<exists>|/exists EXPR>
31573205for the latter purpose.
31583206
31593207=end original
31603208
31613209ハッシュの要素に対して用いると、value が定義されているか否かを
31623210返すものであって、ハッシュに key が存在するか否かを返すのではありません。
31633211この用途には、L<C<exists>|/exists EXPR> を使ってください。
31643212
31653213=begin original
31663214
31673215Examples:
31683216
31693217=end original
31703218
31713219例:
31723220
31733221 print if defined $switch{D};
31743222 print "$val\n" while defined($val = pop(@ary));
31753223 die "Can't readlink $sym: $!"
31763224 unless defined($value = readlink $sym);
31773225 sub foo { defined &$bar ? $bar->(@_) : die "No bar"; }
31783226 $debugging = 0 unless defined $debugging;
31793227
31803228=begin original
31813229
31823230Note: Many folks tend to overuse L<C<defined>|/defined EXPR> and are
31833231then surprised to discover that the number C<0> and C<""> (the
31843232zero-length string) are, in fact, defined values. For example, if you
31853233say
31863234
31873235=end original
31883236
31893237注意: 多くの人々が L<C<defined>|/defined EXPR> を使いすぎて、C<0> と
31903238C<"">(空文字列) が実際のところ定義された値であることに驚くようです。
31913239例えば、以下のように書くと:
31923240
31933241 "ab" =~ /a(.*)b/;
31943242
31953243=begin original
31963244
31973245The pattern match succeeds and C<$1> is defined, although it
31983246matched "nothing". It didn't really fail to match anything. Rather, it
31993247matched something that happened to be zero characters long. This is all
32003248very above-board and honest. When a function returns an undefined value,
32013249it's an admission that it couldn't give you an honest answer. So you
32023250should use L<C<defined>|/defined EXPR> only when questioning the
32033251integrity of what you're trying to do. At other times, a simple
32043252comparison to C<0> or C<""> is what you want.
32053253
32063254=end original
32073255
32083256パターンマッチングが成功し、C<$1> が定義されても、実際には
32093257「なし」にマッチしています。
32103258しかしこれは何にもマッチしていないわけではありません。
32113259何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。
32123260これは非常に率直で正直なことです。
32133261関数が未定義値を返すとき、正直な答えを返すことができないことを
32143262告白しています。
32153263ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ
32163264L<C<defined>|/defined EXPR> を使うべきです。
32173265その他の場合では、単に C<0> または C<""> と比較するというのがあなたの
32183266求めているものです。
32193267
32203268=begin original
32213269
32223270See also L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>,
32233271L<C<ref>|/ref EXPR>.
32243272
32253273=end original
32263274
32273275L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, L<C<ref>|/ref EXPR> も
32283276参照してください。
32293277
32303278=item delete EXPR
32313279X<delete>
32323280
32333281=for Pod::Functions deletes a value from a hash
32343282
32353283=begin original
32363284
32373285Given an expression that specifies an element or slice of a hash,
32383286L<C<delete>|/delete EXPR> deletes the specified elements from that hash
32393287so that L<C<exists>|/exists EXPR> on that element no longer returns
32403288true. Setting a hash element to the undefined value does not remove its
32413289key, but deleting it does; see L<C<exists>|/exists EXPR>.
32423290
32433291=end original
32443292
32453293ハッシュの要素やスライスを指定する式を取り、L<C<delete>|/delete EXPR> は
32463294指定された要素をハッシュから削除するので、
32473295その要素に対する L<C<exists>|/exists EXPR> はもはや真を返さなくなります。
32483296ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、
32493297delete では削除されます; L<C<exists>|/exists EXPR> を参照してください。
32503298
32513299=begin original
32523300
32533301In list context, usually returns the value or values deleted, or the last such
32543302element in scalar context. The return list's length corresponds to that of
32553303the argument list: deleting non-existent elements returns the undefined value
3256in their corresponding positions. When a
3304in their corresponding positions. Since Perl 5.28, a
3257L<keyE<sol>value hash slice|perldata/KeyE<sol>Value Hash Slices> is passed to
3305L<keyE<sol>value hash slice|perldata/KeyE<sol>Value Hash Slices> can be passed
3258C<delete>, the return value is a list of key/value pairs (two elements for each
3306to C<delete>, and the return value is a list of key/value pairs (two elements
3259item deleted from the hash).
3307for each item deleted from the hash).
32603308
32613309=end original
32623310
32633311リストコンテキストでは通常は削除された要素を返し、スカラコンテキストでは
32643312削除された要素のうち最後のものを返します。
32653313返されたリストの長さは常に引数リストの長さに対応します:
32663314存在しない要素を削除すると、対応する位置に未定義値をセットして返します。
3267L<キーE<sol>値ハッシュスライス|perldata/KeyE<sol>Value Hash Slices> が
3315Perl 5.28 から、
3268C<delete> に渡されると、返り値はキー/値の組(それぞれのアイテムについて
3316L<キーE<sol>値ハッシュスライス|perldata/KeyE<sol>Value Hash Slices>
3317C<delete> に渡すことができ、
3318そして返り値はキー/値の組(それぞれのアイテムについて
32693319二つの要素が元のハッシュから削除されたもの)です。
32703320
32713321=begin original
32723322
32733323L<C<delete>|/delete EXPR> may also be used on arrays and array slices,
32743324but its behavior is less straightforward. Although
32753325L<C<exists>|/exists EXPR> will return false for deleted entries,
32763326deleting array elements never changes indices of existing values; use
32773327L<C<shift>|/shift ARRAY> or L<C<splice>|/splice
32783328ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements
32793329fall at the end of an array, the array's size shrinks to the position of
32803330the highest element that still tests true for L<C<exists>|/exists EXPR>,
32813331or to 0 if none do. In other words, an array won't have trailing
32823332nonexistent elements after a delete.
32833333
32843334=end original
32853335
32863336L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その
32873337振る舞いはあまり直感的ではありません。
32883338削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、
32893339配列要素を削除しても、存在する値の添え字は変わりません; このためには
32903340L<C<shift>|/shift ARRAY> や L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> を
32913341使ってください。
32923342しかし、削除された要素が配列の末尾であった場合、配列のサイズは
32933343L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に
32943344切り詰められます。
32953345言い換えると、delete の後には配列の末尾に値のない要素はありません。
32963346
32973347=begin original
32983348
32993349B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is
33003350strongly discouraged. The
33013351notion of deleting or checking the existence of Perl array elements is not
33023352conceptually coherent, and can lead to surprising behavior.
33033353
33043354=end original
33053355
33063356B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く
33073357非推奨です。
33083358Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
33093359驚くべき振る舞いを引き起こすことがあります。
33103360
33113361=begin original
33123362
33133363Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment.
33143364Deleting from a hash tied to a DBM file deletes the entry from the DBM
33153365file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not
33163366necessarily return anything; it depends on the implementation of the
33173367L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever
33183368it pleases.
33193369
33203370=end original
33213371
33223372L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。
33233373DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを
33243374削除します。
33253375しかし、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたハッシュや配列からの
33263376削除は、値を返すとは限りません; これは
33273377L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE
33283378メソッドの実装に依存するので、どんなことでも起こります。
33293379
33303380=begin original
33313381
33323382The C<delete local EXPR> construct localizes the deletion to the current
33333383block at run time. Until the block exits, elements locally deleted
33343384temporarily no longer exist. See L<perlsub/"Localized deletion of elements
33353385of composite types">.
33363386
33373387=end original
33383388
33393389C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。
33403390ブロックから出るまで、ローカルで削除された要素は存在しなくなります。
33413391L<perlsub/"Localized deletion of elements of composite types"> を
33423392参照してください。
33433393
33443394 my %hash = (foo => 11, bar => 22, baz => 33);
33453395 my $scalar = delete $hash{foo}; # $scalar is 11
33463396 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
33473397 my @array = delete @hash{qw(foo baz)}; # @array is (undef,33)
33483398
33493399=begin original
33503400
33513401The following (inefficiently) deletes all the values of %HASH and @ARRAY:
33523402
33533403=end original
33543404
33553405以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します:
33563406
33573407 foreach my $key (keys %HASH) {
33583408 delete $HASH{$key};
33593409 }
33603410
33613411 foreach my $index (0 .. $#ARRAY) {
33623412 delete $ARRAY[$index];
33633413 }
33643414
33653415=begin original
33663416
33673417And so do these:
33683418
33693419=end original
33703420
33713421そして以下のようにもできます:
33723422
33733423 delete @HASH{keys %HASH};
33743424
33753425 delete @ARRAY[0 .. $#ARRAY];
33763426
33773427=begin original
33783428
33793429But both are slower than assigning the empty list
33803430or undefining %HASH or @ARRAY, which is the customary
33813431way to empty out an aggregate:
33823432
33833433=end original
33843434
33853435しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、
33863436単に空リストを代入するか、%HASH や @ARRAY を
33873437undef するより遅いです:
33883438
33893439 %HASH = (); # completely empty %HASH
33903440 undef %HASH; # forget %HASH ever existed
33913441
33923442 @ARRAY = (); # completely empty @ARRAY
33933443 undef @ARRAY; # forget @ARRAY ever existed
33943444
33953445=begin original
33963446
33973447The EXPR can be arbitrarily complicated provided its
33983448final operation is an element or slice of an aggregate:
33993449
34003450=end original
34013451
34023452最終的な操作が集合の要素かスライスである限りは、
34033453いずれかである限りは、EXPR には任意の複雑な式を置くことができます:
34043454
34053455 delete $ref->[$x][$y]{$key};
3406 delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};
3456 delete $ref->[$x][$y]->@{$key1, $key2, @morekeys};
34073457
34083458 delete $ref->[$x][$y][$index];
3409 delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
3459 delete $ref->[$x][$y]->@[$index1, $index2, @moreindices];
34103460
34113461=item die LIST
34123462X<die> X<throw> X<exception> X<raise> X<$@> X<abort>
34133463
34143464=for Pod::Functions raise an exception or bail out
34153465
34163466=begin original
34173467
34183468L<C<die>|/die LIST> raises an exception. Inside an L<C<eval>|/eval EXPR>
34193469the exception is stuffed into L<C<$@>|perlvar/$@> and the L<C<eval>|/eval
34203470EXPR> is terminated with the undefined value. If the exception is
34213471outside of all enclosing L<C<eval>|/eval EXPR>s, then the uncaught
34223472exception is printed to C<STDERR> and perl exits with an exit code
34233473indicating failure. If you need to exit the process with a specific
34243474exit code, see L<C<exit>|/exit EXPR>.
34253475
34263476=end original
34273477
34283478L<C<die>|/die LIST> は例外を発生させます。
34293479L<C<eval>|/eval EXPR> の中で使用すると、例外が
34303480L<C<$@>|perlvar/$@> に入り、L<C<eval>|/eval EXPR> は
34313481未定義値を返して終了します。
34323482例外が全ての L<C<eval>|/eval EXPR> の外側の場合は、捕捉されなかった例外は
34333483C<STDERR> に表示され、perl は失敗を示す終了コードで終了します。
34343484特定の終了コードでプロセスを終了させる必要がある場合は、
34353485L<C<exit>|/exit EXPR> を参照してください。
34363486
34373487=begin original
34383488
34393489Equivalent examples:
34403490
34413491=end original
34423492
34433493等価な例:
34443494
34453495 die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
34463496 chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
34473497
34483498=begin original
34493499
34503500Most of the time, C<die> is called with a string to use as the exception.
34513501You may either give a single non-reference operand to serve as the
34523502exception, or a list of two or more items, which will be stringified
34533503and concatenated to make the exception.
34543504
34553505=end original
34563506
34573507ほとんどの場合、C<die> は例外として使うための文字列と共に呼び出されます。
34583508例外として圧から割れる単一の非リファレンスオペランドか、
34593509例外を作るために文字列化されて連結される、二つ以上のアイテムのリストを
34603510指定することができます。
34613511
34623512=begin original
34633513
34643514If the string exception does not end in a newline, the current
34653515script line number and input line number (if any) and a newline
34663516are appended to it. Note that the "input line number" (also
34673517known as "chunk") is subject to whatever notion of "line" happens to
34683518be currently in effect, and is also available as the special variable
34693519L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
34703520
34713521=end original
34723522
34733523文字列例外が改行で終わっていなければ、その時点のスクリプト名と
34743524スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が
34753525それに追加されます。
34763526「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると
34773527仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。
34783528L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。
34793529
34803530=begin original
34813531
34823532Hint: sometimes appending C<", stopped"> to your message will cause it
34833533to make better sense when the string C<"at foo line 123"> is appended.
34843534Suppose you are running script "canasta".
34853535
34863536=end original
34873537
34883538ヒント: メッセージの最後を C<", stopped"> のようなもので
34893539終わるようにしておけば、C<"at foo line 123"> のように
34903540追加されて、わかりやすくなります。
34913541"canasta" というスクリプトを実行しているとします。
34923542
34933543 die "/etc/games is no good";
34943544 die "/etc/games is no good, stopped";
34953545
34963546=begin original
34973547
34983548produce, respectively
34993549
35003550=end original
35013551
35023552これは、それぞれ以下のように表示します。
35033553
35043554 /etc/games is no good at canasta line 123.
35053555 /etc/games is no good, stopped at canasta line 123.
35063556
35073557=begin original
35083558
35093559If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@>
35103560already contains an exception value (typically from a previous
35113561L<C<eval>|/eval EXPR>), then that value is reused after
35123562appending C<"\t...propagated">. This is useful for propagating exceptions:
35133563
35143564=end original
35153565
35163566出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が
35173567(典型的には前回の L<C<eval>|/eval EXPR> で)
35183568既に例外値を持っている場合、
35193569値は C<"\t...propagated"> を追加した後再利用されます。
35203570これは例外を伝播させる場合に有効です:
35213571
35223572 eval { ... };
35233573 die unless $@ =~ /Expected exception/;
35243574
35253575=begin original
35263576
35273577If LIST was empty or made an empty string,
35283578and L<C<$@>|perlvar/$@> contains an object
35293579reference that has a C<PROPAGATE> method, that method will be called
35303580with additional file and line number parameters. The return value
35313581replaces the value in L<C<$@>|perlvar/$@>; i.e., as if
35323582C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called.
35333583
35343584=end original
35353585
35363586出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が C<PROPAGATE> メソッドを
35373587含むオブジェクトへのリファレンスを含む場合、
35383588このメソッドが追加ファイルと行番号を引数として呼び出されます。
35393589返り値は L<C<$@>|perlvar/$@> の値を置き換えます;
35403590つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が
35413591呼び出されたかのようになります。
35423592
35433593=begin original
35443594
35453595If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@>
35463596is also empty, then the string C<"Died"> is used.
35473597
35483598=end original
35493599
35503600LIST が空か空文字列を作り、L<C<$@>|perlvar/$@> も空の場合、
35513601C<"Died"> が使われます。
35523602
35533603=begin original
35543604
35553605You can also call L<C<die>|/die LIST> with a reference argument, and if
35563606this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@>
35573607contains that reference. This permits more elaborate exception handling
35583608using objects that maintain arbitrary state about the exception. Such a
35593609scheme is sometimes preferable to matching particular string values of
35603610L<C<$@>|perlvar/$@> with regular expressions.
35613611
35623612=end original
35633613
35643614L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これが
35653615L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は
35663616そのリファレンスを持ちます。
35673617これは、例外の性質について任意の状態を管理するオブジェクトを使った
35683618より複雑な例外処理の実装を可能にします。
35693619このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って
35703620マッチングするときに時々好まれます。
35713621
35723622=begin original
35733623
35743624Because Perl stringifies uncaught exception messages before display,
35753625you'll probably want to overload stringification operations on
35763626exception objects. See L<overload> for details about that.
35773627The stringified message should be non-empty, and should end in a newline,
35783628in order to fit in with the treatment of string exceptions.
35793629Also, because an exception object reference cannot be stringified
35803630without destroying it, Perl doesn't attempt to append location or other
35813631information to a reference exception. If you want location information
35823632with a complex exception object, you'll have to arrange to put the
35833633location information into the object yourself.
35843634
35853635=end original
35863636
35873637perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、
35883638このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと
35893639思うかもしれません。
35903640これに関する詳細は L<overload> を参照してください。
35913641文字列化されたメッセージは、文字列例外の扱いに合わせるために、
35923642空ではなく、末尾は改行であるべきです。
35933643また、例外オブジェクトリファレンスはそれを破壊することなく
35943644文字列化することができないので、Perl はリファレンス例外に位置や
35953645その他の情報を追加しようとしません。
35963646複雑な例外オブジェクトに位置情報が欲しい場合、
35973647オブジェクト自身に位置情報を設定するように用意する必要があります。
35983648
35993649=begin original
36003650
36013651Because L<C<$@>|perlvar/$@> is a global variable, be careful that
36023652analyzing an exception caught by C<eval> doesn't replace the reference
36033653in the global variable. It's
36043654easiest to make a local copy of the reference before any manipulations.
36053655Here's an example:
36063656
36073657=end original
36083658
36093659L<C<$@>|perlvar/$@> はグローバル変数なので、
36103660C<eval> により補足された例外の解析はグローバル変数の
36113661リファレンスを置き換えないことに注意を払わなければなりません。
36123662他の操作をする前にリファレンスのローカルコピーを
36133663作るのが一番簡単です。
36143664以下に例を示します:
36153665
36163666 use Scalar::Util "blessed";
36173667
36183668 eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) };
36193669 if (my $ev_err = $@) {
36203670 if (blessed($ev_err)
36213671 && $ev_err->isa("Some::Module::Exception")) {
36223672 # handle Some::Module::Exception
36233673 }
36243674 else {
36253675 # handle all other possible exceptions
36263676 }
36273677 }
36283678
36293679=begin original
36303680
36313681If an uncaught exception results in interpreter exit, the exit code is
36323682determined from the values of L<C<$!>|perlvar/$!> and
36333683L<C<$?>|perlvar/$?> with this pseudocode:
36343684
36353685=end original
36363686
36373687例外が捕捉されないとインタプリタは終了し、終了コードは以下の
36383688擬似コードのように、L<C<$!>|perlvar/$!> と L<C<$?>|perlvar/$?> の値から
36393689決定されます:
36403690
36413691 exit $! if $!; # errno
36423692 exit $? >> 8 if $? >> 8; # child exit status
36433693 exit 255; # last resort
36443694
36453695=begin original
36463696
36473697As with L<C<exit>|/exit EXPR>, L<C<$?>|perlvar/$?> is set prior to
36483698unwinding the call stack; any C<DESTROY> or C<END> handlers can then
36493699alter this value, and thus Perl's exit code.
36503700
36513701=end original
36523702
36533703L<C<exit>|/exit EXPR> と同様に、コールスタックを巻き戻す前に
36543704L<C<$?>|perlvar/$?> が設定されます; C<DESTROY> と C<END> のハンドラが
36553705それからこの値を変更して、これが Perl の終了コードになります。
36563706
36573707=begin original
36583708
36593709The intent is to squeeze as much possible information about the likely cause
36603710into the limited space of the system exit code. However, as
36613711L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by
36623712any system call, this means that the value of the exit code used by
36633713L<C<die>|/die LIST> can be non-predictable, so should not be relied
36643714upon, other than to be non-zero.
36653715
36663716=end original
36673717
36683718この意図は、できるだけ多くの似たような原因に関する情報を、システム終了
36693719コードという限られた領域に圧縮することです。
36703720しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の
36713721C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は
36723722予測不能であることを意味するので、非 0 ということ以上にこの値に
36733723依存するべきではありません。
36743724
36753725=begin original
36763726
36773727You can arrange for a callback to be run just before the
36783728L<C<die>|/die LIST> does its deed, by setting the
36793729L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called
36803730with the exception as an argument, and can change the exception,
36813731if it sees fit, by
36823732calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on
36833733setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some
36843734examples. Although this feature was to be run only right before your
36853735program was to exit, this is not currently so: the
36863736L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside
36873737L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do
36883738nothing in such situations, put
36893739
36903740=end original
36913741
36923742L<C<$SIG{__DIE__}>|perlvar/%SIG> フックをセットすることで、
36933743L<C<die>|/die LIST> がその行動を行う
36943744直前に実行されるコールバックを設定できます。
36953745結び付けられたハンドラは例外を引数として呼び出され、
36963746必要なら再び L<C<die>|/die LIST> を呼び出すことで例外を変更できます。
36973747L<C<%SIG>|perlvar/%SIG> のエントリをセットする詳細については、
36983748L<perlvar/%SIG> を、例については L<C<eval>|/eval EXPR> を参照してください。
36993749この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、
37003750現在ではそうではありません:
37013751L<C<$SIG{__DIE__}>|perlvar/%SIG> フックは L<C<eval>|/eval EXPR> された
37023752ブロック/文字列の中でも呼ばれるのです!
37033753もしそのような状況で何もしなくない時は:
37043754
37053755 die @_ if $^S;
37063756
37073757=begin original
37083758
37093759as the first line of the handler (see L<perlvar/$^S>). Because
37103760this promotes strange action at a distance, this counterintuitive
37113761behavior may be fixed in a future release.
37123762
37133763=end original
37143764
37153765をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。
37163766これは離れたところで不思議な行動を引き起こすので、
37173767この直感的でない振る舞いは将来のリリースで修正されるかもしれません。
37183768
37193769=begin original
37203770
37213771See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp>
37223772module.
37233773
37243774=end original
37253775
37263776L<C<exit>|/exit EXPR> と L<C<warn>|/warn LIST> と L<Carp> モジュールも
37273777参照してください。
37283778
37293779=item do BLOCK
37303780X<do> X<block>
37313781
37323782=for Pod::Functions turn a BLOCK into a TERM
37333783
37343784=begin original
37353785
37363786Not really a function. Returns the value of the last command in the
37373787sequence of commands indicated by BLOCK. When modified by the C<while> or
37383788C<until> loop modifier, executes the BLOCK once before testing the loop
37393789condition. (On other statements the loop modifiers test the conditional
37403790first.)
37413791
37423792=end original
37433793
37443794実際は関数ではありません。
37453795BLOCK で示されるコマンド列の最後の値を返します。
37463796C<while> や C<until> ループ修飾子で修飾すると、
37473797ループ条件を調べる前に 1 度、BLOCK を実行します。
37483798(これ以外の実行文は、ループ修飾子により、条件が最初に
37493799調べられます。)
37503800
37513801=begin original
37523802
37533803C<do BLOCK> does I<not> count as a loop, so the loop control statements
37543804L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
37553805L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
37563806See L<perlsyn> for alternative strategies.
37573807
37583808=end original
37593809
37603810C<do BLOCK> はループとしては I<扱われません>; 従って、L<C<next>|/next LABEL>,
37613811L<C<last>|/last LABEL>,L<C<redo>|/redo LABEL> といったループ制御文は
37623812ブロックから抜けたり再開することはできません。
37633813その他の戦略については L<perlsyn> を参照してください。
37643814
37653815=item do EXPR
37663816X<do>
37673817
37683818=begin original
37693819
37703820Uses the value of EXPR as a filename and executes the contents of the
37713821file as a Perl script:
37723822
37733823=end original
37743824
37753825EXPR の値をファイル名として用い、そのファイルの中身を
37763826Perl のスクリプトとして実行します:
37773827
37783828 # load the exact specified file (./ and ../ special-cased)
37793829 do '/foo/stat.pl';
37803830 do './stat.pl';
37813831 do '../foo/stat.pl';
37823832
37833833 # search for the named file within @INC
37843834 do 'stat.pl';
37853835 do 'foo/stat.pl';
37863836
37873837=begin original
37883838
37893839C<do './stat.pl'> is largely like
37903840
37913841=end original
37923842
37933843C<do './stat.pl'> はだいたい以下のものと同じようなものですが、
37943844
37953845 eval `cat stat.pl`;
37963846
37973847=begin original
37983848
37993849except that it's more concise, runs no external processes, and keeps
38003850track of the current filename for error messages. It also differs in that
38013851code evaluated with C<do FILE> cannot see lexicals in the enclosing
38023852scope; C<eval STRING> does. It's the same, however, in that it does
38033853reparse the file every time you call it, so you probably don't want
38043854to do this inside a loop.
38053855
38063856=end original
38073857
38083858より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、
38093859といったことがあります。
38103860C<do FILE> で評価されたコードは、入れ子のスコープにある
38113861レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、
38123862という違いがあります。
38133863しかし、呼び出すたびにファイルを解析し直すという点では同じですから、
38143864ループ内でこれを使おうなどとは、間違っても思ったりしないように。
38153865
38163866=begin original
38173867
38183868Using C<do> with a relative path (except for F<./> and F<../>), like
38193869
38203870=end original
38213871
38223872次のように、C<do> に (F<./> と F<../> 以外の) 相対パスを使うと:
38233873
38243874 do 'foo/stat.pl';
38253875
38263876=begin original
38273877
38283878will search the L<C<@INC>|perlvar/@INC> directories, and update
38293879L<C<%INC>|perlvar/%INC> if the file is found. See L<perlvar/@INC>
38303880and L<perlvar/%INC> for these variables. In particular, note that
38313881whilst historically L<C<@INC>|perlvar/@INC> contained '.' (the
38323882current directory) making these two cases equivalent, that is no
38333883longer necessarily the case, as '.' is not included in C<@INC> by default
38343884in perl versions 5.26.0 onwards. Instead, perl will now warn:
38353885
38363886=end original
38373887
38383888L<C<@INC>|perlvar/@INC> ディレクトリを検索し、ファイルが見つかれば
38393889L<C<%INC>|perlvar/%INC> を更新します。
38403890これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を参照してください。
38413891特に、歴史的には L<C<@INC>|perlvar/@INC> に '.' (カレントディレクトリ) を
38423892含んでいたのでこの二つの場合は等価でしたが、
38433893perl バージョン 5.26.0 以降ではデフォルトでは C<@INC> に '.' を
38443894含んでいないので、もはやそうではないことに注意してください。
38453895代わりに、perl は次のような警告を出します:
38463896
38473897 do "stat.pl" failed, '.' is no longer in @INC;
38483898 did you mean do "./stat.pl"?
38493899
38503900=begin original
38513901
38523902If L<C<do>|/do EXPR> can read the file but cannot compile it, it
38533903returns L<C<undef>|/undef EXPR> and sets an error message in
38543904L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it
38553905returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check
38563906L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also
38573907sets L<C<$!>|perlvar/$!>. If the file is successfully compiled,
38583908L<C<do>|/do EXPR> returns the value of the last expression evaluated.
38593909
38603910=end original
38613911
38623912L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、
38633913L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを
38643914設定します。
38653915L<C<do>|/do EXPR>がファイルを読み込めなかった場合、undef を返して
38663916L<C<$!>|perlvar/$!> にエラーを設定します。
38673917コンパイルに失敗したときにも L<C<$!>|perlvar/$!> が設定されるので、
38683918常に L<C<$@>|perlvar/$@> を先にチェックします。
38693919ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の
38703920値を返します。
38713921
38723922=begin original
38733923
38743924Inclusion of library modules is better done with the
38753925L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION>
38763926operators, which also do automatic error checking and raise an exception
38773927if there's a problem.
38783928
38793929=end original
38803930
38813931ライブラリモジュールのインクルードには、
38823932L<C<use>|/use Module VERSION LIST> 演算子や
38833933L<C<require>|/require VERSION> 演算子を使った方がよいです;
38843934これらは自動的にエラーをチェックして、問題があれば例外を発生させます。
38853935
38863936=begin original
38873937
38883938You might like to use L<C<do>|/do EXPR> to read in a program
38893939configuration file. Manual error checking can be done this way:
38903940
38913941=end original
38923942
38933943L<C<do>|/do EXPR> をプログラム設定ファイルを読み込むのに
38943944使いたいかもしれません。
38953945手動のエラーチェックは以下のようにして行えます:
38963946
38973947 # Read in config files: system first, then user.
38983948 # Beware of using relative pathnames here.
38993949 for $file ("/share/prog/defaults.rc",
39003950 "$ENV{HOME}/.someprogrc")
39013951 {
39023952 unless ($return = do $file) {
39033953 warn "couldn't parse $file: $@" if $@;
39043954 warn "couldn't do $file: $!" unless defined $return;
39053955 warn "couldn't run $file" unless $return;
39063956 }
39073957 }
39083958
39093959=item dump LABEL
39103960X<dump> X<core> X<undump>
39113961
39123962=item dump EXPR
39133963
39143964=item dump
39153965
39163966=for Pod::Functions create an immediate core dump
39173967
39183968=begin original
39193969
39203970This function causes an immediate core dump. See also the B<-u>
39213971command-line switch in L<perlrun|perlrun/-u>, which does the same thing.
39223972Primarily this is so that you can use the B<undump> program (not
39233973supplied) to turn your core dump into an executable binary after
39243974having initialized all your variables at the beginning of the
39253975program. When the new binary is executed it will begin by executing
39263976a C<goto LABEL> (with all the restrictions that L<C<goto>|/goto LABEL>
39273977suffers).
39283978Think of it as a goto with an intervening core dump and reincarnation.
39293979If C<LABEL> is omitted, restarts the program from the top. The
39303980C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be
39313981computed at run time, being otherwise identical to C<dump LABEL>.
39323982
39333983=end original
39343984
39353985この関数は即座にコアダンプを行ないます。
39363986同様のことを行う <perlrun|perlrun/-u> の B<-u> オプションも参照してください。
39373987プログラムの先頭で、
39383988すべての変数を初期化したあとのコアダンプを B<undump>
39393989プログラム(提供していません)を使って実行ファイルに返ることができます。
39403990この新しいバイナリが実行されると、C<goto LABEL> から始めます
39413991(L<C<goto>|/goto LABEL> に関する制限はすべて適用されます)。
39423992コアダンプをはさんで再生する goto と考えてください。
39433993C<LABEL> が省略されると、プログラムを先頭から再開します。
39443994Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される
39453995名前が使えます; その他は C<dump LABEL> と同一です。
39463996
39473997=begin original
39483998
39493999B<WARNING>: Any files opened at the time of the dump will I<not>
39504000be open any more when the program is reincarnated, with possible
39514001resulting confusion by Perl.
39524002
39534003=end original
39544004
39554005B<警告>: dump 時点でオープンされていたファイルは、プログラムが
39564006再生されたときには、もはやオープンされて I<いません>; Perl を
39574007混乱させる可能性があります。
39584008
39594009=begin original
39604010
39614011This function is now largely obsolete, mostly because it's very hard to
39624012convert a core file into an executable. As of Perl 5.30, it must be invoked
39634013as C<CORE::dump()>.
39644014
39654015=end original
39664016
39674017この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを
39684018実行形式に変換するのが非常に困難であることです。
39694019Perl 5.30 から、これは C<CORE::dump()> として起動しなければなりません。
39704020
39714021=begin original
39724022
39734023Unlike most named operators, this has the same precedence as assignment.
39744024It is also exempt from the looks-like-a-function rule, so
39754025C<dump ("foo")."bar"> will cause "bar" to be part of the argument to
39764026L<C<dump>|/dump LABEL>.
39774027
39784028=end original
39794029
39804030ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
39814031また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と
39824032すると "bar" は L<C<dump>|/dump LABEL> への引数の一部になります。
39834033
39844034=begin original
39854035
39864036Portability issues: L<perlport/dump>.
39874037
39884038=end original
39894039
39904040移植性の問題: L<perlport/dump>。
39914041
39924042=item each HASH
39934043X<each> X<hash, iterator>
39944044
39954045=item each ARRAY
39964046X<array, iterator>
39974047
39984048=for Pod::Functions retrieve the next key/value pair from a hash
39994049
40004050=begin original
40014051
40024052When called on a hash in list context, returns a 2-element list
40034053consisting of the key and value for the next element of a hash. In Perl
400440545.12 and later only, it will also return the index and value for the next
40054055element of an array so that you can iterate over it; older Perls consider
40064056this a syntax error. When called in scalar context, returns only the key
40074057(not the value) in a hash, or the index in an array.
40084058
40094059=end original
40104060
40114061ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、
40124062ハッシュのキーと値を返します。
40134063Perl 5.12 以降でのみ、配列のインデックスと値からなる
401440642 要素のリストを返すので、反復を行えます; より古い Perl ではこれは
40154065文法エラーと考えられます。
40164066スカラコンテキストで呼び出した場合は、
40174067ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。
40184068
40194069=begin original
40204070
40214071Hash entries are returned in an apparently random order. The actual random
40224072order is specific to a given hash; the exact same series of operations
40234073on two hashes may result in a different order for each hash. Any insertion
40244074into the hash may change the order, as will any deletion, with the exception
40254075that the most recent key returned by L<C<each>|/each HASH> or
40264076L<C<keys>|/keys HASH> may be deleted without changing the order. So
40274077long as a given hash is unmodified you may rely on
40284078L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
40294079L<C<each>|/each HASH> to repeatedly return the same order
40304080as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
40314081details on why hash order is randomized. Aside from the guarantees
40324082provided here the exact details of Perl's hash algorithm and the hash
40334083traversal order are subject to change in any release of Perl.
40344084
40354085=end original
40364086
40374087ハッシュ要素は見かけ上、ランダムな順序で返されます。
40384088実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
40394089操作を行っても、ハッシュによって異なった順序になります。
40404090ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
40414091L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
40424092最近のキーは順序を変えることなく削除できます。
40434093ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
4044L<C<each>|/each HASH> が繰り返し同じ順序で
4094L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
4045返すことに依存してもかまいません。
40464095なぜハッシュの順序がランダム化されているかの詳細については
40474096L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
40484097ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
40494098正確な詳細は Perl のリリースによって変更される可能性があります。
40504099
40514100=begin original
40524101
40534102After L<C<each>|/each HASH> has returned all entries from the hash or
40544103array, the next call to L<C<each>|/each HASH> returns the empty list in
40554104list context and L<C<undef>|/undef EXPR> in scalar context; the next
40564105call following I<that> one restarts iteration. Each hash or array has
40574106its own internal iterator, accessed by L<C<each>|/each HASH>,
40584107L<C<keys>|/keys HASH>, and L<C<values>|/values HASH>. The iterator is
40594108implicitly reset when L<C<each>|/each HASH> has reached the end as just
40604109described; it can be explicitly reset by calling L<C<keys>|/keys HASH>
40614110or L<C<values>|/values HASH> on the hash or array, or by referencing
40624111the hash (but not array) in list context. If you add or delete
40634112a hash's elements while iterating over it, the effect on the iterator is
40644113unspecified; for example, entries may be skipped or duplicated--so don't
40654114do that. Exception: It is always safe to delete the item most recently
40664115returned by L<C<each>|/each HASH>, so the following code works properly:
40674116
40684117=end original
40694118
40704119L<C<each>|/each HASH> がハッシュをすべて読み込んでしまった後、
40714120次の L<C<each>|/each HASH> 呼び出しでは、リストコンテキストでは空リストが
40724121返され、スカラコンテキストでは L<C<undef>|/undef EXPR> が返されます;
40734122I<そのあと> もう一度呼び出すと、再び反復を始めます。
40744123ハッシュや配列毎にそれぞれ反復子があり、L<C<each>|/each HASH>、
40754124L<C<keys>|/keys HASH>、L<C<values>|/values HASH> でアクセスされます。
40764125反復子は、前述したように L<C<each>|/each HASH> が要素をすべて読むことによって
40774126暗黙にリセットされます; また、ハッシュや配列に対して L<C<keys>|/keys HASH>,
40784127L<C<values>|/values HASH> を呼び出すか、リストコンテキストで
40794128(配列ではなく)ハッシュを参照ことで明示的にリセットできます。
40804129繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、
40814130反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします--
40824131従って、してはいけません。
40834132例外: 一番最近に L<C<each>|/each HASH> から返されたものを削除するのは常に
40844133安全です; これは以下のようなコードが正しく動くことを意味します:
40854134
40864135 while (my ($key, $value) = each %hash) {
40874136 print $key, "\n";
40884137 delete $hash{$key}; # This is safe
40894138 }
40904139
40914140=begin original
40924141
40934142Tied hashes may have a different ordering behaviour to perl's hash
40944143implementation.
40954144
40964145=end original
40974146
40984147tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。
40994148
41004149=begin original
41014150
41024151The iterator used by C<each> is attached to the hash or array, and is
41034152shared between all iteration operations applied to the same hash or array.
41044153Thus all uses of C<each> on a single hash or array advance the same
41054154iterator location. All uses of C<each> are also subject to having the
41064155iterator reset by any use of C<keys> or C<values> on the same hash or
41074156array, or by the hash (but not array) being referenced in list context.
41084157This makes C<each>-based loops quite fragile: it is easy to arrive at
41094158such a loop with the iterator already part way through the object, or to
41104159accidentally clobber the iterator state during execution of the loop body.
41114160It's easy enough to explicitly reset the iterator before starting a loop,
41124161but there is no way to insulate the iterator state used by a loop from
41134162the iterator state used by anything else that might execute during the
41144163loop body. To avoid these problems, use a C<foreach> loop rather than
41154164C<while>-C<each>.
41164165
41174166=end original
41184167
41194168C<each> で使われる反復子はハッシュや配列に付随し、
41204169同じハッシュや配列に適用される全ての反復操作の間で共有されます。
41214170従って、一つのハッシュや配列での C<each> の全ての使用は同じ反復位置を
41224171進めます。
41234172また、全ての C<each> は、同じハッシュまたはキーに対する
41244173C<keys> や C<values> の使用によって、または
41254174(リストではなく)ハッシュがリストコンテキストで参照されることによって、
41264175反復子がリセットされることになります。
41274176これは、C<each> を基にしたループをかなり不安定にします:
41284177そのようなループが既にオブジェクトを部分的に通りぬけた反復子で行われたり、
41294178ループ本体の実行中に誤って反復子の状態を壊すことは容易です。
41304179ループを始める前に反復子を明示的にリセットするのは十分容易ですが、
41314180ループ本体の間に実行しているかもしれない他の何かによって使われている
41324181反復子の状態から、
41334182ループによって使われている反復子の状態を分離する方法はありません。
41344183これらの問題を避けるには、C<while>-C<each> ではなく
41354184C<foreach> ループを使ってください。
41364185
41374186=begin original
41384187
4188This extends to using C<each> on the result of an anonymous hash or
4189array constructor. A new underlying array or hash is created each
4190time so each will always start iterating from scratch, eg:
4191
4192=end original
4193
4194これは、無名ハッシュや配列のコンストラクタの結果に
4195C<each> を使うように拡張します。
4196新しい基となる配列やハッシュは毎回作られるので、
4197それぞれは常に最初から反復します; 例:
4198
4199 # loops forever
4200 while (my ($key, $value) = each @{ +{ a => 1 } }) {
4201 print "$key=$value\n";
4202 }
4203
4204=begin original
4205
41394206This prints out your environment like the L<printenv(1)> program,
41404207but in a different order:
41414208
41424209=end original
41434210
41444211これは、L<printenv(1)> プログラムのように環境変数を表示しますが、
41454212順序は異なっています:
41464213
41474214 while (my ($key,$value) = each %ENV) {
41484215 print "$key=$value\n";
41494216 }
41504217
41514218=begin original
41524219
41534220Starting with Perl 5.14, an experimental feature allowed
41544221L<C<each>|/each HASH> to take a scalar expression. This experiment has
41554222been deemed unsuccessful, and was removed as of Perl 5.24.
41564223
41574224=end original
41584225
41594226Perl 5.14 から、L<C<each>|/each HASH> がスカラ式を取ることが出来るという
41604227実験的機能がありました。
41614228この実験は失敗と見なされ、Perl 5.24 で削除されました。
41624229
41634230=begin original
41644231
41654232As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while>
41664233loop, which will set L<C<$_>|perlvar/$_> on every iteration.
41674234If either an C<each> expression or an explicit assignment of an C<each>
41684235expression to a scalar is used as a C<while>/C<for> condition, then
41694236the condition actually tests for definedness of the expression's value,
41704237not for its regular truth value.
41714238
41724239=end original
41734240
41744241Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます;
41754242これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。
41764243C<each> 式または C<each> 式からスカラへの明示的な代入が
41774244C<while>/C<for> の条件部として使われた場合、
41784245条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
41794246テストします。
41804247
41814248 while (each %ENV) {
41824249 print "$_=$ENV{$_}\n";
41834250 }
41844251
41854252=begin original
41864253
41874254To avoid confusing would-be users of your code who are running earlier
41884255versions of Perl with mysterious syntax errors, put this sort of thing at
41894256the top of your file to signal that your code will work I<only> on Perls of
41904257a recent vintage:
41914258
41924259=end original
41934260
41944261あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
41954262文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
41964263I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
41974264書いてください:
41984265
4199 use 5.012; # so keys/values/each work on arrays
4266 use v5.12; # so keys/values/each work on arrays
4200 use 5.018; # so each assigns to $_ in a lone while test
4267 use v5.18; # so each assigns to $_ in a lone while test
42014268
42024269=begin original
42034270
42044271See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and
42054272L<C<sort>|/sort SUBNAME LIST>.
42064273
42074274=end original
42084275
42094276L<C<keys>|/keys HASH> や L<C<values>|/values HASH> や
42104277L<C<sort>|/sort SUBNAME LIST> も参照してください。
42114278
42124279=item eof FILEHANDLE
42134280X<eof>
42144281X<end of file>
42154282X<end-of-file>
42164283
42174284=item eof ()
42184285
42194286=item eof
42204287
42214288=for Pod::Functions test a filehandle for its end
42224289
42234290=begin original
42244291
42254292Returns 1 if the next read on FILEHANDLE will return end of file I<or> if
42264293FILEHANDLE is not open. FILEHANDLE may be an expression whose value
42274294gives the real filehandle. (Note that this function actually
42284295reads a character and then C<ungetc>s it, so isn't useful in an
42294296interactive context.) Do not read from a terminal file (or call
42304297C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such
42314298as terminals may lose the end-of-file condition if you do.
42324299
42334300=end original
42344301
42354302次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、
42364303I<または> FILEHANDLE がオープンされていないと、1 を返します。
42374304FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。
42384305(この関数は、実際に文字を読み、C<ungetc> を行ないますので、
42394306対話型の場合には有用ではありません。)
42404307端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を
42414308呼び出したりしてはいけません。
42424309そのようなことをすると、端末のようなファイルタイプは
42434310EOF 状態を失ってしまうかもしれません。
42444311
42454312=begin original
42464313
42474314An L<C<eof>|/eof FILEHANDLE> without an argument uses the last file
42484315read. Using L<C<eof()>|/eof FILEHANDLE> with empty parentheses is
42494316different. It refers to the pseudo file formed from the files listed on
42504317the command line and accessed via the C<< <> >> operator. Since
42514318C<< <> >> isn't explicitly opened, as a normal filehandle is, an
42524319L<C<eof()>|/eof FILEHANDLE> before C<< <> >> has been used will cause
42534320L<C<@ARGV>|perlvar/@ARGV> to be examined to determine if input is
42544321available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >>
42554322has returned end-of-file will assume you are processing another
42564323L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set
42574324L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see
42584325L<perlop/"I/O Operators">.
42594326
42604327=end original
42614328
42624329引数を省略した L<C<eof>|/eof FILEHANDLE> は、最後に読み込みを行なった
42634330ファイルを使います。
42644331空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。
42654332これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で
42664333アクセスされる擬似ファイルを示すために用いられます。
42674334通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、
42684335C<< <> >> を使う前に L<C<eof()>|/eof FILEHANDLE> を使うと、
42694336入力が正常か確認するために L<C<@ARGV>|perlvar/@ARGV> がテストされます。
42704337同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、
42714338他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし
42724339L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます;
42734340L<perlop/"I/O Operators"> を参照してください。
42744341
42754342=begin original
42764343
42774344In a C<< while (<>) >> loop, L<C<eof>|/eof FILEHANDLE> or C<eof(ARGV)>
42784345can be used to detect the end of each file, whereas
42794346L<C<eof()>|/eof FILEHANDLE> will detect the end of the very last file
42804347only. Examples:
42814348
42824349=end original
42834350
42844351C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、
42854352L<C<eof>|/eof FILEHANDLE> か C<eof(ARGV)> を用いるのに対して
42864353L<C<eof()>|/eof FILEHANDLE> は最後のファイルの終わりのみを調べます。
42874354例:
42884355
42894356 # reset line numbering on each input file
42904357 while (<>) {
42914358 next if /^\s*#/; # skip comments
42924359 print "$.\t$_";
42934360 } continue {
42944361 close ARGV if eof; # Not eof()!
42954362 }
42964363
42974364 # insert dashes just before last line of last file
42984365 while (<>) {
42994366 if (eof()) { # check for end of last file
43004367 print "--------------\n";
43014368 }
43024369 print;
43034370 last if eof(); # needed if we're reading from a terminal
43044371 }
43054372
43064373=begin original
43074374
43084375Practical hint: you almost never need to use L<C<eof>|/eof FILEHANDLE>
43094376in Perl, because the input operators typically return L<C<undef>|/undef
43104377EXPR> when they run out of data or encounter an error.
43114378
43124379=end original
43134380
43144381現実的なヒント: Perl で L<C<eof>|/eof FILEHANDLE> が必要となることは、
43154382ほとんどありません;
43164383基本的には、データがなくなったときやエラーがあったときに、入力演算子が
43174384L<C<undef>|/undef EXPR> を返してくれるからです。
43184385
43194386=item eval EXPR
43204387X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute>
43214388X<error, handling> X<exception, handling>
43224389
43234390=item eval BLOCK
43244391
43254392=item eval
43264393
43274394=for Pod::Functions catch exceptions or compile and run code
43284395
43294396=begin original
43304397
43314398C<eval> in all its forms is used to execute a little Perl program,
43324399trapping any errors encountered so they don't crash the calling program.
43334400
43344401=end original
43354402
43364403どの型式の C<eval> も、小さな Perl のプログラムであるかのように実行され、
43374404遭遇した全てのエラーをトラップするので、呼び出したプログラムが
43384405クラッシュすることはありません。
43394406
43404407=begin original
43414408
43424409Plain C<eval> with no argument is just C<eval EXPR>, where the
43434410expression is understood to be contained in L<C<$_>|perlvar/$_>. Thus
43444411there are only two real C<eval> forms; the one with an EXPR is often
43454412called "string eval". In a string eval, the value of the expression
43464413(which is itself determined within scalar context) is first parsed, and
43474414if there were no errors, executed as a block within the lexical context
43484415of the current Perl program. This form is typically used to delay
43494416parsing and subsequent execution of the text of EXPR until run time.
43504417Note that the value is parsed every time the C<eval> executes.
43514418
43524419=end original
43534420
43544421引数なしの C<eval> は単に C<eval EXPR> で、式は L<C<$_>|perlvar/$_> に
43554422含まれているものとして考えられます。
43564423従って実際には二つだけの C<eval> 形式があります:
43574424EXPR のものはしばしば「文字列 eval」(string eval) と呼ばれます。
43584425「文字列 eval」では、
43594426式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、
43604427エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして
43614428実行されます。
43624429この形は主に EXPR のテキストのパースと実行を実行時にまで
43634430遅延させるのに用います。
43644431返される値は C<eval> が実行されるごとにパースされることに注意してください。
43654432
43664433=begin original
43674434
43684435The other form is called "block eval". It is less general than string
43694436eval, but the code within the BLOCK is parsed only once (at the same
43704437time the code surrounding the C<eval> itself was parsed) and executed
43714438within the context of the current Perl program. This form is typically
43724439used to trap exceptions more efficiently than the first, while also
43734440providing the benefit of checking the code within BLOCK at compile time.
43744441BLOCK is parsed and compiled just once. Since errors are trapped, it
43754442often is used to check if a given feature is available.
43764443
43774444=end original
43784445
43794446もう一つの型式は「ブロック eval」と呼ばれます。
43804447これは文字列 eval ほど一般的ではありませんが、
43814448BLOCK 内部のコードは一度だけパースされ (コードを
43824449囲む C<eval> 自身がパースされるのと同じ時点です) 現在の
43834450Perl プログラムのコンテキストで実行されます。
43844451この形式は典型的には第一の形式より効率的に例外をトラップします;
43854452また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。
43864453BLOCK は一度だけパース及びコンパイルされます。
43874454エラーはトラップされてるので、しばしば与えられた機能が利用可能かを
43884455チェックするために使われます。
43894456
43904457=begin original
43914458
43924459In both forms, the value returned is the value of the last expression
43934460evaluated inside the mini-program; a return statement may also be used, just
43944461as with subroutines. The expression providing the return value is evaluated
43954462in void, scalar, or list context, depending on the context of the
43964463C<eval> itself. See L<C<wantarray>|/wantarray> for more
43974464on how the evaluation context can be determined.
43984465
43994466=end original
44004467
44014468どちらの形式でも、返される値はミニプログラムの内部で最後に評価された
44024469表現の値です; サブルーチンと同様、return 文も使えます。
44034470返り値として提供される表現は、C<eval> 自身のコンテキストに
44044471依存して無効・スカラ・リストのいずれかのコンテキストで評価されます。
44054472評価コンテキストの決定方法についての詳細は L<C<wantarray>|/wantarray> を
44064473参照してください。
44074474
44084475=begin original
44094476
44104477If there is a syntax error or runtime error, or a L<C<die>|/die LIST>
44114478statement is executed, C<eval> returns
44124479L<C<undef>|/undef EXPR> in scalar context, or an empty list in list
44134480context, and L<C<$@>|perlvar/$@> is set to the error message. (Prior to
441444815.16, a bug caused L<C<undef>|/undef EXPR> to be returned in list
44154482context for syntax errors, but not for runtime errors.) If there was no
44164483error, L<C<$@>|perlvar/$@> is set to the empty string. A control flow
44174484operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can
44184485bypass the setting of L<C<$@>|perlvar/$@>. Beware that using
44194486C<eval> neither silences Perl from printing warnings to
44204487STDERR, nor does it stuff the text of warning messages into
44214488L<C<$@>|perlvar/$@>. To do either of those, you have to use the
44224489L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside
44234490the BLOCK or EXPR using S<C<no warnings 'all'>>. See
44244491L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>.
44254492
44264493=end original
44274494
44284495構文エラーや実行エラーが発生するか、L<C<die>|/die LIST> 文が実行されると、
44294496C<eval> はスカラコンテキストでは L<C<undef>|/undef EXPR> が、
44304497リストコンテキストでは空リストが設定され、
44314498L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。
44324499(5.16 以前では、バグによって、リストコンテキストで構文エラーの時には
44334500L<C<undef>|/undef EXPR> を返していましたが、実行エラーの時には
44344501返していませんでした。)
44354502エラーがなければ、L<C<$@>|perlvar/$@> は空文字列に設定されます。
44364503L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようなフロー制御演算子は
44374504L<C<$@>|perlvar/$@> の設定を回避できます。
44384505C<eval> を、STDERR に警告メッセージを表示させない目的や、
44394506警告メッセージを L<C<$@>|perlvar/$@> に格納する目的では使わないでください。
44404507そのような用途では、L<C<$SIG{__WARN__}>|perlvar/%SIG> 機能を使うか、
44414508S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を
44424509オフにする必要があります。
44434510L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。
44444511
44454512=begin original
44464513
44474514Note that, because C<eval> traps otherwise-fatal errors,
44484515it is useful for determining whether a particular feature (such as
44494516L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> or
44504517L<C<symlink>|/symlink OLDFILE,NEWFILE>) is implemented. It is also
44514518Perl's exception-trapping mechanism, where the L<C<die>|/die LIST>
44524519operator is used to raise exceptions.
44534520
44544521=end original
44554522
44564523C<eval> は、致命的エラーとなるようなものを
44574524トラップすることができるので、
44584525(L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や
44594526L<C<symlink>|/symlink OLDFILE,NEWFILE> といった) 特定の機能が
44604527実装されているかを、
44614528調べるために使うことができることに注意してください。
44624529L<C<die>|/die LIST> 演算子が例外を発生させるものとすれば、これはまた、
44634530Perl の例外捕捉機能と捉えることもできます。
44644531
44654532=begin original
44664533
44674534Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before
44684535restoration
44694536of localized variables, which means that for your code to run on older
44704537versions, a temporary is required if you want to mask some, but not all
44714538errors:
44724539
44734540=end original
44744541
44754542Perl 5.14 より前では、L<C<$@>|perlvar/$@> への代入はローカル化された変数の
44764543復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの
44774544エラーをマスクしたい場合には一時変数が必要です:
44784545
44794546 # alter $@ on nefarious repugnancy only
44804547 {
44814548 my $e;
44824549 {
44834550 local $@; # protect existing $@
44844551 eval { test_repugnancy() };
44854552 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
44864553 $@ =~ /nefarious/ and $e = $@;
44874554 }
44884555 die $e if defined $e
44894556 }
44904557
44914558=begin original
44924559
44934560There are some different considerations for each form:
44944561
44954562=end original
44964563
44974564それぞれの型式について、異なった考慮事項があります:
44984565
44994566=over 4
45004567
45014568=item String eval
45024569
45034570(文字列 eval)
45044571
45054572=begin original
45064573
45074574Since the return value of EXPR is executed as a block within the lexical
45084575context of the current Perl program, any outer lexical variables are
45094576visible to it, and any package variable settings or subroutine and
45104577format definitions remain afterwards.
45114578
45124579=end original
45134580
45144581EXPR の返り値は現在の Perl プログラムのレキシカルコンテキストの中で
45154582実行されるので、外側のレキシカルスコープはそこから見え、
45164583パッケージ変数設定やサブルーチンとフォーマット設定は後に残ります。
45174584
45184585=over 4
45194586
45204587=item Under the L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
45214588
45224589=begin original
45234590
45244591If this feature is enabled (which is the default under a C<use 5.16> or
4525higher declaration), EXPR is considered to be
4592higher declaration), Perl assumes that EXPR is a character string.
4526in the same encoding as the surrounding program. Thus if
4593Any S<C<use utf8>> or S<C<no utf8>> declarations within
4527S<L<C<use utf8>|utf8>> is in effect, the string will be treated as being
4594the string thus have no effect. Source filters are forbidden as well.
4528UTF-8 encoded. Otherwise, the string is considered to be a sequence of
4595(C<unicode_strings>, however, can appear within the string.)
4529independent bytes. Bytes that correspond to ASCII-range code points
4530will have their normal meanings for operators in the string. The
4531treatment of the other bytes depends on if the
4532L<C<'unicode_strings"> feature|feature/The 'unicode_strings' feature> is
4533in effect.
45344596
45354597=end original
45364598
45374599この機能が有効の場合(これは C<use 5.16> またはそれ以上が
45384600宣言されている場合はデフォルトです)、
4539EXPR は周りプログラムと同じエンコーディングであるとして扱われます。
4601Perl は EXPR が文字文字列であると仮定します。
4540従ってS<L<C<use utf8>|utf8>> が有の場合、
4602従って文字列中の S<C<use utf8>> や S<C<no utf8>> 宣言は無です。
4541文字列は UTF-8 エンコドされているのとして扱われます。
4603スフィルタ禁止されます。
4542さもなければこの文字列は個々バイト列として扱われます。
4604(しかしC<unicode_strings> は文字列の中に現れます。)
4543ASCII の範囲の符号位置に対応するバイトは、
4544文字列の操作に関して通常の意味を持ちます。
4545その他のバイトの扱いは、
4546<C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か
4547どうかに依存します。
45484605
45494606=begin original
45504607
4551In a plain C<eval> without an EXPR argument, being in S<C<use utf8>> or
4608See also the L<C<evalbytes>|/evalbytes EXPR> operator, which works properly
4552not is irrelevant; the UTF-8ness of C<$_> itself determines the
4609with source filters.
4553behavior.
45544610
45554611=end original
45564612
4557EXPR 引数のない単なる C<eval> の場合、S<C<use utf8>> の有無は無関係です;
4558C<$_> 自身の UTF-8 性が振る舞いを決定します。
4559
4560=begin original
4561
4562Any S<C<use utf8>> or S<C<no utf8>> declarations within the string have
4563no effect, and source filters are forbidden. (C<unicode_strings>,
4564however, can appear within the string.) See also the
4565L<C<evalbytes>|/evalbytes EXPR> operator, which works properly with
4566source filters.
4567
4568=end original
4569
4570文字列中の S<C<use utf8>> や S<C<no utf8>> 宣言は無効で、ソースフィルタは
4571禁止されます。
4572(しかし、C<unicode_strings> は文字列の中に現れます。)
45734613ソースフィルタが適切に動作する
45744614L<C<evalbytes>|/evalbytes EXPR> 演算子も参照してください。
45754615
4576=begin original
4577
4578Variables defined outside the C<eval> and used inside it retain their
4579original UTF-8ness. Everything inside the string follows the normal
4580rules for a Perl program with the given state of S<C<use utf8>>.
4581
4582=end original
4583
4584Variables defined outside the
4585C<eval> の外側で定義され、内側で使われた変数は、
4586元の UTF-8 性を維持します。
4587内側の文字列は、S<C<use utf8>> の状態によって Perl プログラムに適用される
4588通常の規則に従います。
4589
45904616=item Outside the C<"unicode_eval"> feature
45914617
45924618=begin original
45934619
45944620In this case, the behavior is problematic and is not so easily
45954621described. Here are two bugs that cannot easily be fixed without
45964622breaking existing programs:
45974623
45984624=end original
45994625
46004626この場合、振る舞いには問題があり、それほど簡単には説明できません。
46014627既存のプログラムを壊さずに簡単に修正することが出来ない二つのバグがあります:
46024628
46034629=over 4
46044630
46054631=item *
46064632
46074633=begin original
46084634
4609It can lose track of whether something should be encoded as UTF-8 or
4635Perl's internal storage of EXPR affects the behavior of the executed code.
4610not.
4636For example:
46114637
46124638=end original
46134639
4614あるものが UTF-8 でエンコードされているかどうかを見失うことがあります。
4640Perl's internal storage of
4641EXPR の Perl の内部ストーレージは実行されるコードの振る舞いに影響を与えます。
4642例えば:
46154643
4644 my $v = eval "use utf8; '$expr'";
4645
4646=begin original
4647
4648If $expr is C<"\xc4\x80"> (U+0100 in UTF-8), then the value stored in C<$v>
4649will depend on whether Perl stores $expr "upgraded" (cf. L<utf8>) or
4650not:
4651
4652=end original
4653
4654$expr が C<"\xc4\x80"> (U+0100 in UTF-8) の場合、C<$v> に保管される値は、
4655Perl が $expr を「昇格」(L<utf8> 参照)して保管するかどうかによります:
4656
4657=over
4658
4659=item * If upgraded, C<$v> will be C<"\xc4\x80"> (i.e., the
4660C<use utf8> has no effect.)
4661
4662(昇格されると、C<$v> will be C<"\xc4\x80"> になります
4663(つまり、C<use utf8> は無効です。))
4664
4665=item * If non-upgraded, C<$v> will be C<"\x{100}">.
4666
4667(昇格されないと、C<$v> は C<"\x{100}">です。)
4668
4669=back
4670
4671This is undesirable since being
4672upgraded or not should not affect a string's behavior.
4673
46164674=item *
46174675
46184676=begin original
46194677
46204678Source filters activated within C<eval> leak out into whichever file
46214679scope is currently being compiled. To give an example with the CPAN module
46224680L<Semi::Semicolons>:
46234681
46244682=end original
46254683
46264684C<eval> の中で有効にされたソースフィルタは、現在どちらのファイルスコープで
46274685コンパイルされているかをリークさせます。
46284686CPAN モジュール L<Semi::Semicolons> を使った例は:
46294687
46304688 BEGIN { eval "use Semi::Semicolons; # not filtered" }
46314689 # filtered here!
46324690
46334691=begin original
46344692
46354693L<C<evalbytes>|/evalbytes EXPR> fixes that to work the way one would
46364694expect:
46374695
46384696=end original
46394697
46404698L<C<evalbytes>|/evalbytes EXPR> は、人が想定するだろう手法で動作するように
46414699これを修正します:
46424700
46434701 use feature "evalbytes";
46444702 BEGIN { evalbytes "use Semi::Semicolons; # filtered" }
46454703 # not filtered
46464704
46474705=back
46484706
46494707=back
46504708
46514709=begin original
46524710
46534711Problems can arise if the string expands a scalar containing a floating
46544712point number. That scalar can expand to letters, such as C<"NaN"> or
46554713C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the
46564714decimal point character may be something other than a dot (such as a
46574715comma). None of these are likely to parse as you are likely expecting.
46584716
46594717=end original
46604718
46614719文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。
46624720そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に
46634721展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、
46644722小数点文字は (カンマのような) ドット以外の文字かもしれません。
46654723これらはどれもあなたがおそらく予測しているようにはパースされません。
46664724
46674725=begin original
46684726
46694727You should be especially careful to remember what's being looked at
46704728when:
46714729
46724730=end original
46734731
46744732以下のような場合に、何が調べられるかに特に注意しておくことが必要です:
46754733
46764734 eval $x; # CASE 1
46774735 eval "$x"; # CASE 2
46784736
46794737 eval '$x'; # CASE 3
46804738 eval { $x }; # CASE 4
46814739
46824740 eval "\$$x++"; # CASE 5
46834741 $$x++; # CASE 6
46844742
46854743=begin original
46864744
46874745Cases 1 and 2 above behave identically: they run the code contained in
46884746the variable $x. (Although case 2 has misleading double quotes making
46894747the reader wonder what else might be happening (nothing is).) Cases 3
46904748and 4 likewise behave in the same way: they run the code C<'$x'>, which
46914749does nothing but return the value of $x. (Case 4 is preferred for
46924750purely visual reasons, but it also has the advantage of compiling at
46934751compile-time instead of at run-time.) Case 5 is a place where
46944752normally you I<would> like to use double quotes, except that in this
46954753particular situation, you can just use symbolic references instead, as
46964754in case 6.
46974755
46984756=end original
46994757
47004758上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の
47014759コードを実行します。
47024760(ただし、CASE 2 では、必要のないダブルクォートによって、
47034761読む人が何が起こるか混乱することでしょう (何も起こりませんが)。)
47044762同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に
4705何もしない C<$x> というコードを実行します
4763何もしない C<$x> というコードを実行します
47064764(純粋に見た目の問題で、CASE 4 が好まれますが、
47074765実行時でなくコンパイル時にコンパイルされるという利点もあります)。
47084766CASE 5 の場合は、通常ダブルクォートを使用 I<します>;
47094767この状況を除けば、CASE 6 のように、単に
47104768シンボリックリファレンスを使えば良いでしょう。
47114769
47124770=begin original
47134771
47144772An C<eval ''> executed within a subroutine defined
47154773in the C<DB> package doesn't see the usual
47164774surrounding lexical scope, but rather the scope of the first non-DB piece
47174775of code that called it. You don't normally need to worry about this unless
47184776you are writing a Perl debugger.
47194777
47204778=end original
47214779
47224780C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の
47234781レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の
47244782スコープになります。
47254783Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は
47264784ありません。
47274785
47284786=begin original
47294787
47304788The final semicolon, if any, may be omitted from the value of EXPR.
47314789
47324790=end original
47334791
47344792最後のセミコロンは、もしあれば、EXPR の値から省くことができます。
47354793
47364794=item Block eval
47374795
47384796=begin original
47394797
47404798If the code to be executed doesn't vary, you may use the eval-BLOCK
47414799form to trap run-time errors without incurring the penalty of
47424800recompiling each time. The error, if any, is still returned in
47434801L<C<$@>|perlvar/$@>.
47444802Examples:
47454803
47464804=end original
47474805
47484806実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、
47494807実行時エラーのトラップを行なうために、
47504808eval-BLOCK 形式を使うことができます。
47514809エラーがあれば、やはり L<C<$@>|perlvar/$@> に返されます。
47524810例:
47534811
47544812 # make divide-by-zero nonfatal
47554813 eval { $answer = $a / $b; }; warn $@ if $@;
47564814
47574815 # same thing, but less efficient
47584816 eval '$answer = $a / $b'; warn $@ if $@;
47594817
47604818 # a compile-time error
47614819 eval { $answer = }; # WRONG
47624820
47634821 # a run-time error
47644822 eval '$answer ='; # sets $@
47654823
47664824=begin original
47674825
47684826If you want to trap errors when loading an XS module, some problems with
47694827the binary interface (such as Perl version skew) may be fatal even with
47704828C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See
47714829L<perlrun|perlrun/PERL_DL_NONLAZY>.
47724830
47734831=end original
47744832
47754833XS モジュールのロード中のエラーをトラップしたいなら、
47764834(Perl バージョンの違いのような) バイナリインターフェースに関する問題に
47774835ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない
47784836C<eval> でも致命的エラーになるかもしれません。
47794837L<perlrun|perlrun/PERL_DL_NONLAZY> を参照してください。
47804838
47814839=begin original
47824840
47834841Using the C<eval {}> form as an exception trap in libraries does have some
47844842issues. Due to the current arguably broken state of C<__DIE__> hooks, you
47854843may wish not to trigger any C<__DIE__> hooks that user code may have installed.
47864844You can use the C<local $SIG{__DIE__}> construct for this purpose,
47874845as this example shows:
47884846
47894847=end original
47904848
47914849C<eval{}> 形式をライブラリの例外を捕捉するために使うときには
47924850問題があります。
47934851現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、
47944852ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。
47954853この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。
47964854
47974855 # a private exception trap for divide-by-zero
47984856 eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
47994857 warn $@ if $@;
48004858
48014859=begin original
48024860
48034861This is especially significant, given that C<__DIE__> hooks can call
48044862L<C<die>|/die LIST> again, which has the effect of changing their error
48054863messages:
48064864
48074865=end original
48084866
48094867これは特に顕著です; 与えられた C<__DIE__> フックは L<C<die>|/die LIST> を
48104868もう一度呼び出すことができ、これによってエラーメッセージを変える
48114869効果があります:
48124870
48134871 # __DIE__ hooks may modify error messages
48144872 {
48154873 local $SIG{'__DIE__'} =
48164874 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
48174875 eval { die "foo lives here" };
48184876 print $@ if $@; # prints "bar lives here"
48194877 }
48204878
48214879=begin original
48224880
48234881Because this promotes action at a distance, this counterintuitive behavior
48244882may be fixed in a future release.
48254883
48264884=end original
48274885
48284886これは距離の離れた行動であるため、この直感的でない振る舞いは
48294887将来のリリースでは修正されるかもしれません。
48304888
48314889=begin original
48324890
48334891C<eval BLOCK> does I<not> count as a loop, so the loop control statements
48344892L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
48354893L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
48364894
48374895=end original
48384896
48394897C<eval BLOCK> はループとして I<扱われません>; 従って、L<C<next>|/next LABEL>,
48404898L<C<last>|/last LABEL>, L<C<redo>|/redo LABEL> といったループ制御文で
48414899ブロックから離れたり再実行したりはできません。
48424900
48434901=begin original
48444902
48454903The final semicolon, if any, may be omitted from within the BLOCK.
48464904
48474905=end original
48484906
48494907最後のセミコロンは、もしあれば、BLOCK の中から削除されます。
48504908
48514909=back
48524910
48534911=item evalbytes EXPR
48544912X<evalbytes>
48554913
48564914=item evalbytes
48574915
48584916=for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream
48594917
48604918=begin original
48614919
48624920This function is similar to a L<string eval|/eval EXPR>, except it
48634921always parses its argument (or L<C<$_>|perlvar/$_> if EXPR is omitted)
4864as a string of independent bytes.
4922as a byte string. If the string contains any code points above 255, then
4923it cannot be a byte string, and the C<evalbytes> will fail with the error
4924stored in C<$@>.
48654925
48664926=end original
48674927
48684928この関数は L<文字列 eval|/eval EXPR> に似ていますが、引数(EXPR が
48694929省略された場合はL<C<$_>|perlvar/$_>) を常にバイト単位のの文字列として
48704930扱います。
4931文字列に 255 を超える符号位置が含まれている場合、バイト単位文字列に
4872=begin original
4932することができないので、
4873
4874If called when S<C<use utf8>> is in effect, the string will be assumed
4875to be encoded in UTF-8, and C<evalbytes> will make a temporary copy to
4876work from, downgraded to non-UTF-8. If this is not possible
4877(because one or more characters in it require UTF-8), the C<evalbytes>
4878will fail with the error stored in C<$@>.
4879
4880=end original
4881
4882S<C<use utf8>> が有効のときに呼び出されると、
4883文字列は UTF-8 でエンコードされていると仮定され、
4884C<evalbytes> は、非 UTF-8 にダウングレードした一時的なコピーを作ります。
4885(UTF-8 が必要な文字があるために) これが不可能な場合、
48864933C<evalbytes> は失敗し、エラーは C<$@> に保管されます。
48874934
48884935=begin original
48894936
4890Bytes that correspond to ASCII-range code points will have their normal
4937C<use utf8> and C<no utf8> within the string have their usual effect.
4891meanings for operators in the string. The treatment of the other bytes
4892depends on if the L<C<'unicode_strings"> feature|feature/The
4893'unicode_strings' feature> is in effect.
48944938
48954939=end original
48964940
4897ASCII範囲の符号位置に対応るバイトは、
4941文字列中の C<use utf8> と C<no utf8> は通常効果を持ちま
4898文字列の操作に関して通常の意味を持ちます。
4899その他のバイトの扱いは、
4900<C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か
4901どうかに依存します。
49024942
49034943=begin original
49044944
4905Of course, variables that are UTF-8 and are referred to in the string
4906retain that:
4907
4908=end original
4909
4910もちろん、UTF-8 で文字列の中で参照されている変数はそのままです:
4911
4912 my $a = "\x{100}";
4913 evalbytes 'print ord $a, "\n"';
4914
4915=begin original
4916
4917prints
4918
4919=end original
4920
4921というのは、次を表示し、
4922
4923 256
4924
4925=begin original
4926
4927and C<$@> is empty.
4928
4929=end original
4930
4931C<$@> は空になります。
4932
4933=begin original
4934
49354945Source filters activated within the evaluated code apply to the code
49364946itself.
49374947
49384948=end original
49394949
49404950eval されたコード内で有効になったソースフィルタはコード自体に適用されます。
49414951
49424952=begin original
49434953
49444954L<C<evalbytes>|/evalbytes EXPR> is available starting in Perl v5.16. To
49454955access it, you must say C<CORE::evalbytes>, but you can omit the
49464956C<CORE::> if the
49474957L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
49484958is enabled. This is enabled automatically with a C<use v5.16> (or
49494959higher) declaration in the current scope.
49504960
49514961=end original
49524962
49534963L<C<evalbytes>|/evalbytes EXPR> は Perl v5.16 から利用可能です。
49544964これにアクセスするには C<CORE::evalbytes> とする必要がありますが、
49554965L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> が
49564966有効なら C<CORE::> を省略できます。
49574967これは現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると
49584968自動的に有効になります。
49594969
49604970=item exec LIST
49614971X<exec> X<execute>
49624972
49634973=item exec PROGRAM LIST
49644974
49654975=for Pod::Functions abandon this program to run another
49664976
49674977=begin original
49684978
49694979The L<C<exec>|/exec LIST> function executes a system command I<and never
49704980returns>; use L<C<system>|/system LIST> instead of L<C<exec>|/exec LIST>
49714981if you want it to return. It fails and
49724982returns false only if the command does not exist I<and> it is executed
49734983directly instead of via your system's command shell (see below).
49744984
49754985=end original
49764986
49774987L<C<exec>|/exec LIST> 関数は、システムのコマンドを実行し、I<戻ってはきません>;
49784988戻って欲しい場合には、L<C<exec>|/exec LIST>ではなく
49794989L<C<system>|/system LIST> 関数を使ってください。
49804990コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく
49814991直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。
49824992
49834993=begin original
49844994
49854995Since it's a common mistake to use L<C<exec>|/exec LIST> instead of
49864996L<C<system>|/system LIST>, Perl warns you if L<C<exec>|/exec LIST> is
49874997called in void context and if there is a following statement that isn't
49884998L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, or L<C<exit>|/exit EXPR> (if
49894999L<warnings> are enabled--but you always do that, right?). If you
49905000I<really> want to follow an L<C<exec>|/exec LIST> with some other
49915001statement, you can use one of these styles to avoid the warning:
49925002
49935003=end original
49945004
49955005L<C<system>|/system LIST> の代わりに L<C<exec>|/exec LIST> を使うという
49965006よくある間違いを防ぐために、L<C<exec>|/exec LIST> が無効コンテキストで
49975007呼び出されて、引き続く文が L<C<die>|/die LIST>, L<C<warn>|/warn LIST>,
49985008L<C<exit>|/exit EXPR> 以外の場合、Perl は警告を出します(L<warnings> が
49995009有効の場合 -- でもいつもセットしてますよね?)。
50005010もし I<本当に> L<C<exec>|/exec LIST> の後に他の文を書きたい場合、以下の
50015011どちらかのスタイルを使うことで警告を回避できます:
50025012
50035013 exec ('foo') or print STDERR "couldn't exec foo: $!";
50045014 { exec ('foo') }; print STDERR "couldn't exec foo: $!";
50055015
50065016=begin original
50075017
50085018If there is more than one argument in LIST, this calls L<execvp(3)> with the
50095019arguments in LIST. If there is only one element in LIST, the argument is
50105020checked for shell metacharacters, and if there are any, the entire
50115021argument is passed to the system's command shell for parsing (this is
50125022C</bin/sh -c> on Unix platforms, but varies on other platforms). If
50135023there are no shell metacharacters in the argument, it is split into words
50145024and passed directly to C<execvp>, which is more efficient. Examples:
50155025
50165026=end original
50175027
50185028LIST に複数の引数がある場合は、LIST の引数を使って L<execvp(3)> を
50195029呼び出します。
50205030LIST に要素が一つのみの場合には、その引数からシェルのメタ文字をチェックし、
50215031もしメタ文字があれば、引数全体をシステムのコマンドシェル(これはUnix では
50225032C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。
50235033シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に
50245034渡されます; この方がより効率的です。
50255035例:
50265036
50275037 exec '/bin/echo', 'Your arguments are: ', @ARGV;
50285038 exec "sort $outfile | uniq";
50295039
50305040=begin original
50315041
50325042If you don't really want to execute the first argument, but want to lie
50335043to the program you are executing about its own name, you can specify
50345044the program you actually want to run as an "indirect object" (without a
50355045comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always
50365046forces interpretation of the LIST as a multivalued list, even if there
50375047is only a single scalar in the list.) Example:
50385048
50395049=end original
50405050
50415051第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の
50425052名前を教えたい場合には、C<exec PROGRAM LIST> のように、LIST の前に
50435053「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを
50445054指定することができます。
50455055(これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、
50465056LIST の解釈を行ないます。)
50475057例:
50485058
50495059 my $shell = '/bin/csh';
50505060 exec $shell '-sh'; # pretend it's a login shell
50515061
50525062=begin original
50535063
50545064or, more directly,
50555065
50565066=end original
50575067
50585068あるいは、より直接的に、
50595069
50605070 exec {'/bin/csh'} '-sh'; # pretend it's a login shell
50615071
50625072=begin original
50635073
50645074When the arguments get executed via the system shell, results are
50655075subject to its quirks and capabilities. See L<perlop/"`STRING`">
50665076for details.
50675077
50685078=end original
50695079
50705080引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって
50715081変わります。
50725082詳細については L<perlop/"`STRING`"> を参照してください。
50735083
50745084=begin original
50755085
50765086Using an indirect object with L<C<exec>|/exec LIST> or
50775087L<C<system>|/system LIST> is also more secure. This usage (which also
50785088works fine with L<C<system>|/system LIST>) forces
50795089interpretation of the arguments as a multivalued list, even if the
50805090list had just one argument. That way you're safe from the shell
50815091expanding wildcards or splitting up words with whitespace in them.
50825092
50835093=end original
50845094
50855095L<C<exec>|/exec LIST> や L<C<system>|/system LIST> で間接オブジェクトを
50865096使うのもより安全です。
50875097この使い方(L<C<system>|/system LIST> でも同様にうまく動きます)は、たとえ
50885098引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを
50895099強制します。
50905100この方法で、シェルによるワイルドカード展開や、空白による単語の分割から
50915101守られます。
50925102
50935103 my @args = ( "echo surprise" );
50945104
50955105 exec @args; # subject to shell escapes
50965106 # if @args == 1
50975107 exec { $args[0] } @args; # safe even with one-arg list
50985108
50995109=begin original
51005110
51015111The first version, the one without the indirect object, ran the I<echo>
51025112program, passing it C<"surprise"> an argument. The second version didn't;
51035113it tried to run a program named I<"echo surprise">, didn't find it, and set
51045114L<C<$?>|perlvar/$?> to a non-zero value indicating failure.
51055115
51065116=end original
51075117
51085118間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、
51095119C<"surprise"> が引数として渡されます。
51105120二つ目のバージョンでは違います; I<"echo surprise"> という名前の
51115121プログラムを実行しようとして、見つからないので、失敗したことを示すために
51125122L<C<$?>|perlvar/$?> に非 0 がセットされます。
51135123
51145124=begin original
51155125
51165126On Windows, only the C<exec PROGRAM LIST> indirect object syntax will
51175127reliably avoid using the shell; C<exec LIST>, even with more than one
51185128element, will fall back to the shell if the first spawn fails.
51195129
51205130=end original
51215131
51225132Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを
51235133使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が
51245134あっても、最初の spawn が失敗したときにシェルに
51255135フォールバックすることがあります。
51265136
51275137=begin original
51285138
51295139Perl attempts to flush all files opened for output before the exec,
51305140but this may not be supported on some platforms (see L<perlport>).
51315141To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
51325142(C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of
51335143L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost
51345144output.
51355145
51365146=end original
51375147
5138v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを
5148Perl は exec の前に出力用に開かれている全てのファイルを
51395149フラッシュしようとしますが、これに対応していないプラットフォームもあります
51405150(L<perlport> を参照してください)。
51415151安全のためには、出力が重複するのを避けるために、全てのオープンしている
51425152ハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
51435153(L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、
51445154L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
51455155呼ぶ必要があるかもしれません。
51465156
51475157=begin original
51485158
51495159Note that L<C<exec>|/exec LIST> will not call your C<END> blocks, nor
51505160will it invoke C<DESTROY> methods on your objects.
51515161
51525162=end original
51535163
51545164L<C<exec>|/exec LIST> は C<END> ブロックや、オブジェクトの
51555165C<DESTROY> メソッドを起動しないことに注意してください。
51565166
51575167=begin original
51585168
51595169Portability issues: L<perlport/exec>.
51605170
51615171=end original
51625172
51635173移植性の問題: L<perlport/exec>。
51645174
51655175=item exists EXPR
51665176X<exists> X<autovivification>
51675177
51685178=for Pod::Functions test whether a hash key is present
51695179
51705180=begin original
51715181
51725182Given an expression that specifies an element of a hash, returns true if the
51735183specified element in the hash has ever been initialized, even if the
51745184corresponding value is undefined.
51755185
51765186=end original
51775187
51785188ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、
51795189たとえ対応する値が未定義でも真を返します。
51805190
51815191 print "Exists\n" if exists $hash{$key};
51825192 print "Defined\n" if defined $hash{$key};
51835193 print "True\n" if $hash{$key};
51845194
51855195=begin original
51865196
51875197exists may also be called on array elements, but its behavior is much less
51885198obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on
51895199arrays.
51905200
51915201=end original
51925202
51935203exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに
51945204不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く
51955205結びついています。
51965206
51975207=begin original
51985208
51995209B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is
52005210strongly discouraged. The
52015211notion of deleting or checking the existence of Perl array elements is not
52025212conceptually coherent, and can lead to surprising behavior.
52035213
52045214=end original
52055215
52065216B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く
52075217非推奨です。
52085218Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
52095219驚くべき振る舞いを引き起こすことがあります。
52105220
52115221 print "Exists\n" if exists $array[$index];
52125222 print "Defined\n" if defined $array[$index];
52135223 print "True\n" if $array[$index];
52145224
52155225=begin original
52165226
52175227A hash or array element can be true only if it's defined and defined only if
52185228it exists, but the reverse doesn't necessarily hold true.
52195229
52205230=end original
52215231
52225232ハッシュまたは配列要素は、定義されているときにのみ真となり、
52235233存在しているときにのみ定義されますが、逆は必ずしも真ではありません。
52245234
52255235=begin original
52265236
52275237Given an expression that specifies the name of a subroutine,
52285238returns true if the specified subroutine has ever been declared, even
52295239if it is undefined. Mentioning a subroutine name for exists or defined
52305240does not count as declaring it. Note that a subroutine that does not
52315241exist may still be callable: its package may have an C<AUTOLOAD>
52325242method that makes it spring into existence the first time that it is
52335243called; see L<perlsub>.
52345244
52355245=end original
52365246
52375247引数としてサブルーチンの名前が指定された場合、
52385248指定されたサブルーチンが宣言されていれば(たとえ未定義でも)
52395249真を返します。
52405250exists や defined のために言及されているサブルーチン名は
52415251宣言としてのカウントに入りません。
52425252存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください:
52435253パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に
52445254存在を作り出すかもしれません; L<perlsub> を参照してください。
52455255
52465256 print "Exists\n" if exists &subroutine;
52475257 print "Defined\n" if defined &subroutine;
52485258
52495259=begin original
52505260
52515261Note that the EXPR can be arbitrarily complicated as long as the final
52525262operation is a hash or array key lookup or subroutine name:
52535263
52545264=end original
52555265
52565266最終的な操作がハッシュや配列の key による検索または
52575267サブルーチン名である限りは、EXPR には任意の複雑な式を置くことができます:
52585268
52595269 if (exists $ref->{A}->{B}->{$key}) { }
52605270 if (exists $hash{A}{B}{$key}) { }
52615271
52625272 if (exists $ref->{A}->{B}->[$ix]) { }
52635273 if (exists $hash{A}{B}[$ix]) { }
52645274
52655275 if (exists &{$ref->{A}{B}{$key}}) { }
52665276
52675277=begin original
52685278
52695279Although the most deeply nested array or hash element will not spring into
52705280existence just because its existence was tested, any intervening ones will.
52715281Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring
52725282into existence due to the existence test for the C<$key> element above.
52735283This happens anywhere the arrow operator is used, including even here:
52745284
52755285=end original
52765286
52775287最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは
52785288存在するようにはなりませんが、途中のものは存在するようになります。
52795289従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の C<$key> の
52805290存在をテストしたことによって存在するようになります。
52815291これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも
52825292起こります。
52835293
52845294 undef $ref;
52855295 if (exists $ref->{"Some key"}) { }
52865296 print $ref; # prints HASH(0x80d3d5c)
52875297
52885298=begin original
52895299
52905300Use of a subroutine call, rather than a subroutine name, as an argument
52915301to L<C<exists>|/exists EXPR> is an error.
52925302
52935303=end original
52945304
52955305L<C<exists>|/exists EXPR> の引数としてサブルーチン名でなくサブルーチン
52965306呼び出しを使うと、エラーになります。
52975307
52985308 exists &sub; # OK
52995309 exists &sub(); # Error
53005310
53015311=item exit EXPR
53025312X<exit> X<terminate> X<abort>
53035313
53045314=item exit
53055315
53065316=for Pod::Functions terminate this program
53075317
53085318=begin original
53095319
53105320Evaluates EXPR and exits immediately with that value. Example:
53115321
53125322=end original
53135323
53145324EXPR を評価し、即座にその値を持って終了します。
53155325例:
53165326
53175327 my $ans = <STDIN>;
53185328 exit 0 if $ans =~ /^[Xx]/;
53195329
53205330=begin original
53215331
53225332See also L<C<die>|/die LIST>. If EXPR is omitted, exits with C<0>
53235333status. The only
53245334universally recognized values for EXPR are C<0> for success and C<1>
53255335for error; other values are subject to interpretation depending on the
53265336environment in which the Perl program is running. For example, exiting
5327533769 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause
53285338the mailer to return the item undelivered, but that's not true everywhere.
53295339
53305340=end original
53315341
53325342L<C<die>|/die LIST> も参照してください。
53335343EXPR が省略された場合には、ステータスを C<0> として終了します。
53345344EXPR の値として広く利用可能なのは C<0> が成功で C<1> が
53355345エラーということだけです; その他の値は、 Perl が実行される環境によって異なる
53365346解釈がされる可能性があります。
53375347例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると
53385348メーラーはアイテムを配達せずに差し戻しますが、
53395349これはいつでも真ではありません。
53405350
53415351=begin original
53425352
53435353Don't use L<C<exit>|/exit EXPR> to abort a subroutine if there's any
53445354chance that someone might want to trap whatever error happened. Use
53455355L<C<die>|/die LIST> instead, which can be trapped by an
53465356L<C<eval>|/eval EXPR>.
53475357
53485358=end original
53495359
53505360誰かが発生したエラーをトラップしようと考えている可能性がある場合は、
53515361サブルーチンの中断に L<C<exit>|/exit EXPR> を使わないでください。
53525362代わりに L<C<eval>|/eval EXPR> でトラップできる L<C<die>|/die LIST> を
53535363使ってください。
53545364
53555365=begin original
53565366
53575367The L<C<exit>|/exit EXPR> function does not always exit immediately. It
53585368calls any defined C<END> routines first, but these C<END> routines may
53595369not themselves abort the exit. Likewise any object destructors that
53605370need to be called are called before the real exit. C<END> routines and
53615371destructors can change the exit status by modifying L<C<$?>|perlvar/$?>.
53625372If this is a problem, you can call
53635373L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor
53645374processing. See L<perlmod> for details.
53655375
53665376=end original
53675377
53685378L<C<exit>|/exit EXPR> 関数は常に直ちに終了するわけではありません。
53695379まず、定義されている C<END> ルーチンを呼び出しますが、
53705380C<END> ルーチン自身は exit を止められません。
53715381同様に、呼び出す必要のあるオブジェクトデストラクタは
53725382すべて、実際の終了前に呼び出されます。
53735383C<END> ルーチンとデストラクタは L<C<$?>|perlvar/$?> を修正することで
53745384終了コードを変更できます。
53755385これが問題になる場合は、C<END> やデストラクタが実行されることを
53765386防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。
53775387詳しくは L<perlmod> を参照してください。
53785388
53795389=begin original
53805390
53815391Portability issues: L<perlport/exit>.
53825392
53835393=end original
53845394
53855395移植性の問題: L<perlport/exit>。
53865396
53875397=item exp EXPR
53885398X<exp> X<exponential> X<antilog> X<antilogarithm> X<e>
53895399
53905400=item exp
53915401
53925402=for Pod::Functions raise I<e> to a power
53935403
53945404=begin original
53955405
53965406Returns I<e> (the natural logarithm base) to the power of EXPR.
53975407If EXPR is omitted, gives C<exp($_)>.
53985408
53995409=end original
54005410
54015411I<e> (自然対数の底) の EXPR 乗を返します。
54025412EXPR を省略した場合には、C<exp($_)> を返します。
54035413
54045414=item fc EXPR
54055415X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold>
54065416
54075417=item fc
54085418
54095419=for Pod::Functions +fc return casefolded version of a string
54105420
54115421=begin original
54125422
54135423Returns the casefolded version of EXPR. This is the internal function
54145424implementing the C<\F> escape in double-quoted strings.
54155425
54165426=end original
54175427
54185428EXPR の畳み込み版を返します。
54195429これは、ダブルクォート文字列における、C<\F> エスケープを
54205430実装する内部関数です。
54215431
54225432=begin original
54235433
54245434Casefolding is the process of mapping strings to a form where case
54255435differences are erased; comparing two strings in their casefolded
54265436form is effectively a way of asking if two strings are equal,
54275437regardless of case.
54285438
54295439=end original
54305440
54315441畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です;
54325442畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に
54335443関わらず等しいかどうかを比較する効率的な方法です。
54345444
54355445=begin original
54365446
54375447Roughly, if you ever found yourself writing this
54385448
54395449=end original
54405450
54415451おおよそ、自分自身で以下のように書いていたとしても
54425452
54435453 lc($this) eq lc($that) # Wrong!
54445454 # or
54455455 uc($this) eq uc($that) # Also wrong!
54465456 # or
54475457 $this =~ /^\Q$that\E\z/i # Right!
54485458
54495459=begin original
54505460
54515461Now you can write
54525462
54535463=end original
54545464
54555465今では以下のように書けます
54565466
54575467 fc($this) eq fc($that)
54585468
54595469=begin original
54605470
54615471And get the correct results.
54625472
54635473=end original
54645474
54655475そして正しい結果を得られます。
54665476
54675477=begin original
54685478
54695479Perl only implements the full form of casefolding, but you can access
54705480the simple folds using L<Unicode::UCD/B<casefold()>> and
54715481L<Unicode::UCD/B<prop_invmap()>>.
54725482For further information on casefolding, refer to
54735483the Unicode Standard, specifically sections 3.13 C<Default Case Operations>,
547454844.2 C<Case-Normative>, and 5.18 C<Case Mappings>,
54755485available at L<https://www.unicode.org/versions/latest/>, as well as the
54765486Case Charts available at L<https://www.unicode.org/charts/case/>.
54775487
54785488=end original
54795489
54805490Perl は完全な形式の畳み込みのみを実装していますが、
54815491L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って
54825492単純なたたみ込みにアクセスできます。
54835493畳み込みに関するさらなる情報については、
54845494L<https://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に
548554953.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18
54865496C<Case Mappings> および、L<https://www.unicode.org/charts/case/> で
54875497利用可能なケース表を参照してください。
54885498
54895499=begin original
54905500
54915501If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
54925502
54935503=end original
54945504
54955505EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
54965506
54975507=begin original
54985508
54995509This function behaves the same way under various pragmas, such as within
55005510L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>,
55015511as L<C<lc>|/lc EXPR> does, with the single exception of
55025512L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the
55035513scope of L<S<C<use locale>>|locale>. The foldcase of this character
55045514would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR>
55055515section, case
55065516changes that cross the 255/256 boundary are problematic under locales,
55075517and are hence prohibited. Therefore, this function under locale returns
55085518instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER
55095519LONG S>. Since that character itself folds to C<"s">, the string of two
55105520of them together should be equivalent to a single U+1E9E when foldcased.
55115521
55125522=end original
55135523
55145524この関数は、
55155525L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>
55165526のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に
55175527振る舞います;
55185528但し、L<S<C<use locale>>|locale> のスコープ内での
55195529I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。
55205530この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で
55215531説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は
55225532問題があるので、禁止されています。
55235533従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である
55245534C<"\x{17F}\x{17F}"> を返します。
55255535この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は
55265536畳み込まれた場合は単一の U+1E9E と等価になります。
55275537
55285538=begin original
55295539
55305540While the Unicode Standard defines two additional forms of casefolding,
55315541one for Turkic languages and one that never maps one character into multiple
55325542characters, these are not provided by the Perl core. However, the CPAN module
55335543L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation.
55345544
55355545=end original
55365546
55375547Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して
55385548一つの文字が複数の文字にマッピングされないもの、を定義していますが、
55395549これらは Perl コアでは提供されません。
55405550しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を
55415551提供しています。
55425552
55435553=begin original
55445554
55455555L<C<fc>|/fc EXPR> is available only if the
55465556L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
55475557prefixed with C<CORE::>. The
55485558L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
55495559with a C<use v5.16> (or higher) declaration in the current scope.
55505560
55515561=end original
55525562
55535563L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
55545564C<CORE::> が前置されたときにのみ利用可能です。
55555565L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
55565566C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
55575567
55585568=item fcntl FILEHANDLE,FUNCTION,SCALAR
55595569X<fcntl>
55605570
55615571=for Pod::Functions file control system call
55625572
55635573=begin original
55645574
55655575Implements the L<fcntl(2)> function. You'll probably have to say
55665576
55675577=end original
55685578
55695579L<fcntl(2)> 関数を実装します。
55705580正しい定数定義を得るために、まず
55715581
55725582 use Fcntl;
55735583
55745584=begin original
55755585
55765586first to get the correct constant definitions. Argument processing and
55775587value returned work just like L<C<ioctl>|/ioctl
55785588FILEHANDLE,FUNCTION,SCALAR> below. For example:
55795589
55805590=end original
55815591
55825592と書くことが必要でしょう。
55835593引数の処理と返り値については、下記の
55845594L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同様に動作します。
55855595例えば:
55865596
55875597 use Fcntl;
55885598 my $flags = fcntl($filehandle, F_GETFL, 0)
55895599 or die "Can't fcntl F_GETFL: $!";
55905600
55915601=begin original
55925602
55935603You don't have to check for L<C<defined>|/defined EXPR> on the return
55945604from L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>. Like
55955605L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, it maps a C<0> return
55965606from the system call into C<"0 but true"> in Perl. This string is true
55975607in boolean context and C<0> in numeric context. It is also exempt from
55985608the normal
55995609L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
56005610L<warnings> on improper numeric conversions.
56015611
56025612=end original
56035613
56045614L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> からの返り値のチェックに
56055615L<C<defined>|/defined EXPR> を使う必要はありません。
56065616L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と違って、これは
56075617システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。
56085618この文字列は真偽値コンテキストでは真となり、
56095619数値コンテキストでは C<0> になります。
56105620これはまた、不適切な数値変換に関する通常の
56115621L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
56125622L<warnings> を回避します。
56135623
56145624=begin original
56155625
56165626Note that L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> raises an
56175627exception if used on a machine that doesn't implement L<fcntl(2)>. See
56185628the L<Fcntl> module or your L<fcntl(2)> manpage to learn what functions
56195629are available on your system.
56205630
56215631=end original
56225632
56235633L<fcntl(2)> が実装されていないマシンでは、
56245634L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を
56255635引き起こすことに注意してください。
56265636システムでどの関数が利用可能かについては L<Fcntl> モジュールや
56275637L<fcntl(2)> man ページを参照してください。
56285638
56295639=begin original
56305640
56315641Here's an example of setting a filehandle named C<$REMOTE> to be
56325642non-blocking at the system level. You'll have to negotiate
56335643L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though.
56345644
56355645=end original
56365646
56375647これは C<$REMOTE> というファイルハンドルをシステムレベルで
56385648非ブロックモードにセットする例です。
56395649ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。
56405650
56415651 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
56425652
56435653 my $flags = fcntl($REMOTE, F_GETFL, 0)
56445654 or die "Can't get flags for the socket: $!\n";
56455655
56465656 fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK)
56475657 or die "Can't set flags for the socket: $!\n";
56485658
56495659=begin original
56505660
56515661Portability issues: L<perlport/fcntl>.
56525662
56535663=end original
56545664
56555665移植性の問題: L<perlport/fcntl>。
56565666
56575667=item __FILE__
56585668X<__FILE__>
56595669
56605670=for Pod::Functions the name of the current source file
56615671
56625672=begin original
56635673
56645674A special token that returns the name of the file in which it occurs.
56655675It can be altered by the mechanism described at
56665676L<perlsyn/"Plain Old Comments (Not!)">.
56675677
56685678=end original
56695679
56705680これが書いてあるファイルの名前を返す特殊トークン。
56715681L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って
56725682置き換えられます。
56735683
56745684=item fileno FILEHANDLE
56755685X<fileno>
56765686
56775687=item fileno DIRHANDLE
56785688
56795689=for Pod::Functions return file descriptor from filehandle
56805690
56815691=begin original
56825692
56835693Returns the file descriptor for a filehandle or directory handle,
56845694or undefined if the
56855695filehandle is not open. If there is no real file descriptor at the OS
56865696level, as can happen with filehandles connected to memory objects via
56875697L<C<open>|/open FILEHANDLE,MODE,EXPR> with a reference for the third
56885698argument, -1 is returned.
56895699
56905700=end original
56915701
56925702ファイルハンドルやディレクトリハンドルに対するファイル記述子を返します;
56935703ファイルハンドルがオープンしていない場合は未定義値を返します。
56945704OS レベルで実際のファイル記述子がない(
56955705L<C<open>|/open FILEHANDLE,MODE,EXPR> の第 3 引数にリファレンスを
56965706指定してファイルハンドルがメモリオブジェクトと結びつけられたときに
56975707起こります)場合、-1 が返されます。
56985708
56995709=begin original
57005710
57015711This is mainly useful for constructing bitmaps for
57025712L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX
57035713tty-handling operations.
57045714If FILEHANDLE is an expression, the value is taken as an indirect
57055715filehandle, generally its name.
57065716
57075717=end original
57085718
57095719これは主に L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> や低レベル
57105720POSIX tty 操作に対する、ビットマップを構成するときに便利です。
57115721FILEHANDLE が式であれば、
57125722その値が間接ファイルハンドル(普通は名前)として使われます。
57135723
57145724=begin original
57155725
57165726You can use this to find out whether two handles refer to the
57175727same underlying descriptor:
57185728
57195729=end original
57205730
57215731これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに
57225732使えます:
57235733
57245734 if (fileno($this) != -1 && fileno($this) == fileno($that)) {
57255735 print "\$this and \$that are dups\n";
57265736 } elsif (fileno($this) != -1 && fileno($that) != -1) {
57275737 print "\$this and \$that have different " .
57285738 "underlying file descriptors\n";
57295739 } else {
57305740 print "At least one of \$this and \$that does " .
57315741 "not have a real file descriptor\n";
57325742 }
57335743
57345744=begin original
57355745
57365746The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle
57375747depends on the operating system. On a system with L<dirfd(3)> or
57385748similar, L<C<fileno>|/fileno FILEHANDLE> on a directory
57395749handle returns the underlying file descriptor associated with the
57405750handle; on systems with no such support, it returns the undefined value,
57415751and sets L<C<$!>|perlvar/$!> (errno).
57425752
57435753=end original
57445754
57455755ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは
57465756オペレーティングシステムに依存します。
57475757L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する
57485758L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる
57495759ファイル記述子を返します;
57505760そのような対応がないシステムでは、未定義値を返し、
57515761L<C<$!>|perlvar/$!> (errno) を設定します。
57525762
57535763=item flock FILEHANDLE,OPERATION
57545764X<flock> X<lock> X<locking>
57555765
57565766=for Pod::Functions lock an entire file with an advisory lock
57575767
57585768=begin original
57595769
57605770Calls L<flock(2)>, or an emulation of it, on FILEHANDLE. Returns true
57615771for success, false on failure. Produces a fatal error if used on a
57625772machine that doesn't implement L<flock(2)>, L<fcntl(2)> locking, or
57635773L<lockf(3)>. L<C<flock>|/flock FILEHANDLE,OPERATION> is Perl's portable
57645774file-locking interface, although it locks entire files only, not
57655775records.
57665776
57675777=end original
57685778
57695779FILEHANDLE に対して L<flock(2)>、またはそのエミュレーションを呼び出します。
57705780成功時には真を、失敗時には偽を返します。
57715781L<flock(2)>, L<fcntl(2)> ロック, L<lockf(3)> のいずれかを実装していない
57725782マシンで使うと、致命的エラーが発生します。
57735783L<C<flock>|/flock FILEHANDLE,OPERATION> は Perl の移植性のある
57745784ファイルロックインターフェースです;
57755785しかしレコードではなく、ファイル全体のみをロックします。
57765786
57775787=begin original
57785788
57795789Two potentially non-obvious but traditional L<C<flock>|/flock
57805790FILEHANDLE,OPERATION> semantics are
57815791that it waits indefinitely until the lock is granted, and that its locks
57825792are B<merely advisory>. Such discretionary locks are more flexible, but
57835793offer fewer guarantees. This means that programs that do not also use
57845794L<C<flock>|/flock FILEHANDLE,OPERATION> may modify files locked with
57855795L<C<flock>|/flock FILEHANDLE,OPERATION>. See L<perlport>,
57865796your port's specific documentation, and your system-specific local manpages
57875797for details. It's best to assume traditional behavior if you're writing
57885798portable programs. (But if you're not, you should as always feel perfectly
57895799free to write for your own system's idiosyncrasies (sometimes called
57905800"features"). Slavish adherence to portability concerns shouldn't get
57915801in the way of your getting your job done.)
57925802
57935803=end original
57945804
57955805明白ではないものの、伝統的な L<C<flock>|/flock FILEHANDLE,OPERATION> の
57965806動作としては、ロックが得られるまで
57975807無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。
57985808このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。
57995809これは、L<C<flock>|/flock FILEHANDLE,OPERATION> を使わないプログラムが
58005810L<C<flock>|/flock FILEHANDLE,OPERATION> でロックされたファイルを
58015811書き換えるかもしれないことを意味します。
58025812詳細については、L<perlport>、システム固有のドキュメント、システム固有の
58035813ローカルの man ページを参照してください。
58045814移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが
58055815ベストです。
58065816(しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば
58075817「仕様」と呼ばれます)に合わせて書くことも完全に自由です。
58085818盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは
58095819ありません。)
58105820
58115821=begin original
58125822
58135823OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with
58145824LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but
58155825you can use the symbolic names if you import them from the L<Fcntl> module,
58165826either individually, or as a group using the C<:flock> tag. LOCK_SH
58175827requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN
58185828releases a previously requested lock. If LOCK_NB is bitwise-or'ed with
58195829LOCK_SH or LOCK_EX, then L<C<flock>|/flock FILEHANDLE,OPERATION> returns
58205830immediately rather than blocking waiting for the lock; check the return
58215831status to see if you got it.
58225832
58235833=end original
58245834
58255835OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と
58265836組み合わされることもあります。
58275837これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから
58285838シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、
58295839シンボル名をを使うことができます。
58305840LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は
58315841前回要求したロックを開放します。
58325842LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、
58335843L<C<flock>|/flock FILEHANDLE,OPERATION> は
58345844ロックを取得するまで待つのではなく、すぐに返ります;
58355845ロックが取得できたかどうかは返り値を調べます。
58365846
58375847=begin original
58385848
58395849To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE
58405850before locking or unlocking it.
58415851
58425852=end original
58435853
58445854不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に
58455855FILEHANDLE をフラッシュします。
58465856
58475857=begin original
58485858
58495859Note that the emulation built with L<lockf(3)> doesn't provide shared
58505860locks, and it requires that FILEHANDLE be open with write intent. These
58515861are the semantics that L<lockf(3)> implements. Most if not all systems
58525862implement L<lockf(3)> in terms of L<fcntl(2)> locking, though, so the
58535863differing semantics shouldn't bite too many people.
58545864
58555865=end original
58565866
58575867L<lockf(3)> で作成されたエミュレーションは共有ロックを提供せず、
58585868FILEHANDLE が書き込みモードで開いていることを必要とすることに
58595869注意してください。
58605870これは L<lockf(3)> が実装している動作です。
58615871しかし、全てではないにしてもほとんどのシステムでは L<fcntl(2)> を使って
58625872L<lockf(3)> を実装しているので、異なった動作で多くの人々を混乱させることは
58635873ないはずです。
58645874
58655875=begin original
58665876
58675877Note that the L<fcntl(2)> emulation of L<flock(3)> requires that FILEHANDLE
58685878be open with read intent to use LOCK_SH and requires that it be open
58695879with write intent to use LOCK_EX.
58705880
58715881=end original
58725882
58735883L<flock(3)> の L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには
58745884FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには
58755885書き込みで開いている必要があることに注意してください。
58765886
58775887=begin original
58785888
58795889Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION>
58805890cannot lock things over the network; you would need to use the more
58815891system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for
58825892that. If you like you can force Perl to ignore your system's L<flock(2)>
58835893function, and so provide its own L<fcntl(2)>-based emulation, by passing
58845894the switch C<-Ud_flock> to the F<Configure> program when you configure
58855895and build a new Perl.
58865896
58875897=end original
58885898
58895899ネットワーク越しにはロックできない L<C<flock>|/flock FILEHANDLE,OPERATION> も
58905900あることに注意してください;
58915901このためには、よりシステム依存な
58925902L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> を使う必要があります。
58935903Perl にシステムの L<flock(2)> 関数を無視させ、自身の L<fcntl(2)> ベースの
58945904エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに
58955905F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。
58965906
58975907=begin original
58985908
58995909Here's a mailbox appender for BSD systems.
59005910
59015911=end original
59025912
59035913BSD システムでのメールボックスへの追加処理の例を示します。
59045914
59055915 # import LOCK_* and SEEK_END constants
59065916 use Fcntl qw(:flock SEEK_END);
59075917
59085918 sub lock {
59095919 my ($fh) = @_;
59105920 flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
59115921 # and, in case we're running on a very old UNIX
59125922 # variant without the modern O_APPEND semantics...
59135923 seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
59145924 }
59155925
59165926 sub unlock {
59175927 my ($fh) = @_;
59185928 flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
59195929 }
59205930
59215931 open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
59225932 or die "Can't open mailbox: $!";
59235933
59245934 lock($mbox);
59255935 print $mbox $msg,"\n\n";
59265936 unlock($mbox);
59275937
59285938=begin original
59295939
59305940On systems that support a real L<flock(2)>, locks are inherited across
59315941L<C<fork>|/fork> calls, whereas those that must resort to the more
59325942capricious L<fcntl(2)> function lose their locks, making it seriously
59335943harder to write servers.
59345944
59355945=end original
59365946
59375947真の L<flock(2)> に対応しているシステムではロックは L<C<fork>|/fork> を通して
59385948継承されるのに対して、より不安定な L<fcntl(2)> に頼らなければならない場合、
59395949サーバを書くのは本当により難しくなります。
59405950
59415951=begin original
59425952
59435953See also L<DB_File> for other L<C<flock>|/flock FILEHANDLE,OPERATION>
59445954examples.
59455955
59465956=end original
59475957
59485958その他の L<C<flock>|/flock FILEHANDLE,OPERATION> の例としては L<DB_File> も
59495959参照してください。
59505960
59515961=begin original
59525962
59535963Portability issues: L<perlport/flock>.
59545964
59555965=end original
59565966
59575967移植性の問題: L<perlport/flock>。
59585968
59595969=item fork
59605970X<fork> X<child> X<parent>
59615971
59625972=for Pod::Functions create a new process just like this one
59635973
59645974=begin original
59655975
59665976Does a L<fork(2)> system call to create a new process running the
59675977same program at the same point. It returns the child pid to the
59685978parent process, C<0> to the child process, or L<C<undef>|/undef EXPR> if
59695979the fork is
59705980unsuccessful. File descriptors (and sometimes locks on those descriptors)
59715981are shared, while everything else is copied. On most systems supporting
59725982L<fork(2)>, great care has gone into making it extremely efficient (for
59735983example, using copy-on-write technology on data pages), making it the
59745984dominant paradigm for multitasking over the last few decades.
59755985
59765986=end original
59775987
59785988同じプログラムの同じ地点から開始する新しいプロセスを作成するために
59795989システムコール L<fork(2)> を行ないます。
59805990親プロセスには、チャイルドプロセスの pid を、
59815991チャイルドプロセスに C<0> を返しますが、
59825992fork に失敗したときには、L<C<undef>|/undef EXPR>を返します。
59835993ファイル記述子(および記述子に関連するロック)は共有され、
59845994その他の全てはコピーされます。
59855995L<fork(2)> に対応するほとんどのシステムでは、
59865996これを極めて効率的にするために多大な努力が払われてきました
59875997(例えば、データページへの copy-on-write テクノロジーなどです);
59885998これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。
59895999
59906000=begin original
59916001
59926002Perl attempts to flush all files opened for output before forking the
59936003child process, but this may not be supported on some platforms (see
59946004L<perlport>). To be safe, you may need to set
59956005L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) or
59966006call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> on
59976007any open handles to avoid duplicate output.
59986008
59996009=end original
60006010
6001v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての
6011Perl は子プロセスを fork する前に出力用にオープンしている全ての
60026012ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも
60036013あります(L<perlport> を参照してください)。
60046014安全のためには、出力が重複するのを避けるために、
60056015全てのオープンしているハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
60066016(L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、
60076017L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
60086018呼ぶ必要があるかもしれません。
60096019
60106020=begin original
60116021
60126022If you L<C<fork>|/fork> without ever waiting on your children, you will
60136023accumulate zombies. On some systems, you can avoid this by setting
60146024L<C<$SIG{CHLD}>|perlvar/%SIG> to C<"IGNORE">. See also L<perlipc> for
60156025more examples of forking and reaping moribund children.
60166026
60176027=end original
60186028
60196029チャイルドプロセスの終了を待たずに、L<C<fork>|/fork> を繰り返せば、
60206030ゾンビをためこむことになります。
60216031L<C<$SIG{CHLD}>|perlvar/%SIG> に C<"IGNORE"> を指定することでこれを
60226032回避できるシステムもあります。
60236033fork と消滅しかけている子プロセスを回収するための更なる例については
60246034L<perlipc> も参照してください。
60256035
60266036=begin original
60276037
60286038Note that if your forked child inherits system file descriptors like
60296039STDIN and STDOUT that are actually connected by a pipe or socket, even
60306040if you exit, then the remote server (such as, say, a CGI script or a
60316041backgrounded job launched from a remote shell) won't think you're done.
60326042You should reopen those to F</dev/null> if it's any issue.
60336043
60346044=end original
60356045
60366046fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を
60376047継承する場合、(CGI スクリプトやリモートシェルといった
60386048バックグラウンドジョブのような)リモートサーバは考え通りに
60396049動かないであろうことに注意してください。
60406050このような場合ではこれらを F</dev/null> として再オープンするべきです。
60416051
60426052=begin original
60436053
60446054On some platforms such as Windows, where the L<fork(2)> system call is
60456055not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl
60466056interpreter. The emulation is designed, at the level of the Perl
60476057program, to be as compatible as possible with the "Unix" L<fork(2)>.
60486058However it has limitations that have to be considered in code intended
60496059to be portable. See L<perlfork> for more details.
60506060
60516061=end original
60526062
60536063Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
60546064L<C<fork>|/fork> を Perl インタプリタでエミュレートします。
60556065エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)> と
60566066互換性があるように設計されています。
60576067しかしコードが移植性があると考えられるように制限があります。
60586068さらなる詳細については L<perlfork> を参照してください。
60596069
60606070=begin original
60616071
60626072Portability issues: L<perlport/fork>.
60636073
60646074=end original
60656075
60666076移植性の問題: L<perlport/fork>。
60676077
60686078=item format
60696079X<format>
60706080
60716081=for Pod::Functions declare a picture format with use by the write() function
60726082
60736083=begin original
60746084
60756085Declare a picture format for use by the L<C<write>|/write FILEHANDLE>
60766086function. For example:
60776087
60786088=end original
60796089
60806090L<C<write>|/write FILEHANDLE> 関数で使うピクチャーフォーマットを宣言します。
60816091例えば:
60826092
60836093 format Something =
60846094 Test: @<<<<<<<< @||||| @>>>>>
60856095 $str, $%, '$' . int($num)
60866096 .
60876097
60886098 $str = "widget";
60896099 $num = $cost/$quantity;
60906100 $~ = 'Something';
60916101 write;
60926102
60936103=begin original
60946104
60956105See L<perlform> for many details and examples.
60966106
60976107=end original
60986108
60996109詳細と例については L<perlform> を参照してください。
61006110
61016111=item formline PICTURE,LIST
61026112X<formline>
61036113
61046114=for Pod::Functions internal function used for formats
61056115
61066116=begin original
61076117
61086118This is an internal function used by L<C<format>|/format>s, though you
61096119may call it, too. It formats (see L<perlform>) a list of values
61106120according to the contents of PICTURE, placing the output into the format
61116121output accumulator, L<C<$^A>|perlvar/$^A> (or C<$ACCUMULATOR> in
61126122L<English>). Eventually, when a L<C<write>|/write FILEHANDLE> is done,
61136123the contents of L<C<$^A>|perlvar/$^A> are written to some filehandle.
61146124You could also read L<C<$^A>|perlvar/$^A> and then set
61156125L<C<$^A>|perlvar/$^A> back to C<"">. Note that a format typically does
61166126one L<C<formline>|/formline PICTURE,LIST> per line of form, but the
61176127L<C<formline>|/formline PICTURE,LIST> function itself doesn't care how
61186128many newlines are embedded in the PICTURE. This means that the C<~> and
61196129C<~~> tokens treat the entire PICTURE as a single line. You may
61206130therefore need to use multiple formlines to implement a single record
61216131format, just like the L<C<format>|/format> compiler.
61226132
61236133=end original
61246134
61256135これは、L<C<format>|/format> が使用する内部関数ですが、直接呼び出すことも
61266136できます。
61276137これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を
61286138参照してください)、結果をフォーマット出力アキュムレータL<C<$^A>|perlvar/$^A>
61296139(L<English> モジュールでは C<$ACCUMULATOR>) に納めます。
61306140最終的に、L<C<write>|/write FILEHANDLE> が実行されると、
61316141L<C<$^A>|perlvar/$^A> の中身が、何らかのファイルハンドルに書き出されます。
61326142また、自分で L<C<$^A>|perlvar/$^A> を読んで、L<C<$^A>|perlvar/$^A> の内容を
61336143C<""> に戻してもかまいません。
61346144format は通常、1 行ごとに L<C<formline>|/formline PICTURE,LIST> を
61356145行ないますが、L<C<formline>|/formline PICTURE,LIST> 関数自身は、PICTURE の中に
61366146いくつの改行が入っているかは、関係がありません。
61376147これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。
61386148従って、1 レコードフォーマットを実装するためには
61396149L<C<format>|/format> コンパイラのような複数 formline を使う必要があります。
61406150
61416151=begin original
61426152
61436153Be careful if you put double quotes around the picture, because an C<@>
61446154character may be taken to mean the beginning of an array name.
61456155L<C<formline>|/formline PICTURE,LIST> always returns true. See
61466156L<perlform> for other examples.
61476157
61486158=end original
61496159
61506160ダブルクォートで PICTURE を囲む場合には、C<@> という文字が
61516161配列名の始まりと解釈されますので、注意してください。
61526162L<C<formline>|/formline PICTURE,LIST> は常に真を返します。
61536163その他の例については L<perlform> を参照してください。
61546164
61556165=begin original
61566166
61576167If you are trying to use this instead of L<C<write>|/write FILEHANDLE>
61586168to capture the output, you may find it easier to open a filehandle to a
61596169scalar (C<< open my $fh, ">", \$output >>) and write to that instead.
61606170
61616171=end original
61626172
61636173出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを
61646174使おうとした場合、スカラにファイルハンドルを開いて
61656175(C<< open my $fh, ">", \$output >>)、
61666176代わりにここに出力する方が簡単であることに気付くでしょう。
61676177
61686178=item getc FILEHANDLE
61696179X<getc> X<getchar> X<character> X<file, read>
61706180
61716181=item getc
61726182
61736183=for Pod::Functions get the next character from the filehandle
61746184
61756185=begin original
61766186
61776187Returns the next character from the input file attached to FILEHANDLE,
61786188or the undefined value at end of file or if there was an error (in
61796189the latter case L<C<$!>|perlvar/$!> is set). If FILEHANDLE is omitted,
61806190reads from
61816191STDIN. This is not particularly efficient. However, it cannot be
61826192used by itself to fetch single characters without waiting for the user
61836193to hit enter. For that, try something more like:
61846194
61856195=end original
61866196
61876197FILEHANDLE につながれている入力ファイルから、次の一文字を返します;
61886198ファイルの最後、またはエラーが発生した場合は、未定義値を返します
61896199(後者の場合は L<C<$!>|perlvar/$!> がセットされます)。
61906200FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。
61916201これは特に効率的ではありません。
61926202しかし、これはユーザーがリターンキーを押すのを待つことなく
61936203一文字を読み込む用途には使えません。
61946204そのような場合には、以下のようなものを試して見てください:
61956205
61966206 if ($BSD_STYLE) {
61976207 system "stty cbreak </dev/tty >/dev/tty 2>&1";
61986208 }
61996209 else {
62006210 system "stty", '-icanon', 'eol', "\001";
62016211 }
62026212
62036213 my $key = getc(STDIN);
62046214
62056215 if ($BSD_STYLE) {
62066216 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
62076217 }
62086218 else {
62096219 system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
62106220 }
62116221 print "\n";
62126222
62136223=begin original
62146224
62156225Determination of whether C<$BSD_STYLE> should be set is left as an
62166226exercise to the reader.
62176227
62186228=end original
62196229
62206230C<$BSD_STYLE> をセットするべきかどうかを決定する方法については
62216231読者への宿題として残しておきます。
62226232
62236233=begin original
62246234
62256235The L<C<POSIX::getattr>|POSIX/C<getattr>> function can do this more
62266236portably on systems purporting POSIX compliance. See also the
62276237L<C<Term::ReadKey>|Term::ReadKey> module on CPAN.
62286238
62296239=end original
62306240
62316241L<C<POSIX::getattr>|POSIX/C<getattr>> 関数は POSIX 準拠を主張するシステムで
62326242これをより移植性のある形で行います。
62336243CPAN にある L<C<Term::ReadKey>|Term::ReadKey> モジュールも
62346244参照してください。
62356245
62366246=item getlogin
62376247X<getlogin> X<login>
62386248
62396249=for Pod::Functions return who logged in at this tty
62406250
62416251=begin original
62426252
62436253This implements the C library function of the same name, which on most
62446254systems returns the current login from F</etc/utmp>, if any. If it
62456255returns the empty string, use L<C<getpwuid>|/getpwuid UID>.
62466256
62476257=end original
62486258
62496259これは同じ名前の C ライブラリ関数を実装していて、
62506260多くのシステムでは、もしあれば、F</etc/utmp> から現在のログイン名を返します。
62516261もし空文字列が返ってきた場合は、L<C<getpwuid>|/getpwuid UID> を
62526262使ってください。
62536263
62546264 my $login = getlogin || getpwuid($<) || "Kilroy";
62556265
62566266=begin original
62576267
62586268Do not consider L<C<getlogin>|/getlogin> for authentication: it is not
62596269as secure as L<C<getpwuid>|/getpwuid UID>.
62606270
62616271=end original
62626272
62636273L<C<getlogin>|/getlogin> を認証に使ってはいけません: これは
62646274L<C<getpwuid>|/getpwuid UID> のように安全ではありません。
62656275
62666276=begin original
62676277
62686278Portability issues: L<perlport/getlogin>.
62696279
62706280=end original
62716281
62726282移植性の問題: L<perlport/getlogin>。
62736283
62746284=item getpeername SOCKET
62756285X<getpeername> X<peer>
62766286
62776287=for Pod::Functions find the other end of a socket connection
62786288
62796289=begin original
62806290
62816291Returns the packed sockaddr address of the other end of the SOCKET
62826292connection.
62836293
62846294=end original
62856295
62866296SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。
62876297
62886298 use Socket;
62896299 my $hersockaddr = getpeername($sock);
62906300 my ($port, $iaddr) = sockaddr_in($hersockaddr);
62916301 my $herhostname = gethostbyaddr($iaddr, AF_INET);
62926302 my $herstraddr = inet_ntoa($iaddr);
62936303
62946304=item getpgrp PID
62956305X<getpgrp> X<group>
62966306
62976307=for Pod::Functions get process group
62986308
62996309=begin original
63006310
63016311Returns the current process group for the specified PID. Use
63026312a PID of C<0> to get the current process group for the
63036313current process. Will raise an exception if used on a machine that
63046314doesn't implement L<getpgrp(2)>. If PID is omitted, returns the process
63056315group of the current process. Note that the POSIX version of
63066316L<C<getpgrp>|/getpgrp PID> does not accept a PID argument, so only
63076317C<PID==0> is truly portable.
63086318
63096319=end original
63106320
63116321指定された PID の現在のプロセスグループを返します。
63126322PID に C<0> を与えるとカレントプロセスの指定となります。
63136323L<getpgrp(2)> を実装していないマシンで実行した場合には、例外が発生します。
63146324PID を省略するとカレントプロセスのプロセスグループを返します。
63156325POSIX 版の L<C<getpgrp>|/getpgrp PID> は PID 引数を受け付けないので、
63166326C<PID==0> のみが完全に移植性があります。
63176327
63186328=begin original
63196329
63206330Portability issues: L<perlport/getpgrp>.
63216331
63226332=end original
63236333
63246334移植性の問題: L<perlport/getpgrp>。
63256335
63266336=item getppid
63276337X<getppid> X<parent> X<pid>
63286338
63296339=for Pod::Functions get parent process ID
63306340
63316341=begin original
63326342
63336343Returns the process id of the parent process.
63346344
63356345=end original
63366346
63376347親プロセスのプロセス id を返します。
63386348
63396349=begin original
63406350
63416351Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
63426352around non-POSIX thread semantics the minority of Linux systems (and
63436353Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
63446354has since been removed. See the documentation for L<$$|perlvar/$$> for
63456355details.
63466356
63476357=end original
63486358
63496359Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は
63506360LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな
63516361Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。
63526362このエミュレーションは削除されました;
63536363詳しくは L<$$|perlvar/$$> の文書を参照してください。
63546364
63556365=begin original
63566366
63576367Portability issues: L<perlport/getppid>.
63586368
63596369=end original
63606370
63616371移植性の問題: L<perlport/getppid>。
63626372
63636373=item getpriority WHICH,WHO
63646374X<getpriority> X<priority> X<nice>
63656375
63666376=for Pod::Functions get current nice value
63676377
63686378=begin original
63696379
63706380Returns the current priority for a process, a process group, or a user.
63716381(See L<getpriority(2)>.) Will raise a fatal exception if used on a
63726382machine that doesn't implement L<getpriority(2)>.
63736383
63746384=end original
63756385
63766386プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。
63776387(L<getpriority(2)> を参照してください。)
63786388L<getpriority(2)> を実装していない
63796389マシンで実行した場合には、致命的例外が発生します。
63806390
63816391=begin original
63826392
63836393C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER>
63846394imported from L<POSIX/RESOURCE CONSTANTS>.
63856395
63866396=end original
63876397
6388C<WHICH> は L<POSIX/RESOURCE CONSTANTS> からインポートされた
6398C<WHICH> はL<POSIX/RESOURCE CONSTANTS> からインポートされた
63896399C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。
63906400
63916401=begin original
63926402
63936403Portability issues: L<perlport/getpriority>.
63946404
63956405=end original
63966406
63976407移植性の問題: L<perlport/getpriority>。
63986408
63996409=item getpwnam NAME
64006410X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname>
64016411X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr>
64026412X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent>
64036413X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent>
64046414X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent>
64056415X<endnetent> X<endprotoent> X<endservent>
64066416
64076417=for Pod::Functions get passwd record given user login name
64086418
64096419=item getgrnam NAME
64106420
64116421=for Pod::Functions get group record given group name
64126422
64136423=item gethostbyname NAME
64146424
64156425=for Pod::Functions get host record given name
64166426
64176427=item getnetbyname NAME
64186428
64196429=for Pod::Functions get networks record given name
64206430
64216431=item getprotobyname NAME
64226432
64236433=for Pod::Functions get protocol record given name
64246434
64256435=item getpwuid UID
64266436
64276437=for Pod::Functions get passwd record given user ID
64286438
64296439=item getgrgid GID
64306440
64316441=for Pod::Functions get group record given group user ID
64326442
64336443=item getservbyname NAME,PROTO
64346444
64356445=for Pod::Functions get services record given its name
64366446
64376447=item gethostbyaddr ADDR,ADDRTYPE
64386448
64396449=for Pod::Functions get host record given its address
64406450
64416451=item getnetbyaddr ADDR,ADDRTYPE
64426452
64436453=for Pod::Functions get network record given its address
64446454
64456455=item getprotobynumber NUMBER
64466456
64476457=for Pod::Functions get protocol record numeric protocol
64486458
64496459=item getservbyport PORT,PROTO
64506460
64516461=for Pod::Functions get services record given numeric port
64526462
64536463=item getpwent
64546464
64556465=for Pod::Functions get next passwd record
64566466
64576467=item getgrent
64586468
64596469=for Pod::Functions get next group record
64606470
64616471=item gethostent
64626472
64636473=for Pod::Functions get next hosts record
64646474
64656475=item getnetent
64666476
64676477=for Pod::Functions get next networks record
64686478
64696479=item getprotoent
64706480
64716481=for Pod::Functions get next protocols record
64726482
64736483=item getservent
64746484
64756485=for Pod::Functions get next services record
64766486
64776487=item setpwent
64786488
64796489=for Pod::Functions prepare passwd file for use
64806490
64816491=item setgrent
64826492
64836493=for Pod::Functions prepare group file for use
64846494
64856495=item sethostent STAYOPEN
64866496
64876497=for Pod::Functions prepare hosts file for use
64886498
64896499=item setnetent STAYOPEN
64906500
64916501=for Pod::Functions prepare networks file for use
64926502
64936503=item setprotoent STAYOPEN
64946504
64956505=for Pod::Functions prepare protocols file for use
64966506
64976507=item setservent STAYOPEN
64986508
64996509=for Pod::Functions prepare services file for use
65006510
65016511=item endpwent
65026512
65036513=for Pod::Functions be done using passwd file
65046514
65056515=item endgrent
65066516
65076517=for Pod::Functions be done using group file
65086518
65096519=item endhostent
65106520
65116521=for Pod::Functions be done using hosts file
65126522
65136523=item endnetent
65146524
65156525=for Pod::Functions be done using networks file
65166526
65176527=item endprotoent
65186528
65196529=for Pod::Functions be done using protocols file
65206530
65216531=item endservent
65226532
65236533=for Pod::Functions be done using services file
65246534
65256535=begin original
65266536
65276537These routines are the same as their counterparts in the
65286538system C library. In list context, the return values from the
65296539various get routines are as follows:
65306540
65316541=end original
65326542
65336543これらのルーチンは、システムの C ライブラリの同名の関数と同じです。
65346544リストコンテキストでは、さまざまな
65356545get ルーチンからの返り値は、次のようになります:
65366546
65376547 # 0 1 2 3 4
65386548 my ( $name, $passwd, $gid, $members ) = getgr*
65396549 my ( $name, $aliases, $addrtype, $net ) = getnet*
65406550 my ( $name, $aliases, $port, $proto ) = getserv*
65416551 my ( $name, $aliases, $proto ) = getproto*
65426552 my ( $name, $aliases, $addrtype, $length, @addrs ) = gethost*
65436553 my ( $name, $passwd, $uid, $gid, $quota,
65446554 $comment, $gcos, $dir, $shell, $expire ) = getpw*
65456555 # 5 6 7 8 9
65466556
65476557=begin original
65486558
65496559(If the entry doesn't exist, the return value is a single meaningless true
65506560value.)
65516561
65526562=end original
65536563
65546564(エントリが存在しなければ、返り値は単一の意味のない真の値です。)
65556565
65566566=begin original
65576567
65586568The exact meaning of the $gcos field varies but it usually contains
65596569the real name of the user (as opposed to the login name) and other
65606570information pertaining to the user. Beware, however, that in many
65616571system users are able to change this information and therefore it
65626572cannot be trusted and therefore the $gcos is tainted (see
65636573L<perlsec>). The $passwd and $shell, user's encrypted password and
65646574login shell, are also tainted, for the same reason.
65656575
65666576=end original
65676577
65686578$gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく)
65696579ユーザーの実際の名前とユーザーに付随する情報を含みます。
65706580但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は
65716581信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。
65726582ユーザーの暗号化されたパスワードとログインシェルである $passwd と
65736583$shell も、同様の理由で汚染されます。
65746584
65756585=begin original
65766586
65776587In scalar context, you get the name, unless the function was a
65786588lookup by name, in which case you get the other thing, whatever it is.
65796589(If the entry doesn't exist you get the undefined value.) For example:
65806590
65816591=end original
65826592
65836593スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、
65846594name を返し、NAME で検索するものは、何か別のものを返します。
65856595(エントリが存在しなければ、未定義値が返ります。)
65866596例えば:
65876597
65886598 my $uid = getpwnam($name);
65896599 my $name = getpwuid($num);
65906600 my $name = getpwent();
65916601 my $gid = getgrnam($name);
65926602 my $name = getgrgid($num);
65936603 my $name = getgrent();
65946604 # etc.
65956605
65966606=begin original
65976607
65986608In I<getpw*()> the fields $quota, $comment, and $expire are special
65996609in that they are unsupported on many systems. If the
66006610$quota is unsupported, it is an empty scalar. If it is supported, it
66016611usually encodes the disk quota. If the $comment field is unsupported,
66026612it is an empty scalar. If it is supported it usually encodes some
66036613administrative comment about the user. In some systems the $quota
66046614field may be $change or $age, fields that have to do with password
66056615aging. In some systems the $comment field may be $class. The $expire
66066616field, if present, encodes the expiration period of the account or the
66076617password. For the availability and the exact meaning of these fields
66086618in your system, please consult L<getpwnam(3)> and your system's
66096619F<pwd.h> file. You can also find out from within Perl what your
66106620$quota and $comment fields mean and whether you have the $expire field
66116621by using the L<C<Config>|Config> module and the values C<d_pwquota>, C<d_pwage>,
66126622C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password
66136623files are supported only if your vendor has implemented them in the
66146624intuitive fashion that calling the regular C library routines gets the
66156625shadow versions if you're running under privilege or if there exists
66166626the L<shadow(3)> functions as found in System V (this includes Solaris
66176627and Linux). Those systems that implement a proprietary shadow password
66186628facility are unlikely to be supported.
66196629
66206630=end original
66216631
66226632I<getpw*()> では、$quota, $comment, $expire フィールドは、
66236633多くのシステムでは対応していないので特別な処理がされます。
66246634$quota が非対応の場合、空のスカラになります。
66256635対応している場合、通常はディスククォータの値が入ります。
66266636$comment フィールドが非対応の場合、空のスカラになります。
66276637対応している場合、通常はユーザーに関する管理上のコメントが入ります。
66286638$quota フィールドはパスワードの寿命を示す $change や $age である
66296639システムもあります。
66306640$comment フィールドは $class であるシステムもあります。
66316641$expire フィールドがある場合は、アカウントやパスワードが時間切れになる
66326642期間が入ります。
66336643動作させるシステムでのこれらのフィールドの有効性と正確な意味については、
66346644L<getpwnam(3)> のドキュメントと F<pwd.h> ファイルを参照してください。
66356645$quota と $comment フィールドが何を意味しているかと、$expire フィールドが
66366646あるかどうかは、L<C<Config>|Config> モジュールを使って、C<d_pwquota>,
66376647C<d_pwage>, C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を
66386648調べることによって Perl 自身で調べることも出来ます。
66396649シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で
66406650呼び出すことでシャドウ版が取得できるか、System V にあるような
66416651(Solaris と Linux を含みます) L<shadow(3)> 関数があるといった、
66426652直感的な方法で実装されている場合にのみ対応されます。
66436653独占的なシャドウパスワード機能を実装しているシステムでは、
66446654それに対応されることはないでしょう。
66456655
66466656=begin original
66476657
66486658The $members value returned by I<getgr*()> is a space-separated list of
66496659the login names of the members of the group.
66506660
66516661=end original
66526662
66536663I<getgr*()> によって返る値 $members は、グループのメンバの
66546664ログイン名をスペースで区切ったものです。
66556665
66566666=begin original
66576667
66586668For the I<gethost*()> functions, if the C<h_errno> variable is supported in
66596669C, it will be returned to you via L<C<$?>|perlvar/$?> if the function
66606670call fails. The
66616671C<@addrs> value returned by a successful call is a list of raw
66626672addresses returned by the corresponding library call. In the
66636673Internet domain, each address is four bytes long; you can unpack it
66646674by saying something like:
66656675
66666676=end original
66676677
66686678I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、
66696679関数呼出が失敗したときに、L<C<$?>|perlvar/$?> を通して、その値が返されます。
66706680成功時に返される C<@addrs> 値は、対応するシステムコールが返す、
66716681生のアドレスのリストです。
66726682インターネットドメインでは、個々のアドレスは、4 バイト長です;
66736683以下のようにして unpack することができます:
66746684
66756685 my ($w,$x,$y,$z) = unpack('W4',$addr[0]);
66766686
66776687=begin original
66786688
66796689The Socket library makes this slightly easier:
66806690
66816691=end original
66826692
66836693Socket ライブラリを使うともう少し簡単になります。
66846694
66856695 use Socket;
66866696 my $iaddr = inet_aton("127.1"); # or whatever address
66876697 my $name = gethostbyaddr($iaddr, AF_INET);
66886698
66896699 # or going the other way
66906700 my $straddr = inet_ntoa($iaddr);
66916701
66926702=begin original
66936703
66946704In the opposite way, to resolve a hostname to the IP address
66956705you can write this:
66966706
66976707=end original
66986708
66996709逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます:
67006710
67016711 use Socket;
67026712 my $packed_ip = gethostbyname("www.perl.org");
67036713 my $ip_address;
67046714 if (defined $packed_ip) {
67056715 $ip_address = inet_ntoa($packed_ip);
67066716 }
67076717
67086718=begin original
67096719
67106720Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR
67116721context and that its return value is checked for definedness.
67126722
67136723=end original
67146724
67156725L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで
67166726呼び出すようにして、返り値が定義されているかを必ずチェックしてください。
67176727
67186728=begin original
67196729
67206730The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even
67216731though it only takes one argument, has the precedence of a list
67226732operator, so beware:
67236733
67246734=end original
67256735
67266736L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか
67276737取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って
67286738注意してください:
67296739
67306740 getprotobynumber $number eq 'icmp' # WRONG
67316741 getprotobynumber($number eq 'icmp') # actually means this
67326742 getprotobynumber($number) eq 'icmp' # better this way
67336743
67346744=begin original
67356745
67366746If you get tired of remembering which element of the return list
67376747contains which return value, by-name interfaces are provided in standard
67386748modules: L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
67396749L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
67406750L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
67416751L<C<Time::localtime>|Time::localtime>, and
67426752L<C<User::grent>|User::grent>. These override the normal built-ins,
67436753supplying versions that return objects with the appropriate names for
67446754each field. For example:
67456755
67466756=end original
67476757
67486758返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、
67496759名前ベースのインターフェースが標準モジュールで提供されています:
67506760L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
67516761L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
67526762L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
67536763L<C<Time::localtime>|Time::localtime>,
67546764L<C<User::grent>|User::grent> です。
67556765これらは通常の組み込みを上書きし、
67566766それぞれのフィールドに適切な名前をつけたオブジェクトを返します。
67576767例えば:
67586768
67596769 use File::stat;
67606770 use User::pwent;
67616771 my $is_his = (stat($filename)->uid == pwent($whoever)->uid);
67626772
67636773=begin original
67646774
67656775Even though it looks as though they're the same method calls (uid),
67666776they aren't, because a C<File::stat> object is different from
67676777a C<User::pwent> object.
67686778
67696779=end original
67706780
67716781同じメソッド(uid)を呼び出しているように見えますが、違います;
67726782なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは
67736783異なるからです。
67746784
67756785=begin original
67766786
67776787Many of these functions are not safe in a multi-threaded environment
67786788where more than one thread can be using them. In particular, functions
67796789like C<getpwent()> iterate per-process and not per-thread, so if two
67806790threads are simultaneously iterating, neither will get all the records.
67816791
67826792=end original
67836793
67846794これらの関数の多くは、複数のスレッドがこれらを使うような
67856795マルチスレッド環境では安全ではありません。
67866796特に、
67876797C<getpwent()> のような関数はスレッド単位ではなくプロセス単位で
67886798反復するので、二つのスレッドが同時に反復すると、
67896799どちらも全てのレコードを得られません。
67906800
67916801=begin original
67926802
67936803Some systems have thread-safe versions of some of the functions, such as
67946804C<getpwnam_r()> instead of C<getpwnam()>. There, Perl automatically and
67956805invisibly substitutes the thread-safe version, without notice. This
67966806means that code that safely runs on some systems can fail on others that
67976807lack the thread-safe versions.
67986808
67996809=end original
68006810
68016811一部のシステムは、
68026812C<getpwnam()> の代わりの C<getpwnam_r()> のように、一部の関数について
68036813スレッドセーフ版を持っています。
68046814その場合、Perl は自動的かつ目に見えないように、通知なしで
68056815スレッドセーフ版に置き換えます。
68066816つまり、一部のシステムで安全に実行できるコードが
68076817スレッドセーフ版のないその他のシステムでは失敗することがあるということです。
68086818
68096819=begin original
68106820
68116821Portability issues: L<perlport/getpwnam> to L<perlport/endservent>.
68126822
68136823=end original
68146824
68156825移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。
68166826
68176827=item getsockname SOCKET
68186828X<getsockname>
68196829
68206830=for Pod::Functions retrieve the sockaddr for a given socket
68216831
68226832=begin original
68236833
68246834Returns the packed sockaddr address of this end of the SOCKET connection,
68256835in case you don't know the address because you have several different
68266836IPs that the connection might have come in on.
68276837
68286838=end original
68296839
68306840SOCKET 接続のこちら側の pack された sockaddr アドレスを返します;
68316841複数の異なる IP から接続されるためにアドレスがわからない場合に使います。
68326842
68336843 use Socket;
68346844 my $mysockaddr = getsockname($sock);
68356845 my ($port, $myaddr) = sockaddr_in($mysockaddr);
68366846 printf "Connect to %s [%s]\n",
68376847 scalar gethostbyaddr($myaddr, AF_INET),
68386848 inet_ntoa($myaddr);
68396849
68406850=item getsockopt SOCKET,LEVEL,OPTNAME
68416851X<getsockopt>
68426852
68436853=for Pod::Functions get socket options on a given socket
68446854
68456855=begin original
68466856
68476857Queries the option named OPTNAME associated with SOCKET at a given LEVEL.
68486858Options may exist at multiple protocol levels depending on the socket
68496859type, but at least the uppermost socket level SOL_SOCKET (defined in the
68506860L<C<Socket>|Socket> module) will exist. To query options at another
68516861level the protocol number of the appropriate protocol controlling the
68526862option should be supplied. For example, to indicate that an option is
68536863to be interpreted by the TCP protocol, LEVEL should be set to the
68546864protocol number of TCP, which you can get using
68556865L<C<getprotobyname>|/getprotobyname NAME>.
68566866
68576867=end original
68586868
68596869与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを
68606870問い合わせます。
68616871オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも
68626872ありますが、少なくとも最上位ソケットレベル SOL_SOCKET
68636873(L<C<Socket>|Socket> モジュールで定義されています)は存在します。
68646874その他のレベルのオプションを問い合わせるには、そのオプションを制御する
68656875適切なプロトコルのプロトコル番号を指定します。
68666876例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、
68676877LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の
68686878プロトコル番号を設定します。
68696879
68706880=begin original
68716881
68726882The function returns a packed string representing the requested socket
68736883option, or L<C<undef>|/undef EXPR> on error, with the reason for the
68746884error placed in L<C<$!>|perlvar/$!>. Just what is in the packed string
68756885depends on LEVEL and OPTNAME; consult L<getsockopt(2)> for details. A
68766886common case is that the option is an integer, in which case the result
68776887is a packed integer, which you can decode using
68786888L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format.
68796889
68806890=end original
68816891
68826892この関数は、要求されたソケットオプションの pack された文字列表現か、
68836893あるいはエラーの場合は L<C<undef>|/undef EXPR> を返し、エラーの理由は
68846894L<C<$!>|perlvar/$!> にあります。
68856895pack された文字列の中身は LEVEL と OPTNAME に依存します;
68866896詳細については L<getsockopt(2)> を確認してください。
68876897一般的な場合はオプションが整数の場合で、この場合結果は
68886898L<C<unpack>|/unpack TEMPLATE,EXPR> の C<i>
68896899(あるいは C<I>)フォーマットでデコードできる pack された整数です。
68906900
68916901=begin original
68926902
68936903Here's an example to test whether Nagle's algorithm is enabled on a socket:
68946904
68956905=end original
68966906
68976907あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です:
68986908
68996909 use Socket qw(:all);
69006910
69016911 defined(my $tcp = getprotobyname("tcp"))
69026912 or die "Could not determine the protocol number for tcp";
69036913 # my $tcp = IPPROTO_TCP; # Alternative
69046914 my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
69056915 or die "getsockopt TCP_NODELAY: $!";
69066916 my $nodelay = unpack("I", $packed);
69076917 print "Nagle's algorithm is turned ",
69086918 $nodelay ? "off\n" : "on\n";
69096919
69106920=begin original
69116921
69126922Portability issues: L<perlport/getsockopt>.
69136923
69146924=end original
69156925
69166926移植性の問題: L<perlport/getsockopt>。
69176927
69186928=item glob EXPR
69196929X<glob> X<wildcard> X<filename, expansion> X<expand>
69206930
69216931=item glob
69226932
69236933=for Pod::Functions expand filenames using wildcards
69246934
69256935=begin original
69266936
69276937In list context, returns a (possibly empty) list of filename expansions on
6928the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
6938the value of EXPR such as the Unix shell Bash would do. In
69296939scalar context, glob iterates through such filename expansions, returning
6930undef when the list is exhausted. This is the internal function
6940L<C<undef>|/undef EXPR> when the list is exhausted. If EXPR is omitted,
6931implementing the C<< <*.c> >> operator, but you can use it directly. If
6941L<C<$_>|perlvar/$_> is used.
6932EXPR is omitted, L<C<$_>|perlvar/$_> is used. The C<< <*.c> >> operator
6933is discussed in more detail in L<perlop/"I/O Operators">.
69346942
69356943=end original
69366944
69376945リストコンテキストでは、
6938EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように
6946EXPR の値を、Unix シェル Bash が行なうように
69396947ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。
69406948スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、
6941リストがなくなったら undef を返します。
6949リストがなくなったら L<C<undef>|/undef EXPR> を返します。
6942これは、C<< <*.c> >> 演算子を実装する内部関数ですが、
6943直接使用することもできます。
69446950EXPR が省略されると、L<C<$_>|perlvar/$_> が使われます。
6945C<< <*.c> >>演算子については
6946L<perlop/"I/O Operators"> でより詳細に議論しています。
69476951
6952 # List context
6953 my @txt_files = glob("*.txt");
6954 my @perl_files = glob("*.pl *.pm");
6955
6956 # Scalar context
6957 while (my $file = glob("*.mp3")) {
6958 # Do stuff
6959 }
6960
69486961=begin original
69496962
6963Glob also supports an alternate syntax using C<< < >> C<< > >> as
6964delimiters. While this syntax is supported, it is recommended that you
6965use C<glob> instead as it is more readable and searchable.
6966
6967=end original
6968
6969glob はまた区切り文字として C<< < >> C<< > >> を使うもう一つの文法に
6970対応しています。
6971この文法は対応していますが、可読性と検索性がより高いので、代わりに
6972C<glob> を使うことを勧めます。
6973
6974 my @txt_files = <"*.txt">;
6975
6976=begin original
6977
6978If you need case insensitive file globbing that can be achieved using the
6979C<:nocase> parameter of the L<C<bsd_glob>|File::Glob/C<bsd_glob>> module.
6980
6981=end original
6982
6983大文字小文字を区別するファイルグロブが必要な場合、
6984L<C<bsd_glob>|File::Glob/C<bsd_glob>> モジュールの C<:nocase> 引数を
6985使うことで達成できます:
6986
6987 use File::Glob qw(:globally :nocase);
6988
6989 my @txt = glob("readme*"); # README readme.txt Readme.md
6990
6991=begin original
6992
69506993Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and
69516994treats
69526995each segment as separate pattern. As such, C<glob("*.c *.h")>
69536996matches all files with a F<.c> or F<.h> extension. The expression
69546997C<glob(".* *")> matches all files in the current working directory.
69556998If you want to glob filenames that might contain whitespace, you'll
69566999have to use extra quotes around the spacey filename to protect it.
69577000For example, to glob filenames that have an C<e> followed by a space
69587001followed by an C<f>, use one of:
69597002
69607003=end original
69617004
69627005L<C<glob>|/glob EXPR> は引数を空白で分割して、それぞれを分割された
69637006パターンとして扱います。
69647007従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに
69657008マッチングします。
69667009式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに
69677010マッチングします。
69687011空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために
69697012空白入りファイル名の周りに追加のクォートを使う必要があります。
69707013例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには
69717014以下の一つを使います:
69727015
69737016 my @spacies = <"*e f*">;
6974 my @spacies = glob '"*e f*"';
7017 my @spacies = glob('"*e f*"');
6975 my @spacies = glob q("*e f*");
7018 my @spacies = glob(q("*e f*"));
69767019
69777020=begin original
69787021
69797022If you had to get a variable through, you could do this:
69807023
69817024=end original
69827025
69837026変数を通す必要があった場合、以下のようにできました:
69847027
6985 my @spacies = glob "'*${var}e f*'";
7028 my @spacies = glob("'*${var}e f*'");
6986 my @spacies = glob qq("*${var}e f*");
7029 my @spacies = glob(qq("*${var}e f*"));
69877030
69887031=begin original
69897032
69907033If non-empty braces are the only wildcard characters used in the
69917034L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many
69927035strings are returned. For example, this produces nine strings, one for
69937036each pairing of fruits and colors:
69947037
69957038=end original
69967039
69977040空でない中かっこが L<C<glob>|/glob EXPR> で使われている唯一の
69987041ワイルドカード文字列の場合、ファイル名とはマッチングせず、
69997042可能性のある文字列が返されます。
70007043例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに
70017044なります:
70027045
7003 my @many = glob "{apple,tomato,cherry}={green,yellow,red}";
7046 my @many = glob("{apple,tomato,cherry}={green,yellow,red}");
70047047
70057048=begin original
70067049
70077050This operator is implemented using the standard C<File::Glob> extension.
7008See L<File::Glob> for details, including
7051See L<C<bsd_glob>|File::Glob/C<bsd_glob>> for details, including
70097052L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace
70107053as a pattern separator.
70117054
70127055=end original
70137056
7014v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って
7057この演算子は標準の C<File::Glob> 拡張を使って
70157058実装されています。
70167059空白をパターンのセパレータとして扱わない
70177060L<C<bsd_glob>|File::Glob/C<bsd_glob>> を含めた
7018詳細は L<File::Glob> を参照してください。
7061詳細は L<C<bsd_glob>|File::Glob/C<bsd_glob>> を参照してください。
70197062
70207063=begin original
70217064
70227065If a C<glob> expression is used as the condition of a C<while> or C<for>
70237066loop, then it will be implicitly assigned to C<$_>. If either a C<glob>
70247067expression or an explicit assignment of a C<glob> expression to a scalar
70257068is used as a C<while>/C<for> condition, then the condition actually
70267069tests for definedness of the expression's value, not for its regular
70277070truth value.
70287071
70297072=end original
70307073
70317074C<glob> 式が C<while> や C<for> ループの条件として使われた場合、
70327075これは暗黙に C<$_> に代入されます。
70337076C<glob> 式または C<glob> 式からスカラへの明示的な代入が
70347077C<while>/C<for> の条件部として使われた場合、
70357078条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
70367079テストします。
70377080
70387081=begin original
70397082
7083Internal implemenation details:
7084
7085=end original
7086
7087内部実装の詳細:
7088
7089=begin original
7090
7091This is the internal function implementing the C<< <*.c> >> operator,
7092but you can use it directly. The C<< <*.c> >> operator is discussed in
7093more detail in L<perlop/"I/O Operators">.
7094
7095=end original
7096
7097これは、C<< <*.c> >> 演算子を実装する内部関数ですが、
7098直接使用することもできます。
7099C<< <*.c> >>演算子については
7100L<perlop/"I/O Operators"> でより詳細に議論しています。
7101
7102=begin original
7103
70407104Portability issues: L<perlport/glob>.
70417105
70427106=end original
70437107
70447108移植性の問題: L<perlport/glob>。
70457109
70467110=item gmtime EXPR
70477111X<gmtime> X<UTC> X<Greenwich>
70487112
70497113=item gmtime
70507114
70517115=for Pod::Functions convert UNIX time into record or string using Greenwich time
70527116
70537117=begin original
70547118
7055Works just like L<C<localtime>|/localtime EXPR> but the returned values
7119Works just like L<C<localtime>|/localtime EXPR>, but the returned values
70567120are localized for the standard Greenwich time zone.
70577121
70587122=end original
70597123
70607124L<C<localtime>|/localtime EXPR> と同様に働きますが、返り値はグリニッジ標準時に
70617125ローカライズされています。
70627126
70637127=begin original
70647128
70657129Note: When called in list context, $isdst, the last value
70667130returned by gmtime, is always C<0>. There is no
70677131Daylight Saving Time in GMT.
70687132
70697133=end original
70707134
70717135注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である
70727136$isdst は常に C<0> です。
70737137GMT には夏時間はありません。
70747138
70757139=begin original
70767140
70777141Portability issues: L<perlport/gmtime>.
70787142
70797143=end original
70807144
70817145移植性の問題: L<perlport/gmtime>。
70827146
70837147=item goto LABEL
70847148X<goto> X<jump> X<jmp>
70857149
70867150=item goto EXPR
70877151
70887152=item goto &NAME
70897153
70907154=for Pod::Functions create spaghetti code
70917155
70927156=begin original
70937157
70947158The C<goto LABEL> form finds the statement labeled with LABEL and
70957159resumes execution there. It can't be used to get out of a block or
70967160subroutine given to L<C<sort>|/sort SUBNAME LIST>. It can be used to go
70977161almost anywhere else within the dynamic scope, including out of
70987162subroutines, but it's usually better to use some other construct such as
70997163L<C<last>|/last LABEL> or L<C<die>|/die LIST>. The author of Perl has
71007164never felt the need to use this form of L<C<goto>|/goto LABEL> (in Perl,
71017165that is; C is another matter). (The difference is that C does not offer
71027166named loops combined with loop control. Perl does, and this replaces
71037167most structured uses of L<C<goto>|/goto LABEL> in other languages.)
71047168
71057169=end original
71067170
71077171C<goto LABEL> の形式は、LABEL というラベルの付いた文を
71087172探して、そこへ実行を移すものです。
71097173L<C<sort>|/sort SUBNAME LIST> で与えられたブロックやサブルーチンから外へ
71107174出ることはできません。
71117175これ以外は、サブルーチンの外を含む、動的スコープ内の
71127176ほとんどすべての場所へ行くために使用できますが、普通は、
71137177L<C<last>|/last LABEL> や L<C<die>|/die LIST> といった別の構造を使った方が
71147178良いでしょう。
71157179Perl の作者はこの形式の L<C<goto>|/goto LABEL> を使う必要を感じたことは、
711671801 度もありません (Perl では; C は別のお話です)。
71177181(違いは、C にはループ制御と結びついた名前つきのループがないことです。
71187182Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL> の
71197183使用法を置き換えます。)
71207184
71217185=begin original
71227186
71237187The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or
71247188a label name. If it evaluates to a code reference, it will be handled
71257189like C<goto &NAME>, below. This is especially useful for implementing
71267190tail recursion via C<goto __SUB__>.
71277191
71287192=end original
71297193
71307194C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名として
71317195評価することを想定します。
71327196コードリファレンスとして評価する場合、後述する C<goto &NAME> のように
71337197扱います。
71347198これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。
71357199
71367200=begin original
71377201
71387202If the expression evaluates to a label name, its scope will be resolved
71397203dynamically. This allows for computed L<C<goto>|/goto LABEL>s per
71407204FORTRAN, but isn't necessarily recommended if you're optimizing for
71417205maintainability:
71427206
71437207=end original
71447208
71457209式がラベル名に評価される場合、このスコープは動的に解決されます。
71467210これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、
71477211保守性を重視するならお勧めしません。
71487212
71497213 goto ("FOO", "BAR", "GLARCH")[$i];
71507214
71517215=begin original
71527216
71537217As shown in this example, C<goto EXPR> is exempt from the "looks like a
71547218function" rule. A pair of parentheses following it does not (necessarily)
71557219delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>.
71567220Also, unlike most named operators, this has the same precedence as
71577221assignment.
71587222
71597223=end original
71607224
71617225この例で示したように、C<goto EXPR> は「関数のように見える」ルールから
71627226除外されます。
71637227これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。
71647228C<goto("NE")."XT"> は C<goto NEXT> と等価です。
71657229また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
71667230
71677231=begin original
71687232
71697233Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is
71707234deprecated and will issue a warning. Even then, it may not be used to
71717235go into any construct that requires initialization, such as a
71727236subroutine, a C<foreach> loop, or a C<given>
71737237block. In general, it may not be used to jump into the parameter
71747238of a binary or list operator, but it may be used to jump into the
71757239I<first> parameter of a binary operator. (The C<=>
71767240assignment operator's "first" operand is its right-hand
71777241operand.) It also can't be used to go into a
71787242construct that is optimized away.
71797243
71807244=end original
71817245
71827246構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは
71837247非推奨で、警告が発生します。
71847248それでも、サブルーチンや C<foreach> ループや C<given> ブロックのような、
71857249初期化が必要な
71867250構造の中に入るために使うことは出来ません。
71877251一般的に、2 項演算子やリスト演算子の引数に飛び込むことはできませんが、
718872522 項演算子の I<最初の> 引数に飛び込むために使われていました。
71897253(C<=> 代入演算子の「最初の」オペランドはその右オペランドです。)
71907254また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。
71917255
71927256=begin original
71937257
71947258The C<goto &NAME> form is quite different from the other forms of
71957259L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at
71967260all, and doesn't have the stigma associated with other gotos. Instead,
71977261it exits the current subroutine (losing any changes set by
71987262L<C<local>|/local EXPR>) and immediately calls in its place the named
71997263subroutine using the current value of L<C<@_>|perlvar/@_>. This is used
72007264by C<AUTOLOAD> subroutines that wish to load another subroutine and then
72017265pretend that the other subroutine had been called in the first place
72027266(except that any modifications to L<C<@_>|perlvar/@_> in the current
72037267subroutine are propagated to the other subroutine.) After the
72047268L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able
72057269to tell that this routine was called first.
72067270
72077271=end original
72087272
72097273C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり
72107274異なったものです。
72117275実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、
72127276他の goto が持つ不名誉を持っていません。
72137277現在のサブルーチンを終了し (L<C<local>|/local EXPR> による変更は失われます)、
72147278直ちに現在の L<C<@_>|perlvar/@_> の値を使って指定された名前のサブルーチンを
72157279呼び出します。
72167280これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、
72177281その別のサブルーチンが最初に呼ばれたようにするために使われます
72187282(ただし、現在のサブルーチンで L<C<@_>|perlvar/@_> を修正した場合には、
72197283その別のサブルーチンに伝えられます)。
72207284L<C<goto>|/goto LABEL> のあとは、L<C<caller>|/caller EXPR> でさえも、現在の
72217285サブルーチンが最初に呼び出されたと言うことができません。
72227286
72237287=begin original
72247288
72257289NAME needn't be the name of a subroutine; it can be a scalar variable
72267290containing a code reference or a block that evaluates to a code
72277291reference.
72287292
72297293=end original
72307294
72317295NAME はサブルーチンの名前である必要はありません; コードリファレンスを
72327296含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。
72337297
72347298=item grep BLOCK LIST
72357299X<grep>
72367300
72377301=item grep EXPR,LIST
72387302
72397303=for Pod::Functions locate elements in a list test true against a given criterion
72407304
72417305=begin original
72427306
72437307This is similar in spirit to, but not the same as, L<grep(1)> and its
72447308relatives. In particular, it is not limited to using regular expressions.
72457309
72467310=end original
72477311
72487312これは L<grep(1)> とその親類と同じようなものですが、同じではありません。
72497313特に、正規表現の使用に制限されません。
72507314
72517315=begin original
72527316
72537317Evaluates the BLOCK or EXPR for each element of LIST (locally setting
72547318L<C<$_>|perlvar/$_> to each element) and returns the list value
72557319consisting of those
72567320elements for which the expression evaluated to true. In scalar
72577321context, returns the number of times the expression was true.
72587322
72597323=end original
72607324
72617325LIST の個々の要素に対して、BLOCK か EXPR を評価し
72627326(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
72637327その要素のうち、評価した式が真となったものからなるリスト値が返されます。
72647328スカラコンテキストでは、式が真となった回数を返します。
72657329
72667330 my @foo = grep(!/^#/, @bar); # weed out comments
72677331
72687332=begin original
72697333
72707334or equivalently,
72717335
72727336=end original
72737337
72747338あるいは等価な例として:
72757339
72767340 my @foo = grep {!/^#/} @bar; # weed out comments
72777341
72787342=begin original
72797343
72807344Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
72817345be used to
72827346modify the elements of the LIST. While this is useful and supported,
72837347it can cause bizarre results if the elements of LIST are not variables.
72847348Similarly, grep returns aliases into the original list, much as a for
72857349loop's index variable aliases the list elements. That is, modifying an
72867350element of a list returned by grep (for example, in a C<foreach>,
72877351L<C<map>|/map BLOCK LIST> or another L<C<grep>|/grep BLOCK LIST>)
72887352actually modifies the element in the original list.
72897353This is usually something to be avoided when writing clear code.
72907354
72917355=end original
72927356
72937357L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
72947358変更するために使うことができます。
72957359これは、便利でサポートされていますが、
72967360LIST の要素が変数でないと、おかしな結果になります。
72977361同様に、grep は元のリストへのエイリアスを返します; for ループの
72987362インデックス変数がリスト要素のエイリアスであるのと同様です。
72997363つまり、grep で返されたリストの要素を
73007364(C<foreach>, L<C<map>|/map BLOCK LIST>, または他の
73017365L<C<grep>|/grep BLOCK LIST> で)修正すると元のリストの要素が変更されます。
73027366これはきれいなコードを書くときには普通は回避されます。
73037367
73047368=begin original
73057369
73067370See also L<C<map>|/map BLOCK LIST> for a list composed of the results of
73077371the BLOCK or EXPR.
73087372
73097373=end original
73107374
73117375BLOCK や EXPR の結果をリストの形にしたい場合は L<C<map>|/map BLOCK LIST> を
73127376参照してください。
73137377
73147378=item hex EXPR
73157379X<hex> X<hexadecimal>
73167380
73177381=item hex
73187382
73197383=for Pod::Functions convert a hexadecimal string to a number
73207384
73217385=begin original
73227386
73237387Interprets EXPR as a hex string and returns the corresponding numeric value.
73247388If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
73257389
73267390=end original
73277391
73287392EXPR を 16 進数の文字列と解釈して、対応する数値を返します。
73297393EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
73307394
73317395 print hex '0xAf'; # prints '175'
73327396 print hex 'aF'; # same
73337397 $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/
73347398
73357399=begin original
73367400
73377401A hex string consists of hex digits and an optional C<0x> or C<x> prefix.
73387402Each hex digit may be preceded by a single underscore, which will be ignored.
73397403Any other character triggers a warning and causes the rest of the string
73407404to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>).
73417405Only integers can be represented, and integer overflow triggers a warning.
73427406
73437407=end original
73447408
7345740916 進文字列は 16 進数と、オプションの C<0x> または C<x> 接頭辞からなります。
73467410それぞれの 16 進数は一つの下線を前に置くことができ、これは無視されます。
73477411その他の文字は警告を引き起こし、(例え先頭の空白でも、L<C<oct>|/oct EXPR> と
73487412異なり)文字列の残りの部分は無視されます。
73497413整数のみを表現でき、整数オーバーフローは警告を引き起こします。
73507414
73517415=begin original
73527416
73537417To convert strings that might start with any of C<0>, C<0x>, or C<0b>,
73547418see L<C<oct>|/oct EXPR>. To present something as hex, look into
73557419L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
73567420L<C<sprintf>|/sprintf FORMAT, LIST>, and
73577421L<C<unpack>|/unpack TEMPLATE,EXPR>.
73587422
73597423=end original
73607424
73617425C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、
73627426L<C<oct>|/oct EXPR> を参照してください。
73637427何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
73647428L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を
73657429参照してください。
73667430
73677431=item import LIST
73687432X<import>
73697433
73707434=for Pod::Functions patch a module's namespace into your own
73717435
73727436=begin original
73737437
73747438There is no builtin L<C<import>|/import LIST> function. It is just an
73757439ordinary method (subroutine) defined (or inherited) by modules that wish
73767440to export names to another module. The
73777441L<C<use>|/use Module VERSION LIST> function calls the
73787442L<C<import>|/import LIST> method for the package used. See also
73797443L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>.
73807444
73817445=end original
73827446
73837447組み込みの L<C<import>|/import LIST> 関数というものはありません。
73847448これは単に、別のモジュールに名前をエクスポートしたいモジュールが
73857449定義した(または継承した)、通常のメソッド(サブルーチン)です。
73867450L<C<use>|/use Module VERSION LIST> 関数はパッケージを使う時に
73877451L<C<import>|/import LIST> メソッドを呼び出します。
73887452L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も
73897453参照してください。
73907454
73917455=item index STR,SUBSTR,POSITION
73927456X<index> X<indexOf> X<InStr>
73937457
73947458=item index STR,SUBSTR
73957459
73967460=for Pod::Functions find a substring within a string
73977461
73987462=begin original
73997463
74007464The index function searches for one string within another, but without
74017465the wildcard-like behavior of a full regular-expression pattern match.
74027466It returns the position of the first occurrence of SUBSTR in STR at
74037467or after POSITION. If POSITION is omitted, starts searching from the
74047468beginning of the string. POSITION before the beginning of the string
74057469or after its end is treated as if it were the beginning or the end,
74067470respectively. POSITION and the return value are based at zero.
74077471If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION>
74087472returns -1.
74097473
74107474=end original
74117475
74127476index 関数は ある文字列をもうひとつの文字列から検索しますが、
74137477完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。
74147478STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。
74157479POSITION が省略された場合には、STR の最初から探し始めます。
74167480POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、
74177481それぞれ先頭と末尾を指定されたものとして扱われます。
74187482POSITION と返り値のベースは、0 です。
74197483SUBSTR が見つからなかった場合には、L<C<index>|/index STR,SUBSTR,POSITION> は
74207484-1 が返されます。
74217485
7486=begin original
7487
7488Find characters or strings:
7489
7490=end original
7491
7492文字や文字列を探すには:
7493
7494 index("Perl is great", "P"); # Returns 0
7495 index("Perl is great", "g"); # Returns 8
7496 index("Perl is great", "great"); # Also returns 8
7497
7498=begin original
7499
7500Attempting to find something not there:
7501
7502=end original
7503
7504ないものを探そうとすると:
7505
7506 index("Perl is great", "Z"); # Returns -1 (not found)
7507
7508=begin original
7509
7510Using an offset to find the I<second> occurrence:
7511
7512=end original
7513
7514I<2 番目> の出現位置を探すためにオフセットを使うと:
7515
7516 index("Perl is great", "e", 5); # Returns 10
7517
74227518=item int EXPR
74237519X<int> X<integer> X<truncate> X<trunc> X<floor>
74247520
74257521=item int
74267522
74277523=for Pod::Functions get the integer portion of a number
74287524
74297525=begin original
74307526
74317527Returns the integer portion of EXPR. If EXPR is omitted, uses
74327528L<C<$_>|perlvar/$_>.
74337529You should not use this function for rounding: one because it truncates
74347530towards C<0>, and two because machine representations of floating-point
74357531numbers can sometimes produce counterintuitive results. For example,
74367532C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's
74377533because it's really more like -268.99999999999994315658 instead. Usually,
74387534the L<C<sprintf>|/sprintf FORMAT, LIST>,
74397535L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the
74407536L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>>
74417537functions will serve you better than will L<C<int>|/int EXPR>.
74427538
74437539=end original
74447540
74457541EXPR の整数部を返します。
74467542EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
74477543この関数を丸めのために使うべきではありません: 第一の理由として C<0> の
74487544方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に
74497545反した結果を生み出すからです。
74507546たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を
74517547返します: これは実際には -268.99999999999994315658 というような値に
74527548なっているからです。
74537549通常、L<C<sprintf>|/sprintf FORMAT, LIST>,
74547550L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
74557551L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が
74567552L<C<int>|/int EXPR> より便利です。
74577553
74587554=item ioctl FILEHANDLE,FUNCTION,SCALAR
74597555X<ioctl>
74607556
74617557=for Pod::Functions system-dependent device control system call
74627558
74637559=begin original
74647560
74657561Implements the L<ioctl(2)> function. You'll probably first have to say
74667562
74677563=end original
74687564
74697565L<ioctl(2)> 関数を実装します。
74707566正しい関数の定義を得るために、おそらく最初に
74717567
74727568 require "sys/ioctl.ph"; # probably in
74737569 # $Config{archlib}/sys/ioctl.ph
74747570
74757571=begin original
74767572
74777573to get the correct function definitions. If F<sys/ioctl.ph> doesn't
74787574exist or doesn't have the correct definitions you'll have to roll your
74797575own, based on your C header files such as F<< <sys/ioctl.h> >>.
74807576(There is a Perl script called B<h2ph> that comes with the Perl kit that
74817577may help you in this, but it's nontrivial.) SCALAR will be read and/or
74827578written depending on the FUNCTION; a C pointer to the string value of SCALAR
74837579will be passed as the third argument of the actual
74847580L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR
74857581has no string value but does have a numeric value, that value will be
74867582passed rather than a pointer to the string value. To guarantee this to be
74877583true, add a C<0> to the scalar before using it.) The
74887584L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
74897585functions may be needed to manipulate the values of structures used by
74907586L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>.
74917587
74927588=end original
74937589
74947590としなくてはならないでしょう。
74957591F<sys/ioctl.ph> がないか、間違った定義をしている場合には、
74967592F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、
74977593自分で作らなければなりません。
74987594(Perl の配布キットに入っている B<h2ph> という Perl スクリプトが
74997595これを手助けしてくれるでしょうが、これは自明ではありません。)
75007596FOUNCTION に応じて SCALAR が読み書きされます;
75017597SCALAR の文字列値へのポインタが、実際の
75027598L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの
750375993 番目の引数として渡されます。
75047600(SCALAR が文字列値を持っておらず、数値を持っている場合には、
75057601文字列値へのポインタの代わりに、その値が渡されます。
75067602このことを保証するためには、使用する前に SCALAR にC<0> を足してください。)
75077603L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> で使われる構造体の値を
75087604操作するには、L<C<pack>|/pack TEMPLATE,LIST> 関数と
75097605L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。
75107606
75117607=begin original
75127608
75137609The return value of L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> (and
75147610L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows:
75157611
75167612=end original
75177613
75187614L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>
75197615(と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、
75207616以下のようになります:
75217617
75227618=begin original
75237619
75247620 if OS returns: then Perl returns:
75257621 -1 undefined value
75267622 0 string "0 but true"
75277623 anything else that number
75287624
75297625=end original
75307626
75317627 OS が返した値: Perl が返す値:
75327628 -1 未定義値
75337629 0 「0 だが真」の文字列
75347630 その他 その値そのもの
75357631
75367632=begin original
75377633
75387634Thus Perl returns true on success and false on failure, yet you can
75397635still easily determine the actual value returned by the operating
75407636system:
75417637
75427638=end original
75437639
75447640つまり Perl は、成功時に「真」、失敗時に「偽」を返す
75457641ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。
75467642
75477643 my $retval = ioctl(...) || -1;
75487644 printf "System returned %d\n", $retval;
75497645
75507646=begin original
75517647
75527648The special string C<"0 but true"> is exempt from
75537649L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
75547650L<warnings> on improper numeric conversions.
75557651
75567652=end original
75577653
75587654特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する
75597655L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
75607656L<warnings> 警告を回避します。
75617657
75627658=begin original
75637659
75647660Portability issues: L<perlport/ioctl>.
75657661
75667662=end original
75677663
75687664移植性の問題: L<perlport/ioctl>。
75697665
75707666=item join EXPR,LIST
75717667X<join>
75727668
75737669=for Pod::Functions join a list into a string using a separator
75747670
75757671=begin original
75767672
75777673Joins the separate strings of LIST into a single string with fields
75787674separated by the value of EXPR, and returns that new string. Example:
75797675
75807676=end original
75817677
75827678LIST の個別の文字列を、EXPR の値で区切って
758376791 つの文字列につなげ、その文字列を返します。
75847680例:
75857681
75867682 my $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
75877683
75887684=begin original
75897685
75907686Beware that unlike L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
75917687L<C<join>|/join EXPR,LIST> doesn't take a pattern as its first argument.
75927688Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>.
75937689
75947690=end original
75957691
75967692L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と違って、
75977693L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに
75987694注意してください。
75997695L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と比較してください。
76007696
76017697=item keys HASH
76027698X<keys> X<key>
76037699
76047700=item keys ARRAY
76057701
76067702=for Pod::Functions retrieve list of indices from a hash
76077703
76087704=begin original
76097705
76107706Called in list context, returns a list consisting of all the keys of the
76117707named hash, or in Perl 5.12 or later only, the indices of an array. Perl
76127708releases prior to 5.12 will produce a syntax error if you try to use an
76137709array argument. In scalar context, returns the number of keys or indices.
76147710
76157711=end original
76167712
76177713リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは
76187714Perl 5.12 以降でのみ、配列のインデックスからなるリストを返します。
761977155.12 より前の Perl は配列引数を使おうとすると文法エラーを出力します。
76207716スカラコンテキストでは、キーやインデックスの数を返します。
76217717
76227718=begin original
76237719
76247720Hash entries are returned in an apparently random order. The actual random
76257721order is specific to a given hash; the exact same series of operations
76267722on two hashes may result in a different order for each hash. Any insertion
76277723into the hash may change the order, as will any deletion, with the exception
76287724that the most recent key returned by L<C<each>|/each HASH> or
76297725L<C<keys>|/keys HASH> may be deleted without changing the order. So
76307726long as a given hash is unmodified you may rely on
76317727L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each
76327728HASH> to repeatedly return the same order
76337729as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
76347730details on why hash order is randomized. Aside from the guarantees
76357731provided here the exact details of Perl's hash algorithm and the hash
76367732traversal order are subject to change in any release of Perl. Tied hashes
76377733may behave differently to Perl's hashes with respect to changes in order on
76387734insertion and deletion of items.
76397735
76407736=end original
76417737
76427738ハッシュ要素は見かけ上、ランダムな順序で返されます。
76437739実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
76447740操作を行っても、ハッシュによって異なった順序になります。
76457741ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
76467742L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
76477743最近のキーは順序を変えることなく削除できます。
76487744ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
7649L<C<each>|/each HASH> が繰り返し同じ順序で
7745L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
7650返すことに依存してもかまいません。
76517746なぜハッシュの順序がランダム化されているかの詳細については
76527747L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
76537748ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
76547749正確な詳細は Perl のリリースによって変更される可能性があります。
76557750tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
76567751異なった振る舞いをします。
76577752
76587753=begin original
76597754
76607755As a side effect, calling L<C<keys>|/keys HASH> resets the internal
76617756iterator of the HASH or ARRAY (see L<C<each>|/each HASH>) before
76627757yielding the keys. In
76637758particular, calling L<C<keys>|/keys HASH> in void context resets the
76647759iterator with no other overhead.
76657760
76667761=end original
76677762
76687763副作用として、L<C<keys>|/keys HASH> の呼び出しは、
76697764キーを取り出す前に HASH や ARRAY の反復子を
76707765初期化します (L<C<each>|/each HASH> を参照してください)。
76717766特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと
76727767オーバーヘッドなしで反復子を初期化します。
76737768
76747769=begin original
76757770
76767771Here is yet another way to print your environment:
76777772
76787773=end original
76797774
76807775環境変数を表示する別の例です:
76817776
76827777 my @keys = keys %ENV;
76837778 my @values = values %ENV;
76847779 while (@keys) {
76857780 print pop(@keys), '=', pop(@values), "\n";
76867781 }
76877782
76887783=begin original
76897784
76907785or how about sorted by key:
76917786
76927787=end original
76937788
76947789key でソートしてもいいでしょう:
76957790
76967791 foreach my $key (sort(keys %ENV)) {
76977792 print $key, '=', $ENV{$key}, "\n";
76987793 }
76997794
77007795=begin original
77017796
77027797The returned values are copies of the original keys in the hash, so
77037798modifying them will not affect the original hash. Compare
77047799L<C<values>|/values HASH>.
77057800
77067801=end original
77077802
77087803返される値はハッシュにある元のキーのコピーなので、
77097804これを変更しても元のハッシュには影響を与えません。
77107805L<C<values>|/values HASH> と比較してください。
77117806
77127807=begin original
77137808
77147809To sort a hash by value, you'll need to use a
77157810L<C<sort>|/sort SUBNAME LIST> function. Here's a descending numeric
77167811sort of a hash by its values:
77177812
77187813=end original
77197814
77207815ハッシュを値でソートするためには、L<C<sort>|/sort SUBNAME LIST> 関数を使う
77217816必要があります。
77227817以下ではハッシュの値を数値の降順でソートしています:
77237818
77247819 foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
77257820 printf "%4d %s\n", $hash{$key}, $key;
77267821 }
77277822
77287823=begin original
77297824
77307825Used as an lvalue, L<C<keys>|/keys HASH> allows you to increase the
77317826number of hash buckets
77327827allocated for the given hash. This can gain you a measure of efficiency if
77337828you know the hash is going to get big. (This is similar to pre-extending
77347829an array by assigning a larger number to $#array.) If you say
77357830
77367831=end original
77377832
77387833左辺値として使うことで、L<C<keys>|/keys HASH> を使うことで与えられたハッシュに
77397834割り当てられたハッシュ表の大きさを増やすことができます。
77407835これによって、ハッシュが大きくなっていくなっていくときの
77417836効率の測定ができます。
77427837(これは大きい値を $#array に代入することで配列を予め拡張することに
77437838似ています。)
77447839以下のようにすると:
77457840
77467841 keys %hash = 200;
77477842
77487843=begin original
77497844
77507845then C<%hash> will have at least 200 buckets allocated for it--256 of them,
77517846in fact, since it rounds up to the next power of two. These
77527847buckets will be retained even if you do C<%hash = ()>, use C<undef
77537848%hash> if you want to free the storage while C<%hash> is still in scope.
77547849You can't shrink the number of buckets allocated for the hash using
77557850L<C<keys>|/keys HASH> in this way (but you needn't worry about doing
77567851this by accident, as trying has no effect). C<keys @array> in an lvalue
77577852context is a syntax error.
77587853
77597854=end original
77607855
77617856C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
77627857実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。
77637858この表はたとえ C<%hash = ()> としても残るので、
77647859もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は
77657860C<undef %hash> を使います。
77667861この方法で L<C<keys>|/keys HASH> を使うことで、表の大きさを小さくすることは
77677862できません
77687863(間違えてそのようなことをしても何も起きないので気にすることはありません)。
77697864左辺値コンテキストでの C<keys @array> は文法エラーとなります。
77707865
77717866=begin original
77727867
77737868Starting with Perl 5.14, an experimental feature allowed
77747869L<C<keys>|/keys HASH> to take a scalar expression. This experiment has
77757870been deemed unsuccessful, and was removed as of Perl 5.24.
77767871
77777872=end original
77787873
77797874Perl 5.14 から、L<C<keys>|/keys HASH> がスカラ式を取ることが出来るという
77807875実験的機能がありました。
77817876この実験は失敗と見なされ、Perl 5.24 で削除されました。
77827877
77837878=begin original
77847879
77857880To avoid confusing would-be users of your code who are running earlier
77867881versions of Perl with mysterious syntax errors, put this sort of thing at
77877882the top of your file to signal that your code will work I<only> on Perls of
77887883a recent vintage:
77897884
77907885=end original
77917886
77927887あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
77937888文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
77947889I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
77957890書いてください:
77967891
7797 use 5.012; # so keys/values/each work on arrays
7892 use v5.12; # so keys/values/each work on arrays
77987893
77997894=begin original
78007895
78017896See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and
78027897L<C<sort>|/sort SUBNAME LIST>.
78037898
78047899=end original
78057900
78067901L<C<each>|/each HASH>, L<C<values>|/values HASH>,
78077902L<C<sort>|/sort SUBNAME LIST> も参照してください。
78087903
78097904=item kill SIGNAL, LIST
78107905
78117906=item kill SIGNAL
78127907X<kill> X<signal>
78137908
78147909=for Pod::Functions send a signal to a process or process group
78157910
78167911=begin original
78177912
78187913Sends a signal to a list of processes. Returns the number of arguments
78197914that were successfully used to signal (which is not necessarily the same
78207915as the number of processes actually killed, e.g. where a process group is
78217916killed).
78227917
78237918=end original
78247919
78257920プロセスのリストにシグナルを送ります。
78267921シグナル送信に使われた引数の数を返します
78277922(例えばプロセスグループが kill された場合のように、実際に kill された
78287923プロセスの数と同じとは限りません)。
78297924
78307925 my $cnt = kill 'HUP', $child1, $child2;
78317926 kill 'KILL', @goners;
78327927
78337928=begin original
78347929
78357930SIGNAL may be either a signal name (a string) or a signal number. A signal
78367931name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the
78377932same signal. The string form of SIGNAL is recommended for portability because
78387933the same signal may have different numbers in different operating systems.
78397934
78407935=end original
78417936
78427937SIGNAL はシグナル名(文字列)かシグナル番号のどちらかです。
78437938シグナル名は C<SIG> 接頭辞で始まることがあるので、C<FOO> と C<SIGFOO> は同じ
78447939シグナルを意味します。
78457940移植性から文字列形式の SIGNAL が推奨されます; 同じシグナルが異なった
78467941オペレーティングシステムでは異なった番号になることがあるからです。
78477942
78487943=begin original
78497944
78507945A list of signal names supported by the current platform can be found in
78517946C<$Config{sig_name}>, which is provided by the L<C<Config>|Config>
78527947module. See L<Config> for more details.
78537948
78547949=end original
78557950
78567951現在のプラットフォームが対応しているシグナル名の一覧は、L<C<Config>|Config>
78577952モジュールによって提供される C<$Config{sig_name}> にあります。
78587953さらなる詳細については L<Config> を参照してください。
78597954
78607955=begin original
78617956
78627957A negative signal name is the same as a negative signal number, killing process
78637958groups instead of processes. For example, C<kill '-KILL', $pgrp> and
78647959C<kill -9, $pgrp> will send C<SIGKILL> to
78657960the entire process group specified. That
78667961means you usually want to use positive not negative signals.
78677962
78687963=end original
78697964
78707965負のシグナル名は負のシグナル番号と同じで、
78717966プロセスではなくプロセスグループに対して kill を行ないます。
78727967たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された
78737968プロセスグループ全体に C<SIGKILL> を送ります。
78747969すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。
78757970
78767971=begin original
78777972
78787973If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>),
78797974no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST>
78807975checks whether it's I<possible> to send a signal to it
78817976(that means, to be brief, that the process is owned by the same user, or we are
78827977the super-user). This is useful to check that a child process is still
78837978alive (even if only as a zombie) and hasn't changed its UID. See
78847979L<perlport> for notes on the portability of this construct.
78857980
78867981=end original
78877982
78887983SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに
78897984シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、
78907985シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、
78917986プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを
78927987意味します)。
78937988これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が
78947989変わっていないことを調べる時に有用です。
78957990この構成の移植性に関する注意については L<perlport> を参照してください。
78967991
78977992=begin original
78987993
78997994The behavior of kill when a I<PROCESS> number is zero or negative depends on
79007995the operating system. For example, on POSIX-conforming systems, zero will
79017996signal the current process group, -1 will signal all processes, and any
79027997other negative PROCESS number will act as a negative signal number and
79037998kill the entire process group specified.
79047999
79058000=end original
79068001
79078002I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは
79088003オペレーティングシステムに依存します。
79098004例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、
79108005-1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は
79118006負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。
79128007
79138008=begin original
79148009
79158010If both the SIGNAL and the PROCESS are negative, the results are undefined.
79168011A warning may be produced in a future version.
79178012
79188013=end original
79198014
79208015SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。
79218016将来のバージョンでは警告が出るかも知れません。
79228017
79238018=begin original
79248019
79258020See L<perlipc/"Signals"> for more details.
79268021
79278022=end original
79288023
79298024詳細は L<perlipc/"Signals"> を参照してください。
79308025
79318026=begin original
79328027
79338028On some platforms such as Windows where the L<fork(2)> system call is not
79348029available, Perl can be built to emulate L<C<fork>|/fork> at the
79358030interpreter level.
79368031This emulation has limitations related to kill that have to be considered,
79378032for code running on Windows and in code intended to be portable.
79388033
79398034=end original
79408035
79418036Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
79428037L<C<fork>|/fork> をインタプリタレベルでエミュレートします。
79438038エミュレーションは kill に関連して、コードが Windows で実行されて
79448039しかしコードが移植性があると考えられるように制限があります。
79458040
79468041=begin original
79478042
79488043See L<perlfork> for more details.
79498044
79508045=end original
79518046
79528047さらなる詳細については L<perlfork> を参照してください。
79538048
79548049=begin original
79558050
79568051If there is no I<LIST> of processes, no signal is sent, and the return
79578052value is 0. This form is sometimes used, however, because it causes
7958tainting checks to be run. But see
8053tainting checks to be run, if your perl support taint checks. But see
79598054L<perlsec/Laundering and Detecting Tainted Data>.
79608055
79618056=end original
79628057
79638058処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。
7964しかし、この形式は時々使われます; 実行するために汚染チェック
8059しかし、この形式は時々使われます; perl が汚染チェックに対応している場合、
7965引き起こすからです。
8060実行するために汚染チェックを引き起こすからです。
79668061しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。
79678062
79688063=begin original
79698064
79708065Portability issues: L<perlport/kill>.
79718066
79728067=end original
79738068
79748069移植性の問題: L<perlport/kill>。
79758070
79768071=item last LABEL
79778072X<last> X<break>
79788073
79798074=item last EXPR
79808075
79818076=item last
79828077
79838078=for Pod::Functions exit a block prematurely
79848079
79858080=begin original
79868081
79878082The L<C<last>|/last LABEL> command is like the C<break> statement in C
79888083(as used in
79898084loops); it immediately exits the loop in question. If the LABEL is
79908085omitted, the command refers to the innermost enclosing
79918086loop. The C<last EXPR> form, available starting in Perl
799280875.18.0, allows a label name to be computed at run time,
79938088and is otherwise identical to C<last LABEL>. The
79948089L<C<continue>|/continue BLOCK> block, if any, is not executed:
79958090
79968091=end original
79978092
79988093L<C<last>|/last LABEL> コマンドは、(ループ内で使った) C の C<break> 文と
79998094同じようなもので、LABEL で指定されるループを即座に抜けます。
80008095LABEL が省略されると、コマンドは一番内側のループを参照します。
80018096Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算される
80028097ラベル名を使えます; それ以外は C<last LABEL> と同一です。
80038098L<C<continue>|/continue BLOCK> ブロックがあっても実行されません:
80048099
80058100 LINE: while (<STDIN>) {
80068101 last LINE if /^$/; # exit when done with header
80078102 #...
80088103 }
80098104
80108105=begin original
80118106
80128107L<C<last>|/last LABEL> cannot return a value from a block that typically
80138108returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
80148109its flow control behavior, which precludes any return value. It should not be
80158110used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
80168111operation.
80178112
80188113=end original
80198114
80208115L<C<last>|/last LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
80218116典型的には値を返すブロックから値を返せません。
80228117これは、返り値を不可能にするフロー制御の振る舞いを実行します。
80238118L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
80248119使うべきではありません。
80258120
80268121=begin original
80278122
80288123Note that a block by itself is semantically identical to a loop
80298124that executes once. Thus L<C<last>|/last LABEL> can be used to effect
80308125an early exit out of such a block.
80318126
80328127=end original
80338128
80348129ブロック自身は一回だけ実行されるループと文法的に同一であることに
80358130注意してください。
80368131従って、L<C<last>|/last LABEL> でそのようなブロックを途中で
80378132抜け出すことができます。
80388133
80398134=begin original
80408135
80418136See also L<C<continue>|/continue BLOCK> for an illustration of how
80428137L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
80438138L<C<redo>|/redo LABEL> work.
80448139
80458140=end original
80468141
80478142L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
80488143どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
80498144
80508145=begin original
80518146
80528147Unlike most named operators, this has the same precedence as assignment.
80538148It is also exempt from the looks-like-a-function rule, so
80548149C<last ("foo")."bar"> will cause "bar" to be part of the argument to
80558150L<C<last>|/last LABEL>.
80568151
80578152=end original
80588153
80598154ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
80608155また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と
80618156すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。
80628157
80638158=item lc EXPR
80648159X<lc> X<lowercase>
80658160
80668161=item lc
80678162
80688163=for Pod::Functions return lower-case version of a string
80698164
80708165=begin original
80718166
8072Returns a lowercased version of EXPR. This is the internal function
8167Returns a lowercased version of EXPR. If EXPR is omitted, uses
8073implementing the C<\L> escape in double-quoted strings.
8168L<C<$_>|perlvar/$_>.
80748169
80758170=end original
80768171
80778172EXPR を小文字に変換したものを返します。
8078これは、ダブルクォート文字列における、
8079C<\L> エスケープを実装する内部関数です。
8080
8081=begin original
8082
8083If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
8084
8085=end original
8086
80878173EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
80888174
8175 my $str = lc("Perl is GREAT"); # "perl is great"
8176
80898177=begin original
80908178
80918179What gets returned depends on several factors:
80928180
80938181=end original
80948182
80958183返り値として得られるものは色々な要素に依存します:
80968184
80978185=over
80988186
80998187=item If C<use bytes> is in effect:
81008188
81018189(C<use bytes> が有効の場合)
81028190
81038191=begin original
81048192
81058193The results follow ASCII rules. Only the characters C<A-Z> change,
81068194to C<a-z> respectively.
81078195
81088196=end original
81098197
81108198結果は ASCII の規則に従います。
81118199C<A-Z> のみが変換され、それぞれ C<a-z> になります。
81128200
81138201=item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect:
81148202
81158203(それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効の場合)
81168204
81178205=begin original
81188206
81198207Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode
81208208rules for the remaining code points (this last can only happen if
81218209the UTF8 flag is also set). See L<perllocale>.
81228210
81238211=end original
81248212
81258213符号位置 < 256 に対しては現在の C<LC_CTYPE> ロケールに従います; そして
81268214残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも
81278215設定されている場合にのみ起こります)。
81288216L<perllocale> を参照してください。
81298217
81308218=begin original
81318219
81328220Starting in v5.20, Perl uses full Unicode rules if the locale is
81338221UTF-8. Otherwise, there is a deficiency in this scheme, which is that
81348222case changes that cross the 255/256
81358223boundary are not well-defined. For example, the lower case of LATIN CAPITAL
81368224LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII
81378225platforms). But under C<use locale> (prior to v5.20 or not a UTF-8
81388226locale), the lower case of U+1E9E is
81398227itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the
81408228current locale, and Perl has no way of knowing if that character even
81418229exists in the locale, much less what code point it is. Perl returns
81428230a result that is above 255 (almost always the input character unchanged),
81438231for all instances (and there aren't many) where the 255/256 boundary
81448232would otherwise be crossed; and starting in v5.22, it raises a
81458233L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning.
81468234
81478235=end original
81488236
81498237v5.20 から、ロケールが UTF-8 の場合は Perl は完全な Unicode の規則を使います。
81508238さもなければ、この手法には、255/266 の境界をまたぐ大文字小文字の変換は
81518239未定義であるという欠点があります。
81528240例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は
81538241(ASCII プラットフォームでは) U+00DF です。
81548242しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の
81558243小文字は自分自身です; なぜなら 0xDF は現在のロケールでは
81568244LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が
81578245存在するかどうかを知る方法がなく、ましてどの符号位置かを知る方法が
81588246ないからです。
81598247Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については
81608248(ほとんど常に入力文字を変更せずに)256 以上の値を返します;
81618249そして v5.22 から
81628250L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".>
81638251警告を出力します。
81648252
81658253=item Otherwise, If EXPR has the UTF8 flag set:
81668254
81678255(その他の場合で、EXPR に UTF8 フラグがセットされている場合)
81688256
81698257=begin original
81708258
81718259Unicode rules are used for the case change.
81728260
81738261=end original
81748262
81758263大文字小文字変換には Unicode の規則が使われます。
81768264
81778265=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect:
81788266
81798267(それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合)
81808268
81818269=begin original
81828270
81838271Unicode rules are used for the case change.
81848272
81858273=end original
81868274
81878275大文字小文字変換には Unicode の規則が使われます。
81888276
81898277=item Otherwise:
81908278
81918279(それ以外の場合)
81928280
81938281=begin original
81948282
81958283ASCII rules are used for the case change. The lowercase of any character
81968284outside the ASCII range is the character itself.
81978285
81988286=end original
81998287
82008288大文字小文字変換には ASCII の規則が使われます。
82018289ASCII の範囲外の文字の「小文字」はその文字自身です。
82028290
82038291=back
82048292
8293=begin original
8294
8295B<Note:> This is the internal function implementing the
8296L<C<\L>|perlop/"Quote and Quote-like Operators"> escape in double-quoted
8297strings.
8298
8299=end original
8300
8301B<注意:> これは、ダブルクォート文字列における、
8302L<C<\L>|perlop/"Quote and Quote-like Operators"> エスケープを実装する
8303内部関数です。
8304
8305 my $str = "Perl is \LGREAT\E"; # "Perl is great"
8306
82058307=item lcfirst EXPR
82068308X<lcfirst> X<lowercase>
82078309
82088310=item lcfirst
82098311
82108312=for Pod::Functions return a string with just the next letter in lower case
82118313
82128314=begin original
82138315
82148316Returns the value of EXPR with the first character lowercased. This
82158317is the internal function implementing the C<\l> escape in
82168318double-quoted strings.
82178319
82188320=end original
82198321
82208322最初の文字だけを小文字にした、EXPR を返します。
82218323これは、ダブルクォート文字列における、C<\l> エスケープを
82228324実装する内部関数です。
82238325
82248326=begin original
82258327
82268328If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
82278329
82288330=end original
82298331
82308332EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
82318333
82328334=begin original
82338335
82348336This function behaves the same way under various pragmas, such as in a locale,
82358337as L<C<lc>|/lc EXPR> does.
82368338
82378339=end original
82388340
82398341この関数は、ロケールのようなさまざまなプラグマの影響下では、
82408342L<C<lc>|/lc EXPR> と同様に振る舞います。
82418343
82428344=item length EXPR
82438345X<length> X<size>
82448346
82458347=item length
82468348
82478349=for Pod::Functions return the number of characters in a string
82488350
82498351=begin original
82508352
82518353Returns the length in I<characters> of the value of EXPR. If EXPR is
82528354omitted, returns the length of L<C<$_>|perlvar/$_>. If EXPR is
82538355undefined, returns L<C<undef>|/undef EXPR>.
82548356
82558357=end original
82568358
82578359EXPR の値の I<文字> の長さを返します。
82588360EXPR が省略されたときには、L<C<$_>|perlvar/$_> の長さを返します。
82598361EXPR が未定義値の場合、L<C<undef>|/undef EXPR> を返します。
82608362
82618363=begin original
82628364
82638365This function cannot be used on an entire array or hash to find out how
82648366many elements these have. For that, use C<scalar @array> and C<scalar keys
82658367%hash>, respectively.
82668368
82678369=end original
82688370
82698371この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを
82708372調べるためには使えません。
82718373そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を
82728374利用してください。
82738375
82748376=begin original
82758377
82768378Like all Perl character operations, L<C<length>|/length EXPR> normally
82778379deals in logical
82788380characters, not physical bytes. For how many bytes a string encoded as
82798381UTF-8 would take up, use C<length(Encode::encode('UTF-8', EXPR))>
82808382(you'll have to C<use Encode> first). See L<Encode> and L<perlunicode>.
82818383
82828384=end original
82838385
82848386全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な
82858387バイトではなく論理文字を扱います。
82868388UTF-8 でエンコードされた文字列が何バイトかを知るには、
82878389C<length(Encode::encode('UTF-8', EXPR))> を使ってください (先に
82888390C<use Encode> する必要があります)。
82898391L<Encode> と L<perlunicode> を参照してください。
82908392
82918393=item __LINE__
82928394X<__LINE__>
82938395
82948396=for Pod::Functions the current source line number
82958397
82968398=begin original
82978399
82988400A special token that compiles to the current line number.
82998401It can be altered by the mechanism described at
83008402L<perlsyn/"Plain Old Comments (Not!)">.
83018403
83028404=end original
83038405
83048406現在の行番号にコンパイルされる特殊トークン。
83058407L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って
83068408置き換えられます。
83078409
83088410=item link OLDFILE,NEWFILE
83098411X<link>
83108412
83118413=for Pod::Functions create a hard link in the filesystem
83128414
83138415=begin original
83148416
83158417Creates a new filename linked to the old filename. Returns true for
83168418success, false otherwise.
83178419
83188420=end original
83198421
83208422OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。
83218423成功時には真を、さもなければ偽を返します。
83228424
83238425=begin original
83248426
83258427Portability issues: L<perlport/link>.
83268428
83278429=end original
83288430
83298431移植性の問題: L<perlport/link>。
83308432
83318433=item listen SOCKET,QUEUESIZE
83328434X<listen>
83338435
83348436=for Pod::Functions register your socket as a server
83358437
83368438=begin original
83378439
83388440Does the same thing that the L<listen(2)> system call does. Returns true if
83398441it succeeded, false otherwise. See the example in
83408442L<perlipc/"Sockets: Client/Server Communication">.
83418443
83428444=end original
83438445
83448446L<listen(2)> システムコールと同じことをします。
83458447成功時には真を、さもなければ偽を返します。
83468448L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
83478449
83488450=item local EXPR
83498451X<local>
83508452
83518453=for Pod::Functions create a temporary value for a global variable (dynamic scoping)
83528454
83538455=begin original
83548456
83558457You really probably want to be using L<C<my>|/my VARLIST> instead,
83568458because L<C<local>|/local EXPR> isn't what most people think of as
83578459"local". See L<perlsub/"Private Variables via my()"> for details.
83588460
83598461=end original
83608462
83618463あなたはが本当に望んでいるのは L<C<my>|/my VARLIST> の方でしょう;
83628464L<C<local>|/local EXPR> はほとんどの人々が「ローカル」と考えるものと
83638465違うからです。
8364は L<perlsub/"Private Variables via my()"> を参照してください。
8466しくは L<perlsub/"Private Variables via my()"> を参照してください。
83658467
83668468=begin original
83678469
83688470A local modifies the listed variables to be local to the enclosing
83698471block, file, or eval. If more than one value is listed, the list must
83708472be placed in parentheses. See L<perlsub/"Temporary Values via local()">
83718473for details, including issues with tied arrays and hashes.
83728474
83738475=end original
83748476
83758477"local" はリストアップされた変数を、囲っているブロック、
83768478ファイル、eval の中で、ローカルなものにします。
8377複数の値を指定する場合は、リストはかっこでくくらなければなりません。
8479複数の値を指定する場合は、リストはかっこで囲まなければなりません。
83788480tie した配列とハッシュに関する事項を含む詳細については
83798481L<perlsub/"Temporary Values via local()"> を参照してください。
83808482
83818483=begin original
83828484
83838485The C<delete local EXPR> construct can also be used to localize the deletion
83848486of array/hash elements to the current block.
83858487See L<perlsub/"Localized deletion of elements of composite types">.
83868488
83878489=end original
83888490
83898491C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の
83908492ブロックにローカル化するためにも使われていました。
83918493L<perlsub/"Localized deletion of elements of composite types"> を
83928494参照してください。
83938495
83948496=item localtime EXPR
83958497X<localtime> X<ctime>
83968498
83978499=item localtime
83988500
83998501=for Pod::Functions convert UNIX time into record or string using local time
84008502
84018503=begin original
84028504
84038505Converts a time as returned by the time function to a 9-element list
84048506with the time analyzed for the local time zone. Typically used as
84058507follows:
84068508
84078509=end original
84088510
84098511time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、
841085129 要素の配列に変換します。
84118513普通は、以下のようにして使います:
84128514
84138515 # 0 1 2 3 4 5 6 7 8
84148516 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
84158517 localtime(time);
84168518
84178519=begin original
84188520
84198521All list elements are numeric and come straight out of the C `struct
84208522tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours
84218523of the specified time.
84228524
84238525=end original
84248526
84258527すべてのリスト要素は数値で、C の `struct tm' 構造体から
84268528直接持ってきます。
84278529C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。
84288530
84298531=begin original
84308532
84318533C<$mday> is the day of the month and C<$mon> the month in
84328534the range C<0..11>, with 0 indicating January and 11 indicating December.
84338535This makes it easy to get a month name from a list:
84348536
84358537=end original
84368538
84378539C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が
843885401 月、11 が 12 月です。
84398541これにより、リストから月の名前を得るのが簡単になります:
84408542
84418543 my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
84428544 print "$abbr[$mon] $mday";
84438545 # $mon=9, $mday=18 gives "Oct 18"
84448546
84458547=begin original
84468548
84478549C<$year> contains the number of years since 1900. To get a 4-digit
84488550year write:
84498551
84508552=end original
84518553
84528554C<$year> は 1900 年からの年数を持ちます。
845385554 桁の年を得るには以下のようにします:
84548556
84558557 $year += 1900;
84568558
84578559=begin original
84588560
84598561To get the last two digits of the year (e.g., "01" in 2001) do:
84608562
84618563=end original
84628564
84638565西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします:
84648566
84658567 $year = sprintf("%02d", $year % 100);
84668568
84678569=begin original
84688570
84698571C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating
84708572Wednesday. C<$yday> is the day of the year, in the range C<0..364>
84718573(or C<0..365> in leap years.)
84728574
84738575=end original
84748576
84758577C<$wday> は曜日で、0 が日曜日、3 が水曜日です。
84768578C<$yday> はその年の何日目かで、C<0..364> の値を取ります
84778579(うるう年は C<0..365> です。)
84788580
84798581=begin original
84808582
8481C<$isdst> is true if the specified time occurs during Daylight Saving
8583C<$isdst> is true if the specified time occurs when Daylight Saving
8482Time, false otherwise.
8584Time is in effect, false otherwise.
84838585
84848586=end original
84858587
8486C<$isdst> は指定された時刻夏時間の場合は真、そうでなければ偽です。
8588C<$isdst> は指定された時刻夏時間が有効の場合は真、そうでなければ偽です。
84878589
84888590=begin original
84898591
84908592If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current
84918593time (as returned by L<C<time>|/time>).
84928594
84938595=end original
84948596
84958597EXPR が省略されると、L<C<localtime>|/localtime EXPR> は
84968598(L<C<time>|/time> によって返される) 現在時刻を使います。
84978599
84988600=begin original
84998601
85008602In scalar context, L<C<localtime>|/localtime EXPR> returns the
85018603L<ctime(3)> value:
85028604
85038605=end original
85048606
85058607スカラコンテキストでは、L<C<localtime>|/localtime EXPR> は L<ctime(3)> の値を
85068608返します:
85078609
8508 my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
8610 my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
85098611
85108612=begin original
85118613
8512The format of this scalar value is B<not> locale-dependent but built
8614This scalar value is always in English, and is B<not> locale-dependent.
8513into Perl. For GMT instead of local time use the
8615To get similar but locale-dependent date strings, try for example:
8514L<C<gmtime>|/gmtime EXPR> builtin. See also the
8515L<C<Time::Local>|Time::Local> module (for converting seconds, minutes,
8516hours, and such back to the integer value returned by L<C<time>|/time>),
8517and the L<POSIX> module's L<C<strftime>|POSIX/C<strftime>> and
8518L<C<mktime>|POSIX/C<mktime>> functions.
85198616
85208617=end original
85218618
8522このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です
8619このスカラ値は常に英語で、ロケール依存では B<ありません>。
8523ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み
8524関数を使ってください。
8525また、(秒、分、時などの形から、L<C<time>|/time> が返す値である
85261970 年 1 月 1 日の真夜中からの秒数に変換する)
8527L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される
8528L<C<strftime>|POSIX/C<strftime>> と L<C<mktime>|POSIX/C<mktime>> 関数も
8529参照してください。
8530
8531=begin original
8532
8533To get somewhat similar but locale-dependent date strings, set up your
8534locale environment variables appropriately (please see L<perllocale>) and
8535try for example:
8536
8537=end original
8538
85398620似たような、しかしロケール依存の日付文字列がほしい場合は、
8540ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、
85418621以下の例を試してください:
85428622
8543 use POSIX qw(strftime);
8623 use POSIX qw(strftime);
8544 my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
8624 my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
8545 # or for GMT formatted appropriately for your locale:
8625 # or for GMT formatted appropriately for your locale:
8546 my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
8626 my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
85478627
85488628=begin original
85498629
8550Note that C<%a> and C<%b>, the short forms of the day of the week
8630C$now_string> will be formatted according to the current LC_TIME locale
8551and the month of the year, may not necessarily be three characters wide.
8631the program or thread is running in. See L<perllocale> for how to set
8632up and change that locale. Note that C<%a> and C<%b>, the short forms
8633of the day of the week and the month of the year, may not necessarily be
8634three characters wide.
85528635
85538636=end original
85548637
8638C$now_string> はプログラムやスレッドが実行されている現在の LC_TIME ロケールに
8639従ってフォーマットされます。
8640このロケールの設定と変更の方法については L<perllocale> を参照してください。
85558641曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに
85568642注意してください。
85578643
85588644=begin original
85598645
85608646The L<Time::gmtime> and L<Time::localtime> modules provide a convenient,
85618647by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and
85628648L<C<localtime>|/localtime EXPR> functions, respectively.
85638649
85648650=end original
85658651
85668652L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ
85678653L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、
85688654名前でアクセスする機構を提供する便利なモジュールです。
85698655
85708656=begin original
85718657
85728658For a comprehensive date and time representation look at the
85738659L<DateTime> module on CPAN.
85748660
85758661=end original
85768662
85778663包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
85788664参照してください。
85798665
85808666=begin original
85818667
8668For GMT instead of local time use the L<C<gmtime>|/gmtime EXPR> builtin.
8669
8670=end original
8671
8672ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み
8673関数を使ってください。
8674
8675=begin original
8676
8677See also the L<C<Time::Local>|Time::Local> module (for converting
8678seconds, minutes, hours, and such back to the integer value returned by
8679L<C<time>|/time>), and the L<POSIX> module's
8680L<C<mktime>|POSIX/C<mktime>> function.
8681
8682=end original
8683
8684また、(秒、分、時などの形から、L<C<time>|/time> が返す値である
86851970 年 1 月 1 日の真夜中からの秒数に変換する)
8686L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される
8687L<C<mktime>|POSIX/C<mktime>> 関数も参照してください。
8688
8689=begin original
8690
85828691Portability issues: L<perlport/localtime>.
85838692
85848693=end original
85858694
85868695移植性の問題: L<perlport/localtime>。
85878696
85888697=item lock THING
85898698X<lock>
85908699
85918700=for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method
85928701
85938702=begin original
85948703
85958704This function places an advisory lock on a shared variable or referenced
85968705object contained in I<THING> until the lock goes out of scope.
85978706
85988707=end original
85998708
86008709この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、
86018710スコープから出るまでアドバイサリロックを掛けます.
86028711
86038712=begin original
86048713
86058714The value returned is the scalar itself, if the argument is a scalar, or a
86068715reference, if the argument is a hash, array or subroutine.
86078716
86088717=end original
86098718
86108719返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、
86118720サブルーチンならリファレンスです。
86128721
86138722=begin original
86148723
86158724L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've
86168725defined a function
86178726by this name (before any calls to it), that function will be called
86188727instead. If you are not under C<use threads::shared> this does nothing.
86198728See L<threads::shared>.
86208729
86218730=end original
86228731
86238732L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に)
86248733この名前で関数を定義すると、定義された関数の方が呼び出されます。
86258734C<use threads::shared> の影響下でない場合は、これは何もしません。
86268735L<threads::shared> を参照してください。
86278736
86288737=item log EXPR
86298738X<log> X<logarithm> X<e> X<ln> X<base>
86308739
86318740=item log
86328741
86338742=for Pod::Functions retrieve the natural logarithm for a number
86348743
86358744=begin original
86368745
86378746Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted,
86388747returns the log of L<C<$_>|perlvar/$_>. To get the
86398748log of another base, use basic algebra:
86408749The base-N log of a number is equal to the natural log of that number
86418750divided by the natural log of N. For example:
86428751
86438752=end original
86448753
86458754EXPR の (I<e> を底とする) 自然対数を返します。
86468755EXPR が省略されると、L<C<$_>|perlvar/$_> の対数を返します。
86478756底の異なる対数を求めるためには、基礎代数を利用してください:
86488757ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。
86498758例えば:
86508759
86518760 sub log10 {
86528761 my $n = shift;
86538762 return log($n)/log(10);
86548763 }
86558764
86568765=begin original
86578766
86588767See also L<C<exp>|/exp EXPR> for the inverse operation.
86598768
86608769=end original
86618770
86628771逆操作については L<C<exp>|/exp EXPR> を参照してください。
86638772
86648773=item lstat FILEHANDLE
86658774X<lstat>
86668775
86678776=item lstat EXPR
86688777
86698778=item lstat DIRHANDLE
86708779
86718780=item lstat
86728781
86738782=for Pod::Functions stat a symbolic link
86748783
86758784=begin original
86768785
86778786Does the same thing as the L<C<stat>|/stat FILEHANDLE> function
86788787(including setting the special C<_> filehandle) but stats a symbolic
86798788link instead of the file the symbolic link points to. If symbolic links
86808789are unimplemented on your system, a normal L<C<stat>|/stat FILEHANDLE>
86818790is done. For much more detailed information, please see the
86828791documentation for L<C<stat>|/stat FILEHANDLE>.
86838792
86848793=end original
86858794
86868795(特別なファイルハンドルである C<_> の設定を含めて)
86878796L<C<stat>|/stat FILEHANDLE> 関数と同じことをしますが、シンボリックリンクが
86888797指しているファイルではなく、シンボリックリンク自体の stat をとります。
86898798シンボリックリンクがシステムに実装されていないと、通常の
86908799L<C<stat>|/stat FILEHANDLE> が行なわれます。
86918800さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を
86928801参照してください。
86938802
86948803=begin original
86958804
86968805If EXPR is omitted, stats L<C<$_>|perlvar/$_>.
86978806
86988807=end original
86998808
87008809EXPR が省略されると、L<C<$_>|perlvar/$_> の stat をとります。
87018810
87028811=begin original
87038812
87048813Portability issues: L<perlport/lstat>.
87058814
87068815=end original
87078816
87088817移植性の問題: L<perlport/lstat>。
87098818
87108819=item m//
87118820
87128821=for Pod::Functions match a string with a regular expression pattern
87138822
87148823=begin original
87158824
87168825The match operator. See L<perlop/"Regexp Quote-Like Operators">.
87178826
87188827=end original
87198828
87208829マッチ演算子です。
87218830L<perlop/"Regexp Quote-Like Operators"> を参照してください。
87228831
87238832=item map BLOCK LIST
87248833X<map>
87258834
87268835=item map EXPR,LIST
87278836
87288837=for Pod::Functions apply a change to a list to get back a new list with the changes
87298838
87308839=begin original
87318840
87328841Evaluates the BLOCK or EXPR for each element of LIST (locally setting
87338842L<C<$_>|perlvar/$_> to each element) and composes a list of the results of
87348843each such evaluation. Each element of LIST may produce zero, one, or more
87358844elements in the generated list, so the number of elements in the generated
87368845list may differ from that in LIST. In scalar context, returns the total
87378846number of elements so generated. In list context, returns the generated list.
87388847
87398848=end original
87408849
87418850LIST の個々の要素に対して、BLOCK か EXPR を評価し
87428851(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
87438852それぞれの評価結果からなるリストを作ります。
87448853LIST の個々の要素によって作られる、生成されたリストの要素数は、
874588540 個の場合もあれば、複数の場合もあるので、
87468855生成されたリストの要素数は LIST の要素数と異なるかも知れません。
87478856スカラコンテキストでは、生成された要素の数を返します。
87488857リストコンテキストでは、生成されたリストを返します。
87498858
87508859 my @chars = map(chr, @numbers);
87518860
87528861=begin original
87538862
87548863translates a list of numbers to the corresponding characters.
87558864
87568865=end original
87578866
87588867は、数のリストを対応する文字に変換します。
87598868
87608869 my @squares = map { $_ * $_ } @numbers;
87618870
87628871=begin original
87638872
87648873translates a list of numbers to their squared values.
87658874
87668875=end original
87678876
87688877これは数値のリストを、その 2 乗に変換します。
87698878
87708879 my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers;
87718880
87728881=begin original
87738882
87748883shows that number of returned elements can differ from the number of
87758884input elements. To omit an element, return an empty list ().
87768885This could also be achieved by writing
87778886
87788887=end original
87798888
87808889のように、返された要素の数が入力要素の数と異なる場合もあります。
87818890要素を省略するには、空リスト () を返します。
87828891これは以下のように書くことでも達成できて
87838892
87848893 my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers;
87858894
87868895=begin original
87878896
87888897which makes the intention more clear.
87898898
87908899=end original
87918900
87928901この方が目的がよりはっきりします。
87938902
87948903=begin original
87958904
87968905Map always returns a list, which can be
87978906assigned to a hash such that the elements
87988907become key/value pairs. See L<perldata> for more details.
87998908
88008909=end original
88018910
88028911map は常にリストを返し、要素がキー/値の組になるようなハッシュに
88038912代入できます。
88048913さらなる詳細については L<perldata> を参照してください。
88058914
88068915 my %hash = map { get_a_key_for($_) => $_ } @array;
88078916
88088917=begin original
88098918
88108919is just a funny way to write
88118920
88128921=end original
88138922
88148923は以下のものをちょっと変わった書き方で書いたものです。
88158924
88168925 my %hash;
88178926 foreach (@array) {
88188927 $hash{get_a_key_for($_)} = $_;
88198928 }
88208929
88218930=begin original
88228931
88238932Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
88248933be used to modify the elements of the LIST. While this is useful and
88258934supported, it can cause bizarre results if the elements of LIST are not
88268935variables. Using a regular C<foreach> loop for this purpose would be
88278936clearer in most cases. See also L<C<grep>|/grep BLOCK LIST> for a
88288937list composed of those items of the original list for which the BLOCK
88298938or EXPR evaluates to true.
88308939
88318940=end original
88328941
88338942L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
88348943変更するために使うことができます。
88358944これは、便利でサポートされていますが、
88368945LIST の要素が変数でないと、おかしな結果になります。
88378946この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は
88388947より明確になります。
88398948BLOCK や EXPR が真になる元のリストの要素からなるリストについては、
88408949L<C<grep>|/grep BLOCK LIST> も参照してください。
88418950
88428951=begin original
88438952
88448953C<{> starts both hash references and blocks, so C<map { ...> could be either
88458954the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look
88468955ahead for the closing C<}> it has to take a guess at which it's dealing with
88478956based on what it finds just after the
88488957C<{>. Usually it gets it right, but if it
88498958doesn't it won't realize something is wrong until it gets to the C<}> and
88508959encounters the missing (or unexpected) comma. The syntax error will be
88518960reported close to the C<}>, but you'll need to change something near the C<{>
88528961such as using a unary C<+> or semicolon to give Perl some help:
88538962
88548963=end original
88558964
88568965C<{> はハッシュリファレンスとブロックの両方の開始文字なので、
88578966C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。
88588967Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て
88598968どちらとして扱うかを推測します。
88608969通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで
88618970カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに
88628971気付きません。
88638972C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> や
88648973セミコロンを使うというように、C<{> の近くの何かを変更する必要があります。
88658974
88668975 my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
88678976 my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
88688977 my %hash = map {; "\L$_" => 1 } @array # this also works
88698978 my %hash = map { ("\L$_" => 1) } @array # as does this
88708979 my %hash = map { lc($_) => 1 } @array # and this.
88718980 my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
88728981
88738982 my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
88748983
88758984=begin original
88768985
88778986or to force an anon hash constructor use C<+{>:
88788987
88798988=end original
88808989
88818990または C<+{> を使って無名ハッシュコンストラクタを強制します:
88828991
88838992 my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs
88848993 # comma at end
88858994
88868995=begin original
88878996
88888997to get a list of anonymous hashes each with only one entry apiece.
88898998
88908999=end original
88919000
88929001こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。
88939002
88949003=item mkdir FILENAME,MODE
88959004X<mkdir> X<md> X<directory, create>
88969005
88979006=item mkdir FILENAME
88989007
88999008=item mkdir
89009009
89019010=for Pod::Functions create a directory
89029011
89039012=begin original
89049013
89059014Creates the directory specified by FILENAME, with permissions
89069015specified by MODE (as modified by L<C<umask>|/umask EXPR>). If it
89079016succeeds it returns true; otherwise it returns false and sets
89089017L<C<$!>|perlvar/$!> (errno).
89099018MODE defaults to 0777 if omitted, and FILENAME defaults
89109019to L<C<$_>|perlvar/$_> if omitted.
89119020
89129021=end original
89139022
89149023FILENAME で指定したディレクトリを、MODE で指定した許可モード(を
89159024L<C<umask>|/umask EXPR> で修正したもの) で作成します。
89169025成功時には真を返します; さもなければ偽を返して
89179026L<C<$!>|perlvar/$!> (errno) を設定します。
89189027MODE を省略すると、0777 とみなし、
89199028FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。
89209029
89219030=begin original
89229031
89239032In general, it is better to create directories with a permissive MODE
89249033and let the user modify that with their L<C<umask>|/umask EXPR> than it
89259034is to supply
89269035a restrictive MODE and give the user no way to be more permissive.
89279036The exceptions to this rule are when the file or directory should be
89289037kept private (mail files, for instance). The documentation for
89299038L<C<umask>|/umask EXPR> discusses the choice of MODE in more detail.
89309039
89319040=end original
89329041
89339042一般的に、制限された MODE を使ってユーザーがより寛容にする方法を
89349043与えないより、寛容な MODE でディレクトリを作り、ユーザーが自身の
89359044L<C<umask>|/umask EXPR> で修正するようにした方がよいです。
89369045例外は、(例えばメールファイルのような)プライベートに保つべきファイルや
89379046ディレクトリを書く場合です。
89389047L<C<umask>|/umask EXPR> の文書で、MODE の選択に関して詳細に議論しています。
89399048
89409049=begin original
89419050
89429051Note that according to the POSIX 1003.1-1996 the FILENAME may have any
89439052number of trailing slashes. Some operating and filesystems do not get
89449053this right, so Perl automatically removes all trailing slashes to keep
89459054everyone happy.
89469055
89479056=end original
89489057
89499058POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを
89509059つけることができます。
89519060このようには動かない OS やファイルシステムもあるので、Perl はみんなが
89529061幸せになれるように、自動的に末尾のスラッシュを削除します。
89539062
89549063=begin original
89559064
89569065To recursively create a directory structure, look at
89579066the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function
89589067of the L<File::Path> module.
89599068
89609069=end original
89619070
89629071ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの
89639072L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を
89649073参照してください。
89659074
89669075=item msgctl ID,CMD,ARG
89679076X<msgctl>
89689077
89699078=for Pod::Functions SysV IPC message control operations
89709079
89719080=begin original
89729081
89739082Calls the System V IPC function L<msgctl(2)>. You'll probably have to say
89749083
89759084=end original
89769085
89779086System V IPC 関数 L<msgctl(2)> を呼び出します。
89789087正しい定数定義を得るために、まず
89799088
89809089 use IPC::SysV;
89819090
89829091=begin original
89839092
89849093first to get the correct constant definitions. If CMD is C<IPC_STAT>,
89859094then ARG must be a variable that will hold the returned C<msqid_ds>
89869095structure. Returns like L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
89879096the undefined value for error, C<"0 but true"> for zero, or the actual
89889097return value otherwise. See also L<perlipc/"SysV IPC"> and the
89899098documentation for L<C<IPC::SysV>|IPC::SysV> and
89909099L<C<IPC::Semaphore>|IPC::Semaphore>.
89919100
89929101=end original
89939102
89949103と書くことが必要でしょう。
89959104CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を
89969105納める変数でなければなりません。
89979106L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
89989107未定義値、ゼロのときは C<"0 but true">、それ以外なら、その値そのものを
89999108返します。
9000L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
9109L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
90019110L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
90029111
90039112=begin original
90049113
90059114Portability issues: L<perlport/msgctl>.
90069115
90079116=end original
90089117
90099118移植性の問題: L<perlport/msgctl>。
90109119
90119120=item msgget KEY,FLAGS
90129121X<msgget>
90139122
90149123=for Pod::Functions get SysV IPC message queue
90159124
90169125=begin original
90179126
90189127Calls the System V IPC function L<msgget(2)>. Returns the message queue
90199128id, or L<C<undef>|/undef EXPR> on error. See also L<perlipc/"SysV IPC">
90209129and the documentation for L<C<IPC::SysV>|IPC::SysV> and
90219130L<C<IPC::Msg>|IPC::Msg>.
90229131
90239132=end original
90249133
90259134System V IPC 関数 L<msgget(2)> を呼び出します。
90269135メッセージキューの ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
9027L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
9136L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
90289137L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
90299138
90309139=begin original
90319140
90329141Portability issues: L<perlport/msgget>.
90339142
90349143=end original
90359144
90369145移植性の問題: L<perlport/msgget>。
90379146
90389147=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
90399148X<msgrcv>
90409149
90419150=for Pod::Functions receive a SysV IPC message from a message queue
90429151
90439152=begin original
90449153
90459154Calls the System V IPC function msgrcv to receive a message from
90469155message queue ID into variable VAR with a maximum message size of
90479156SIZE. Note that when a message is received, the message type as a
90489157native long integer will be the first thing in VAR, followed by the
90499158actual message. This packing may be opened with C<unpack("l! a*")>.
90509159Taints the variable. Returns true if successful, false
90519160on error. See also L<perlipc/"SysV IPC"> and the documentation for
90529161L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
90539162
90549163=end original
90559164
90569165System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、
90579166変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。
90589167メッセージが受信された時、ネイティブな long 整数のメッセージタイプが
90599168VAR の先頭となり、実際のメッセージが続きます。
90609169このパッキングは C<unpack("l! a*")> で展開できます。
90619170変数は汚染されます。
90629171成功時には真を、エラー時には偽を返します。
9063L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
9172L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
90649173L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
90659174
90669175=begin original
90679176
90689177Portability issues: L<perlport/msgrcv>.
90699178
90709179=end original
90719180
90729181移植性の問題: L<perlport/msgrcv>。
90739182
90749183=item msgsnd ID,MSG,FLAGS
90759184X<msgsnd>
90769185
90779186=for Pod::Functions send a SysV IPC message to a message queue
90789187
90799188=begin original
90809189
90819190Calls the System V IPC function msgsnd to send the message MSG to the
90829191message queue ID. MSG must begin with the native long integer message
9083type, be followed by the length of the actual message, and then finally
9192type, followed by the message itself. This kind of packing can be achieved
9084the message itself. This kind of packing can be achieved with
9193with C<pack("l! a*", $type, $message)>. Returns true if successful,
9085C<pack("l! a*", $type, $message)>. Returns true if successful,
90869194false on error. See also L<perlipc/"SysV IPC"> and the documentation
90879195for L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
90889196
90899197=end original
90909198
90919199System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に
90929200メッセージ MSG を送信します。
90939201MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、
9094メッセージの長さ、メッセージ本体続きます。
9202メッセージ本体続きます。
90959203これは、C<pack("l! a*", $type, $message)> として生成できます。
90969204成功時には真を、エラー時には偽を返します。
9097L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
9205L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
90989206L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
90999207
91009208=begin original
91019209
91029210Portability issues: L<perlport/msgsnd>.
91039211
91049212=end original
91059213
91069214移植性の問題: L<perlport/msgsnd>。
91079215
91089216=item my VARLIST
91099217X<my>
91109218
91119219=item my TYPE VARLIST
91129220
91139221=item my VARLIST : ATTRS
91149222
91159223=item my TYPE VARLIST : ATTRS
91169224
91179225=for Pod::Functions declare and assign a local variable (lexical scoping)
91189226
91199227=begin original
91209228
91219229A L<C<my>|/my VARLIST> declares the listed variables to be local
91229230(lexically) to the enclosing block, file, or L<C<eval>|/eval EXPR>. If
91239231more than one variable is listed, the list must be placed in
91249232parentheses.
91259233
91269234=end original
91279235
91289236L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、
91299237L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。
9130複数の変数を指定する場合は、リストはかっこでくくらなければなりません。
9238複数の変数を指定する場合は、リストはかっこで囲まなければなりません。
91319239
91329240=begin original
91339241
9242Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
9243as a dummy placeholder, for example to skip assignment of initial
9244values:
9245
9246=end original
9247
9248かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
9249飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
9250
9251 my ( undef, $min, $hour ) = localtime;
9252
9253=begin original
9254
9255Redeclaring a variable in the same scope or statement will "shadow" the
9256previous declaration, creating a new instance and preventing access to
9257the previous one. This is usually undesired and, if warnings are enabled,
9258will result in a warning in the C<shadow> category.
9259
9260=end original
9261
9262同じスコープや文で変数を再宣言すると、以前の宣言を「隠し」、
9263新しい実体を作って、以前の実体にアクセスできなくなります。
9264これは普通は望まれているものではなく、警告が有効なら、
9265C<shadow> カテゴリの警告が出ます。
9266
9267=begin original
9268
91349269The exact semantics and interface of TYPE and ATTRS are still
91359270evolving. TYPE may be a bareword, a constant declared
91369271with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It
91379272is
91389273currently bound to the use of the L<fields> pragma,
91399274and attributes are handled using the L<attributes> pragma, or starting
91409275from Perl 5.8.0 also via the L<Attribute::Handlers> module. See
91419276L<perlsub/"Private Variables via my()"> for details.
91429277
91439278=end original
91449279
91459280TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
91469281TYPE は、裸の単語、L<C<use constant>|constant> で宣言された定数、
91479282L<C<__PACKAGE__>|/__PACKAGE__> のいずれかです。
91489283現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
91499284属性は L<attributes> プラグマか、Perl 5.8.0 からは
91509285L<Attribute::Handlers> モジュールと結び付けられています。
91519286詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
91529287
9153=begin original
9154
9155Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
9156as a dummy placeholder, for example to skip assignment of initial
9157values:
9158
9159=end original
9160
9161かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
9162飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
9163
9164 my ( undef, $min, $hour ) = localtime;
9165
91669288=item next LABEL
91679289X<next> X<continue>
91689290
91699291=item next EXPR
91709292
91719293=item next
91729294
91739295=for Pod::Functions iterate a block prematurely
91749296
91759297=begin original
91769298
91779299The L<C<next>|/next LABEL> command is like the C<continue> statement in
91789300C; it starts the next iteration of the loop:
91799301
91809302=end original
91819303
91829304L<C<next>|/next LABEL> コマンドは、C での C<continue> 文のようなもので、
91839305ループの次の繰り返しを開始します:
91849306
91859307 LINE: while (<STDIN>) {
91869308 next LINE if /^#/; # discard comments
91879309 #...
91889310 }
91899311
91909312=begin original
91919313
91929314Note that if there were a L<C<continue>|/continue BLOCK> block on the
91939315above, it would get
91949316executed even on discarded lines. If LABEL is omitted, the command
91959317refers to the innermost enclosing loop. The C<next EXPR> form, available
91969318as of Perl 5.18.0, allows a label name to be computed at run time, being
91979319otherwise identical to C<next LABEL>.
91989320
91999321=end original
92009322
92019323L<C<continue>|/continue BLOCK> ブロックが存在すれば、たとえ捨てられる行に
92029324あっても、それが実行されます。
92039325LABEL が省略されると、コマンドは一番内側のループを参照します。
92049326Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される
92059327ラベル名が使えます; それ以外は C<next LABEL> と同一です。
92069328
92079329=begin original
92089330
92099331L<C<next>|/next LABEL> cannot return a value from a block that typically
92109332returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
92119333its flow control behavior, which precludes any return value. It should not be
92129334used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
92139335operation.
92149336
92159337=end original
92169338
92179339L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
92189340典型的には値を返すブロックから値を返せません。
92199341これは、返り値を不可能にするフロー制御の振る舞いを実行します。
92209342L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
92219343使うべきではありません。
92229344
92239345=begin original
92249346
92259347Note that a block by itself is semantically identical to a loop
92269348that executes once. Thus L<C<next>|/next LABEL> will exit such a block
92279349early.
92289350
92299351=end original
92309352
92319353ブロック自身は一回だけ実行されるループと文法的に同一であることに
92329354注意してください。
92339355従って、L<C<next>|/next LABEL> はそのようなブロックから早く抜けるのに使えます。
92349356
92359357=begin original
92369358
92379359See also L<C<continue>|/continue BLOCK> for an illustration of how
92389360L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
92399361L<C<redo>|/redo LABEL> work.
92409362
92419363=end original
92429364
92439365L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
92449366どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
92459367
92469368=begin original
92479369
92489370Unlike most named operators, this has the same precedence as assignment.
92499371It is also exempt from the looks-like-a-function rule, so
92509372C<next ("foo")."bar"> will cause "bar" to be part of the argument to
92519373L<C<next>|/next LABEL>.
92529374
92539375=end original
92549376
92559377ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
92569378また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と
92579379すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。
92589380
92599381=item no MODULE VERSION LIST
92609382X<no declarations>
92619383X<unimporting>
92629384
92639385=item no MODULE VERSION
92649386
92659387=item no MODULE LIST
92669388
92679389=item no MODULE
92689390
92699391=item no VERSION
92709392
92719393=for Pod::Functions unimport some module symbols or semantics at compile time
92729394
92739395=begin original
92749396
92759397See the L<C<use>|/use Module VERSION LIST> function, of which
92769398L<C<no>|/no MODULE VERSION LIST> is the opposite.
92779399
92789400=end original
92799401
92809402L<C<use>|/use Module VERSION LIST> 関数を参照してください;
92819403L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。
92829404
92839405=item oct EXPR
92849406X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin>
92859407
92869408=item oct
92879409
92889410=for Pod::Functions convert a string to an octal number
92899411
92909412=begin original
92919413
92929414Interprets EXPR as an octal string and returns the corresponding
9293value. (If EXPR happens to start off with C<0x>, interprets it as a
9415value. An octal string consists of octal digits and, as of Perl 5.33.5,
9294hex string. If EXPR starts off with C<0b>, it is interpreted as a
9416an optional C<0o> or C<o> prefix. Each octal digit may be preceded by
9417a single underscore, which will be ignored.
9418(If EXPR happens to start off with C<0x> or C<x>, interprets it as a
9419hex string. If EXPR starts off with C<0b> or C<b>, it is interpreted as a
92959420binary string. Leading whitespace is ignored in all three cases.)
92969421The following will handle decimal, binary, octal, and hex in standard
92979422Perl notation:
92989423
92999424=end original
93009425
93019426EXPR を 8 進数文字列と解釈して、対応する値を返します。
9302(EXPR が C<0x> で始まるときには、16文字解釈します。
94278 進数文字列は、8 進文字と、Perl 5.33.5 からはオプションの
9303EXPR が C<0b>で始るとき、2 進数文字列と解釈します。
9428C<0o> C<o> 接頭辞からなります。
9429各 8 進文字の前には一つの下線を置くことができ、これは無視されます。
9430(EXPR が C<0x> か C<x> で始まるときには、16 進数文字列と解釈します。
9431EXPR が C<0b> か C<b> で始まるときは、2 進数文字列と解釈します。
93049432どの場合でも、先頭の空白は無視されます。)
93059433以下の例は、標準的な Perl の記法での
9306943410 進数、2 進数、8 進数、16 進数を扱います:
93079435
93089436 $val = oct($val) if $val =~ /^0/;
93099437
93109438=begin original
93119439
93129440If EXPR is omitted, uses L<C<$_>|perlvar/$_>. To go the other way
93139441(produce a number in octal), use L<C<sprintf>|/sprintf FORMAT, LIST> or
93149442L<C<printf>|/printf FILEHANDLE FORMAT, LIST>:
93159443
93169444=end original
93179445
93189446EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
93199447(8 進数を扱う)その他の方法をとしては L<C<sprintf>|/sprintf FORMAT, LIST> や
93209448L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります:
93219449
93229450 my $dec_perms = (stat("filename"))[2] & 07777;
93239451 my $oct_perm_str = sprintf "%o", $perms;
93249452
93259453=begin original
93269454
93279455The L<C<oct>|/oct EXPR> function is commonly used when a string such as
93289456C<644> needs
93299457to be converted into a file mode, for example. Although Perl
93309458automatically converts strings into numbers as needed, this automatic
93319459conversion assumes base 10.
93329460
93339461=end original
93349462
93359463L<C<oct>|/oct EXPR> 関数は例えば、 C<644> といった文字列をファイルモードに
93369464変換する時によく使います。
93379465Perl は必要に応じて自動的に文字列を数値に変換しますが、
93389466この自動変換は十進数を仮定します。
93399467
93409468=begin original
93419469
93429470Leading white space is ignored without warning, as too are any trailing
93439471non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles
93449472non-negative integers, not negative integers or floating point).
93459473
93469474=end original
93479475
93489476先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます
93499477(L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。
93509478
93519479
93529480=item open FILEHANDLE,MODE,EXPR
93539481X<open> X<pipe> X<file, open> X<fopen>
93549482
93559483=item open FILEHANDLE,MODE,EXPR,LIST
93569484
93579485=item open FILEHANDLE,MODE,REFERENCE
93589486
93599487=item open FILEHANDLE,EXPR
93609488
93619489=item open FILEHANDLE
93629490
93639491=for Pod::Functions open a file, pipe, or descriptor
93649492
93659493=begin original
93669494
93679495Associates an internal FILEHANDLE with the external file specified by
93689496EXPR. That filehandle will subsequently allow you to perform
93699497I/O operations on that file, such as reading from it or writing to it.
93709498
93719499=end original
93729500
93739501内部の FILEHANDLE を、EXPR で指定された外部ファイルに関連付けます。
93749502このファイルハンドルはその後、読んだり書いたりといったそのファイルへの
93759503I/O 操作をできるようにします。
93769504
93779505=begin original
93789506
93799507Instead of a filename, you may specify an external command
93809508(plus an optional argument list) or a scalar reference, in order to open
93819509filehandles on commands or in-memory scalars, respectively.
93829510
93839511=end original
93849512
93859513ファイル名の代わりに、コマンドやメモリ内スカラへのファイルハンドルを
93869514開くために、外部コマンド (とオプションの引数リスト) やスカラリファレンスを
93879515指定できます。
93889516
93899517=begin original
93909518
93919519A thorough reference to C<open> follows. For a gentler introduction to
93929520the basics of C<open>, see also the L<perlopentut> manual page.
93939521
93949522=end original
93959523
93969524C<open> の完全なリファレンスは後述します。
93979525C<open> の基本に関するより親切な導入に関しては、
93989526L<perlopentut> man ページも参照してください。
93999527
94009528=over
94019529
94029530=item Working with files
94039531
94049532=begin original
94059533
94069534Most often, C<open> gets invoked with three arguments: the required
94079535FILEHANDLE (usually an empty scalar variable), followed by MODE (usually
94089536a literal describing the I/O mode the filehandle will use), and then the
94099537filename that the new filehandle will refer to.
94109538
94119539=end original
94129540
94139541ほとんどの場合、C<open> は 3 引数で起動されます:
94149542必須の FILEHANDLE (通常は空のスカラ変数), 引き続いて MODE (通常は
94159543ファイルハンドルを使う I/O モードを記述するリテラル)、
94169544それから新しいファイルハンドルが参照するファイル名です。
94179545
94189546=over
94199547
94209548=item Simple examples
94219549
94229550(単純な例)
94239551
94249552=begin original
94259553
94269554Reading from a file:
94279555
94289556=end original
94299557
94309558ファイルからの読み込み:
94319559
94329560 open(my $fh, "<", "input.txt")
94339561 or die "Can't open < input.txt: $!";
94349562
94359563 # Process every line in input.txt
94369564 while (my $line = <$fh>) {
94379565 #
94389566 # ... do something interesting with $line here ...
94399567 #
94409568 }
94419569
94429570=begin original
94439571
94449572or writing to one:
94459573
94469574=end original
94479575
94489576そして書き込み:
94499577
94509578 open(my $fh, ">", "output.txt")
94519579 or die "Can't open > output.txt: $!";
94529580
94539581 print $fh "This line gets printed into output.txt.\n";
94549582
94559583=begin original
94569584
94579585For a summary of common filehandle operations such as these, see
94589586L<perlintro/Files and I/O>.
94599587
94609588=end original
94619589
94629590このような基本的なファイルハンドル操作の要約については、
94639591L<perlintro/Files and I/O> を参照してください。
94649592
94659593=item About filehandles
94669594
94679595(ファイルハンドルについて)
94689596
94699597=begin original
94709598
94719599The first argument to C<open>, labeled FILEHANDLE in this reference, is
94729600usually a scalar variable. (Exceptions exist, described in "Other
94739601considerations", below.) If the call to C<open> succeeds, then the
94749602expression provided as FILEHANDLE will get assigned an open
94759603I<filehandle>. That filehandle provides an internal reference to the
94769604specified external file, conveniently stored in a Perl variable, and
94779605ready for I/O operations such as reading and writing.
94789606
94799607=end original
94809608
94819609このリファレンスでは FILEHANDLE というラベルが付いている、
94829610C<open> の最初の引数は、通常はスカラ変数です。
94839611(例外があります; 後述する "Other considerations" で記述されます。)
94849612C<open> の呼び出しが成功すると、
94859613FILEHANDLE として提供された式には、
94869614開いた I<ファイルハンドル> が代入されます。
94879615このファイルハンドルは指定された外部ファイルへの内部参照を提供し、
94889616好都合なように Perl 変数に保管し、読み書きのような I/O 操作の準備をします。
94899617
94909618=item About modes
94919619
94929620(モードについて)
94939621
94949622=begin original
94959623
94969624When calling C<open> with three or more arguments, the second argument
94979625-- labeled MODE here -- defines the I<open mode>. MODE is usually a
94989626literal string comprising special characters that define the intended
94999627I/O role of the filehandle being created: whether it's read-only, or
95009628read-and-write, and so on.
95019629
95029630=end original
95039631
950496323 引数以上で C<open> を呼び出すとき、
950596332 番目の引数 -- ここでは MODE -- は I<開くモード> を定義します。
95069634MODE は普通、作られるファイルハンドルが意図している I/O の役割 (読み込み専用、
95079635読み書き、など)を定義する特別な文字で構成されるリテラルな文字列です。
95089636
95099637=begin original
95109638
95119639If MODE is C<< < >>, the file is opened for input (read-only).
95129640If MODE is C<< > >>, the file is opened for output, with existing files
95139641first being truncated ("clobbered") and nonexisting files newly created.
95149642If MODE is C<<< >> >>>, the file is opened for appending, again being
95159643created if necessary.
95169644
95179645=end original
95189646
95199647MODE が C<< < >> の場合、ファイルは入力用(読み込み専用)に開かれます。
95209648MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが
95219649ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。
95229650MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら
95239651作成されます。
95249652
95259653=begin original
95269654
95279655You can put a C<+> in front of the C<< > >> or C<< < >> to
95289656indicate that you want both read and write access to the file; thus
95299657C<< +< >> is almost always preferred for read/write updates--the
95309658C<< +> >> mode would clobber the file first. You can't usually use
95319659either read-write mode for updating textfiles, since they have
95329660variable-length records. See the B<-i> switch in
95339661L<perlrun|perlrun/-i[extension]> for a better approach. The file is
95349662created with permissions of C<0666> modified by the process's
95359663L<C<umask>|/umask EXPR> value.
95369664
95379665=end original
95389666
95399667ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、
95409668C<< > >> や C<< < >> の前に C<+> を付けることができます:
95419669従って、ほとんど常に C<< +< >> が読み書き更新のために使われます --
95429670C<< +> >> モードはまずファイルを上書きします。
95439671普通はこれらの読み書きモードをテキストファイルの更新のためには使えません;
95449672なぜなら可変長のレコードで構成されているからです。
95459673よりよい手法については L<perlrun|perlrun/-i[extension]> の
95469674B<-i> オプションを参照してください。
95479675ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した
95489676パーミッションで作成されます。
95499677
95509678=begin original
95519679
95529680These various prefixes correspond to the L<fopen(3)> modes of C<r>,
95539681C<r+>, C<w>, C<w+>, C<a>, and C<a+>.
95549682
95559683=end original
95569684
95579685これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>,
95589686C<w>, C<w+>, C<a>, C<a+> のモードに対応します。
95599687
95609688=begin original
95619689
95629690More examples of different modes in action:
95639691
95649692=end original
95659693
95669694実用的な異なったモードに関する更なる例:
95679695
95689696 # Open a file for concatenation
95699697 open(my $log, ">>", "/usr/spool/news/twitlog")
95709698 or warn "Couldn't open log file; discarding input";
95719699
95729700 # Open a file for reading and writing
95739701 open(my $dbase, "+<", "dbase.mine")
95749702 or die "Can't open 'dbase.mine' for update: $!";
95759703
95769704=item Checking the return value
95779705
95789706(返り値をチェックする)
95799707
95809708=begin original
95819709
95829710Open returns nonzero on success, the undefined value otherwise. If the
95839711C<open> involved a pipe, the return value happens to be the pid of the
95849712subprocess.
95859713
95869714=end original
95879715
95889716open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。
95899717パイプに関る C<open> のときには、返り値は
95909718サブプロセスの pid となります。
95919719
95929720=begin original
95939721
95949722When opening a file, it's seldom a good idea to continue if the request
95959723failed, so C<open> is frequently used with L<C<die>|/die LIST>. Even if
95969724you want your code to do something other than C<die> on a failed open,
95979725you should still always check the return value from opening a file.
95989726
95999727=end original
96009728
96019729ファイルを開く時、開くのに失敗した時に通常の処理を続けるのは普通は悪い
96029730考えなので、C<open> はしばしば
96039731L<C<die>|/die LIST> と結び付けられて使われます。
96049732開くときに失敗したときに L<C<die>|/die LIST> 意外の何かを
96059733したい場合でも、ファイルを開いた時の返り値を常にチェックするべきです。
96069734
96079735=back
96089736
96099737=item Specifying I/O layers in MODE
96109738
96119739(MODE で I/O 層を指定する)
96129740
96139741=begin original
96149742
96159743You can use the three-argument form of open to specify
96169744I/O layers (sometimes referred to as "disciplines") to apply to the new
96179745filehandle. These affect how the input and output are processed (see
96189746L<open> and
96199747L<PerlIO> for more details). For example:
96209748
96219749=end original
96229750
96239751新しいファイルハンドルに適用する
96249752I/O 層(「ディシプリン」とも呼ばれます)を指定するために
96259753open の 3 引数形式を使えます。
96269754これらはどのように入出力が処理されるかに影響を与えます
96279755(詳細については L<open> と L<PerlIO> を参照してください)。
96289756例えば:
96299757
9758 # loads PerlIO::encoding automatically
96309759 open(my $fh, "<:encoding(UTF-8)", $filename)
96319760 || die "Can't open UTF-8 encoded $filename: $!";
96329761
96339762=begin original
96349763
96359764This opens the UTF8-encoded file containing Unicode characters;
96369765see L<perluniintro>. Note that if layers are specified in the
96379766three-argument form, then default layers stored in
96389767L<C<${^OPEN}>|perlvar/${^OPEN}>
96399768(usually set by the L<open> pragma or the switch C<-CioD>) are ignored.
96409769Those layers will also be ignored if you specify a colon with no name
96419770following it. In that case the default layer for the operating system
96429771(:raw on Unix, :crlf on Windows) is used.
96439772
96449773=end original
96459774
96469775これは、Unicode 文字を含む UTF8 エンコードされたファイルを開きます;
96479776L<perluniintro> を参照してください。
964897773 引数形式で層を指定すると、L<C<${^OPEN}>|perlvar/${^OPEN}>
96499778(通常は L<open> プラグマか C<-CioD> オプションでセットされます) に
96509779保存されたデフォルト層は無視されることに注意してください。
96519780これらの層は、名前なしでコロンを指定した場合にも無視されます。
96529781この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が
96539782使われます。
96549783
96559784=begin original
96569785
96579786On some systems (in general, DOS- and Windows-based systems)
96589787L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
96599788working with a text file. For the sake of portability it is a good idea
96609789always to use it when appropriate, and never to use it when it isn't
96619790appropriate. Also, people can set their I/O to be by default
96629791UTF8-encoded Unicode, not bytes.
96639792
96649793=end original
96659794
96669795テキストファイルでないものを扱う場合に
96679796L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
96689797システムもあります(一般的には DOS と Windows ベースのシステムです)。
96699798移植性のために、適切なときには常にこれを使い、適切でないときには
96709799決して使わないというのは良い考えです。
96719800また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
96729801Unicode にセットすることも出来ます。
96739802
96749803=item Using C<undef> for temporary files
96759804
96769805(一時ファイルとして C<undef> を使う)
96779806
96789807=begin original
96799808
96809809As a special case the three-argument form with a read/write mode and the third
96819810argument being L<C<undef>|/undef EXPR>:
96829811
96839812=end original
96849813
96859814特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が
96869815L<C<undef>|/undef EXPR> の場合:
96879816
96889817 open(my $tmp, "+>", undef) or die ...
96899818
96909819=begin original
96919820
96929821opens a filehandle to a newly created empty anonymous temporary file.
96939822(This happens under any mode, which makes C<< +> >> the only useful and
96949823sensible mode to use.) You will need to
96959824L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading.
96969825
96979826=end original
96989827
96999828新しく作成した空の無名一時ファイルとしてファイルハンドルを開きます。
9700(これはどのモードでも起こりますが、C<< +> >> のみが有用で意味があります)
9829(これはどのモードでも起こりますが、C<< +> >> のみが有用で意味があります)
97019830読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が
97029831必要です。
97039832
97049833=item Opening a filehandle into an in-memory scalar
97059834
97069835(ファイルハンドルをメモリ内スカラに開く)
97079836
97089837=begin original
97099838
97109839You can open filehandles directly to Perl scalars instead of a file or
97119840other resource external to the program. To do so, provide a reference to
97129841that scalar as the third argument to C<open>, like so:
97139842
97149843=end original
97159844
97169845ファイルやその他のプログラムから見ての外部リソースではなく、
97179846Perl スカラに対して直接ファイルハンドルを開くことができます。
97189847そうするためには、次のように、C<open> の 3 番目の引数としてその
97199848スカラへのリファレンスを提供します:
97209849
97219850 open(my $memory, ">", \$var)
97229851 or die "Can't open memory file: $!";
97239852 print $memory "foo!\n"; # output will appear in $var
97249853
97259854=begin original
97269855
97279856To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
97289857
97299858=end original
97309859
97319860C<STDOUT> や C<STDERR> を「オンメモリの」ファイルとして
97329861再び開きたい場合は、先にそれを閉じます:
97339862
97349863 close STDOUT;
97359864 open(STDOUT, ">", \$variable)
97369865 or die "Can't open STDOUT: $!";
97379866
97389867=begin original
97399868
97409869The scalars for in-memory files are treated as octet strings: unless
97419870the file is being opened with truncation the scalar may not contain
97429871any code points over 0xFF.
97439872
97449873=end original
97459874
97469875オンメモリファイルのためのスカラはオクテット文字列として扱われます:
97479876ファイルが切り詰められて開かれない限り、
97489877スカラは 0xFF を超える符号位置を含みません。
97499878
97509879=begin original
97519880
97529881Opening in-memory files I<can> fail for a variety of reasons. As with
97539882any other C<open>, check the return value for success.
97549883
97559884=end original
97569885
97579886オンメモリファイルを開くのは様々な理由で失敗する I<ことがあります>。
97589887その他の C<open> と同様、成功したかを返り値でチェックしてください。
97599888
97609889=begin original
97619890
97629891I<Technical note>: This feature works only when Perl is built with
97639892PerlIO -- the default, except with older (pre-5.16) Perl installations
97649893that were configured to not include it (e.g. via C<Configure
97659894-Uuseperlio>). You can see whether your Perl was built with PerlIO by
97669895running C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO;
97679896otherwise you don't.
97689897
97699898=end original
97709899
97719900I<技術ノート>: この機能は Perl が PerlIO を使ってビルドされている
97729901場合にのみ動作します; これは (C<Configure -Uuseperlio> によって)
97739902これを含まないように設定されていた古い (5.16 より前の) Perl でない限り、
97749903デフォルトです。
97759904Perl が PerlIO つきでビルドされているかどうかを確認するには、
97769905C<perl -V:useperlio> を見ます。
97779906これが C<'define'> なら PerlIO を使っています;
97789907そうでなければ使っていません。
97799908
97809909=begin original
97819910
97829911See L<perliol> for detailed info on PerlIO.
97839912
97849913=end original
97859914
97869915PerlIO に関する詳しい情報については L<perliol> を参照してください。
97879916
97889917=item Opening a filehandle into a command
97899918
97909919(ファイルハンドルをコマンドに開く)
97919920
97929921=begin original
97939922
97949923If MODE is C<|->, then the filename is
97959924interpreted as a command to which output is to be piped, and if MODE
97969925is C<-|>, the filename is interpreted as a command that pipes
97979926output to us. In the two-argument (and one-argument) form, one should
97989927replace dash (C<->) with the command.
97999928See L<perlipc/"Using open() for IPC"> for more examples of this.
98009929(You are not allowed to L<C<open>|/open FILEHANDLE,MODE,EXPR> to a command
98019930that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and
98029931L<perlipc/"Bidirectional Communication with Another Process"> for
98039932alternatives.)
98049933
98059934=end original
98069935
98079936MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして
98089937解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに
98099938パイプされるコマンドとして解釈されます。
981099392 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。
98119940これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
98129941参照してください。
98139942(L<C<open>|/open FILEHANDLE,MODE,EXPR> を入出力 I<両用> にパイプすることは
98149943出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>,
98159944L<perlipc/"Bidirectional Communication with Another Process"> を
98169945参照してください。)
98179946
98189947 open(my $article_fh, "-|", "caesar <$article") # decrypt
98199948 # article
98209949 or die "Can't start caesar: $!";
98219950
98229951 open(my $article_fh, "caesar <$article |") # ditto
98239952 or die "Can't start caesar: $!";
98249953
98259954 open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id
98269955 or die "Can't start sort: $!";
98279956
98289957=begin original
98299958
98309959In the form of pipe opens taking three or more arguments, if LIST is specified
98319960(extra arguments after the command name) then LIST becomes arguments
98329961to the command invoked if the platform supports it. The meaning of
98339962L<C<open>|/open FILEHANDLE,MODE,EXPR> with more than three arguments for
98349963non-pipe modes is not yet defined, but experimental "layers" may give
98359964extra LIST arguments meaning.
98369965
98379966=end original
98389967
98399968パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が
98409969指定されると、プラットフォームが対応していれば、LIST は起動される
98419970コマンドへの引数となります。
98429971パイプモードではない L<C<open>|/open FILEHANDLE,MODE,EXPR> での
98439972三つ以上の引数の意味はまだ未定義ですが、実験的な「層」は
98449973追加の LIST 引数の意味を与えます。
98459974
98469975=begin original
98479976
98489977If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|>
98499978with the one- or two-argument forms of
98509979L<C<open>|/open FILEHANDLE,MODE,EXPR>), an implicit L<C<fork>|/fork> is done,
98519980so L<C<open>|/open FILEHANDLE,MODE,EXPR> returns twice: in the parent process
98529981it returns the pid
98539982of the child process, and in the child process it returns (a defined) C<0>.
98549983Use C<defined($pid)> or C<//> to determine whether the open was successful.
98559984
98569985=end original
98579986
985899871 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR>) で
98599988(C<-|> や C<|-> というふうに) C<-> というコマンドにパイプを開くと、
98609989暗黙の L<C<fork>|/fork> が行なわれるので、
98619990L<C<open>|/open FILEHANDLE,MODE,EXPR> は 2 回返ります;
98629991親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が
98639992返されます。
98649993open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を
98659994使います。
98669995
98679996=begin original
98689997
98699998For example, use either
98709999
987110000=end original
987210001
987310002例えば、以下の二つ
987410003
987510004 my $child_pid = open(my $from_kid, "-|")
987610005 // die "Can't fork: $!";
987710006
987810007=begin original
987910008
988010009or
988110010
988210011=end original
988310012
988410013または
988510014
988610015 my $child_pid = open(my $to_kid, "|-")
988710016 // die "Can't fork: $!";
988810017
988910018=begin original
989010019
989110020followed by
989210021
989310022=end original
989410023
989510024を使って、後で以下のようにします。
989610025
989710026 if ($child_pid) {
989810027 # am the parent:
989910028 # either write $to_kid or else read $from_kid
990010029 ...
990110030 waitpid $child_pid, 0;
990210031 } else {
990310032 # am the child; use STDIN/STDOUT normally
990410033 ...
990510034 exit;
990610035 }
990710036
990810037=begin original
990910038
991010039The filehandle behaves normally for the parent, but I/O to that
991110040filehandle is piped from/to the STDOUT/STDIN of the child process.
991210041In the child process, the filehandle isn't opened--I/O happens from/to
991310042the new STDOUT/STDIN. Typically this is used like the normal
991410043piped open when you want to exercise more control over just how the
991510044pipe command gets executed, such as when running setuid and
991610045you don't want to have to scan shell commands for metacharacters.
991710046
991810047=end original
991910048
992010049親プロセスでは、このファイルハンドルは通常通りに動作しますが、行なわれる
992110050入出力は、子プロセスの STDIN/STDOUT にパイプされます。
992210051子プロセス側では、そのファイルハンドルは開かれず、入出力は新しい STDOUT か
992310052STDIN に対して行なわれます。
992410053これは、setuid で実行して、シェルコマンドのメタ文字を
992510054検索させたくないような場合に、パイプコマンドの起動の仕方を
992610055制御したいとき、普通のパイプの open と同じように使います。
992710056
992810057=begin original
992910058
993010059The following blocks are more or less equivalent:
993110060
993210061=end original
993310062
993410063以下の組み合わせは、だいたい同じものです:
993510064
993610065 open(my $fh, "|tr '[a-z]' '[A-Z]'");
993710066 open(my $fh, "|-", "tr '[a-z]' '[A-Z]'");
993810067 open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]';
993910068 open(my $fh, "|-", "tr", '[a-z]', '[A-Z]');
994010069
994110070 open(my $fh, "cat -n '$file'|");
994210071 open(my $fh, "-|", "cat -n '$file'");
994310072 open(my $fh, "-|") || exec "cat", "-n", $file;
994410073 open(my $fh, "-|", "cat", "-n", $file);
994510074
994610075=begin original
994710076
994810077The last two examples in each block show the pipe as "list form", which
994910078is not yet supported on all platforms. (If your platform has a real
995010079L<C<fork>|/fork>, such as Linux and macOS, you can use the list form; it
995110080also works on Windows with Perl 5.22 or later.) You would want to use
995210081the list form of the pipe so you can pass literal arguments to the
995310082command without risk of the shell interpreting any shell metacharacters
995410083in them. However, this also bars you from opening pipes to commands that
995510084intentionally contain shell metacharacters, such as:
995610085
995710086=end original
995810087
995910088それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、
996010089これはまだ全てのプラットフォームで対応しているわけではなりません。
996110090(もし実行しているプラットフォームで本当の
996210091L<C<fork>|/fork> があれば(Linux や
996310092MacOS X なら)リスト形式が使えます; Perl 5.22 以降では Windows でも
996410093動作します。)
996510094パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、
996610095シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。
996710096しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして
996810097開くことを妨げます:
996910098
997010099 open(my $fh, "|cat -n | expand -4 | lpr")
997110100 || die "Can't open pipeline to lpr: $!";
997210101
997310102=begin original
997410103
997510104See L<perlipc/"Safe Pipe Opens"> for more examples of this.
997610105
997710106=end original
997810107
997910108これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を
998010109参照してください。
998110110
998210111=item Duping filehandles
998310112
998410113(ハンドルの複製)
998510114
998610115=begin original
998710116
998810117You may also, in the Bourne shell tradition, specify an EXPR beginning
998910118with C<< >& >>, in which case the rest of the string is interpreted
999010119as the name of a filehandle (or file descriptor, if numeric) to be
999110120duped (as in L<dup(2)>) and opened. You may use C<&> after C<< > >>,
999210121C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>.
999310122The mode you specify should match the mode of the original filehandle.
999410123(Duping a filehandle does not take into account any existing contents
999510124of IO buffers.) If you use the three-argument
999610125form, then you can pass either a
999710126number, the name of a filehandle, or the normal "reference to a glob".
999810127
999910128=end original
1000010129
1000110130Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >>
1000210131を付けると、EXPR の残りの文字列をファイルハンドル名
1000310132(数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によって)
1000410133複製してオープンします。
1000510134C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>,
1000610135C<< +< >>というモード指定に付けることができます。
1000710136指定するモード指定は、もとのファイルハンドルのモードと
1000810137合っていないといけません。
1000910138(ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。)
10010101393 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、
1001110140通常の「グロブへのリファレンス」を渡します。
1001210141
1001310142=begin original
1001410143
1001510144Here is a script that saves, redirects, and restores C<STDOUT> and
1001610145C<STDERR> using various methods:
1001710146
1001810147=end original
1001910148
1002010149C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します:
1002110150
1002210151 #!/usr/bin/perl
1002310152 open(my $oldout, ">&STDOUT")
1002410153 or die "Can't dup STDOUT: $!";
1002510154 open(OLDERR, ">&", \*STDERR)
1002610155 or die "Can't dup STDERR: $!";
1002710156
1002810157 open(STDOUT, '>', "foo.out")
1002910158 or die "Can't redirect STDOUT: $!";
1003010159 open(STDERR, ">&STDOUT")
1003110160 or die "Can't dup STDOUT: $!";
1003210161
1003310162 select STDERR; $| = 1; # make unbuffered
1003410163 select STDOUT; $| = 1; # make unbuffered
1003510164
1003610165 print STDOUT "stdout 1\n"; # this works for
1003710166 print STDERR "stderr 1\n"; # subprocesses too
1003810167
1003910168 open(STDOUT, ">&", $oldout)
1004010169 or die "Can't dup \$oldout: $!";
1004110170 open(STDERR, ">&OLDERR")
1004210171 or die "Can't dup OLDERR: $!";
1004310172
1004410173 print STDOUT "stdout 2\n";
1004510174 print STDERR "stderr 2\n";
1004610175
1004710176=begin original
1004810177
1004910178If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
1005010179or a filehandle, then Perl will do an equivalent of C's L<fdopen(3)> of
1005110180that file descriptor (and not call L<dup(2)>); this is more
1005210181parsimonious of file descriptors. For example:
1005310182
1005410183=end original
1005510184
1005610185C<X> をファイル記述子の番号かファイルハンドルとして、
1005710186C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する
1005810187C の L<fdopen(3)> と同じことを行ないます(そして L<dup(2)> は呼び出しません);
1005910188これはファイル記述子をより節約します。
1006010189例えば:
1006110190
1006210191 # open for input, reusing the fileno of $fd
1006310192 open(my $fh, "<&=", $fd)
1006410193
1006510194=begin original
1006610195
1006710196or
1006810197
1006910198=end original
1007010199
1007110200または
1007210201
1007310202 open(my $fh, "<&=$fd")
1007410203
1007510204=begin original
1007610205
1007710206or
1007810207
1007910208=end original
1008010209
1008110210または
1008210211
1008310212 # open for append, using the fileno of $oldfh
1008410213 open(my $fh, ">>&=", $oldfh)
1008510214
1008610215=begin original
1008710216
1008810217Being parsimonious on filehandles is also useful (besides being
1008910218parsimonious) for example when something is dependent on file
1009010219descriptors, like for example locking using
1009110220L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just
1009210221C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the
1009310222same file descriptor as C<$B>, and therefore C<flock($A)> will not
1009410223C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>,
1009510224the filehandles will share the same underlying system file descriptor.
1009610225
1009710226=end original
1009810227
1009910228ファイルハンドルを倹約することは、(倹約できること以外に)何かが
1010010229ファイル記述子に依存している場合、例えば
1010110230L<C<flock>|/flock FILEHANDLE,OPERATION> を使った
1010210231ファイルロックといった場合に有用です。
1010310232C<< open(my $A, ">>&", $B) >> とすると、ファイルハンドル C<$A> は C<$B> と同じ
1010410233ファイル記述子にはならないので、C<flock($A)> と C<flock($B)> は別々になります。
1010510234しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの
1010610235同じファイル記述子を共有します。
1010710236
1010810237=begin original
1010910238
1011010239Note that under Perls older than 5.8.0, Perl uses the standard C library's'
1011110240L<fdopen(3)> to implement the C<=> functionality. On many Unix systems,
1011210241L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255.
1011310242For Perls 5.8.0 and later, PerlIO is (most often) the default.
1011410243
1011510244=end original
1011610245
10117102465.8.0 より前の Perl の場合、C<=> 機能の実装は
1011810247標準 C ライブラリの L<fdopen(3)> を使っています。
1011910248多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値
1012010249(典型的には 255)を超えた場合に失敗することが知られています。
101215.8.0 以降の Perl では、(ほとんどの場合) PerlIO がデフォルトです。
102505.8.0 以降の Perl では、(ほぼ確実に) PerlIO がデフォルトです。
1012210251
1012310252=item Legacy usage
1012410253
1012510254(古い使い方)
1012610255
1012710256=begin original
1012810257
1012910258This section describes ways to call C<open> outside of best practices;
1013010259you may encounter these uses in older code. Perl does not consider their
1013110260use deprecated, exactly, but neither is it recommended in new code, for
1013210261the sake of clarity and readability.
1013310262
1013410263=end original
1013510264
1013610265この節では、ベストプラクティスではない C<open> の呼び出し方について
1013710266記述します; より古いコードでこれらが使われているのに遭遇するかもしれません。
1013810267厳密には、Perl はこれらの仕様を廃止予定にはしていませんが、
1013910268明瞭性と可読性のために、新しいコードには薦めません。
1014010269
1014110270=over
1014210271
1014310272=item Specifying mode and filename as a single argument
1014410273
1014510274(モードとファイル名を一つの引数で指定する)
1014610275
1014710276=begin original
1014810277
1014910278In the one- and two-argument forms of the call, the mode and filename
1015010279should be concatenated (in that order), preferably separated by white
1015110280space. You can--but shouldn't--omit the mode in these forms when that mode
1015210281is C<< < >>. It is safe to use the two-argument form of
1015310282L<C<open>|/open FILEHANDLE,MODE,EXPR> if the filename argument is a known literal.
1015410283
1015510284=end original
1015610285
10157102861 引数 と 2 引数の形式ではモードとファイル名は(この順番で)
1015810287結合されます(空白によって分割されているかもしれません)。
1015910288この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、
1016010289するべきではありません)。
1016110290ファイル引数が既知のリテラルの場合、2 引数形式の
1016210291L<C<open>|/open FILEHANDLE,MODE,EXPR> は安全です。
1016310292
1016410293 open(my $dbase, "+<dbase.mine") # ditto
1016510294 or die "Can't open 'dbase.mine' for update: $!";
1016610295
1016710296=begin original
1016810297
1016910298In the two-argument (and one-argument) form, opening C<< <- >>
1017010299or C<-> opens STDIN and opening C<< >- >> opens STDOUT.
1017110300
1017210301=end original
1017310302
10174103032 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が
1017510304オープンされ、C<< >- >> を open すると STDOUT がオープンされます。
1017610305
1017710306=begin original
1017810307
1017910308New code should favor the three-argument form of C<open> over this older
1018010309form. Declaring the mode and the filename as two distinct arguments
1018110310avoids any confusion between the two.
1018210311
1018310312=end original
1018410313
1018510314新しいコードでは、このより古い形式ではなく、3 引数形式の C<open> を
1018610315使うべきです。
1018710316モードとファイル名を異なった二つの引数として指定することで、
1018810317二つの間の混乱を避けられます。
1018910318
1019010319=item Calling C<open> with one argument via global variables
1019110320
1019210321(グローバル変数を使って C<open> を 1 引数で呼び出す)
1019310322
1019410323=begin original
1019510324
1019610325As a shortcut, a one-argument call takes the filename from the global
1019710326scalar variable of the same name as the filehandle:
1019810327
1019910328=end original
1020010329
1020110330短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前の
1020210331グローバルなスカラ変数から取ります:
1020310332
1020410333 $ARTICLE = 100;
1020510334 open(ARTICLE)
1020610335 or die "Can't find article $ARTICLE: $!\n";
1020710336
1020810337=begin original
1020910338
1021010339Here C<$ARTICLE> must be a global (package) scalar variable - not one
1021110340declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>.
1021210341
1021310342=end original
1021410343
1021510344ここで C<$ARTICLE> はグローバル(パッケージ)スカラ変数でなければなりません -
1021610345L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言された
1021710346変数ではありません。
1021810347
1021910348=item Assigning a filehandle to a bareword
1022010349
1022110350(ファイルハンドルを裸の単語に代入する)
1022210351
1022310352=begin original
1022410353
1022510354An older style is to use a bareword as the filehandle, as
1022610355
1022710356=end original
1022810357
1022910358より古いスタイルは、次のように、ファイルハンドルとして裸の単語を使います
1023010359
1023110360 open(FH, "<", "input.txt")
1023210361 or die "Can't open < input.txt: $!";
1023310362
1023410363=begin original
1023510364
1023610365Then you can use C<FH> as the filehandle, in C<< close FH >> and C<<
1023710366<FH> >> and so on. Note that it's a global variable, so this form is
10238not recommended when dealing with filehandles other than Perl's built-in ones (e.g. STDOUT and STDIN).
10367not recommended when dealing with filehandles other than Perl's built-in ones
10368(e.g. STDOUT and STDIN). In fact, using a bareword for the filehandle is
10369an error when the C<bareword_filehandles> feature has been disabled. This
10370feature is disabled by default when in the scope of C<use v5.36.0> or later.
1023910371
1024010372=end original
1024110373
1024210374それから C<FH> を、C<< close FH >> や C<< <FH> >> などのように、
1024310375ファイルハンドルとして使えます。
1024410376これはグローバル変数なので、Perl の組み込みのもの (例えば STDOUT と STDIN)
1024510377以外では非推奨であることに注意してください。
10378実際、C<bareword_filehandles> 機能が無効になっている場合は
10379ファイルハンドルに裸の単語を使うことはエラーです。
10380この機能は、C<use v5.36.0> 以降のスコープ内ではデフォルトでは
10381無効になっています。
1024610382
1024710383=back
1024810384
1024910385=item Other considerations
1025010386
1025110387(その他の考慮点)
1025210388
1025310389=over
1025410390
1025510391=item Automatic filehandle closure
1025610392
1025710393(自動的にファイルハンドルを閉じる)
1025810394
1025910395=begin original
1026010396
1026110397The filehandle will be closed when its reference count reaches zero. If
1026210398it is a lexically scoped variable declared with L<C<my>|/my VARLIST>,
1026310399that usually means the end of the enclosing scope. However, this
1026410400automatic close does not check for errors, so it is better to explicitly
1026510401close filehandles, especially those used for writing:
1026610402
1026710403=end original
1026810404
1026910405ファイルハンドルは、参照カウントが 0 になったときに閉じられます。
1027010406これが L<C<my>|/my VARLIST> で宣言されたレキシカルスコープを持つ変数の場合、
1027110407普通は囲まれたスコープの終わりを意味します。
1027210408しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、
1027310409明示的にファイルハンドルを閉じる方がよいです。
1027410410
1027510411 close($handle)
1027610412 || warn "close failed: $!";
1027710413
1027810414=item Automatic pipe flushing
1027910415
1028010416(パイプの自動フラッシュ)
1028110417
1028210418=begin original
1028310419
1028410420Perl will attempt to flush all files opened for
1028510421output before any operation that may do a fork, but this may not be
1028610422supported on some platforms (see L<perlport>). To be safe, you may need
1028710423to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
1028810424or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
1028910425on any open handles.
1029010426
1029110427=end original
1029210428
10293v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
10429Perl は書き込み用に開いている全てのファイルに対して
1029410430fork を行う前にフラッシュしようとしますが、これに対応していない
1029510431プラットフォームもあります(L<perlport> を参照してください)。
1029610432安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
1029710433C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
1029810434L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
1029910435呼び出す必要があるかもしれません。
1030010436
1030110437=begin original
1030210438
1030310439On systems that support a close-on-exec flag on files, the flag will
1030410440be set for the newly opened file descriptor as determined by the value
1030510441of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1030610442
1030710443=end original
1030810444
1030910445ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1031010446フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
1031110447ファイル記述子に対してセットされます。
1031210448L<perlvar/$^F> を参照してください。
1031310449
1031410450=begin original
1031510451
1031610452Closing any piped filehandle causes the parent process to wait for the
1031710453child to finish, then returns the status value in L<C<$?>|perlvar/$?> and
1031810454L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
1031910455
1032010456=end original
1032110457
1032210458パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を
1032310459待ち、それから L<C<$?>|perlvar/$?> と
1032410460L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> にステータス値を
1032510461返します。
1032610462
1032710463=item Direct versus by-reference assignment of filehandles
1032810464
1032910465(ファイルハンドルの直接代入とリファレンスによる代入)
1033010466
1033110467=begin original
1033210468
1033310469If FILEHANDLE -- the first argument in a call to C<open> -- is an
1033410470undefined scalar variable (or array or hash element), a new filehandle
1033510471is autovivified, meaning that the variable is assigned a reference to a
1033610472newly allocated anonymous filehandle. Otherwise if FILEHANDLE is an
1033710473expression, its value is the real filehandle. (This is considered a
1033810474symbolic reference, so C<use strict "refs"> should I<not> be in effect.)
1033910475
1034010476=end original
1034110477
1034210478FILEHANDLE (C<open> を呼び出すときの最初の引数) が未定義のスカラ変数
1034310479(または配列かハッシュの要素)の場合、
1034410480新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた
1034510481無名ファイルハンドルへのリファレンスが代入されます。
1034610482さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の
1034710483ファイルハンドルの名前として使います。
1034810484(これはシンボリックリファレンスとして扱われるので、
1034910485C<use strict "refs"> の影響を I<受けません>。)
1035010486
1035110487=item Whitespace and special characters in the filename argument
1035210488
1035310489(ファイル名引数の空白と特殊文字)
1035410490
1035510491=begin original
1035610492
1035710493The filename passed to the one- and two-argument forms of
1035810494L<C<open>|/open FILEHANDLE,MODE,EXPR> will
1035910495have leading and trailing whitespace deleted and normal
1036010496redirection characters honored. This property, known as "magic open",
1036110497can often be used to good effect. A user could specify a filename of
1036210498F<"rsh cat file |">, or you could change certain filenames as needed:
1036310499
1036410500=end original
1036510501
10366105021 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR> に渡された
1036710503ファイル名は、はじめと終わりの空白が取り除かれ、通常のリダイレクト文字列を
1036810504受け付けます。
1036910505この機能は "magic open" として知られていますが、普通いい効果をもたらします。
1037010506ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、
1037110507特定のファイル名を必要に応じて変更できます。
1037210508
1037310509 $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
1037410510 open(my $fh, $filename)
1037510511 or die "Can't open $filename: $!";
1037610512
1037710513=begin original
1037810514
1037910515Use the three-argument form to open a file with arbitrary weird characters in it,
1038010516
1038110517=end original
1038210518
1038310519妙な文字が含まれているようなファイル名をオープンするには、
10384105203 引数の形を使います。
1038510521
1038610522 open(my $fh, "<", $file)
1038710523 || die "Can't open $file: $!";
1038810524
1038910525=begin original
1039010526
1039110527otherwise it's necessary to protect any leading and trailing whitespace:
1039210528
1039310529=end original
1039410530
1039510531あるいは、次のようにして、最初と最後の空白を保護します:
1039610532
1039710533 $file =~ s#^(\s)#./$1#;
1039810534 open(my $fh, "< $file\0")
1039910535 || die "Can't open $file: $!";
1040010536
1040110537=begin original
1040210538
1040310539(this may not work on some bizarre filesystems). One should
1040410540conscientiously choose between the I<magic> and I<three-argument> form
1040510541of L<C<open>|/open FILEHANDLE,MODE,EXPR>:
1040610542
1040710543=end original
1040810544
1040910545(これは奇妙なファイルシステムでは動作しないかもしれません)。
1041010546L<C<open>|/open FILEHANDLE,MODE,EXPR> の I<magic> と I<3 引数> 形式を誠実に
1041110547選択するべきです。
1041210548
1041310549 open(my $in, $ARGV[0]) || die "Can't open $ARGV[0]: $!";
1041410550
1041510551=begin original
1041610552
1041710553will allow the user to specify an argument of the form C<"rsh cat file |">,
1041810554but will not work on a filename that happens to have a trailing space, while
1041910555
1042010556=end original
1042110557
1042210558とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、
1042310559末尾にスペースがついてしまったファイル名では動作しません; 一方:
1042410560
1042510561 open(my $in, "<", $ARGV[0])
1042610562 || die "Can't open $ARGV[0]: $!";
1042710563
1042810564=begin original
1042910565
1043010566will have exactly the opposite restrictions. (However, some shells
1043110567support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which
1043210568produces a filename that can be opened normally.)
1043310569
1043410570=end original
1043510571
1043610572はまったく逆の制限があります。
1043710573(しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という
1043810574文法に対応していて、普通に開くことが出来るファイル名を出力します。)
1043910575
1044010576=item Invoking C-style C<open>
1044110577
1044210578(C 形式の C<open> の起動)
1044310579
1044410580=begin original
1044510581
1044610582If you want a "real" C L<open(2)>, then you should use the
1044710583L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> function, which involves
1044810584no such magic (but uses different filemodes than Perl
1044910585L<C<open>|/open FILEHANDLE,MODE,EXPR>, which corresponds to C L<fopen(3)>).
1045010586This is another way to protect your filenames from interpretation. For
1045110587example:
1045210588
1045310589=end original
1045410590
1045510591もし「本当の」C 言語の L<open(2)> が必要なら、このような副作用のない
1045610592L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> 関数を使うべきです
1045710593(ただし、C の L<fopen(3)> に対応する Perl の
1045810594L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違うファイルモードを持ちます)。
1045910595これはファイル名を解釈から守るもう一つの方法です。
1046010596例えば:
1046110597
1046210598 use IO::Handle;
1046310599 sysopen(my $fh, $path, O_RDWR|O_CREAT|O_EXCL)
1046410600 or die "Can't open $path: $!";
1046510601 $fh->autoflush(1);
1046610602 print $fh "stuff $$\n";
1046710603 seek($fh, 0, 0);
1046810604 print "File contains: ", readline($fh);
1046910605
1047010606=begin original
1047110607
1047210608See L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> for some details about
1047310609mixing reading and writing.
1047410610
1047510611=end original
1047610612
1047710613読み書きを混ぜる場合の詳細については
1047810614L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> を参照してください。
1047910615
1048010616=item Portability issues
1048110617
1048210618(移植性の問題)
1048310619
1048410620=begin original
1048510621
1048610622See L<perlport/open>.
1048710623
1048810624=end original
1048910625
1049010626L<perlport/open> を参照してください。
1049110627
1049210628=back
1049310629
1049410630=back
1049510631
1049610632=item opendir DIRHANDLE,EXPR
1049710633X<opendir>
1049810634
1049910635=for Pod::Functions open a directory
1050010636
1050110637=begin original
1050210638
1050310639Opens a directory named EXPR for processing by
1050410640L<C<readdir>|/readdir DIRHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
1050510641L<C<seekdir>|/seekdir DIRHANDLE,POS>,
1050610642L<C<rewinddir>|/rewinddir DIRHANDLE>, and
1050710643L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful.
1050810644DIRHANDLE may be an expression whose value can be used as an indirect
1050910645dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined
1051010646scalar variable (or array or hash element), the variable is assigned a
1051110647reference to a new anonymous dirhandle; that is, it's autovivified.
1051210648Dirhandles are the same objects as filehandles; an I/O object can only
1051310649be open as one of these handle types at once.
1051410650
1051510651=end original
1051610652
1051710653L<C<readdir>|/readdir DIRHANDLE>、L<C<telldir>|/telldir DIRHANDLE>、
1051810654L<C<seekdir>|/seekdir DIRHANDLE,POS>、L<C<rewinddir>|/rewinddir DIRHANDLE>、
1051910655L<C<closedir>|/closedir DIRHANDLE> で処理するために、EXPR で指定された名前の
1052010656ディレクトリをオープンします。
1052110657成功時には真を返します。
1052210658DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ
1052310659ハンドルの名前)となる式でも構いません。
1052410660DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は
1052510661新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、
1052610662自動有効化されます。
1052710663ディレクトリハンドルはファイルハンドルと同じオブジェクトです;
1052810664一つの I/O オブジェクトは同時にこれらのハンドル型のどちらかとしてのみ
1052910665開くことができます。
1053010666
1053110667=begin original
1053210668
1053310669See the example at L<C<readdir>|/readdir DIRHANDLE>.
1053410670
1053510671=end original
1053610672
1053710673L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。
1053810674
1053910675=item ord EXPR
1054010676X<ord> X<encoding>
1054110677
1054210678=item ord
1054310679
1054410680=for Pod::Functions find a character's numeric representation
1054510681
1054610682=begin original
1054710683
1054810684Returns the numeric value of the first character of EXPR.
1054910685If EXPR is an empty string, returns 0. If EXPR is omitted, uses
1055010686L<C<$_>|perlvar/$_>.
1055110687(Note I<character>, not byte.)
1055210688
1055310689=end original
1055410690
1055510691EXPR の最初の文字の数値としての値を返します。
1055610692EXPR が空文字列の場合は、0 を返します。
1055710693EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1055810694(バイトではなく I<文字> であることに注意してください。)
1055910695
1056010696=begin original
1056110697
1056210698For the reverse, see L<C<chr>|/chr NUMBER>.
1056310699See L<perlunicode> for more about Unicode.
1056410700
1056510701=end original
1056610702
1056710703逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。
1056810704Unicode については L<perlunicode> を参照してください。
1056910705
1057010706=item our VARLIST
1057110707X<our> X<global>
1057210708
1057310709=item our TYPE VARLIST
1057410710
1057510711=item our VARLIST : ATTRS
1057610712
1057710713=item our TYPE VARLIST : ATTRS
1057810714
1057910715=for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping)
1058010716
1058110717=begin original
1058210718
1058310719L<C<our>|/our VARLIST> makes a lexical alias to a package (i.e. global)
1058410720variable of the same name in the current package for use within the
1058510721current lexical scope.
1058610722
1058710723=end original
1058810724
1058910725L<C<our>|/our VARLIST> は単純名を、現在のレキシカルスコープ内で使うために、
1059010726現在のパッケージの同じ名前のパッケージ(つまりグローバルな)変数への
1059110727レキシカルな別名を作ります。
1059210728
1059310729=begin original
1059410730
1059510731L<C<our>|/our VARLIST> has the same scoping rules as
1059610732L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is
1059710733only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and
1059810734L<C<state>|/state VARLIST>, which both declare new (lexical) variables,
1059910735L<C<our>|/our VARLIST> only creates an alias to an existing variable: a
1060010736package variable of the same name.
1060110737
1060210738=end original
1060310739
1060410740L<C<our>|/our VARLIST> は L<C<my>|/my VARLIST> や
1060510741L<C<state>|/state VARLIST> と同じスコープルールを持ちます; つまり
1060610742レキシカルスコープの中でだけ有効です。
1060710743新しい(レキシカル)変数を宣言する L<C<my>|/my VARLIST> や
1060810744L<C<state>|/state VARLIST> と異なり、L<C<our>|/our VARLIST> は既に
1060910745存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です。
1061010746
1061110747=begin original
1061210748
1061310749This means that when C<use strict 'vars'> is in effect, L<C<our>|/our
1061410750VARLIST> lets you use a package variable without qualifying it with the
1061510751package name, but only within the lexical scope of the
1061610752L<C<our>|/our VARLIST> declaration. This applies immediately--even
1061710753within the same statement.
1061810754
1061910755=end original
1062010756
1062110757つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST> を
1062210758使うことで、
1062310759パッケージ変数をパッケージ名で修飾することなく使うことができますが、
1062410760L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。
1062510761これは(たとえ同じ文の中でも)直ちに適用されます。
1062610762
1062710763 package Foo;
10628 use strict;
10764 use v5.36; # which implies "use strict;"
1062910765
1063010766 $Foo::foo = 23;
1063110767
1063210768 {
1063310769 our $foo; # alias to $Foo::foo
1063410770 print $foo; # prints 23
1063510771 }
1063610772
1063710773 print $Foo::foo; # prints 23
1063810774
1063910775 print $foo; # ERROR: requires explicit package name
1064010776
1064110777=begin original
1064210778
1064310779This works even if the package variable has not been used before, as
1064410780package variables spring into existence when first used.
1064510781
1064610782=end original
1064710783
1064810784これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、
1064910785最初に使われた時にひょっこり現れるからです。
1065010786
1065110787 package Foo;
10652 use strict;
10788 use v5.36;
1065310789
1065410790 our $foo = 23; # just like $Foo::foo = 23
1065510791
1065610792 print $Foo::foo; # prints 23
1065710793
1065810794=begin original
1065910795
1066010796Because the variable becomes legal immediately under C<use strict 'vars'>, so
1066110797long as there is no variable with that name is already in scope, you can then
1066210798reference the package variable again even within the same statement.
1066310799
1066410800=end original
1066510801
1066610802変数は C<use strict 'vars'> の基で直ちに正当になるので、
1066710803スコープ内に同じ名前の変数がない限り、
1066810804たとえ同じ文の中でもパッケージ変数を再び参照できます。
1066910805
1067010806 package Foo;
10671 use strict;
10807 use v5.36;
1067210808
1067310809 my $foo = $foo; # error, undeclared $foo on right-hand side
1067410810 our $foo = $foo; # no errors
1067510811
1067610812=begin original
1067710813
1067810814If more than one variable is listed, the list must be placed
1067910815in parentheses.
1068010816
1068110817=end original
1068210818
10683複数の変数を指定する場合は、リストはかっこでくくらなければなりません。
10819複数の変数を指定する場合は、リストはかっこで囲まなければなりません。
1068410820
1068510821 our($bar, $baz);
1068610822
1068710823=begin original
1068810824
1068910825An L<C<our>|/our VARLIST> declaration declares an alias for a package
1069010826variable that will be visible
1069110827across its entire lexical scope, even across package boundaries. The
1069210828package in which the variable is entered is determined at the point
1069310829of the declaration, not at the point of use. This means the following
1069410830behavior holds:
1069510831
1069610832=end original
1069710833
1069810834L<C<our>|/our VARLIST> 宣言はレキシカルスコープ全体に対して (たとえ
1069910835パッケージ境界を越えていても)見える、パッケージ変数への別名を宣言します。
1070010836この変数が入るパッケージは宣言した時点で定義され、
1070110837使用した時点ではありません。
1070210838これにより、以下のような振る舞いになります:
1070310839
1070410840 package Foo;
1070510841 our $bar; # declares $Foo::bar for rest of lexical scope
1070610842 $bar = 20;
1070710843
1070810844 package Bar;
1070910845 print $bar; # prints 20, as it refers to $Foo::bar
1071010846
1071110847=begin original
1071210848
1071310849Multiple L<C<our>|/our VARLIST> declarations with the same name in the
1071410850same lexical
1071510851scope are allowed if they are in different packages. If they happen
1071610852to be in the same package, Perl will emit warnings if you have asked
1071710853for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike
1071810854a second L<C<my>|/my VARLIST> declaration, which will bind the name to a
1071910855fresh variable, a second L<C<our>|/our VARLIST> declaration in the same
1072010856package, in the same scope, is merely redundant.
1072110857
1072210858=end original
1072310859
1072410860同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の
1072510861L<C<our>|/our VARLIST> 宣言ができます。
1072610862同じパッケージになっていると、警告が出力されるようになっていれば
1072710863複数の L<C<my>|/my VARLIST> 宣言がある場合と同じように警告が出力されます。
1072810864新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と
1072910865違って、同じパッケージの同じスコープで 2 回
1073010866L<C<our>|/our VARLIST> 宣言するのは単に冗長です。
1073110867
1073210868 use warnings;
1073310869 package Foo;
1073410870 our $bar; # declares $Foo::bar for rest of lexical scope
1073510871 $bar = 20;
1073610872
1073710873 package Bar;
1073810874 our $bar = 30; # declares $Bar::bar for rest of lexical scope
1073910875 print $bar; # prints 30
1074010876
1074110877 our $bar; # emits warning but has no other effect
1074210878 print $bar; # still prints 30
1074310879
1074410880=begin original
1074510881
1074610882An L<C<our>|/our VARLIST> declaration may also have a list of attributes
1074710883associated with it.
1074810884
1074910885=end original
1075010886
1075110887L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを
1075210888持つこともあります。
1075310889
1075410890=begin original
1075510891
1075610892The exact semantics and interface of TYPE and ATTRS are still
1075710893evolving. TYPE is currently bound to the use of the L<fields> pragma,
1075810894and attributes are handled using the L<attributes> pragma, or, starting
1075910895from Perl 5.8.0, also via the L<Attribute::Handlers> module. See
1076010896L<perlsub/"Private Variables via my()"> for details.
1076110897
1076210898=end original
1076310899
1076410900TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
1076510901現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
1076610902属性は L<attributes> プラグマか、Perl 5.8.0 からは
1076710903L<Attribute::Handlers> モジュールと結び付けられています。
1076810904詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
1076910905
1077010906=begin original
1077110907
1077210908Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
1077310909as a dummy placeholder, for example to skip assignment of initial
1077410910values:
1077510911
1077610912=end original
1077710913
1077810914かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
1077910915飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
1078010916
1078110917 our ( undef, $min, $hour ) = localtime;
1078210918
1078310919=begin original
1078410920
1078510921L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows
1078610922use of an unqualified name I<only> within the affected package, but
1078710923across scopes.
1078810924
1078910925=end original
1079010926
1079110927L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを
1079210928またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない
1079310929名前を使えるようにします。
1079410930
1079510931=item pack TEMPLATE,LIST
1079610932X<pack>
1079710933
1079810934=for Pod::Functions convert a list into a binary representation
1079910935
1080010936=begin original
1080110937
1080210938Takes a LIST of values and converts it into a string using the rules
1080310939given by the TEMPLATE. The resulting string is the concatenation of
1080410940the converted values. Typically, each converted value looks
1080510941like its machine-level representation. For example, on 32-bit machines
1080610942an integer may be represented by a sequence of 4 bytes, which will in
1080710943Perl be presented as a string that's 4 characters long.
1080810944
1080910945=end original
1081010946
1081110947LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。
1081210948結果の文字列は変換した値を連結したものです。
1081310949典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。
1081410950例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、
1081510951Perl では 4 文字の文字列で表現されます。
1081610952
1081710953=begin original
1081810954
1081910955See L<perlpacktut> for an introduction to this function.
1082010956
1082110957=end original
1082210958
1082310959この関数の説明については L<perlpacktut> を参照してください。
1082410960
1082510961=begin original
1082610962
1082710963The TEMPLATE is a sequence of characters that give the order and type
1082810964of values, as follows:
1082910965
1083010966=end original
1083110967
1083210968TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです:
1083310969
1083410970=begin original
1083510971
1083610972 a A string with arbitrary binary data, will be null padded.
1083710973 A A text (ASCII) string, will be space padded.
1083810974 Z A null-terminated (ASCIZ) string, will be null padded.
1083910975
1084010976=end original
1084110977
1084210978 a 任意のバイナリデータを含む文字列、ヌル文字で埋める。
1084310979 A テキスト (ASCII) 文字列、スペース文字で埋める。
1084410980 Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。
1084510981
1084610982=begin original
1084710983
1084810984 b A bit string (ascending bit order inside each byte,
1084910985 like vec()).
1085010986 B A bit string (descending bit order inside each byte).
1085110987 h A hex string (low nybble first).
1085210988 H A hex string (high nybble first).
1085310989
1085410990=end original
1085510991
1085610992 b ビット列 (バイトごとに昇ビット順、vec() と同じ)。
1085710993 B ビット列 (バイトごとに降ビット順)。
1085810994 h 16 進数文字列 (低位ニブルが先)。
1085910995 H 16 進数文字列 (高位ニブルが先)。
1086010996
1086110997=begin original
1086210998
1086310999 c A signed char (8-bit) value.
1086411000 C An unsigned char (octet) value.
1086511001 W An unsigned char value (can be greater than 255).
1086611002
1086711003=end original
1086811004
1086911005 c signed char (8 ビット) 値。
1087011006 C unsigned char (オクテット) 値。
1087111007 W unsigned char 値 (255 より大きいかもしれません)。
1087211008
1087311009=begin original
1087411010
1087511011 s A signed short (16-bit) value.
1087611012 S An unsigned short value.
1087711013
1087811014=end original
1087911015
1088011016 s signed short (16 ビット) 値。
1088111017 S unsigned short 値。
1088211018
1088311019=begin original
1088411020
1088511021 l A signed long (32-bit) value.
1088611022 L An unsigned long value.
1088711023
1088811024=end original
1088911025
1089011026 l signed long (32 ビット) 値。
1089111027 L unsigned long 値。
1089211028
1089311029=begin original
1089411030
1089511031 q A signed quad (64-bit) value.
1089611032 Q An unsigned quad value.
1089711033 (Quads are available only if your system supports 64-bit
1089811034 integer values _and_ if Perl has been compiled to support
1089911035 those. Raises an exception otherwise.)
1090011036
1090111037=end original
1090211038
1090311039 q 符号付き 64 ビット整数。
1090411040 Q 符号なし 64 ビット整数。
1090511041 (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が
1090611042 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。
1090711043 それ以外の場合は例外が発生します。)
1090811044
1090911045=begin original
1091011046
1091111047 i A signed integer value.
1091211048 I An unsigned integer value.
1091311049 (This 'integer' is _at_least_ 32 bits wide. Its exact
1091411050 size depends on what a local C compiler calls 'int'.)
1091511051
1091611052=end original
1091711053
1091811054 i signed int 値。
1091911055 I unsigned int 値。
1092011056 (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは
1092111057 ローカルの C コンパイラの 'int' のサイズに依存します。)
1092211058
1092311059=begin original
1092411060
1092511061 n An unsigned short (16-bit) in "network" (big-endian) order.
1092611062 N An unsigned long (32-bit) in "network" (big-endian) order.
1092711063 v An unsigned short (16-bit) in "VAX" (little-endian) order.
1092811064 V An unsigned long (32-bit) in "VAX" (little-endian) order.
1092911065
1093011066=end original
1093111067
1093211068 n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。
1093311069 N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。
1093411070 v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。
1093511071 V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。
1093611072
1093711073=begin original
1093811074
1093911075 j A Perl internal signed integer value (IV).
1094011076 J A Perl internal unsigned integer value (UV).
1094111077
1094211078=end original
1094311079
1094411080 j Perl 内部符号付き整数 (IV)。
1094511081 J Perl 内部符号なし整数 (UV)。
1094611082
1094711083=begin original
1094811084
1094911085 f A single-precision float in native format.
1095011086 d A double-precision float in native format.
1095111087
1095211088=end original
1095311089
1095411090 f 機種依存の単精度浮動小数点数。
1095511091 d 機種依存の倍精度浮動小数点数。
1095611092
1095711093=begin original
1095811094
1095911095 F A Perl internal floating-point value (NV) in native format
1096011096 D A float of long-double precision in native format.
1096111097 (Long doubles are available only if your system supports
10962 long double values _and_ if Perl has been compiled to
11098 long double values. Raises an exception otherwise.
10963 support those. Raises an exception otherwise.
1096411099 Note that there are different long double formats.)
1096511100
1096611101=end original
1096711102
1096811103 F ネイティブフォーマットの Perl 内部浮動小数点数 (NV)
1096911104 D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。
10970 (long double は、システムが long double に対応していて、かつ Perl が
11105 (long double は、システムが long double に対応している場合にのみ
10971 long double 対応としてコンパイルされている場合にのみ使用可能です。
11106 使用可能です。それ以外の場合は例外が発生します。
10972 それ以外の場合は例外が発生ます
11107 long double 型式の場合は異なることに注意てください)
10973 long double 型式の場合は異なることに注意してください)
1097411108
1097511109=begin original
1097611110
1097711111 p A pointer to a null-terminated string.
1097811112 P A pointer to a structure (fixed-length string).
1097911113
1098011114=end original
1098111115
1098211116 p ヌル文字で終端する文字列へのポインタ。
1098311117 P 構造体 (固定長文字列) へのポインタ。
1098411118
1098511119=begin original
1098611120
1098711121 u A uuencoded string.
1098811122 U A Unicode character number. Encodes to a character in char-
1098911123 acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in
10990 byte mode.
11124 byte mode. Also on EBCDIC platforms, the character number will
11125 be the native EBCDIC value for character numbers below 256.
11126 This allows most programs using this feature to not have to
11127 care which type of platform they are running on.
1099111128
11129
1099211130=end original
1099311131
1099411132 u uuencode 文字列。
1099511133 U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に
1099611134 (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。
11135 また EBCDIC プラットフォームでは、文字番号が 256 より下の場合は
11136 EBCDIC にネイティブな値です。
11137 これにより、この機能を使うほとんどのプログラムで、どの種類の
11138 プラットフォームで実行されるかを気にする必要がなくなります。
1099711139
1099811140=begin original
1099911141
1100011142 w A BER compressed integer (not an ASN.1 BER, see perlpacktut
1100111143 for details). Its bytes represent an unsigned integer in
1100211144 base 128, most significant digit first, with as few digits
1100311145 as possible. Bit eight (the high bit) is set on each byte
1100411146 except the last.
1100511147
1100611148=end original
1100711149
1100811150 w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を
1100911151 参照してください)。このバイト列はできるだけ少ない桁数で表現された
1101011152 128 を基とした符号なし整数で、最上位ビットから順に並びます。
1101111153 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。
1101211154
1101311155=begin original
1101411156
1101511157 x A null byte (a.k.a ASCII NUL, "\000", chr(0))
1101611158 X Back up a byte.
1101711159 @ Null-fill or truncate to absolute position, counted from the
1101811160 start of the innermost ()-group.
1101911161 . Null-fill or truncate to absolute position specified by
1102011162 the value.
1102111163 ( Start of a ()-group.
1102211164
1102311165=end original
1102411166
1102511167 x ヌル文字 (つまり ASCII NUL, "\000", chr(0))
1102611168 X 1 文字後退。
1102711169 @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で
1102811170 埋めるか切り詰める。
1102911171 . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。
1103011172 ( () の組の開始。
1103111173
1103211174=begin original
1103311175
1103411176One or more modifiers below may optionally follow certain letters in the
1103511177TEMPLATE (the second column lists letters for which the modifier is valid):
1103611178
1103711179=end original
1103811180
1103911181以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで
1104011182付けることができます(表の 2 列目は、その修飾子が有効な文字です):
1104111183
1104211184=begin original
1104311185
1104411186 ! sSlLiI Forces native (short, long, int) sizes instead
1104511187 of fixed (16-/32-bit) sizes.
1104611188
1104711189=end original
1104811190
1104911191 ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな
1105011192 (short, long, int)サイズを強制する。
1105111193
1105211194=begin original
1105311195
1105411196 ! xX Make x and X act as alignment commands.
1105511197
1105611198=end original
1105711199
1105811200 ! xX x と X をアライメントコマンドとして振舞わせる。
1105911201
1106011202=begin original
1106111203
1106211204 ! nNvV Treat integers as signed instead of unsigned.
1106311205
1106411206=end original
1106511207
1106611208 ! nNvV 整数を符号なしではなく符号付きとして扱わせる。
1106711209
1106811210=begin original
1106911211
1107011212 ! @. Specify position as byte offset in the internal
1107111213 representation of the packed string. Efficient
1107211214 but dangerous.
1107311215
1107411216=end original
1107511217
1107611218 ! @. pack された内部表現のバイトオフセットとして位置を指定する。
1107711219 効率的ですが危険です。
1107811220
1107911221=begin original
1108011222
1108111223 > sSiIlLqQ Force big-endian byte-order on the type.
1108211224 jJfFdDpP (The "big end" touches the construct.)
1108311225
1108411226=end original
1108511227
1108611228 > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。
1108711229 jJfFdDpP (「大きい端」が構造に触れています。)
1108811230
1108911231=begin original
1109011232
1109111233 < sSiIlLqQ Force little-endian byte-order on the type.
1109211234 jJfFdDpP (The "little end" touches the construct.)
1109311235
1109411236=end original
1109511237
1109611238 < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。
1109711239 jJfFdDpP (「小さい端」が構造に触れています。)
1109811240
1109911241=begin original
1110011242
1110111243The C<< > >> and C<< < >> modifiers can also be used on C<()> groups
1110211244to force a particular byte-order on all components in that group,
1110311245including all its subgroups.
1110411246
1110511247=end original
1110611248
1110711249C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます;
1110811250この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に
1110911251強制します。
1111011252
1111111253=begin comment
1111211254
1111311255Larry recalls that the hex and bit string formats (H, h, B, b) were added to
1111411256pack for processing data from NASA's Magellan probe. Magellan was in an
1111511257elliptical orbit, using the antenna for the radar mapping when close to
1111611258Venus and for communicating data back to Earth for the rest of the orbit.
1111711259There were two transmission units, but one of these failed, and then the
1111811260other developed a fault whereby it would randomly flip the sense of all the
1111911261bits. It was easy to automatically detect complete records with the correct
1112011262sense, and complete records with all the bits flipped. However, this didn't
1112111263recover the records where the sense flipped midway. A colleague of Larry's
1112211264was able to pretty much eyeball where the records flipped, so they wrote an
1112311265editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to
1112411266manually correct the records and recover the data. For this purpose pack
1112511267gained the hex and bit string format specifiers.
1112611268
1112711269git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit
111281127027e2fb84680b9cc1), but the patch description makes no mention of their
1112911271addition, let alone the story behind them.
1113011272
1113111273=end comment
1113211274
1113311275=begin original
1113411276
1113511277The following rules apply:
1113611278
1113711279=end original
1113811280
1113911281以下の条件が適用されます:
1114011282
1114111283=over
1114211284
1114311285=item *
1114411286
1114511287=begin original
1114611288
1114711289Each letter may optionally be followed by a number indicating the repeat
1114811290count. A numeric repeat count may optionally be enclosed in brackets, as
1114911291in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from
1115011292the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>,
1115111293C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means
1115211294something else, described below. Supplying a C<*> for the repeat count
1115311295instead of a number means to use however many items are left, except for:
1115411296
1115511297=end original
1115611298
1115711299これらの文字の後には、繰り返し数を示す数字を付けることができます。
1115811300数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで
1115911301囲むこともできます。
1116011302C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P>
1116111303以外の全ての型では、LIST から繰り返し数の値を取り出して使います。
1116211304繰り返し数に C<*> を指定すると、以下の例外を除いて、
1116311305その時点で残っているすべての要素を意味します。
1116411306
1116511307=over
1116611308
1116711309=item *
1116811310
1116911311=begin original
1117011312
1117111313C<@>, C<x>, and C<X>, where it is equivalent to C<0>.
1117211314
1117311315=end original
1117411316
1117511317C<@>, C<x>, C<X> では C<0> と等価です。
1117611318
1117711319=item *
1117811320
1117911321=begin original
1118011322
1118111323<.>, where it means relative to the start of the string.
1118211324
1118311325=end original
1118411326
1118511327<.> では文字列の先頭からの相対位置を意味します。
1118611328
1118711329=item *
1118811330
1118911331=begin original
1119011332
1119111333C<u>, where it is equivalent to 1 (or 45, which here is equivalent).
1119211334
1119311335=end original
1119411336
1119511337C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。
1119611338
1119711339=back
1119811340
1119911341=begin original
1120011342
1120111343One can replace a numeric repeat count with a template letter enclosed in
1120211344brackets to use the packed byte length of the bracketed template for the
1120311345repeat count.
1120411346
1120511347=end original
1120611348
1120711349このテンプレートでパックされたバイト長を繰り返し数として使うために、
1120811350大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが
1120911351できます。
1121011352
1121111353=begin original
1121211354
1121311355For example, the template C<x[L]> skips as many bytes as in a packed long,
1121411356and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when
1121511357variable-expanded) unpacks. If the template in brackets contains alignment
1121611358commands (such as C<x![d]>), its packed length is calculated as if the
1121711359start of the template had the maximal possible alignment.
1121811360
1121911361=end original
1122011362
1122111363例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、
1122211364テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を
1122311365unpack したものの 2 倍を unpack します。
1122411366(C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、
1122511367パックされた長さは、テンプレートの先頭で最大限可能なアライメントを
1122611368持っているものとして計算されます。
1122711369
1122811370=begin original
1122911371
1123011372When used with C<Z>, a C<*> as the repeat count is guaranteed to add a
1123111373trailing null byte, so the resulting string is always one byte longer than
1123211374the byte length of the item itself.
1123311375
1123411376=end original
1123511377
1123611378C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが
1123711379保証されるので、結果の文字列は常にアイテム自身のバイト長よりも 1 バイト
1123811380長くなります。
1123911381
1124011382=begin original
1124111383
1124211384When used with C<@>, the repeat count represents an offset from the start
1124311385of the innermost C<()> group.
1124411386
1124511387=end original
1124611388
1124711389C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを
1124811390表現します。
1124911391
1125011392=begin original
1125111393
1125211394When used with C<.>, the repeat count determines the starting position to
1125311395calculate the value offset as follows:
1125411396
1125511397=end original
1125611398
1125711399C<.> で使われると、繰り返し数は以下のようにして、
1125811400値のオフセットを計算するための開始位置を決定するために使われます。
1125911401
1126011402=over
1126111403
1126211404=item *
1126311405
1126411406=begin original
1126511407
1126611408If the repeat count is C<0>, it's relative to the current position.
1126711409
1126811410=end original
1126911411
1127011412繰り返し数が C<0> なら、現在位置からの相対位置となります。
1127111413
1127211414=item *
1127311415
1127411416=begin original
1127511417
1127611418If the repeat count is C<*>, the offset is relative to the start of the
1127711419packed string.
1127811420
1127911421=end original
1128011422
1128111423繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの
1128211424相対位置です。
1128311425
1128411426=item *
1128511427
1128611428=begin original
1128711429
1128811430And if it's an integer I<n>, the offset is relative to the start of the
1128911431I<n>th innermost C<( )> group, or to the start of the string if I<n> is
1129011432bigger then the group level.
1129111433
1129211434=end original
1129311435
1129411436そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの
1129511437先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの
1129611438相対位置です。
1129711439
1129811440=back
1129911441
1130011442=begin original
1130111443
1130211444The repeat count for C<u> is interpreted as the maximal number of bytes
1130311445to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
1130411446count should not be more than 65.
1130511447
1130611448=end original
1130711449
1130811450C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを
1130911451示します; 0, 1, 2 は 45 として扱われます。
1131011452繰り返し数は 65 を超えてはなりません。
1131111453
1131211454=item *
1131311455
1131411456=begin original
1131511457
1131611458The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a
1131711459string of length count, padding with nulls or spaces as needed. When
1131811460unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything
1131911461after the first null, and C<a> returns data with no stripping at all.
1132011462
1132111463=end original
1132211464
1132311465C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、
1132411466繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か
1132511467スペース文字を付け足します。
1132611468unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の
1132711469ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく
1132811470そのまま返します。
1132911471
1133011472=begin original
1133111473
1133211474If the value to pack is too long, the result is truncated. If it's too
1133311475long and an explicit count is provided, C<Z> packs only C<$count-1> bytes,
1133411476followed by a null byte. Thus C<Z> always packs a trailing null, except
1133511477when the count is 0.
1133611478
1133711479=end original
1133811480
1133911481pack する値が長すぎる場合、結果は切り詰められます。
1134011482長すぎてかつ明示的に個数が指定されている場合、
1134111483C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。
1134211484従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが
1134311485つきます。
1134411486
1134511487=item *
1134611488
1134711489=begin original
1134811490
1134911491Likewise, the C<b> and C<B> formats pack a string that's that many bits long.
1135011492Each such format generates 1 bit of the result. These are typically followed
1135111493by a repeat count like C<B8> or C<B64>.
1135211494
1135311495=end original
1135411496
1135511497同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。
1135611498これらの各文字は結果の 1 ビットを生成します。
1135711499これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。
1135811500
1135911501=begin original
1136011502
1136111503Each result bit is based on the least-significant bit of the corresponding
1136211504input character, i.e., on C<ord($char)%2>. In particular, characters C<"0">
1136311505and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">.
1136411506
1136511507=end original
1136611508
1136711509結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします
1136811510(つまり C<ord($char)%2>)。
1136911511特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、
1137011512ビット 0 と 1 を生成します。
1137111513
1137211514=begin original
1137311515
1137411516Starting from the beginning of the input string, each 8-tuple
1137511517of characters is converted to 1 character of output. With format C<b>,
1137611518the first character of the 8-tuple determines the least-significant bit of a
1137711519character; with format C<B>, it determines the most-significant bit of
1137811520a character.
1137911521
1138011522=end original
1138111523
1138211524pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。
1138311525C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります;
1138411526C<B> フォーマットでは出力の最上位ビットとなります。
1138511527
1138611528=begin original
1138711529
1138811530If the length of the input string is not evenly divisible by 8, the
1138911531remainder is packed as if the input string were padded by null characters
1139011532at the end. Similarly during unpacking, "extra" bits are ignored.
1139111533
1139211534=end original
1139311535
1139411536もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の
1139511537最後にヌル文字がパッディングされているものとしてパックされます。
1139611538同様に、unpack 中は「余分な」ビットは無視されます。
1139711539
1139811540=begin original
1139911541
1140011542If the input string is longer than needed, remaining characters are ignored.
1140111543
1140211544=end original
1140311545
1140411546入力文字列が必要な分よりも長い場合、余分な文字は無視されます。
1140511547
1140611548=begin original
1140711549
1140811550A C<*> for the repeat count uses all characters of the input field.
1140911551On unpacking, bits are converted to a string of C<0>s and C<1>s.
1141011552
1141111553=end original
1141211554
1141311555繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
1141411556unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。
1141511557
1141611558=item *
1141711559
1141811560=begin original
1141911561
1142011562The C<h> and C<H> formats pack a string that many nybbles (4-bit groups,
1142111563representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long.
1142211564
1142311565=end original
1142411566
1142511567C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で
1142611568表現可能な 4 ビットグループ)のニブル列に pack します。
1142711569
1142811570=begin original
1142911571
1143011572For each such format, L<C<pack>|/pack TEMPLATE,LIST> generates 4 bits of result.
1143111573With non-alphabetical characters, the result is based on the 4 least-significant
1143211574bits of the input character, i.e., on C<ord($char)%16>. In particular,
1143311575characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
1143411576C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result
1143511577is compatible with the usual hexadecimal digits, so that C<"a"> and
1143611578C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex
1143711579characters with this format.
1143811580
1143911581=end original
1144011582
1144111583このようなフォーマット文字のそれぞれについて、L<C<pack>|/pack TEMPLATE,LIST> は
1144211584結果の 4 ビットを生成します。
1144311585英字でない文字の場合、結果は入力文字の下位 4 ビットを
1144411586基にします(つまり C<ord($char)%16>)。
1144511587特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に
1144611588ニブル 0 と 1 を生成します。
1144711589文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に
1144811590なるので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。
1144911591これらの 16 進文字はこの特定のフォーマットでだけ使ってください。
1145011592
1145111593=begin original
1145211594
1145311595Starting from the beginning of the template to
1145411596L<C<pack>|/pack TEMPLATE,LIST>, each pair
1145511597of characters is converted to 1 character of output. With format C<h>, the
1145611598first character of the pair determines the least-significant nybble of the
1145711599output character; with format C<H>, it determines the most-significant
1145811600nybble.
1145911601
1146011602=end original
1146111603
1146211604L<C<pack>|/pack TEMPLATE,LIST> のテンプレートの先頭から始めて、2 文字毎に
11463116051 文字の出力に変換されます。
1146411606C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、
1146511607C<H> フォーマットでは出力の最上位ニブルとなります。
1146611608
1146711609=begin original
1146811610
1146911611If the length of the input string is not even, it behaves as if padded by
1147011612a null character at the end. Similarly, "extra" nybbles are ignored during
1147111613unpacking.
1147211614
1147311615=end original
1147411616
1147511617入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて
1147611618いるかのように振る舞います。
1147711619同様に、unpack 中は「余分な」ニブルは無視されます。
1147811620
1147911621=begin original
1148011622
1148111623If the input string is longer than needed, extra characters are ignored.
1148211624
1148311625=end original
1148411626
1148511627入力文字列が必要な分より長い場合、余分な部分は無視されます。
1148611628
1148711629=begin original
1148811630
1148911631A C<*> for the repeat count uses all characters of the input field. For
1149011632L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of
1149111633hexadecimal digits.
1149211634
1149311635=end original
1149411636
1149511637繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
1149611638L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に
1149711639変換されます。
1149811640
1149911641=item *
1150011642
1150111643=begin original
1150211644
1150311645The C<p> format packs a pointer to a null-terminated string. You are
1150411646responsible for ensuring that the string is not a temporary value, as that
1150511647could potentially get deallocated before you got around to using the packed
1150611648result. The C<P> format packs a pointer to a structure of the size indicated
1150711649by the length. A null pointer is created if the corresponding value for
1150811650C<p> or C<P> is L<C<undef>|/undef EXPR>; similarly with
1150911651L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into
1151011652L<C<undef>|/undef EXPR>.
1151111653
1151211654=end original
1151311655
1151411656C<p> は、ヌル文字終端文字列へのポインタを pack します。
1151511657文字列が一時的な値でない(つまり pack された結果を使う前に文字列が
1151611658解放されない) ことに責任を持つ必要があります。
1151711659C<P> は、指定した長さの構造体へのポインタを pack します。
1151811660C<p> または C<P> に対応する値が L<C<undef>|/undef EXPR> だった場合、
1151911661ヌルポインタが作成されます; ヌルポインタが L<C<undef>|/undef EXPR> に
1152011662unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。
1152111663
1152211664=begin original
1152311665
1152411666If your system has a strange pointer size--meaning a pointer is neither as
1152511667big as an int nor as big as a long--it may not be possible to pack or
1152611668unpack pointers in big- or little-endian byte order. Attempting to do
1152711669so raises an exception.
1152811670
1152911671=end original
1153011672
1153111673システムのポインタが変わったサイズの場合--つまり、int の大きさでも
1153211674long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの
1153311675バイト順で pack や unpack することはできません。
1153411676そうしようとすると例外が発生します。
1153511677
1153611678=item *
1153711679
1153811680=begin original
1153911681
1154011682The C</> template character allows packing and unpacking of a sequence of
1154111683items where the packed structure contains a packed item count followed by
1154211684the packed items themselves. This is useful when the structure you're
1154311685unpacking has encoded the sizes or repeat counts for some of its fields
1154411686within the structure itself as separate fields.
1154511687
1154611688=end original
1154711689
1154811690C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の
1154911691アイテム列を pack 及び unpack します。
1155011692これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に
1155111693独立したフィールドとしてエンコードされている場合に有効です。
1155211694
1155311695=begin original
1155411696
1155511697For L<C<pack>|/pack TEMPLATE,LIST>, you write
1155611698I<length-item>C</>I<sequence-item>, and the
1155711699I<length-item> describes how the length value is packed. Formats likely
1155811700to be of most use are integer-packing ones like C<n> for Java strings,
1155911701C<w> for ASN.1 or SNMP, and C<N> for Sun XDR.
1156011702
1156111703=end original
1156211704
1156311705L<C<pack>|/pack TEMPLATE,LIST> では I<length-item>C</>I<string-item> の
1156411706形になり、
1156511707I<length-item> は長さの値がどのように pack されているかを指定します。
1156611708もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための
1156711709C<w>、Sun XDR のための C<N> といった整数型です。
1156811710
1156911711=begin original
1157011712
1157111713For L<C<pack>|/pack TEMPLATE,LIST>, I<sequence-item> may have a repeat
1157211714count, in which case
1157311715the minimum of that and the number of available items is used as the argument
1157411716for I<length-item>. If it has no repeat count or uses a '*', the number
1157511717of available items is used.
1157611718
1157711719=end original
1157811720
1157911721L<C<pack>|/pack TEMPLATE,LIST> では、I<sequence-item> は繰り返し数を
1158011722持つことがあり、その場合はその最小値と利用可能なアイテムの数は
1158111723I<length-item> のための引数として使われます。
1158211724繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。
1158311725
1158411726=begin original
1158511727
1158611728For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer
1158711729arguments unpacked so far is
1158811730used. You write C</>I<sequence-item> and the repeat count is obtained by
1158911731popping off the last element from the stack. The I<sequence-item> must not
1159011732have a repeat count.
1159111733
1159211734=end original
1159311735
1159411736L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の
1159511737内部スタックが使われます。
1159611738C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を
1159711739取り出すことで得ます。
1159811740I<sequence-item> は繰り返し数を持っていてはいけません。
1159911741
1160011742=begin original
1160111743
1160211744If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">),
1160311745the I<length-item> is the string length, not the number of strings. With
1160411746an explicit repeat count for pack, the packed string is adjusted to that
1160511747length. For example:
1160611748
1160711749=end original
1160811750
1160911751I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、
1161011752I<length-item> は文字列の数ではなく、文字列の長さです。
1161111753pack で明示的な繰り返し数があると、pack された文字列は与えられた
1161211754長さに調整されます。
1161311755例えば:
1161411756
1161511757 This code: gives this result:
1161611758
1161711759 unpack("W/a", "\004Gurusamy") ("Guru")
1161811760 unpack("a3/A A*", "007 Bond J ") (" Bond", "J")
1161911761 unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".")
1162011762
1162111763 pack("n/a* w/a","hello,","world") "\000\006hello,\005world"
1162211764 pack("a/W2", ord("a") .. ord("z")) "2ab"
1162311765
1162411766=begin original
1162511767
1162611768The I<length-item> is not returned explicitly from
1162711769L<C<unpack>|/unpack TEMPLATE,EXPR>.
1162811770
1162911771=end original
1163011772
1163111773I<length-item> は L<C<unpack>|/unpack TEMPLATE,EXPR> から明示的には
1163211774返されません。
1163311775
1163411776=begin original
1163511777
1163611778Supplying a count to the I<length-item> format letter is only useful with
1163711779C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may
1163811780introduce C<"\000"> characters, which Perl does not regard as legal in
1163911781numeric strings.
1164011782
1164111783=end original
1164211784
1164311785I<length-item> 文字に繰り返し数をつけるのは、
1164411786文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。
1164511787C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が
1164611788出力されることがあり、Perl はこれを有効な数値文字列として認識しません。
1164711789
1164811790=item *
1164911791
1165011792=begin original
1165111793
1165211794The integer types C<s>, C<S>, C<l>, and C<L> may be
1165311795followed by a C<!> modifier to specify native shorts or
1165411796longs. As shown in the example above, a bare C<l> means
1165511797exactly 32 bits, although the native C<long> as seen by the local C compiler
1165611798may be larger. This is mainly an issue on 64-bit platforms. You can
1165711799see whether using C<!> makes any difference this way:
1165811800
1165911801=end original
1166011802
1166111803C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を
1166211804つけることで、ネイティブの short や long を指定できます。
1166311805上述のように、C<l> は正確に 32 ビットですが、ネイティブな
1166411806(ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。
1166511807これは主に 64 ビットプラットフォームで意味があります。
1166611808C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます:
1166711809
1166811810 printf "format s is %d, s! is %d\n",
1166911811 length pack("s"), length pack("s!");
1167011812
1167111813 printf "format l is %d, l! is %d\n",
1167211814 length pack("l"), length pack("l!");
1167311815
1167411816=begin original
1167511817
1167611818C<i!> and C<I!> are also allowed, but only for completeness' sake:
1167711819they are identical to C<i> and C<I>.
1167811820
1167911821=end original
1168011822
1168111823C<i!> と C<I!> も動作しますが、単に完全性のためだけです;
1168211824これは C<i> 及び C<I> と同じです。
1168311825
1168411826=begin original
1168511827
1168611828The actual sizes (in bytes) of native shorts, ints, longs, and long
1168711829longs on the platform where Perl was built are also available from
1168811830the command line:
1168911831
1169011832=end original
1169111833
1169211834Perl がビルドされたプラットフォームでの short, int, long, long long の
1169311835実際の(バイト数での)サイズはコマンドラインから:
1169411836
1169511837 $ perl -V:{short,int,long{,long}}size
1169611838 shortsize='2';
1169711839 intsize='4';
1169811840 longsize='4';
1169911841 longlongsize='8';
1170011842
1170111843=begin original
1170211844
1170311845or programmatically via the L<C<Config>|Config> module:
1170411846
1170511847=end original
1170611848
1170711849あるいは L<C<Config>|Config> モジュールからプログラムで:
1170811850
1170911851 use Config;
1171011852 print $Config{shortsize}, "\n";
1171111853 print $Config{intsize}, "\n";
1171211854 print $Config{longsize}, "\n";
1171311855 print $Config{longlongsize}, "\n";
1171411856
1171511857=begin original
1171611858
1171711859C<$Config{longlongsize}> is undefined on systems without
1171811860long long support.
1171911861
1172011862=end original
1172111863
1172211864システムが long long に対応していない場合は C<$Config{longlongsize}> は
1172311865未定義値になります。
1172411866
1172511867=item *
1172611868
1172711869=begin original
1172811870
1172911871The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are
1173011872inherently non-portable between processors and operating systems because
1173111873they obey native byteorder and endianness. For example, a 4-byte integer
11732118740x12345678 (305419896 decimal) would be ordered natively (arranged in and
1173311875handled by the CPU registers) into bytes as
1173411876
1173511877=end original
1173611878
1173711879整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は
1173811880ネイティブなバイト順序とエンディアンに従っているため、
1173911881本質的にプロセッサ間や OS 間で移植性がありません。
1174011882例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は
1174111883内部では(CPU レジスタによって変換され扱われる形では)
1174211884以下のようなバイト列に並べられます:
1174311885
1174411886 0x12 0x34 0x56 0x78 # big-endian
1174511887 0x78 0x56 0x34 0x12 # little-endian
1174611888
1174711889=begin original
1174811890
1174911891Basically, Intel and VAX CPUs are little-endian, while everybody else,
1175011892including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are
1175111893big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used)
1175211894them in little-endian mode, but SGI/Cray uses them in big-endian mode.
1175311895
1175411896=end original
1175511897
1175611898基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、
1175711899Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては
1175811900ビッグエンディアンです。
1175911901Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで
1176011902使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで
1176111903使っています。
1176211904
1176311905=begin original
1176411906
1176511907The names I<big-endian> and I<little-endian> are comic references to the
1176611908egg-eating habits of the little-endian Lilliputians and the big-endian
1176711909Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>.
1176811910This entered computer lingo via the paper "On Holy Wars and a Plea for
1176911911Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980.
1177011912
1177111913=end original
1177211914
1177311915I<ビッグエンディアン> と I<リトルエンディアン> の名前は、
1177411916ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> での、卵を
1177511917小さい方からむくリリパット国と大きい方からむくブレフスキュ国から
1177611918取られています。
1177711919"On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137,
1177811920April 1, 1980 の文書からコンピュータ用語として取り入れられました。
1177911921
1178011922=begin original
1178111923
1178211924Some systems may have even weirder byte orders such as
1178311925
1178411926=end original
1178511927
1178611928以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません:
1178711929
1178811930 0x56 0x78 0x12 0x34
1178911931 0x34 0x12 0x78 0x56
1179011932
1179111933=begin original
1179211934
1179311935These are called mid-endian, middle-endian, mixed-endian, or just weird.
1179411936
1179511937=end original
1179611938
1179711939これらは mid-endian, middle-endian, mixed-endian あるいは単におかしなものと
1179811940呼ばれます。
1179911941
1180011942=begin original
1180111943
1180211944You can determine your system endianness with this incantation:
1180311945
1180411946=end original
1180511947
1180611948システムの設定は以下のようにして調べられます:
1180711949
1180811950 printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
1180911951
1181011952=begin original
1181111953
1181211954The byteorder on the platform where Perl was built is also available
1181311955via L<Config>:
1181411956
1181511957=end original
1181611958
1181711959Perl がビルドされたプラットフォームでのバイト順序は
1181811960L<Config> 経由か:
1181911961
1182011962 use Config;
1182111963 print "$Config{byteorder}\n";
1182211964
1182311965=begin original
1182411966
1182511967or from the command line:
1182611968
1182711969=end original
1182811970
1182911971あるいはコマンドラインで:
1183011972
1183111973 $ perl -V:byteorder
1183211974
1183311975=begin original
1183411976
1183511977Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321">
1183611978and C<"87654321"> are big-endian. Systems with multiarchitecture binaries
1183711979will have C<"ffff">, signifying that static information doesn't work,
1183811980one must use runtime probing.
1183911981
1184011982=end original
1184111983
1184211984C<"1234"> と C<"12345678"> はリトルエンディアンです;
1184311985C<"4321"> と C<"87654321"> はビッグエンディアンです。
1184411986マルチアーキテクチャバイナリを持つシステムは
1184511987C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が
1184611988あることを示します。
1184711989
1184811990=begin original
1184911991
1185011992For portably packed integers, either use the formats C<n>, C<N>, C<v>,
1185111993and C<V> or else use the C<< > >> and C<< < >> modifiers described
1185211994immediately below. See also L<perlport>.
1185311995
1185411996=end original
1185511997
1185611998移植性のあるパック化された整数がほしい場合は、
1185711999C<n>, C<N>, C<v>, C<V> フォーマットを使うか、
1185812000直後で説明する C<< > >> と C<< < >> の修飾子が使えます。
1185912001L<perlport> も参照してください。
1186012002
1186112003=item *
1186212004
1186312005=begin original
1186412006
1186512007Also floating point numbers have endianness. Usually (but not always)
1186612008this agrees with the integer endianness. Even though most platforms
1186712009these days use the IEEE 754 binary format, there are differences,
1186812010especially if the long doubles are involved. You can see the
1186912011C<Config> variables C<doublekind> and C<longdblkind> (also C<doublesize>,
1187012012C<longdblsize>): the "kind" values are enums, unlike C<byteorder>.
1187112013
1187212014=end original
1187312015
1187412016また、浮動小数点数にもエンディアンがあります。
1187512017通常は(但し常にではありません)これは整数のエンディアンと同じです。
1187612018最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも
1187712019関わらず、(特に long double 関連で) 相違点があります。
1187812020C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>,
1187912021C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、
1188012022順序値です。
1188112023
1188212024=begin original
1188312025
1188412026Portability-wise the best option is probably to keep to the IEEE 754
118851202764-bit doubles, and of agreed-upon endianness. Another possibility
1188612028is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>.
1188712029
1188812030=end original
1188912031
1189012032移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した
1189112033エンディアンを維持することです。
1189212034もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の
1189312035C<"%a"> 型式です。
1189412036
1189512037=item *
1189612038
1189712039=begin original
1189812040
1189912041Starting with Perl 5.10.0, integer and floating-point formats, along with
1190012042the C<p> and C<P> formats and C<()> groups, may all be followed by the
1190112043C<< > >> or C<< < >> endianness modifiers to respectively enforce big-
1190212044or little-endian byte-order. These modifiers are especially useful
1190312045given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers,
119041204664-bit integers, or floating-point values.
1190512047
1190612048=end original
1190712049
1190812050Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、
1190912051全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の
1191012052エンディアン修飾子をつけることで、それぞれ
1191112053ビッグエンディアンとリトルエンディアンに強制させることができます。
1191212054C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に
1191312055対応していないので、これは特に有用です。
1191412056
1191512057=begin original
1191612058
1191712059Here are some concerns to keep in mind when using an endianness modifier:
1191812060
1191912061=end original
1192012062
1192112063エンディアン修飾子を使うときに心に留めておくべきことを記します:
1192212064
1192312065=over
1192412066
1192512067=item *
1192612068
1192712069=begin original
1192812070
1192912071Exchanging signed integers between different platforms works only
1193012072when all platforms store them in the same format. Most platforms store
1193112073signed integers in two's-complement notation, so usually this is not an issue.
1193212074
1193312075=end original
1193412076
1193512077異なったプラットフォームで符号付き整数を交換することは、全ての
1193612078プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。
1193712079ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、
1193812080普通はこれは問題になりません。
1193912081
1194012082=item *
1194112083
1194212084=begin original
1194312085
1194412086The C<< > >> or C<< < >> modifiers can only be used on floating-point
1194512087formats on big- or little-endian machines. Otherwise, attempting to
1194612088use them raises an exception.
1194712089
1194812090=end original
1194912091
1195012092C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの
1195112093マシンでの浮動小数点フォーマットでのみ使えます。
1195212094それ以外では、そのようなことをすると例外が発生します。
1195312095
1195412096=item *
1195512097
1195612098=begin original
1195712099
1195812100Forcing big- or little-endian byte-order on floating-point values for
1195912101data exchange can work only if all platforms use the same
1196012102binary representation such as IEEE floating-point. Even if all
1196112103platforms are using IEEE, there may still be subtle differences. Being able
1196212104to use C<< > >> or C<< < >> on floating-point values can be useful,
1196312105but also dangerous if you don't know exactly what you're doing.
1196412106It is not a general way to portably store floating-point values.
1196512107
1196612108=end original
1196712109
1196812110データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル
1196912111エンディアンに強制することは、全てのプラットフォームが
1197012112IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ
1197112113うまくいきます。
1197212114たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが
1197312115あるかもしれません。
1197412116浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、
1197512117もし自分が何をしているかを正確に理解していなければ、危険です。
1197612118移植性のある浮動小数点数の保存のための一般的な方法はありません。
1197712119
1197812120=item *
1197912121
1198012122=begin original
1198112123
1198212124When using C<< > >> or C<< < >> on a C<()> group, this affects
1198312125all types inside the group that accept byte-order modifiers,
1198412126including all subgroups. It is silently ignored for all other
1198512127types. You are not allowed to override the byte-order within a group
1198612128that already has a byte-order modifier suffix.
1198712129
1198812130=end original
1198912131
1199012132C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを
1199112133含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。
1199212134その他の型については沈黙のうちに無視されます。
1199312135既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは
1199412136できません。
1199512137
1199612138=back
1199712139
1199812140=item *
1199912141
1200012142=begin original
1200112143
1200212144Real numbers (floats and doubles) are in native machine format only.
1200312145Due to the multiplicity of floating-point formats and the lack of a
1200412146standard "network" representation for them, no facility for interchange has been
1200512147made. This means that packed floating-point data written on one machine
1200612148may not be readable on another, even if both use IEEE floating-point
1200712149arithmetic (because the endianness of the memory representation is not part
1200812150of the IEEE spec). See also L<perlport>.
1200912151
1201012152=end original
1201112153
1201212154実数 (float と double) は、機種依存のフォーマットしかありません。
1201312155いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが
1201412156ないため、データ交換のための機能は用意してありません。
1201512157つまり、あるマシンで pack した浮動小数点数は、別のマシンでは
1201612158読めないかもしれないということです; たとえ双方で IEEE フォーマットの
1201712159浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の
1201812160バイト順序までは、規定されていないからです)。
1201912161L<perlport> も参照してください。
1202012162
1202112163=begin original
1202212164
1202312165If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >>
1202412166modifiers to force big- or little-endian byte-order on floating-point values.
1202512167
1202612168=end original
1202712169
1202812170もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の
1202912171バイト順をビッグエンディアンやリトルエンディアンに強制するために、
1203012172C<< > >> と C<< < >> の修飾子が使えます。
1203112173
1203212174=begin original
1203312175
1203412176Because Perl uses doubles (or long doubles, if configured) internally for
1203512177all numeric calculation, converting from double into float and thence
1203612178to double again loses precision, so C<unpack("f", pack("f", $foo)>)
1203712179will not in general equal $foo.
1203812180
1203912181=end original
1204012182
1204112183Perl では、すべての数値演算のために、内部的に double (または設定によっては
1204212184long double) を使用しているので、double から float へ変換し、それから再び
1204312185double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、
1204412186一般には $foo と同じではありません。
1204512187
1204612188=item *
1204712189
1204812190=begin original
1204912191
1205012192Pack and unpack can operate in two modes: character mode (C<C0> mode) where
1205112193the packed string is processed per character, and UTF-8 byte mode (C<U0> mode)
1205212194where the packed string is processed in its UTF-8-encoded Unicode form on
1205312195a byte-by-byte basis. Character mode is the default
1205412196unless the format string starts with C<U>. You
1205512197can always switch mode mid-format with an explicit
1205612198C<C0> or C<U0> in the format. This mode remains in effect until the next
1205712199mode change, or until the end of the C<()> group it (directly) applies to.
1205812200
1205912201=end original
1206012202
1206112203pack と unpack は二つのモードで操作します: pack された文字列を文字単位で
1206212204処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、
1206312205その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。
1206412206文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。
1206512207モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも
1206612208切り替えられます。
1206712209モードは次のモードに切り替えられるか、(直接)適用された C<()> グループが
1206812210終了するまで有効です。
1206912211
1207012212=begin original
1207112213
1207212214Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode
1207312215bytes is not necessarily obvious. Probably only the first of these
1207412216is what you want:
1207512217
1207612218=end original
1207712219
1207812220Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに
1207912221C<U0> を使うというのは必ずしも明白ではありません。
1208012222おそらく、これらのうち最初のものだけが望みのものでしょう:
1208112223
1208212224 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1208312225 perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)'
1208412226 03B1.03C9
1208512227 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1208612228 perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
1208712229 CE.B1.CF.89
1208812230 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1208912231 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)'
1209012232 CE.B1.CF.89
1209112233 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1209212234 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
1209312235 C3.8E.C2.B1.C3.8F.C2.89
1209412236
1209512237=begin original
1209612238
1209712239Those examples also illustrate that you should not try to use
1209812240L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a
1209912241substitute for the L<Encode> module.
1210012242
1210112243=end original
1210212244
1210312245これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/
1210412246L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして
1210512247使おうとするべきではないということも示しています。
1210612248
1210712249=item *
1210812250
1210912251=begin original
1211012252
1211112253You must yourself do any alignment or padding by inserting, for example,
1211212254enough C<"x">es while packing. There is no way for
1211312255L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
1211412256to know where characters are going to or coming from, so they
1211512257handle their output and input as flat sequences of characters.
1211612258
1211712259=end original
1211812260
1211912261pack するときに、例えば十分な数の C<"x"> を挿入することによって
1212012262アライメントやパッディングを行うのは全て自分でしなければなりません。
1212112263L<C<pack>|/pack TEMPLATE,LIST> や L<C<unpack>|/unpack TEMPLATE,EXPR> は、
1212212264文字列がどこへ行くかやどこから来たかを
1212312265知る方法はないので、出力と入力をフラットな文字列として扱います。
1212412266
1212512267=item *
1212612268
1212712269=begin original
1212812270
1212912271A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may
1213012272take a repeat count either as postfix, or for
1213112273L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</>
1213212274template character. Within each repetition of a group, positioning with
1213312275C<@> starts over at 0. Therefore, the result of
1213412276
1213512277=end original
1213612278
1213712279C<()> のグループはかっこで囲われた副テンプレートです。
1213812280グループは繰り返し数を取ることができます; 接尾辞によるか、
1213912281L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。
1214012282グループの繰り返し毎に、C<@> の位置は 0 になります。
1214112283従って、以下の結果は:
1214212284
1214312285 pack("@1A((@2A)@3A)", qw[X Y Z])
1214412286
1214512287=begin original
1214612288
1214712289is the string C<"\0X\0\0YZ">.
1214812290
1214912291=end original
1215012292
1215112293文字列 C<"\0X\0\0YZ"> です。
1215212294
1215312295=item *
1215412296
1215512297=begin original
1215612298
1215712299C<x> and C<X> accept the C<!> modifier to act as alignment commands: they
1215812300jump forward or back to the closest position aligned at a multiple of C<count>
1215912301characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or
1216012302L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like
1216112303
1216212304=end original
1216312305
1216412306C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます:
1216512307これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。
1216612308例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または
1216712309L<C<unpack>|/unpack TEMPLATE,EXPR> するには
1216812310
1216912311 struct {
1217012312 char c; /* one signed, 8-bit character */
1217112313 double d;
1217212314 char cc[2];
1217312315 }
1217412316
1217512317=begin original
1217612318
1217712319one may need to use the template C<c x![d] d c[2]>. This assumes that
1217812320doubles must be aligned to the size of double.
1217912321
1218012322=end original
1218112323
1218212324C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。
1218312325これは double が double のサイズでアライメントされていることを
1218412326仮定しています。
1218512327
1218612328=begin original
1218712329
1218812330For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1;
1218912331both are no-ops.
1219012332
1219112333=end original
1219212334
1219312335アライメントコマンドに対しては、C<count> に 0 を指定するのは
1219412336C<count> に 1 を指定するのと等価です; どちらも何もしません。
1219512337
1219612338=item *
1219712339
1219812340=begin original
1219912341
1220012342C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to
1220112343represent signed 16-/32-bit integers in big-/little-endian order.
1220212344This is portable only when all platforms sharing packed data use the
1220312345same binary representation for signed integers; for example, when all
1220412346platforms use two's-complement representation.
1220512347
1220612348=end original
1220712349
1220812350C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または
122091235132 ビット整数で表現するための C<!> 修飾子を受け入れます。
1221012352これは pack されたデータを共有する全てのプラットフォームが
1221112353符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります;
1221212354例えば、全てのプラットフォームで 2 の補数表現を使う場合です。
1221312355
1221412356=item *
1221512357
1221612358=begin original
1221712359
1221812360Comments can be embedded in a TEMPLATE using C<#> through the end of line.
1221912361White space can separate pack codes from each other, but modifiers and
1222012362repeat counts must follow immediately. Breaking complex templates into
1222112363individual line-by-line components, suitably annotated, can do as much to
1222212364improve legibility and maintainability of pack/unpack formats as C</x> can
1222312365for complicated pattern matches.
1222412366
1222512367=end original
1222612368
1222712369TEMPLATE の中の C<#> から行末まではコメントです。
1222812370空白は pack コードをそれぞれ分けるために使えますが、修飾子と
1222912371繰り返し数は直後に置かなければなりません。
1223012372複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、
1223112373複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack
1223212374フォーマットの読みやすさと保守性が向上します。
1223312375
1223412376=item *
1223512377
1223612378=begin original
1223712379
1223812380If TEMPLATE requires more arguments than L<C<pack>|/pack TEMPLATE,LIST>
1223912381is given, L<C<pack>|/pack TEMPLATE,LIST>
1224012382assumes additional C<""> arguments. If TEMPLATE requires fewer arguments
1224112383than given, extra arguments are ignored.
1224212384
1224312385=end original
1224412386
1224512387TEMPLATE が要求する引数の数が L<C<pack>|/pack TEMPLATE,LIST> が実際に
1224612388与えている数より多い場合、
1224712389L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。
1224812390TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。
1224912391
1225012392=item *
1225112393
1225212394=begin original
1225312395
1225412396Attempting to pack the special floating point values C<Inf> and C<NaN>
1225512397(infinity, also in negative, and not-a-number) into packed integer values
1225612398(like C<"L">) is a fatal error. The reason for this is that there simply
1225712399isn't any sensible mapping for these special values into integers.
1225812400
1225912401=end original
1226012402
1226112403特殊浮動小数点値 C<Inf> と C<NaN>
1226212404((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると
1226312405致命的エラーとなります。
1226412406この理由は、単に特殊値を整数に割り当てられないからです。
1226512407
1226612408=back
1226712409
1226812410=begin original
1226912411
1227012412Examples:
1227112413
1227212414=end original
1227312415
1227412416例:
1227512417
1227612418 $foo = pack("WWWW",65,66,67,68);
1227712419 # foo eq "ABCD"
1227812420 $foo = pack("W4",65,66,67,68);
1227912421 # same thing
1228012422 $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9);
1228112423 # same thing with Unicode circled letters.
1228212424 $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9);
1228312425 # same thing with Unicode circled letters. You don't get the
1228412426 # UTF-8 bytes because the U at the start of the format caused
1228512427 # a switch to U0-mode, so the UTF-8 bytes get joined into
1228612428 # characters
1228712429 $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9);
1228812430 # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9"
1228912431 # This is the UTF-8 encoding of the string in the
1229012432 # previous example
1229112433
1229212434 $foo = pack("ccxxcc",65,66,67,68);
1229312435 # foo eq "AB\0\0CD"
1229412436
1229512437 # NOTE: The examples above featuring "W" and "c" are true
1229612438 # only on ASCII and ASCII-derived systems such as ISO Latin 1
1229712439 # and UTF-8. On EBCDIC systems, the first example would be
1229812440 # $foo = pack("WWWW",193,194,195,196);
1229912441
1230012442 $foo = pack("s2",1,2);
1230112443 # "\001\000\002\000" on little-endian
1230212444 # "\000\001\000\002" on big-endian
1230312445
1230412446 $foo = pack("a4","abcd","x","y","z");
1230512447 # "abcd"
1230612448
1230712449 $foo = pack("aaaa","abcd","x","y","z");
1230812450 # "axyz"
1230912451
1231012452 $foo = pack("a14","abcdefg");
1231112453 # "abcdefg\0\0\0\0\0\0\0"
1231212454
1231312455 $foo = pack("i9pl", gmtime);
1231412456 # a real struct tm (on my system anyway)
1231512457
1231612458 $utmp_template = "Z8 Z8 Z16 L";
1231712459 $utmp = pack($utmp_template, @utmp1);
1231812460 # a struct utmp (BSDish)
1231912461
1232012462 @utmp2 = unpack($utmp_template, $utmp);
1232112463 # "@utmp1" eq "@utmp2"
1232212464
1232312465 sub bintodec {
1232412466 unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
1232512467 }
1232612468
1232712469 $foo = pack('sx2l', 12, 34);
1232812470 # short 12, two zero bytes padding, long 34
1232912471 $bar = pack('s@4l', 12, 34);
1233012472 # short 12, zero fill to position 4, long 34
1233112473 # $foo eq $bar
1233212474 $baz = pack('s.l', 12, 4, 34);
1233312475 # short 12, zero fill to position 4, long 34
1233412476
1233512477 $foo = pack('nN', 42, 4711);
1233612478 # pack big-endian 16- and 32-bit unsigned integers
1233712479 $foo = pack('S>L>', 42, 4711);
1233812480 # exactly the same
1233912481 $foo = pack('s<l<', -42, 4711);
1234012482 # pack little-endian 16- and 32-bit signed integers
1234112483 $foo = pack('(sl)<', -42, 4711);
1234212484 # exactly the same
1234312485
1234412486=begin original
1234512487
1234612488The same template may generally also be used in
1234712489L<C<unpack>|/unpack TEMPLATE,EXPR>.
1234812490
1234912491=end original
1235012492
1235112493一般的には、同じテンプレートが L<C<unpack>|/unpack TEMPLATE,EXPR> でも
1235212494使用できます。
1235312495
1235412496=item package NAMESPACE
1235512497
1235612498=item package NAMESPACE VERSION
1235712499X<package> X<module> X<namespace> X<version>
1235812500
1235912501=item package NAMESPACE BLOCK
1236012502
1236112503=item package NAMESPACE VERSION BLOCK
1236212504X<package> X<module> X<namespace> X<version>
1236312505
1236412506=for Pod::Functions declare a separate global namespace
1236512507
1236612508=begin original
1236712509
1236812510Declares the BLOCK or the rest of the compilation unit as being in the
1236912511given namespace. The scope of the package declaration is either the
1237012512supplied code BLOCK or, in the absence of a BLOCK, from the declaration
1237112513itself through the end of current scope (the enclosing block, file, or
1237212514L<C<eval>|/eval EXPR>). That is, the forms without a BLOCK are
1237312515operative through the end of the current scope, just like the
1237412516L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, and
1237512517L<C<our>|/our VARLIST> operators. All unqualified dynamic identifiers
1237612518in this scope will be in the given namespace, except where overridden by
1237712519another L<C<package>|/package NAMESPACE> declaration or
1237812520when they're one of the special identifiers that qualify into C<main::>,
1237912521like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables.
1238012522
1238112523=end original
1238212524
1238312525BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。
1238412526パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から
1238512527現在のスコープの末尾 (閉じたブロック、ファイル、L<C<eval>|/eval EXPR>) です。
1238612528つまり、BLOCK なしの形式は、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
1238712529L<C<our>|/our VARLIST> 演算子と同様に現在のスコープの末尾にまで作用します。
1238812530このスコープ内の、全ての完全修飾されていない動的識別子は、他の
1238912531L<C<package>|/package NAMESPACE> 宣言によって上書きされるか、
1239012532C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に
1239112533割り当てられる特殊変数でない限り、指定された
1239212534名前空間になります。
1239312535
1239412536=begin original
1239512537
1239612538A package statement affects dynamic variables only, including those
1239712539you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped
1239812540variables, which are created with L<C<my>|/my VARLIST>,
1239912541L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it
1240012542would be the first declaration in a file included by
1240112543L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>.
1240212544You can switch into a
1240312545package in more than one place, since this only determines which default
1240412546symbol table the compiler uses for the rest of that block. You can refer to
1240512547identifiers in other packages than the current one by prefixing the identifier
1240612548with the package name and a double colon, as in C<$SomePack::var>
1240712549or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main>
12408package as assumed. That is, C<$::sail> is equivalent to
12550package is assumed. That is, C<$::sail> is equivalent to
1240912551C<$main::sail> (as well as to C<$main'sail>, still seen in ancient
1241012552code, mostly from Perl 4).
1241112553
1241212554=end original
1241312555
1241412556package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも
1241512557含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
1241612558L<C<our>|/our VARLIST> のいずれかで作成された
1241712559レキシカルなスコープの変数には I<影響しません>。
1241812560典型的にはこれは L<C<require>|/require VERSION> や
1241912561L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの
1242012562最初に宣言されます。
1242112563パッケージを複数の場所で切り替えることができます;
1242212564なぜならこれは単にコンパイラがこのブロックの残りに対してどの
1242312565シンボルテーブルを使うかにのみ影響するからです。
1242412566他のパッケージの識別子は、C<$SomePack::var> や
1242512567C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と
1242612568コロン二つをつけることで参照できます。
1242712569パッケージ名が省略された場合、C<main> パッケージが仮定されます。
1242812570つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、
1242912571古いコードでは C<$main'sail> もまだ見られます)。
1243012572
1243112573=begin original
1243212574
1243312575If VERSION is provided, L<C<package>|/package NAMESPACE> sets the
1243412576C<$VERSION> variable in the given
1243512577namespace to a L<version> object with the VERSION provided. VERSION must be a
1243612578"strict" style version number as defined by the L<version> module: a positive
1243712579decimal number (integer or decimal-fraction) without exponentiation or else a
1243812580dotted-decimal v-string with a leading 'v' character and at least three
1243912581components. You should set C<$VERSION> only once per package.
1244012582
1244112583=end original
1244212584
1244312585VERSION が指定されると、L<C<package>|/package NAMESPACE> は与えられた
1244412586名前空間の C<$VERSION> 変数に、
1244512587指定された VERSION の L<version> オブジェクトをセットします。
1244612588VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で
1244712589なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、
1244812590さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から
1244912591構成されるドット付き 10 進v-文字列です。
1245012592C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。
1245112593
1245212594=begin original
1245312595
1245412596See L<perlmod/"Packages"> for more information about packages, modules,
1245512597and classes. See L<perlsub> for other scoping issues.
1245612598
1245712599=end original
1245812600
1245912601パッケージ、モジュール、クラスに関するさらなる情報については
1246012602L<perlmod/"Packages"> を参照してください。
1246112603その他のスコープに関する話題については L<perlsub> を参照してください。
1246212604
1246312605=item __PACKAGE__
1246412606X<__PACKAGE__>
1246512607
1246612608=for Pod::Functions +5.004 the current package
1246712609
1246812610=begin original
1246912611
1247012612A special token that returns the name of the package in which it occurs.
1247112613
1247212614=end original
1247312615
1247412616これが書いてあるパッケージの名前を返す特殊トークン。
1247512617
1247612618=item pipe READHANDLE,WRITEHANDLE
1247712619X<pipe>
1247812620
1247912621=for Pod::Functions open a pair of connected filehandles
1248012622
1248112623=begin original
1248212624
1248312625Opens a pair of connected pipes like the corresponding system call.
1248412626Note that if you set up a loop of piped processes, deadlock can occur
1248512627unless you are very careful. In addition, note that Perl's pipes use
1248612628IO buffering, so you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
1248712629to flush your WRITEHANDLE after each command, depending on the
1248812630application.
1248912631
1249012632=end original
1249112633
1249212634対応するシステムコールと同じように、接続されたパイプのペアを開きます。
1249312635パイプでプロセスをループにするときには、よほど気を付けないと、
1249412636デッドロックが起こり得ます。
1249512637さらに、Perl のパイプでは、IO のバッファリングを使ので、
1249612638アプリケーションによっては、コマンドごとに WRITEHANDLE を
1249712639フラッシュするように、L<C<$E<verbar>>|perlvar/$E<verbar>> を設定することが
1249812640必要になるかもしれません。
1249912641
1250012642=begin original
1250112643
1250212644Returns true on success.
1250312645
1250412646=end original
1250512647
1250612648成功時には真を返します。
1250712649
1250812650=begin original
1250912651
1251012652See L<IPC::Open2>, L<IPC::Open3>, and
1251112653L<perlipc/"Bidirectional Communication with Another Process">
1251212654for examples of such things.
1251312655
1251412656=end original
1251512657
1251612658これらに関する例については、L<IPC::Open2>, L<IPC::Open3>,
1251712659L<perlipc/"Bidirectional Communication with Another Process"> を
1251812660参照してください。
1251912661
1252012662=begin original
1252112663
1252212664On systems that support a close-on-exec flag on files, that flag is set
1252312665on all newly opened file descriptors whose
1252412666L<C<fileno>|/fileno FILEHANDLE>s are I<higher> than the current value of
1252512667L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>.
1252612668
1252712669=end original
1252812670
1252912671ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1253012672新しくオープンされたファイル記述子のうち、
1253112673L<C<fileno>|/fileno FILEHANDLE> が現在の L<C<$^F>|perlvar/$^F> の値
1253212674(デフォルトでは C<STDERR> の 2)
1253312675I<よりも大きい> ものに対してフラグがセットされます。
1253412676L<perlvar/$^F> を参照してください。
1253512677
1253612678=item pop ARRAY
1253712679X<pop> X<stack>
1253812680
1253912681=item pop
1254012682
1254112683=for Pod::Functions remove the last element from an array and return it
1254212684
1254312685=begin original
1254412686
1254512687Pops and returns the last value of the array, shortening the array by
1254612688one element.
1254712689
1254812690=end original
1254912691
1255012692配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。
1255112693
1255212694=begin original
1255312695
1255412696Returns the undefined value if the array is empty, although this may
1255512697also happen at other times. If ARRAY is omitted, pops the
1255612698L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the
1255712699L<C<@_>|perlvar/@_> array in subroutines, just like
1255812700L<C<shift>|/shift ARRAY>.
1255912701
1256012702=end original
1256112703
1256212704指定された配列に要素がなければ未定義値が返されますが、
1256312705しかしこれは他の場合にも起こり得ます。
1256412706ARRAY が省略されると、L<C<shift>|/shift ARRAY> と同様に、メインプログラムでは
1256512707L<C<@ARGV>|perlvar/@ARGV> が使われますが、
1256612708サブルーチンでは L<C<@_>|perlvar/@_> が使われます。
1256712709
1256812710=begin original
1256912711
1257012712Starting with Perl 5.14, an experimental feature allowed
1257112713L<C<pop>|/pop ARRAY> to take a
1257212714scalar expression. This experiment has been deemed unsuccessful, and was
1257312715removed as of Perl 5.24.
1257412716
1257512717=end original
1257612718
1257712719Perl 5.14 から、L<C<pop>|/pop ARRAY> がスカラ式を取ることが出来るという
1257812720実験的機能がありました。
1257912721この実験は失敗と見なされ、Perl 5.24 で削除されました。
1258012722
1258112723=item pos SCALAR
1258212724X<pos> X<match, position>
1258312725
1258412726=item pos
1258512727
1258612728=for Pod::Functions find or set the offset for the last/next m//g search
1258712729
1258812730=begin original
1258912731
1259012732Returns the offset of where the last C<m//g> search left off for the
1259112733variable in question (L<C<$_>|perlvar/$_> is used when the variable is not
1259212734specified). This offset is in characters unless the
1259312735(no-longer-recommended) L<C<use bytes>|bytes> pragma is in effect, in
1259412736which case the offset is in bytes. Note that 0 is a valid match offset.
1259512737L<C<undef>|/undef EXPR> indicates
1259612738that the search position is reset (usually due to match failure, but
1259712739can also be because no match has yet been run on the scalar).
1259812740
1259912741=end original
1260012742
1260112743対象の変数に対して、前回の C<m//g> が終了した場所の
1260212744オフセットを返します(変数が指定されなかった場合は L<C<$_>|perlvar/$_> が
1260312745使われます)。
1260412746オフセットは、(もはや勧められない) L<C<use bytes>|bytes> プラグマが有効の
1260512747場合(この場合はバイト単位です)を除いて、文字単位です。
12606127480 は有効なマッチオフセットであることに注意してください。
1260712749L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は
1260812750マッチ失敗が原因ですが、このスカラ値にまだマッチングが
1260912751行われていないためかもしれません)。
1261012752
1261112753=begin original
1261212754
1261312755L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp
1261412756engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will
1261512757change that offset, and so will also influence the C<\G> zero-width
1261612758assertion in regular expressions. Both of these effects take place for
1261712759the next match, so you can't affect the position with
1261812760L<C<pos>|/pos SCALAR> during the current match, such as in
1261912761C<(?{pos() = 5})> or C<s//pos() = 5/e>.
1262012762
1262112763=end original
1262212764
1262312765L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を
1262412766直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、
1262512767そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
1262612768これらの効果の両方は次のマッチングのために行われるので、
1262712769C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の
1262812770L<C<pos>|/pos SCALAR> の位置には影響を与えません。
1262912771
1263012772=begin original
1263112773
1263212774Setting L<C<pos>|/pos SCALAR> also resets the I<matched with
1263312775zero-length> flag, described
1263412776under L<perlre/"Repeated Patterns Matching a Zero-length Substring">.
1263512777
1263612778=end original
1263712779
1263812780L<C<pos>|/pos SCALAR> を設定すると、
1263912781L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に
1264012782記述されている、I<長さ 0 でマッチング> フラグもリセットされます。
1264112783
1264212784=begin original
1264312785
1264412786Because a failed C<m//gc> match doesn't reset the offset, the return
1264512787from L<C<pos>|/pos SCALAR> won't change either in this case. See
1264612788L<perlre> and L<perlop>.
1264712789
1264812790=end original
1264912791
1265012792C<m//gc> マッチに失敗してもオフセットはリセットしないので、
1265112793L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。
1265212794L<perlre> と L<perlop> を参照してください。
1265312795
1265412796=item print FILEHANDLE LIST
1265512797X<print>
1265612798
1265712799=item print FILEHANDLE
1265812800
1265912801=item print LIST
1266012802
1266112803=item print
1266212804
1266312805=for Pod::Functions output a list to a filehandle
1266412806
1266512807=begin original
1266612808
1266712809Prints a string or a list of strings. Returns true if successful.
1266812810FILEHANDLE may be a scalar variable containing the name of or a reference
1266912811to the filehandle, thus introducing one level of indirection. (NOTE: If
1267012812FILEHANDLE is a variable and the next token is a term, it may be
1267112813misinterpreted as an operator unless you interpose a C<+> or put
1267212814parentheses around the arguments.) If FILEHANDLE is omitted, prints to the
1267312815last selected (see L<C<select>|/select FILEHANDLE>) output handle. If
1267412816LIST is omitted, prints L<C<$_>|perlvar/$_> to the currently selected
1267512817output handle. To use FILEHANDLE alone to print the content of
1267612818L<C<$_>|perlvar/$_> to it, you must use a bareword filehandle like
1267712819C<FH>, not an indirect one like C<$fh>. To set the default output handle
1267812820to something other than STDOUT, use the select operation.
1267912821
1268012822=end original
1268112823
1268212824文字列か文字列のリストを出力します。
1268312825成功時には真を返します。
1268412826FILEHANDLE は、ファイルハンドル名またはそのリファレンスが
1268512827入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。
1268612828(注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、
1268712829間に C<+> を置くか、引数の前後を括弧で括らなければ、
1268812830誤って解釈されることがあります。)
1268912831FILEHANDLE を省略した場合には、最後に選択された
1269012832(L<C<select>|/select FILEHANDLE> 参照) 出力チャネルに出力します。
1269112833LIST を省略すると、L<C<$_>|perlvar/$_> が現在選択されている出力ハンドルに
1269212834出力されます。
1269312835L<C<$_>|perlvar/$_> の内容を表示するために FILEHANDLE のみを使用するには、
1269412836C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の
1269512837ファイルハンドルを使わなければなりません。
1269612838デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を
1269712839使ってください。
1269812840
1269912841=begin original
1270012842
1270112843The current value of L<C<$,>|perlvar/$,> (if any) is printed between
1270212844each LIST item. The current value of L<C<$\>|perlvar/$\> (if any) is
1270312845printed after the entire LIST has been printed. Because print takes a
1270412846LIST, anything in the LIST is evaluated in list context, including any
1270512847subroutines whose return lists you pass to
1270612848L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print
1270712849keyword with a left
1270812850parenthesis unless you want the corresponding right parenthesis to
1270912851terminate the arguments to the print; put parentheses around all arguments
1271012852(or interpose a C<+>, but that doesn't look as good).
1271112853
1271212854=end original
1271312855
1271412856L<C<$,>|perlvar/$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
1271512857LIST 全体が出力された後、(もしあれば) L<C<$\>|perlvar/$\> の現在の値が
1271612858出力されます。
1271712859print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで
1271812860評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す
1271912861サブルーチンも含みます。
1272012862また、すべての引数を括弧で括るのでなければ、print というキーワードの
1272112863次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください
1272212864(あるいは "print" と引数の間に C<+> を書きますが、これはあまり
1272312865よくありません)。
1272412866
1272512867=begin original
1272612868
1272712869If you're storing handles in an array or hash, or in general whenever
1272812870you're using any expression more complex than a bareword handle or a plain,
1272912871unsubscripted scalar variable to retrieve it, you will have to use a block
1273012872returning the filehandle value instead, in which case the LIST may not be
1273112873omitted:
1273212874
1273312875=end original
1273412876
1273512877もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや
1273612878普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す
1273712879ブロックを使う必要があります; この場合 LIST は省略できません:
1273812880
1273912881 print { $files[$i] } "stuff\n";
1274012882 print { $OK ? *STDOUT : *STDERR } "stuff\n";
1274112883
1274212884=begin original
1274312885
1274412886Printing to a closed pipe or socket will generate a SIGPIPE signal. See
1274512887L<perlipc> for more on signal handling.
1274612888
1274712889=end original
1274812890
1274912891閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。
1275012892さらなるシグナル操作については L<perlipc> を参照してください。
1275112893
1275212894=item printf FILEHANDLE FORMAT, LIST
1275312895X<printf>
1275412896
1275512897=item printf FILEHANDLE
1275612898
1275712899=item printf FORMAT, LIST
1275812900
1275912901=item printf
1276012902
1276112903=for Pod::Functions output a formatted list to a filehandle
1276212904
1276312905=begin original
1276412906
1276512907Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that
1276612908L<C<$\>|perlvar/$\> (the output record separator) is not appended. The
1276712909FORMAT and the LIST are actually parsed as a single list. The first
1276812910argument of the list will be interpreted as the
1276912911L<C<printf>|/printf FILEHANDLE FORMAT, LIST> format. This means that
1277012912C<printf(@_)> will use C<$_[0]> as the format. See
1277112913L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format
1277212914argument. If C<use locale> (including C<use locale ':not_characters'>)
1277312915is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
1277412916called, the character used for the decimal separator in formatted
1277512917floating-point numbers is affected by the C<LC_NUMERIC> locale setting.
1277612918See L<perllocale> and L<POSIX>.
1277712919
1277812920=end original
1277912921
1278012922L<C<$\>|perlvar/$\>(出力レコードセパレータ)を追加しないことを除けば、
1278112923C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。
1278212924FORMAT と LIST は実際には単一のリストとしてパースされます。
1278312925リストの最初の要素は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>
1278412926フォーマットと解釈されます。
1278512927これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うということです。
1278612928フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を
1278712929参照してください。
1278812930(C<use locale ':not_characters'> を含む) C<use locale> が有効で、
1278912931L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、
1279012932小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。
1279112933L<perllocale> と L<POSIX> を参照してください。
1279212934
1279312935=begin original
1279412936
1279512937For historical reasons, if you omit the list, L<C<$_>|perlvar/$_> is
1279612938used as the format;
1279712939to use FILEHANDLE without a list, you must use a bareword filehandle like
1279812940C<FH>, not an indirect one like C<$fh>. However, this will rarely do what
1279912941you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be
1280012942replaced with the empty string and a warning will be emitted if
1280112943L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if
1280212944you want to print the contents of L<C<$_>|perlvar/$_>.
1280312945
1280412946=end original
1280512947
1280612948歴史的な理由により、リストを省略すると、フォーマットとして
1280712949L<C<$_>|perlvar/$_> が使われます;
1280812950リストなしで FILEHANDLE を使用するには、C<$fh> のような
1280912951間接ファイルハンドルではなく、C<FH> のような裸の単語の
1281012952ファイルハンドルを使わなければなりません。
1281112953しかし、これがあなたが求めていることをすることはまれです;
1281212954L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、
1281312955L<warnings> が有効なら警告が出力されます。
1281412956L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に
1281512957L<C<print>|/print FILEHANDLE LIST> を使ってください。
1281612958
1281712959=begin original
1281812960
1281912961Don't fall into the trap of using a
1282012962L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple
1282112963L<C<print>|/print FILEHANDLE LIST> would do. The
1282212964L<C<print>|/print FILEHANDLE LIST> is more efficient and less error
1282312965prone.
1282412966
1282512967=end original
1282612968
1282712969単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで
1282812970L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう
1282912971罠にかからないようにしてください。
1283012972L<C<print>|/print FILEHANDLE LIST> はより効率的で、間違いが起こりにくいです。
1283112973
1283212974=item prototype FUNCTION
1283312975X<prototype>
1283412976
1283512977=item prototype
1283612978
1283712979=for Pod::Functions +5.002 get the prototype (if any) of a subroutine
1283812980
1283912981=begin original
1284012982
1284112983Returns the prototype of a function as a string (or
1284212984L<C<undef>|/undef EXPR> if the
1284312985function has no prototype). FUNCTION is a reference to, or the name of,
1284412986the function whose prototype you want to retrieve. If FUNCTION is omitted,
1284512987L<C<$_>|perlvar/$_> is used.
1284612988
1284712989=end original
1284812990
1284912991関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は
1285012992L<C<undef>|/undef EXPR> を返します)。
1285112993FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。
1285212994FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。
1285312995
1285412996=begin original
1285512997
1285612998If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
1285712999name for a Perl builtin. If the builtin's arguments
1285813000cannot be adequately expressed by a prototype
1285913001(such as L<C<system>|/system LIST>), L<C<prototype>|/prototype FUNCTION>
1286013002returns L<C<undef>|/undef EXPR>, because the builtin
1286113003does not really behave like a Perl function. Otherwise, the string
1286213004describing the equivalent prototype is returned.
1286313005
1286413006=end original
1286513007
1286613008FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として
1286713009扱われます。
1286813010このビルドインの引数が(L<C<system>|/system LIST> のように)プロトタイプとして
1286913011適切に記述できない場合、L<C<prototype>|/prototype FUNCTION> は
1287013012L<C<undef>|/undef EXPR> を返します;
1287113013なぜならビルドインは実際に Perl 関数のように振舞わないからです。
1287213014それ以外では、等価なプロトタイプを表現した文字列が返されます。
1287313015
1287413016=item push ARRAY,LIST
1287513017X<push> X<stack>
1287613018
1287713019=for Pod::Functions append one or more elements to an array
1287813020
1287913021=begin original
1288013022
1288113023Treats ARRAY as a stack by appending the values of LIST to the end of
1288213024ARRAY. The length of ARRAY increases by the length of LIST. Has the same
1288313025effect as
1288413026
1288513027=end original
1288613028
1288713029ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。
1288813030ARRAY の大きさは、LIST の長さ分だけ大きくなります。
1288913031これは、
1289013032
1289113033 for my $value (LIST) {
1289213034 $ARRAY[++$#ARRAY] = $value;
1289313035 }
1289413036
1289513037=begin original
1289613038
1289713039but is more efficient. Returns the number of elements in the array following
1289813040the completed L<C<push>|/push ARRAY,LIST>.
1289913041
1290013042=end original
1290113043
1290213044とするのと同じ効果がありますが、より効率的です。
1290313045L<C<push>|/push ARRAY,LIST> の処理終了後の配列の要素数を返します。
1290413046
1290513047=begin original
1290613048
1290713049Starting with Perl 5.14, an experimental feature allowed
1290813050L<C<push>|/push ARRAY,LIST> to take a
1290913051scalar expression. This experiment has been deemed unsuccessful, and was
1291013052removed as of Perl 5.24.
1291113053
1291213054=end original
1291313055
1291413056Perl 5.14 から、L<C<push>|/push ARRAY,LIST> がスカラ式を取ることが出来るという
1291513057実験的機能がありました。
1291613058この実験は失敗と見なされ、Perl 5.24 で削除されました。
1291713059
1291813060=item q/STRING/
1291913061
1292013062=for Pod::Functions singly quote a string
1292113063
1292213064=item qq/STRING/
1292313065
1292413066=for Pod::Functions doubly quote a string
1292513067
1292613068=item qw/STRING/
1292713069
1292813070=for Pod::Functions quote a list of words
1292913071
1293013072=item qx/STRING/
1293113073
1293213074=for Pod::Functions backquote quote a string
1293313075
1293413076=begin original
1293513077
1293613078Generalized quotes. See L<perlop/"Quote-Like Operators">.
1293713079
1293813080=end original
1293913081
1294013082汎用のクォートです。
1294113083L<perlop/"Quote-Like Operators"> を参照してください。
1294213084
1294313085=item qr/STRING/
1294413086
1294513087=for Pod::Functions +5.005 compile pattern
1294613088
1294713089=begin original
1294813090
1294913091Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">.
1295013092
1295113093=end original
1295213094
1295313095正規表現風のクォートです。
1295413096L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1295513097
1295613098=item quotemeta EXPR
1295713099X<quotemeta> X<metacharacter>
1295813100
1295913101=item quotemeta
1296013102
1296113103=for Pod::Functions quote regular expression magic characters
1296213104
1296313105=begin original
1296413106
1296513107Returns the value of EXPR with all the ASCII non-"word"
1296613108characters backslashed. (That is, all ASCII characters not matching
1296713109C</[A-Za-z_0-9]/> will be preceded by a backslash in the
1296813110returned string, regardless of any locale settings.)
1296913111This is the internal function implementing
1297013112the C<\Q> escape in double-quoted strings.
1297113113(See below for the behavior on non-ASCII code points.)
1297213114
1297313115=end original
1297413116
1297513117EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで
1297613118エスケープしたものを返します。
1297713119(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には
1297813120ロケールに関わらずバックスラッシュが前置されます。)
1297913121これは、ダブルクォート文字列での C<\Q> エスケープを実装するための
1298013122内部関数です。
1298113123(非 ASCII 符号位置での振る舞いについては以下を参照してください。)
1298213124
1298313125=begin original
1298413126
1298513127If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1298613128
1298713129=end original
1298813130
1298913131EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1299013132
1299113133=begin original
1299213134
1299313135quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into
1299413136regular expressions, because by default an interpolated variable will be
1299513137considered a mini-regular expression. For example:
1299613138
1299713139=end original
1299813140
1299913141クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに
1300013142便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として
1300113143扱われるからです。
1300213144例えば:
1300313145
1300413146 my $sentence = 'The quick brown fox jumped over the lazy dog';
1300513147 my $substring = 'quick.*?fox';
1300613148 $sentence =~ s{$substring}{big bad wolf};
1300713149
1300813150=begin original
1300913151
1301013152Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>.
1301113153
1301213154=end original
1301313155
1301413156とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。
1301513157
1301613158=begin original
1301713159
1301813160On the other hand:
1301913161
1302013162=end original
1302113163
1302213164一方:
1302313165
1302413166 my $sentence = 'The quick brown fox jumped over the lazy dog';
1302513167 my $substring = 'quick.*?fox';
1302613168 $sentence =~ s{\Q$substring\E}{big bad wolf};
1302713169
1302813170=begin original
1302913171
1303013172Or:
1303113173
1303213174=end original
1303313175
1303413176あるいは:
1303513177
1303613178 my $sentence = 'The quick brown fox jumped over the lazy dog';
1303713179 my $substring = 'quick.*?fox';
1303813180 my $quoted_substring = quotemeta($substring);
1303913181 $sentence =~ s{$quoted_substring}{big bad wolf};
1304013182
1304113183=begin original
1304213184
1304313185Will both leave the sentence as is.
1304413186Normally, when accepting literal string input from the user,
1304513187L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used.
1304613188
1304713189=end original
1304813190
1304913191とすると、両方ともそのままです。
1305013192普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、
1305113193必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。
1305213194
1305313195=begin original
1305413196
13197Beware that if you put literal backslashes (those not inside
13198interpolated variables) between C<\Q> and C<\E>, double-quotish
13199backslash interpolation may lead to confusing results. If you
13200I<need> to use literal backslashes within C<\Q...\E>,
13201consult L<perlop/"Gory details of parsing quoted constructs">.
13202
13203=end original
13204
13205リテラルな逆スラッシュ (変数置換の中でないもの) を C<\Q> と C<\E> の間に
13206置くと、ダブルクォート風逆スラッシュ変数置換は混乱した結果を
13207引き起こすことがあることに注意してください。
13208C<\Q...\E> の中でリテラルな逆スラッシュを使うことが I<必要> なら、
13209L<perlop/"Gory details of parsing quoted constructs"> を参照してください。
13210
13211=begin original
13212
13213Because the result of S<C<"\Q I<STRING> \E">> has all metacharacters
13214quoted, there is no way to insert a literal C<$> or C<@> inside a
13215C<\Q\E> pair. If protected by C<\>, C<$> will be quoted to become
13216C<"\\\$">; if not, it is interpreted as the start of an interpolated
13217scalar.
13218
13219=end original
13220
13221S<C<"\Q I<STRING> \E">> の結果では全てのメタ文字がクォートされているので、
13222C<\Q\E> の組の中にリテラルな C<$> や C<@> を挿入する方法はありません。
13223C<\> で保護すると、C<$> は C<"\\\$"> になってクォートされます;
13224保護しないと、変数展開されるスカラの開始として解釈されます。
13225
13226=begin original
13227
1305513228In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded
1305613229strings, but not quoted in UTF-8 strings.
1305713230
1305813231=end original
1305913232
1306013233Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた
1306113234文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。
1306213235
1306313236=begin original
1306413237
1306513238Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for
1306613239quoting non-ASCII characters; the quoting of ASCII characters is
1306713240unchanged.
1306813241
1306913242=end original
1307013243
1307113244Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で
1307213245定義された戦略を採用しました; ASCII 文字のクォートは変わりません。
1307313246
1307413247=begin original
1307513248
1307613249Also unchanged is the quoting of non-UTF-8 strings when outside the
1307713250scope of a
1307813251L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>,
1307913252which is to quote all
1308013253characters in the upper Latin1 range. This provides complete backwards
1308113254compatibility for old programs which do not use Unicode. (Note that
1308213255C<unicode_strings> is automatically enabled within the scope of a
1308313256S<C<use v5.12>> or greater.)
1308413257
1308513258=end original
1308613259
1308713260また、
1308813261L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature> の
1308913262範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の
1309013263全ての文字をクォートします。
1309113264これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。
1309213265(C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは
1309313266自動的に有効になることに注意してください。)
1309413267
1309513268=begin original
1309613269
1309713270Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code
1309813271points
1309913272are quoted whether the string is encoded as UTF-8 or not. As mentioned
1310013273above, locale does not affect the quoting of ASCII-range characters.
1310113274This protects against those locales where characters such as C<"|"> are
1310213275considered to be word characters.
1310313276
1310413277=end original
1310513278
1310613279L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は
1310713280文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。
1310813281上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。
1310913282これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。
1311013283
1311113284=begin original
1311213285
1311313286Otherwise, Perl quotes non-ASCII characters using an adaptation from
1311413287Unicode (see L<https://www.unicode.org/reports/tr31/>).
1311513288The only code points that are quoted are those that have any of the
1311613289Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space,
1311713290Default_Ignorable_Code_Point, or General_Category=Control.
1311813291
1311913292=end original
1312013293
1312113294さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします
1312213295(L<https://www.unicode.org/reports/tr31/> 参照)。
1312313296クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです:
1312413297Pattern_Syntax, Pattern_White_Space, White_Space,
1312513298Default_Ignorable_Code_Point, or General_Category=Control。
1312613299
1312713300=begin original
1312813301
1312913302Of these properties, the two important ones are Pattern_Syntax and
1313013303Pattern_White_Space. They have been set up by Unicode for exactly this
1313113304purpose of deciding which characters in a regular expression pattern
1313213305should be quoted. No character that can be in an identifier has these
1313313306properties.
1313413307
1313513308=end original
1313613309
1313713310これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。
1313813311これらはまさに正規表現中パターン中のどの文字をクォートするべきかを
1313913312決定するという目的のために Unicode によって設定されています。
1314013313識別子になる文字はこれらの特性はありません。
1314113314
1314213315=begin original
1314313316
1314413317Perl promises, that if we ever add regular expression pattern
1314513318metacharacters to the dozen already defined
1314613319(C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the
1314713320Pattern_Syntax property. Perl also promises, that if we ever add
1314813321characters that are considered to be white space in regular expressions
1314913322(currently mostly affected by C</x>), they will all have the
1315013323Pattern_White_Space property.
1315113324
1315213325=end original
1315313326
1315413327Perl は、正規表現メタ文字として既に定義されている
1315513328(C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、
1315613329Pattern_Syntax 特性を持つものだけを使うことを約束します。
1315713330Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と
1315813331考えられる文字に追加するときは、Pattern_White_Space 特性を
1315913332持つものであることを約束します。
1316013333
1316113334=begin original
1316213335
1316313336Unicode promises that the set of code points that have these two
1316413337properties will never change, so something that is not quoted in v5.16
1316513338will never need to be quoted in any future Perl release. (Not all the
1316613339code points that match Pattern_Syntax have actually had characters
1316713340assigned to them; so there is room to grow, but they are quoted
1316813341whether assigned or not. Perl, of course, would never use an
1316913342unassigned code point as an actual metacharacter.)
1317013343
1317113344=end original
1317213345
1317313346Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを
1317413347約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも
1317513348クォートする必要はありません。
1317613349(Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている
1317713350文字を持っているわけではありません; したがって拡張する余地がありますが、
1317813351割り当てられているかどうかに関わらずクォートされます。
1317913352Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは
1318013353ありません。)
1318113354
1318213355=begin original
1318313356
1318413357Quoting characters that have the other 3 properties is done to enhance
1318513358the readability of the regular expression and not because they actually
1318613359need to be quoted for regular expression purposes (characters with the
1318713360White_Space property are likely to be indistinguishable on the page or
1318813361screen from those with the Pattern_White_Space property; and the other
1318913362two properties contain non-printing characters).
1319013363
1319113364=end original
1319213365
1319313366その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために
1319413367行われ、実際には正規表現の目的でクォートする必要があるからではありません
1319513368(White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と
1319613369おそらく区別が付かないでしょう; そして残りの
1319713370二つの特性は非表示文字を含んでいます).
1319813371
1319913372=item rand EXPR
1320013373X<rand> X<random>
1320113374
1320213375=item rand
1320313376
1320413377=for Pod::Functions retrieve the next pseudorandom number
1320513378
1320613379=begin original
1320713380
1320813381Returns a random fractional number greater than or equal to C<0> and less
1320913382than the value of EXPR. (EXPR should be positive.) If EXPR is
1321013383omitted, the value C<1> is used. Currently EXPR with the value C<0> is
1321113384also special-cased as C<1> (this was undocumented before Perl 5.8.0
1321213385and is subject to change in future versions of Perl). Automatically calls
1321313386L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been
1321413387called. See also L<C<srand>|/srand EXPR>.
1321513388
1321613389=end original
1321713390
1321813391C<0> 以上 EXPR の値未満の小数の乱数値を返します。
1321913392(EXPR は正の数である必要があります。)
1322013393EXPR が省略されると、C<1> が使われます。
1322113394現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます
1322213395(これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では
1322313396変更される可能性があります)。
1322413397L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に
1322513398L<C<srand>|/srand EXPR> 関数を呼び出します。
1322613399L<C<srand>|/srand EXPR> も参照してください。
1322713400
1322813401=begin original
1322913402
1323013403Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR>
1323113404if you want random integers instead of random fractional numbers. For
1323213405example,
1323313406
1323413407=end original
1323513408
1323613409ランダムな小数ではなく、ランダムな整数がほしい場合は、
1323713410L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR> を
1323813411適用してください。
1323913412例えば:
1324013413
1324113414 int(rand(10))
1324213415
1324313416=begin original
1324413417
1324513418returns a random integer between C<0> and C<9>, inclusive.
1324613419
1324713420=end original
1324813421
1324913422これは C<0> から C<9> の値をランダムに返します。
1325013423
1325113424=begin original
1325213425
1325313426(Note: If your rand function consistently returns numbers that are too
1325413427large or too small, then your version of Perl was probably compiled
1325513428with the wrong number of RANDBITS.)
1325613429
1325713430=end original
1325813431
1325913432(注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを
1326013433返すようなら、お使いになっている Perl が、
1326113434良くない RANDBITS を使ってコンパイルされている可能性があります。)
1326213435
1326313436=begin original
1326413437
1326513438B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
1326613439on it in security-sensitive situations.> As of this writing, a
1326713440number of third-party CPAN modules offer random number generators
1326813441intended by their authors to be cryptographically secure,
1326913442including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1327013443and L<Math::TrulyRandom>.
1327113444
1327213445=end original
1327313446
1327413447B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
1327513448セキュリティ的に重要な状況でこれに頼るべきではありません。>
1327613449これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
1327713450作者によって暗号学的に安全であることを目的とした乱数生成器を
1327813451提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1327913452L<Math::TrulyRandom> などです。
1328013453
1328113454=item read FILEHANDLE,SCALAR,LENGTH,OFFSET
1328213455X<read> X<file, read>
1328313456
1328413457=item read FILEHANDLE,SCALAR,LENGTH
1328513458
1328613459=for Pod::Functions fixed-length buffered input from a filehandle
1328713460
1328813461=begin original
1328913462
1329013463Attempts to read LENGTH I<characters> of data into variable SCALAR
1329113464from the specified FILEHANDLE. Returns the number of characters
1329213465actually read, C<0> at end of file, or undef if there was an error (in
1329313466the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will be grown
1329413467or shrunk
1329513468so that the last character actually read is the last character of the
1329613469scalar after the read.
1329713470
1329813471=end original
1329913472
1330013473指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> のデータを
1330113474読み込みます。
1330213475実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の
1330313476いずれかを返します (後者の場合、L<C<$!>|perlvar/$!> もセットされます)。
1330413477SCALAR は伸び縮みするので、読み込み後は、実際に読み込んだ最後の文字がスカラの
1330513478最後の文字になります。
1330613479
1330713480=begin original
1330813481
1330913482An OFFSET may be specified to place the read data at some place in the
1331013483string other than the beginning. A negative OFFSET specifies
1331113484placement at that many characters counting backwards from the end of
1331213485the string. A positive OFFSET greater than the length of SCALAR
1331313486results in the string being padded to the required size with C<"\0">
1331413487bytes before the result of the read is appended.
1331513488
1331613489=end original
1331713490
1331813491OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
1331913492OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1332013493位置を指定します。
1332113494OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
1332213495追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
1332313496
1332413497=begin original
1332513498
1332613499The call is implemented in terms of either Perl's or your system's native
1332713500L<fread(3)> library function, via the L<PerlIO> layers applied to the
1332813501handle. To get a true L<read(2)> system call, see
1332913502L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>.
1333013503
1333113504=end original
1333213505
1333313506この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って、
1333413507ハンドルに適用されている L<PerlIO> 層経由で実装されています。
1333513508本当の L<read(2)> システムコールを利用するには、
1333613509L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。
1333713510
1333813511=begin original
1333913512
1334013513Note the I<characters>: depending on the status of the filehandle,
1334113514either (8-bit) bytes or characters are read. By default, all
1334213515filehandles operate on bytes, but for example if the filehandle has
1334313516been opened with the C<:utf8> I/O layer (see
1334413517L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open>
1334513518pragma), the I/O will operate on UTF8-encoded Unicode
1334613519characters, not bytes. Similarly for the C<:encoding> layer:
1334713520in that case pretty much any characters can be read.
1334813521
1334913522=end original
1335013523
1335113524I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか
1335213525文字が読み込まれます。
1335313526デフォルトでは全てのファイルハンドルはバイトを処理しますが、
1335413527例えばファイルハンドルが C<:utf8> I/O 層
1335513528(L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください) で
1335613529開かれた場合、I/O はバイトではなく、
1335713530UTF8 エンコードされた Unicode 文字を操作します。
1335813531C<:encoding> 層も同様です:
1335913532この場合、ほとんど大体全ての文字が読み込めます。
1336013533
1336113534=item readdir DIRHANDLE
1336213535X<readdir>
1336313536
1336413537=for Pod::Functions get a directory from a directory handle
1336513538
1336613539=begin original
1336713540
1336813541Returns the next directory entry for a directory opened by
1336913542L<C<opendir>|/opendir DIRHANDLE,EXPR>.
1337013543If used in list context, returns all the rest of the entries in the
1337113544directory. If there are no more entries, returns the undefined value in
1337213545scalar context and the empty list in list context.
1337313546
1337413547=end original
1337513548
1337613549L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリで、次の
1337713550ディレクトリエントリを返します。
1337813551リストコンテキストで用いると、そのディレクトリの残りのエントリを、すべて
1337913552返します。
1338013553エントリが残っていない場合には、スカラコンテキストでは未定義値を、
1338113554リストコンテキストでは空リストを返します。
1338213555
1338313556=begin original
1338413557
1338513558If you're planning to filetest the return values out of a
1338613559L<C<readdir>|/readdir DIRHANDLE>, you'd better prepend the directory in
1338713560question. Otherwise, because we didn't L<C<chdir>|/chdir EXPR> there,
1338813561it would have been testing the wrong file.
1338913562
1339013563=end original
1339113564
1339213565L<C<readdir>|/readdir DIRHANDLE> の返り値をファイルテストに使おうと
1339313566計画しているなら、頭にディレクトリをつける必要があります。
1339413567さもなければ、ここでは L<C<chdir>|/chdir EXPR> はしないので、
1339513568間違ったファイルをテストしてしまうことになるでしょう。
1339613569
1339713570 opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!";
1339813571 my @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
1339913572 closedir $dh;
1340013573
1340113574=begin original
1340213575
1340313576As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a
1340413577C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration.
1340513578If either a C<readdir> expression or an explicit assignment of a
1340613579C<readdir> expression to a scalar is used as a C<while>/C<for> condition,
1340713580then the condition actually tests for definedness of the expression's
1340813581value, not for its regular truth value.
1340913582
1341013583=end original
1341113584
1341213585Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で
1341313586使うことができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。
1341413587C<readdir> 式または C<readdir> 式からスカラへの明示的な代入が
1341513588C<while>/C<for> の条件部として使われた場合、
1341613589条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
1341713590テストします。
1341813591
1341913592 opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!";
1342013593 while (readdir $dh) {
1342113594 print "$some_dir/$_\n";
1342213595 }
1342313596 closedir $dh;
1342413597
1342513598=begin original
1342613599
1342713600To avoid confusing would-be users of your code who are running earlier
1342813601versions of Perl with mysterious failures, put this sort of thing at the
1342913602top of your file to signal that your code will work I<only> on Perls of a
1343013603recent vintage:
1343113604
1343213605=end original
1343313606
1343413607あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1343513608失敗で混乱することを避けるために、コードが最近のバージョンの Perl で
1343613609I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1343713610書いてください:
1343813611
13439 use 5.012; # so readdir assigns to $_ in a lone while test
13612 use v5.12; # so readdir assigns to $_ in a lone while test
1344013613
1344113614=item readline EXPR
1344213615
1344313616=item readline
1344413617X<readline> X<gets> X<fgets>
1344513618
1344613619=for Pod::Functions fetch a record from a file
1344713620
1344813621=begin original
1344913622
1345013623Reads from the filehandle whose typeglob is contained in EXPR (or from
1345113624C<*ARGV> if EXPR is not provided). In scalar context, each call reads and
1345213625returns the next line until end-of-file is reached, whereupon the
1345313626subsequent call returns L<C<undef>|/undef EXPR>. In list context, reads
1345413627until end-of-file is reached and returns a list of lines. Note that the
1345513628notion of "line" used here is whatever you may have defined with
1345613629L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in
1345713630L<English>). See L<perlvar/"$/">.
1345813631
1345913632=end original
1346013633
1346113634型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている
1346213635ファイルハンドルから読み込みます。
1346313636スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの
1346413637最後まで読み込んだら、以後の呼び出しでは L<C<undef>|/undef EXPR> を返します。
1346513638リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。
1346613639ここでの「行」とは、L<C<$E<sol>>|perlvar/$E<sol>> (または
1346713640L<English> モジュールでは C<$INPUT_RECORD_SEPARATOR>) で
1346813641定義されることに注意してください。
1346913642L<perlvar/"$/"> を参照してください。
1347013643
1347113644=begin original
1347213645
1347313646When L<C<$E<sol>>|perlvar/$E<sol>> is set to L<C<undef>|/undef EXPR>,
1347413647when L<C<readline>|/readline EXPR> is in scalar context (i.e., file
1347513648slurp mode), and when an empty file is read, it returns C<''> the first
1347613649time, followed by L<C<undef>|/undef EXPR> subsequently.
1347713650
1347813651=end original
1347913652
1348013653L<C<$E<sol>>|perlvar/$E<sol>> に L<C<undef>|/undef EXPR> を設定した場合は、
1348113654L<C<readline>|/readline EXPR> はスカラコンテキスト (つまりファイル吸い込み
1348213655モード)となり、空のファイルを読み込んだ場合は、最初は C<''> を返し、
1348313656それ以降は L<C<undef>|/undef EXPR> を返します。
1348413657
1348513658=begin original
1348613659
1348713660This is the internal function implementing the C<< <EXPR> >>
1348813661operator, but you can use it directly. The C<< <EXPR> >>
1348913662operator is discussed in more detail in L<perlop/"I/O Operators">.
1349013663
1349113664=end original
1349213665
1349313666これは C<< <EXPR> >> 演算子を実装している内部関数ですが、
1349413667直接使うこともできます。
1349513668C<< <EXPR> >> 演算子についてのさらなる詳細については
1349613669L<perlop/"I/O Operators"> で議論されています。
1349713670
1349813671 my $line = <STDIN>;
1349913672 my $line = readline(STDIN); # same thing
1350013673
1350113674=begin original
1350213675
1350313676If L<C<readline>|/readline EXPR> encounters an operating system error,
1350413677L<C<$!>|perlvar/$!> will be set with the corresponding error message.
1350513678It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from
1350613679filehandles you don't trust, such as a tty or a socket. The following
1350713680example uses the operator form of L<C<readline>|/readline EXPR> and dies
1350813681if the result is not defined.
1350913682
1351013683=end original
1351113684
1351213685L<C<readline>|/readline EXPR> が OS のシステムエラーになると、
1351313686L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。
1351413687tty やソケットといった、信頼できないファイルハンドルから読み込む時には
1351513688L<C<$!>|perlvar/$!> をチェックするのが助けになります。
1351613689以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が
1351713690未定義の場合は die します。
1351813691
1351913692 while ( ! eof($fh) ) {
1352013693 defined( $_ = readline $fh ) or die "readline failed: $!";
1352113694 ...
1352213695 }
1352313696
1352413697=begin original
1352513698
13526Note that you have can't handle L<C<readline>|/readline EXPR> errors
13699Note that you can't handle L<C<readline>|/readline EXPR> errors
1352713700that way with the C<ARGV> filehandle. In that case, you have to open
1352813701each element of L<C<@ARGV>|perlvar/@ARGV> yourself since
1352913702L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently.
1353013703
1353113704=end original
1353213705
1353313706L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では
1353413707扱えないことに注意してください。
1353513708この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、
1353613709L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。
1353713710
1353813711 foreach my $arg (@ARGV) {
1353913712 open(my $fh, $arg) or warn "Can't open $arg: $!";
1354013713
1354113714 while ( ! eof($fh) ) {
1354213715 defined( $_ = readline $fh )
1354313716 or die "readline failed for $arg: $!";
1354413717 ...
1354513718 }
1354613719 }
1354713720
1354813721=begin original
1354913722
1355013723Like the C<< <EXPR> >> operator, if a C<readline> expression is
1355113724used as the condition of a C<while> or C<for> loop, then it will be
1355213725implicitly assigned to C<$_>. If either a C<readline> expression or
1355313726an explicit assignment of a C<readline> expression to a scalar is used
1355413727as a C<while>/C<for> condition, then the condition actually tests for
1355513728definedness of the expression's value, not for its regular truth value.
1355613729
1355713730=end original
1355813731
1355913732C<< <EXPR> >> 演算子と同様、
1356013733C<readline> 式が C<while> や C<for> ループの条件として使われた場合、
1356113734これは暗黙に C<$_> に代入されます。
1356213735C<readline> 式または C<readline> 式からスカラへの明示的な代入が
1356313736C<while>/C<for> の条件部として使われた場合、
1356413737条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
1356513738テストします。
1356613739
1356713740=item readlink EXPR
1356813741X<readlink>
1356913742
1357013743=item readlink
1357113744
1357213745=for Pod::Functions determine where a symbolic link is pointing
1357313746
1357413747=begin original
1357513748
1357613749Returns the value of a symbolic link, if symbolic links are
1357713750implemented. If not, raises an exception. If there is a system
1357813751error, returns the undefined value and sets L<C<$!>|perlvar/$!> (errno).
1357913752If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1358013753
1358113754=end original
1358213755
1358313756シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。
1358413757実装されていないときには、例外が発生します。
1358513758何らかのシステムエラーが検出されると、未定義値を返し、
1358613759L<C<$!>|perlvar/$!> (errno) を設定します。
1358713760EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1358813761
1358913762=begin original
1359013763
1359113764Portability issues: L<perlport/readlink>.
1359213765
1359313766=end original
1359413767
1359513768移植性の問題: L<perlport/readlink>。
1359613769
1359713770=item readpipe EXPR
1359813771
1359913772=item readpipe
1360013773X<readpipe>
1360113774
1360213775=for Pod::Functions execute a system command and collect standard output
1360313776
1360413777=begin original
1360513778
1360613779EXPR is executed as a system command.
1360713780The collected standard output of the command is returned.
1360813781In scalar context, it comes back as a single (potentially
1360913782multi-line) string. In list context, returns a list of lines
1361013783(however you've defined lines with L<C<$E<sol>>|perlvar/$E<sol>> (or
1361113784C<$INPUT_RECORD_SEPARATOR> in L<English>)).
1361213785This is the internal function implementing the C<qx/EXPR/>
1361313786operator, but you can use it directly. The C<qx/EXPR/>
1361413787operator is discussed in more detail in L<perlop/"C<qx/I<STRING>/>">.
1361513788If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1361613789
1361713790=end original
1361813791
1361913792EXPR がシステムコマンドとして実行されます。
1362013793コマンドの標準出力の内容が返されます。
1362113794スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。
1362213795リストコンテキストでは、行のリストを返します
1362313796(但し、行は L<C<$E<sol>>|perlvar/$E<sol>> (または L<English> モジュールでは
1362413797C<$INPUT_RECORD_SEPARATOR> で定義されます)。
1362513798これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。
1362613799C<qx/EXPR/> 演算子は L<perlop/"C<qx/I<STRING>/>"> でより詳細に
1362713800述べられています。
1362813801EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1362913802
1363013803=item recv SOCKET,SCALAR,LENGTH,FLAGS
1363113804X<recv>
1363213805
1363313806=for Pod::Functions receive a message over a Socket
1363413807
1363513808=begin original
1363613809
1363713810Receives a message on a socket. Attempts to receive LENGTH characters
1363813811of data into variable SCALAR from the specified SOCKET filehandle.
1363913812SCALAR will be grown or shrunk to the length actually read. Takes the
1364013813same flags as the system call of the same name. Returns the address
1364113814of the sender if SOCKET's protocol supports this; returns an empty
1364213815string otherwise. If there's an error, returns the undefined value.
1364313816This call is actually implemented in terms of the L<recvfrom(2)> system call.
1364413817See L<perlipc/"UDP: Message Passing"> for examples.
1364513818
1364613819=end original
1364713820
1364813821ソケット上のメッセージを受信します。
1364913822指定されたファイルハンドル SOCKET から、変数 SCALAR に
1365013823LENGTH 文字のデータを読み込もうとします。
1365113824SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。
1365213825同名のシステムコールと同じフラグが指定できます。
1365313826SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。
1365413827エラー発生時には、未定義値を返します。
1365513828実際には、C の L<recvfrom(2)> を呼びます。
1365613829例については L<perlipc/"UDP: Message Passing"> を参照してください。
1365713830
1365813831=begin original
1365913832
1366013833Note that if the socket has been marked as C<:utf8>, C<recv> will
1366113834throw an exception. The C<:encoding(...)> layer implicitly introduces
1366213835the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>.
1366313836
1366413837=end original
1366513838
1366613839ソケットが C<:utf8> としてマークされている場合、
1366713840C<recv> は例外を投げることに注意してください。
1366813841C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。
1366913842L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。
1367013843
1367113844=item redo LABEL
1367213845X<redo>
1367313846
1367413847=item redo EXPR
1367513848
1367613849=item redo
1367713850
1367813851=for Pod::Functions start this loop iteration over again
1367913852
1368013853=begin original
1368113854
1368213855The L<C<redo>|/redo LABEL> command restarts the loop block without
1368313856evaluating the conditional again. The L<C<continue>|/continue BLOCK>
1368413857block, if any, is not executed. If
1368513858the LABEL is omitted, the command refers to the innermost enclosing
1368613859loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a
1368713860label name to be computed at run time, and is otherwise identical to C<redo
1368813861LABEL>. Programs that want to lie to themselves about what was just input
1368913862normally use this command:
1369013863
1369113864=end original
1369213865
1369313866L<C<redo>|/redo LABEL> コマンドは、条件を再評価しないで、ループブロックの
1369413867始めからもう一度実行を開始します。
1369513868L<C<continue>|/continue BLOCK> ブロックがあっても、実行されません。
1369613869LABEL が省略されると、コマンドは一番内側のループを参照します。
1369713870Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が
1369813871使えます; それ以外は C<redo LABEL> と同一です。
1369913872このコマンドは通常、自分への入力を欺くために使用します:
1370013873
1370113874 # a simpleminded Pascal comment stripper
1370213875 # (warning: assumes no { or } in strings)
1370313876 LINE: while (<STDIN>) {
1370413877 while (s|({.*}.*){.*}|$1 |) {}
1370513878 s|{.*}| |;
1370613879 if (s|{.*| |) {
1370713880 my $front = $_;
1370813881 while (<STDIN>) {
1370913882 if (/}/) { # end of comment?
1371013883 s|^|$front\{|;
1371113884 redo LINE;
1371213885 }
1371313886 }
1371413887 }
1371513888 print;
1371613889 }
1371713890
1371813891=begin original
1371913892
1372013893L<C<redo>|/redo LABEL> cannot return a value from a block that typically
1372113894returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
1372213895its flow control behavior, which precludes any return value. It should not be
1372313896used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
1372413897operation.
1372513898
1372613899=end original
1372713900
1372813901L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
1372913902典型的には値を返すブロックから値を返せません。
1373013903これは、返り値を不可能にするフロー制御の振る舞いを実行します。
1373113904L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
1373213905使うべきではありません。
1373313906
1373413907=begin original
1373513908
1373613909Note that a block by itself is semantically identical to a loop
1373713910that executes once. Thus L<C<redo>|/redo LABEL> inside such a block
1373813911will effectively turn it into a looping construct.
1373913912
1374013913=end original
1374113914
1374213915ブロック自身は一回だけ実行されるループと文法的に同一であることに
1374313916注意してください。
1374413917従って、ブロックの中で L<C<redo>|/redo LABEL> を使うことで効果的に
1374513918ループ構造に変換します。
1374613919
1374713920=begin original
1374813921
1374913922See also L<C<continue>|/continue BLOCK> for an illustration of how
1375013923L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
1375113924L<C<redo>|/redo LABEL> work.
1375213925
1375313926=end original
1375413927
1375513928L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
1375613929どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
1375713930
1375813931=begin original
1375913932
1376013933Unlike most named operators, this has the same precedence as assignment.
1376113934It is also exempt from the looks-like-a-function rule, so
1376213935C<redo ("foo")."bar"> will cause "bar" to be part of the argument to
1376313936L<C<redo>|/redo LABEL>.
1376413937
1376513938=end original
1376613939
1376713940ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
1376813941また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と
1376913942すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。
1377013943
1377113944=item ref EXPR
1377213945X<ref> X<reference>
1377313946
1377413947=item ref
1377513948
1377613949=for Pod::Functions find out the type of thing being referenced
1377713950
1377813951=begin original
1377913952
1378013953Examines the value of EXPR, expecting it to be a reference, and returns
1378113954a string giving information about the reference and the type of referent.
1378213955If EXPR is not specified, L<C<$_>|perlvar/$_> will be used.
1378313956
1378413957=end original
1378513958
1378613959Examines the value of
1378713960リファレンスと想定される EXPR の値を調べて、
1378813961そのリファレンスとリファレンス先の型に関する情報を表す
1378913962文字列を返します。
1379013963EXPR が指定されていない場合、L<C<$_>|perlvar/$_> が使われます。
1379113964
1379213965=begin original
1379313966
1379413967If the operand is not a reference, then the empty string will be returned.
1379513968An empty string will only be returned in this situation. C<ref> is often
1379613969useful to just test whether a value is a reference, which can be done
1379713970by comparing the result to the empty string. It is a common mistake
1379813971to use the result of C<ref> directly as a truth value: this goes wrong
1379913972because C<0> (which is false) can be returned for a reference.
1380013973
1380113974=end original
1380213975
1380313976オペランドがリファレンスでない場合、空文字列が返されます。
1380413977空文字列はこの場合にのみ返されます。
1380513978結果を空文字列を比較することでできるので、
1380613979C<ref> は単にある値がリファレンスかどうかを調べるのにしばしば有用です。
1380713980C<ref> の結果を直接真の値として使うのは良くある誤りです:
1380813981リファレンスの場合に (偽である) C<0> が返されることがあるので、
1380913982これは誤りです。
1381013983
1381113984=begin original
1381213985
1381313986If the operand is a reference to a blessed object, then the name of
1381413987the class into which the referent is blessed will be returned. C<ref>
1381513988doesn't care what the physical type of the referent is; blessing takes
1381613989precedence over such concerns. Beware that exact comparison of C<ref>
1381713990results against a class name doesn't perform a class membership test:
1381813991a class's members also include objects blessed into subclasses, for
1381913992which C<ref> will return the name of the subclass. Also beware that
1382013993class names can clash with the built-in type names (described below).
1382113994
1382213995=end original
1382313996
1382413997オペランドが bless されたオブジェクトへのリファレンスの場合、
1382513998リファレンス先が bless されているクラス名が返されます。
1382613999C<ref> はリファレンス先の物理的な種類については気にしません;
1382714000bless されているかがそのような関心より優先されます。
1382814001C<ref> の結果とクラス名の正確な比較は、クラスの所属のテストを
1382914002実行しないことに注意してください:
1383014003C<ref> がサブクラスの名前を返す場合、
1383114004あるクラスのメンバはサブクラスに bless されているオブジェクトを
1383214005含んでいます。
1383314006クラス名は(後述する)組み込みの型名と衝突することにも注意してください。
1383414007
1383514008=begin original
1383614009
1383714010If the operand is a reference to an unblessed object, then the return
1383814011value indicates the type of object. If the unblessed referent is not
1383914012a scalar, then the return value will be one of the strings C<ARRAY>,
1384014013C<HASH>, C<CODE>, C<FORMAT>, or C<IO>, indicating only which kind of
1384114014object it is. If the unblessed referent is a scalar, then the return
1384214015value will be one of the strings C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>,
1384314016C<LVALUE>, or C<REGEXP>, depending on the kind of value the scalar
1384414017currently has. But note that C<qr//> scalars are created already
1384514018blessed, so C<ref qr/.../> will likely return C<Regexp>. Beware that
1384614019these built-in type names can also be used as
1384714020class names, so C<ref> returning one of these names doesn't unambiguously
1384814021indicate that the referent is of the kind to which the name refers.
1384914022
1385014023=end original
1385114024
1385214025オペランドが bless されていないオブジェクトへのリファレンスの場合、
1385314026返り値はオブジェクトの型を示します。
1385414027bless されていないリファレンス先がスカラではない場合、
1385514028返り値はオブジェクトの種類を示す、
1385614029C<ARRAY>, C<HASH>, C<CODE>, C<FORMAT>, C<IO> のいずれかの文字列です。
1385714030bless されていないリファレンス先がスカラの場合、
1385814031返り値はそのスカラが現在保持している種類に依存して、
1385914032C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, C<LVALUE>, C<REGEXP> の
1386014033いずれかの文字列です。
1386114034しかし、C<qr//> は既に bless されて作成されるので、
1386214035C<ref qr/.../> はおそらく C<Regexp> を返すことに注意してください。
1386314036これらの組み込み型名はまたクラス名として使われることができるので、
1386414037C<ref> がこれらの名前の一つを返すことは、
1386514038明らかにリファレンス先がその名前が示している種類のものであることを
1386614039示しているわけではないことに注意してください。
1386714040
1386814041=begin original
1386914042
1387014043The ambiguity between built-in type names and class names significantly
1387114044limits the utility of C<ref>. For unambiguous information, use
1387214045L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> for information about
1387314046blessing, and L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> for
1387414047information about physical types. Use L<the C<isa> method|UNIVERSAL/C<<
1387514048$obj->isa( TYPE ) >>> for class membership tests, though one must be
13876sure of blessedness before attempting a method call.
14049sure of blessedness before attempting a method call. Alternatively, the
14050L<C<isa> operator|perlop/"Class Instance Operator"> can test class
14051membership without checking blessedness first.
1387714052
1387814053=end original
1387914054
1388014055組み込み型とクラス名の間の曖昧さは C<ref> の有用性を大きく制限しています。
1388114056曖昧でない情報のためには、bless に関する情報については
1388214057L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> を、
1388314058物理的な型の情報については
1388414059L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> を使ってください。
1388514060クラスの所属メンバテストには
1388614061L<the C<isa> method|UNIVERSAL/C<<
1388714062$obj->isa( TYPE ) >>> を使ってください;
1388814063但し、メソッド呼び出しを試みる前に bless されていることを
1388914064確認しなければなりません。
14065あるいは、
14066L<C<isa> operator|perlop/"Class Instance Operator"> は、
14067最初に bless されているかを確認することなくクラスメンバをテストできます。
1389014068
1389114069=begin original
1389214070
1389314071See also L<perlref> and L<perlobj>.
1389414072
1389514073=end original
1389614074
1389714075L<perlref> と L<perlobj> も参照してください。
1389814076
1389914077=item rename OLDNAME,NEWNAME
1390014078X<rename> X<move> X<mv> X<ren>
1390114079
1390214080=for Pod::Functions change a filename
1390314081
1390414082=begin original
1390514083
1390614084Changes the name of a file; an existing file NEWNAME will be
13907clobbered. Returns true for success, false otherwise.
14085clobbered. Returns true for success; on failure returns false and sets
14086L<C<$!>|perlvar/$!>.
1390814087
1390914088=end original
1391014089
1391114090ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、
1391214091上書きされるかもしれません。
13913成功時には真を、さもなければ偽を返します
14092成功時には真を返します; 失敗時には偽を返し、
14093L<C<$!>|perlvar/$!> を設定します。
1391414094
1391514095=begin original
1391614096
1391714097Behavior of this function varies wildly depending on your system
1391814098implementation. For example, it will usually not work across file system
1391914099boundaries, even though the system I<mv> command sometimes compensates
1392014100for this. Other restrictions include whether it works on directories,
1392114101open files, or pre-existing files. Check L<perlport> and either the
1392214102L<rename(2)> manpage or equivalent system documentation for details.
1392314103
1392414104=end original
1392514105
1392614106この関数の振る舞いはシステムの実装に大きく依存して異なります。
1392714107例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません;
1392814108システムの I<mv> がこれを補完している場合でもそうです。
1392914109その他の制限には、ディレクトリ、オープンしているファイル、既に存在している
1393014110ファイルに対して使えるか、といったことを含みます。
1393114111詳しくは、L<perlport> および L<rename(2)> man ページあるいは同様の
1393214112システムドキュメントを参照してください。
1393314113
1393414114=begin original
1393514115
1393614116For a platform independent L<C<move>|File::Copy/move> function look at
1393714117the L<File::Copy> module.
1393814118
1393914119=end original
1394014120
1394114121プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については
1394214122L<File::Copy> モジュールを参照してください。
1394314123
1394414124=begin original
1394514125
1394614126Portability issues: L<perlport/rename>.
1394714127
1394814128=end original
1394914129
1395014130移植性の問題: L<perlport/rename>。
1395114131
1395214132=item require VERSION
1395314133X<require>
1395414134
1395514135=item require EXPR
1395614136
1395714137=item require
1395814138
1395914139=for Pod::Functions load in external functions from a library at runtime
1396014140
1396114141=begin original
1396214142
1396314143Demands a version of Perl specified by VERSION, or demands some semantics
1396414144specified by EXPR or by L<C<$_>|perlvar/$_> if EXPR is not supplied.
1396514145
1396614146=end original
1396714147
1396814148VERSION で指定される Perl のバージョンを要求するか、
1396914149EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を
1397014150要求します。
1397114151
1397214152=begin original
1397314153
1397414154VERSION may be either a literal such as v5.24.1, which will be
1397514155compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in L<English>),
1397614156or a numeric argument of the form 5.024001, which will be compared to
1397714157L<C<$]>|perlvar/$]>. An exception is raised if VERSION is greater than
1397814158the version of the current Perl interpreter. Compare with
1397914159L<C<use>|/use Module VERSION LIST>, which can do a similar check at
1398014160compile time.
1398114161
1398214162=end original
1398314163
1398414164VERSION は、v5.24.1 のようなリテラル
1398514165(L<C<$^V>|perlvar/$^V> (または L<English> モジュールでは
1398614166C<$PERL_VERSION>) と比較されます) か、
13987141675.024001 の数値形式(L<C<$]>|perlvar/$]> と比較されます)で指定します。
1398814168VERSION が Perl の現在のバージョンより大きいと、例外が発生します。
1398914169L<C<use>|/use Module VERSION LIST> と似ていますが、これはコンパイル時に
1399014170チェックされます。
1399114171
1399214172=begin original
1399314173
1399414174Specifying VERSION as a numeric argument of the form 5.024001 should
1399514175generally be avoided as older less readable syntax compared to
1399614176v5.24.1. Before perl 5.8.0 (released in 2002), the more verbose numeric
1399714177form was the only supported syntax, which is why you might see it in
1399814178older code.
1399914179
1400014180=end original
1400114181
1400214182VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです;
1400314183v5.24.1 に比べてより古く読みにくい文法だからです。
1400414184(2002 年にリリースされた) perl 5.8.0 より前では、より冗長な
1400514185数値形式が唯一対応している文法でした; これが古いコードでこれを
1400614186見るかも知れない理由です。
1400714187
1400814188=begin original
1400914189
1401014190 require v5.24.1; # run time version check
1401114191 require 5.24.1; # ditto
1401214192 require 5.024_001; # ditto; older syntax compatible
1401314193 with perl 5.6
1401414194
1401514195=end original
1401614196
1401714197 require v5.24.1; # 実行時バージョンチェック
1401814198 require 5.24.1; # 同様
1401914199 require 5.024_001; # 同様; perl 5.6 と互換性のある古い文法
1402014200
1402114201=begin original
1402214202
1402314203Otherwise, L<C<require>|/require VERSION> demands that a library file be
1402414204included if it hasn't already been included. The file is included via
1402514205the do-FILE mechanism, which is essentially just a variety of
1402614206L<C<eval>|/eval EXPR> with the
1402714207caveat that lexical variables in the invoking script will be invisible
1402814208to the included code. If it were implemented in pure Perl, it
1402914209would have semantics similar to the following:
1403014210
1403114211=end original
1403214212
1403314213それ以外の場合には、L<C<require>|/require VERSION> は、既に
1403414214読み込まれていないときに読み込むライブラリファイルを要求するものとなります。
1403514215そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、
1403614216do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は
1403714217読み込まれたコードから見えないという欠点があります。
1403814218ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと
1403914219同じようなものです:
1404014220
1404114221 use Carp 'croak';
1404214222 use version;
1404314223
1404414224 sub require {
1404514225 my ($filename) = @_;
1404614226 if ( my $version = eval { version->parse($filename) } ) {
1404714227 if ( $version > $^V ) {
1404814228 my $vn = $version->normal;
1404914229 croak "Perl $vn required--this is only $^V, stopped";
1405014230 }
1405114231 return 1;
1405214232 }
1405314233
1405414234 if (exists $INC{$filename}) {
1405514235 return 1 if $INC{$filename};
1405614236 croak "Compilation failed in require";
1405714237 }
1405814238
1405914239 foreach $prefix (@INC) {
1406014240 if (ref($prefix)) {
1406114241 #... do other stuff - see text below ....
1406214242 }
1406314243 # (see text below about possible appending of .pmc
1406414244 # suffix to $filename)
1406514245 my $realfilename = "$prefix/$filename";
1406614246 next if ! -e $realfilename || -d _ || -b _;
1406714247 $INC{$filename} = $realfilename;
1406814248 my $result = do($realfilename);
1406914249 # but run in caller's namespace
1407014250
1407114251 if (!defined $result) {
1407214252 $INC{$filename} = undef;
1407314253 croak $@ ? "$@Compilation failed in require"
1407414254 : "Can't locate $filename: $!\n";
1407514255 }
1407614256 if (!$result) {
1407714257 delete $INC{$filename};
1407814258 croak "$filename did not return true value";
1407914259 }
1408014260 $! = 0;
1408114261 return $result;
1408214262 }
1408314263 croak "Can't locate $filename in \@INC ...";
1408414264 }
1408514265
1408614266=begin original
1408714267
1408814268Note that the file will not be included twice under the same specified
1408914269name.
1409014270
1409114271=end original
1409214272
1409314273ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。
1409414274
1409514275=begin original
1409614276
1409714277The file must return true as the last statement to indicate
1409814278successful execution of any initialization code, so it's customary to
1409914279end such a file with C<1;> unless you're sure it'll return true
1410014280otherwise. But it's better just to put the C<1;>, in case you add more
1410114281statements.
1410214282
1410314283=end original
1410414284
1410514285初期化コードの実行がうまくいったことを示すために、ファイルは真を
1410614286返さなければならないので、真を返すようになっている自信がある場合を除いては、
1410714287ファイルの最後に C<1;> と書くのが習慣です。
1410814288しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。
1410914289
1411014290=begin original
1411114291
1411214292If EXPR is a bareword, L<C<require>|/require VERSION> assumes a F<.pm>
1411314293extension and replaces C<::> with C</> in the filename for you,
1411414294to make it easy to load standard modules. This form of loading of
1411514295modules does not risk altering your namespace, however it will autovivify
1411614296the stash for the required module.
1411714297
1411814298=end original
1411914299
1412014300EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、
1412114301L<C<require>|/require VERSION> は拡張子が F<.pm> であり、C<::> を C</> に
1412214302変えたものがファイル名であると仮定します。
1412314303この形式のモジュールロードは、名前空間を変更してしまう危険はありませんが、
1412414304要求されたモジュールのためのスタッシュが自動有効化されます。
1412514305
1412614306=begin original
1412714307
1412814308In other words, if you try this:
1412914309
1413014310=end original
1413114311
1413214312言い換えると、以下のようにすると:
1413314313
1413414314 require Foo::Bar; # a splendid bareword
1413514315
1413614316=begin original
1413714317
1413814318The require function will actually look for the F<Foo/Bar.pm> file in the
1413914319directories specified in the L<C<@INC>|perlvar/@INC> array, and it will
1414014320autovivify the C<Foo::Bar::> stash at compile time.
1414114321
1414214322=end original
1414314323
1414414324require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある
1414514325F<Foo/Bar.pm> ファイルを探し、コンパイル時に
1414614326C<Foo::Bar::> のスタッシュを自動有効化します。
1414714327
1414814328=begin original
1414914329
1415014330But if you try this:
1415114331
1415214332=end original
1415314333
1415414334しかし、以下のようにすると:
1415514335
1415614336 my $class = 'Foo::Bar';
1415714337 require $class; # $class is not a bareword
1415814338 #or
1415914339 require "Foo::Bar"; # not a bareword because of the ""
1416014340
1416114341=begin original
1416214342
1416314343The require function will look for the F<Foo::Bar> file in the
1416414344L<C<@INC>|perlvar/@INC> array and
1416514345will complain about not finding F<Foo::Bar> there. In this case you can do:
1416614346
1416714347=end original
1416814348
1416914349require 関数は L<C<@INC>|perlvar/@INC> 配列の F<Foo::Bar> ファイルを探し、
1417014350おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。
1417114351このような場合には、以下のように:
1417214352
1417314353 eval "require $class";
1417414354
1417514355=begin original
1417614356
1417714357or you could do
1417814358
1417914359=end original
1418014360
1418114361あるいは次のようにも出来ます
1418214362
1418314363 require "Foo/Bar.pm";
1418414364
1418514365=begin original
1418614366
1418714367Neither of these forms will autovivify any stashes at compile time and
1418814368only have run time effects.
1418914369
1419014370=end original
1419114371
1419214372これらのどちらもコンパイル時にスタッシュを自動有効化せず、
1419314373実行時の効果のみを持ちます。
1419414374
1419514375=begin original
1419614376
1419714377Now that you understand how L<C<require>|/require VERSION> looks for
1419814378files with a bareword argument, there is a little extra functionality
1419914379going on behind the scenes. Before L<C<require>|/require VERSION> looks
1420014380for a F<.pm> extension, it will first look for a similar filename with a
1420114381F<.pmc> extension. If this file is found, it will be loaded in place of
1420214382any file ending in a F<.pm> extension. This applies to both the explicit
1420314383C<require "Foo/Bar.pm";> form and the C<require Foo::Bar;> form.
1420414384
1420514385=end original
1420614386
1420714387引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを
1420814388探すかを理解してください; 水面下でちょっとした追加の機能があります。
1420914389L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず
1421014390拡張子 F<.pmc> を持つファイルを探します。
1421114391このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに
1421214392読み込まれます。
1421314393これは明示的な C<require "Foo/Bar.pm";> 形式と C<require Foo::Bar;> 形式の
1421414394両方に適用されます。
1421514395
1421614396=begin original
1421714397
1421814398You can also insert hooks into the import facility by putting Perl code
1421914399directly into the L<C<@INC>|perlvar/@INC> array. There are three forms
1422014400of hooks: subroutine references, array references, and blessed objects.
1422114401
1422214402=end original
1422314403
1422414404L<C<@INC>|perlvar/@INC> 配列に直接 Perl コードを入れることで、インポート機能に
1422514405フックを挿入できます。
14226144063 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、
1422714407bless されたオブジェクトです。
1422814408
1422914409=begin original
1423014410
1423114411Subroutine references are the simplest case. When the inclusion system
1423214412walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, this
1423314413subroutine gets called with two parameters, the first a reference to
1423414414itself, and the second the name of the file to be included (e.g.,
1423514415F<Foo/Bar.pm>). The subroutine should return either nothing or else a
1423614416list of up to four values in the following order:
1423714417
1423814418=end original
1423914419
1424014420サブルーチンへのリファレンスは一番単純な場合です。
1424114421インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに
1424214422出会った場合、このサブルーチンは二つの引数と共に呼び出されます;
1424314423一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名
1424414424(F<Foo/Bar.pm> など)です。
1424514425サブルーチンは何も返さないか、以下の順で最大四つの値のリストを返します。
1424614426
1424714427=over
1424814428
1424914429=item 1
1425014430
1425114431=begin original
1425214432
1425314433A reference to a scalar, containing any initial source code to prepend to
1425414434the file or generator output.
1425514435
1425614436=end original
1425714437
1425814438ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む
1425914439スカラへのリファレンス。
1426014440
1426114441=item 2
1426214442
1426314443=begin original
1426414444
1426514445A filehandle, from which the file will be read.
1426614446
1426714447=end original
1426814448
1426914449ファイルが読み込まれるファイルハンドル。
1427014450
1427114451=item 3
1427214452
1427314453=begin original
1427414454
1427514455A reference to a subroutine. If there is no filehandle (previous item),
1427614456then this subroutine is expected to generate one line of source code per
1427714457call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then
1427814458finally at end of file returning 0. If there is a filehandle, then the
1427914459subroutine will be called to act as a simple source filter, with the
1428014460line as read in L<C<$_>|perlvar/$_>.
1428114461Again, return 1 for each valid line, and 0 after all lines have been
1428214462returned.
1428314463For historical reasons the subroutine will receive a meaningless argument
1428414464(in fact always the numeric value zero) as C<$_[0]>.
1428514465
1428614466=end original
1428714467
1428814468サブルーチンへのリファレンス。
1428914469(一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に
1429014470一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_> に書き込んで 1 を
1429114471返し、それから最終的にファイル終端で 0 を返すものと想定されます。
1429214472ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして
1429314473振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。
1429414474再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。
1429514475歴史的な理由により、サブルーチンは C<$_[0]> として意味のない引数
1429614476(実際には常に数値 0) を受け取ります。
1429714477
1429814478=item 4
1429914479
1430014480=begin original
1430114481
1430214482Optional state for the subroutine. The state is passed in as C<$_[1]>.
1430314483
1430414484=end original
1430514485
1430614486サブルーチンのための状態(オプション)。
1430714487状態は C<$_[1]> として渡されます。
1430814488
1430914489=back
1431014490
1431114491=begin original
1431214492
1431314493If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the
1431414494first 3 values above is returned, then L<C<require>|/require VERSION>
1431514495looks at the remaining elements of L<C<@INC>|perlvar/@INC>.
1431614496Note that this filehandle must be a real filehandle (strictly a typeglob
1431714497or reference to a typeglob, whether blessed or unblessed); tied filehandles
1431814498will be ignored and processing will stop there.
1431914499
1432014500=end original
1432114501
1432214502空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも
1432314503一致しないものが返されると、L<C<require>|/require VERSION> は
1432414504L<C<@INC>|perlvar/@INC> の残りの要素を見ます。
1432514505このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの
1432614506リファレンス、bless されているかに関わらず)でなければなりません;
1432714507tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。
1432814508
1432914509=begin original
1433014510
1433114511If the hook is an array reference, its first element must be a subroutine
1433214512reference. This subroutine is called as above, but the first parameter is
1433314513the array reference. This lets you indirectly pass arguments to
1433414514the subroutine.
1433514515
1433614516=end original
1433714517
1433814518フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの
1433914519リファレンスでなければなりません。
1434014520このサブルーチンは上述のように呼び出されますが、その最初の引数は
1434114521配列のリファレンスです。
1434214522これによって、間接的にサブルーチンに引数を渡すことが出来ます。
1434314523
1434414524=begin original
1434514525
1434614526In other words, you can write:
1434714527
1434814528=end original
1434914529
1435014530言い換えると、以下のように書いたり:
1435114531
1435214532 push @INC, \&my_sub;
1435314533 sub my_sub {
1435414534 my ($coderef, $filename) = @_; # $coderef is \&my_sub
1435514535 ...
1435614536 }
1435714537
1435814538=begin original
1435914539
1436014540or:
1436114541
1436214542=end original
1436314543
1436414544または以下のように書けます:
1436514545
1436614546 push @INC, [ \&my_sub, $x, $y, ... ];
1436714547 sub my_sub {
1436814548 my ($arrayref, $filename) = @_;
1436914549 # Retrieve $x, $y, ...
1437014550 my (undef, @parameters) = @$arrayref;
1437114551 ...
1437214552 }
1437314553
1437414554=begin original
1437514555
1437614556If the hook is an object, it must provide an C<INC> method that will be
1437714557called as above, the first parameter being the object itself. (Note that
1437814558you must fully qualify the sub's name, as unqualified C<INC> is always forced
1437914559into package C<main>.) Here is a typical code layout:
1438014560
1438114561=end original
1438214562
1438314563フックがオブジェクトの場合、C<INC> メソッドを提供している必要があります;
1438414564それが、最初の引数をオブジェクト自身として上述のように呼び出されます。
1438514565(修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、
1438614566サブルーチン名は完全修飾する必要があることに注意してください。)
1438714567以下は典型的なコードレイアウトです:
1438814568
1438914569 # In Foo.pm
1439014570 package Foo;
1439114571 sub new { ... }
1439214572 sub Foo::INC {
1439314573 my ($self, $filename) = @_;
1439414574 ...
1439514575 }
1439614576
1439714577 # In the main program
1439814578 push @INC, Foo->new(...);
1439914579
1440014580=begin original
1440114581
1440214582These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry
1440314583corresponding to the files they have loaded. See L<perlvar/%INC>.
1440414584
1440514585=end original
1440614586
1440714587これらのフックは、読み込まれるファイルに対応する
1440814588L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。
1440914589L<perlvar/%INC> を参照してください。
1441014590
1441114591=begin original
1441214592
1441314593For a yet-more-powerful import facility, see
1441414594L<C<use>|/use Module VERSION LIST> and L<perlmod>.
1441514595
1441614596=end original
1441714597
1441814598より強力な import 機能については、このドキュメントの
1441914599L<C<use>|/use Module VERSION LIST> の項と、L<perlmod> を参照してください。
1442014600
1442114601=item reset EXPR
1442214602X<reset>
1442314603
1442414604=item reset
1442514605
1442614606=for Pod::Functions clear all variables of a given name
1442714607
1442814608=begin original
1442914609
1443014610Generally used in a L<C<continue>|/continue BLOCK> block at the end of a
1443114611loop to clear variables and reset C<m?pattern?> searches so that they
1443214612work again. The
1443314613expression is interpreted as a list of single characters (hyphens
1443414614allowed for ranges). All variables (scalars, arrays, and hashes)
1443514615in the current package beginning with one of
1443614616those letters are reset to their pristine state. If the expression is
1443714617omitted, one-match searches (C<m?pattern?>) are reset to match again.
1443814618Only resets variables or searches in the current package. Always returns
14439146191. Examples:
1444014620
1444114621=end original
1444214622
1444314623通常、ループの最後に、変数をクリアし、C<m?pattern?> 検索を再び動作するように
1444414624リセットするため、L<C<continue>|/continue BLOCK> ブロックで使われます。
1444514625EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と
1444614626解釈されます。
1444714627名前がその文字のいずれかで始まる、現在のパッケージの全ての変数
1444814628(スカラ、配列、ハッシュ)は、
1444914629最初の状態にリセットされます。
1445014630EXPR を省略すると、1 回検索 (C<m?pattern?>) を再びマッチするように
1445114631リセットできます。
1445214632カレントパッケージの変数もしくは検索だけがリセットされます。
1445314633常に 1 を返します。
1445414634例:
1445514635
1445614636 reset 'X'; # reset all X variables
1445714637 reset 'a-z'; # reset lower case variables
1445814638 reset; # just reset m?one-time? searches
1445914639
1446014640=begin original
1446114641
1446214642Resetting C<"A-Z"> is not recommended because you'll wipe out your
1446314643L<C<@ARGV>|perlvar/@ARGV> and L<C<@INC>|perlvar/@INC> arrays and your
1446414644L<C<%ENV>|perlvar/%ENV> hash.
1446514645
1446614646=end original
1446714647
1446814648reset C<"A-Z"> とすると、L<C<@ARGV>|perlvar/@ARGV>,
1446914649L<C<@INC>|perlvar/@INC> 配列や L<C<%ENV>|perlvar/%ENV> ハッシュも
1447014650なくなってしまうので、止めた方が良いでしょう。
1447114651
1447214652=begin original
1447314653
1447414654Resets only package variables; lexical variables are unaffected, but
1447514655they clean themselves up on scope exit anyway, so you'll probably want
1447614656to use them instead. See L<C<my>|/my VARLIST>.
1447714657
1447814658=end original
1447914659
1448014660パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、
1448114661スコープから外れれば自動的に綺麗になるので、これからはこちらを
1448214662使うようにした方がよいでしょう。
1448314663L<C<my>|/my VARLIST> を参照してください。
1448414664
1448514665=item return EXPR
1448614666X<return>
1448714667
1448814668=item return
1448914669
1449014670=for Pod::Functions get out of a function early
1449114671
1449214672=begin original
1449314673
1449414674Returns from a subroutine, L<C<eval>|/eval EXPR>,
1449514675L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex
1449614676eval block (but not a L<C<grep>|/grep BLOCK LIST>,
1449714677L<C<map>|/map BLOCK LIST>, or L<C<do BLOCK>|/do BLOCK> block) with the value
1449814678given in EXPR. Evaluation of EXPR may be in list, scalar, or void
1449914679context, depending on how the return value will be used, and the context
1450014680may vary from one execution to the next (see
1450114681L<C<wantarray>|/wantarray>). If no EXPR
1450214682is given, returns an empty list in list context, the undefined value in
1450314683scalar context, and (of course) nothing at all in void context.
1450414684
1450514685=end original
1450614686
1450714687サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR>,
1450814688L<C<sort>|/sort SUBNAME LIST> ブロックまたは正規表現 eval ブロック
1450914689(但し L<C<grep>|/grep BLOCK LIST>,
1451014690L<C<map>|/map BLOCK LIST>, L<C<do BLOCK>|/do BLOCK> ブロックではない) から
1451114691EXPR で与えられた値をもって、リターンします。
1451214692EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、
1451314693無効コンテキストになります; またコンテキストは実行毎に変わります
1451414694(L<C<wantarray>|/wantarray> を参照してください)。
1451514695EXPR が指定されなかった場合は、リストコンテキストでは空リストを、
1451614696スカラコンテキストでは未定義値を返します; そして(もちろん)
1451714697無効コンテキストでは何も返しません。
1451814698
1451914699=begin original
1452014700
1452114701(In the absence of an explicit L<C<return>|/return EXPR>, a subroutine,
1452214702L<C<eval>|/eval EXPR>,
1452314703or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression
1452414704evaluated.)
1452514705
1452614706=end original
1452714707
1452814708(サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR> に明示的に
1452914709L<C<return>|/return EXPR> がなければ、最後に評価された値で、
1453014710自動的にリターンします。)
1453114711
1453214712=begin original
1453314713
1453414714Unlike most named operators, this is also exempt from the
1453514715looks-like-a-function rule, so C<return ("foo")."bar"> will
1453614716cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>.
1453714717
1453814718=end original
1453914719
1454014720ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも
1454114721免れるので、C<return ("foo")."bar"> とすると C<"bar"> は
1454214722L<C<return>|/return EXPR> への引数の一部となります。
1454314723
1454414724=item reverse LIST
1454514725X<reverse> X<rev> X<invert>
1454614726
1454714727=for Pod::Functions flip a string or a list
1454814728
1454914729=begin original
1455014730
1455114731In list context, returns a list value consisting of the elements
1455214732of LIST in the opposite order. In scalar context, concatenates the
1455314733elements of LIST and returns a string value with all characters
1455414734in the opposite order.
1455514735
1455614736=end original
1455714737
1455814738リストコンテキストでは、LIST を構成する要素を逆順に並べた
1455914739リスト値を返します。
1456014740スカラコンテキストでは、LIST の要素を連結して、
1456114741全ての文字を逆順にした文字列を返します。
1456214742
1456314743 print join(", ", reverse "world", "Hello"); # Hello, world
1456414744
1456514745 print scalar reverse "dlrow ,", "olleH"; # Hello, world
1456614746
1456714747=begin original
1456814748
1456914749Used without arguments in scalar context, L<C<reverse>|/reverse LIST>
1457014750reverses L<C<$_>|perlvar/$_>.
1457114751
1457214752=end original
1457314753
1457414754スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST> は
1457514755L<C<$_>|perlvar/$_> を逆順にします。
1457614756
1457714757 $_ = "dlrow ,olleH";
1457814758 print reverse; # No output, list context
1457914759 print scalar reverse; # Hello, world
1458014760
1458114761=begin original
1458214762
1458314763Note that reversing an array to itself (as in C<@a = reverse @a>) will
1458414764preserve non-existent elements whenever possible; i.e., for non-magical
1458514765arrays or for tied arrays with C<EXISTS> and C<DELETE> methods.
1458614766
1458714767=end original
1458814768
1458914769(C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、
1459014770存在しない要素は可能なら(つまりマジカルでない配列や
1459114771C<EXISTS> と C<DELETE> メソッドがある tie された配列)
1459214772いつでも保存されることに注意してください。
1459314773
1459414774=begin original
1459514775
1459614776This operator is also handy for inverting a hash, although there are some
1459714777caveats. If a value is duplicated in the original hash, only one of those
1459814778can be represented as a key in the inverted hash. Also, this has to
1459914779unwind one hash and build a whole new one, which may take some time
1460014780on a large hash, such as from a DBM file.
1460114781
1460214782=end original
1460314783
1460414784この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。
1460514785元のハッシュで値が重複していると、それらのうち一つだけが
1460614786逆順になったハッシュのキーとして表現されます。
1460714787また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、
1460814788DBM ファイルからのような大きなハッシュでは少し時間がかかります。
1460914789
1461014790 my %by_name = reverse %by_address; # Invert the hash
1461114791
1461214792=item rewinddir DIRHANDLE
1461314793X<rewinddir>
1461414794
1461514795=for Pod::Functions reset directory handle
1461614796
1461714797=begin original
1461814798
1461914799Sets the current position to the beginning of the directory for the
1462014800L<C<readdir>|/readdir DIRHANDLE> routine on DIRHANDLE.
1462114801
1462214802=end original
1462314803
1462414804DIRHANDLE に対する L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
1462514805ディレクトリの最初に設定します。
1462614806
1462714807=begin original
1462814808
1462914809Portability issues: L<perlport/rewinddir>.
1463014810
1463114811=end original
1463214812
1463314813移植性の問題: L<perlport/rewinddir>。
1463414814
1463514815=item rindex STR,SUBSTR,POSITION
1463614816X<rindex>
1463714817
1463814818=item rindex STR,SUBSTR
1463914819
1464014820=for Pod::Functions right-to-left substring search
1464114821
1464214822=begin original
1464314823
1464414824Works just like L<C<index>|/index STR,SUBSTR,POSITION> except that it
1464514825returns the position of the I<last>
1464614826occurrence of SUBSTR in STR. If POSITION is specified, returns the
1464714827last occurrence beginning at or before that position.
1464814828
1464914829=end original
1465014830
1465114831STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、
1465214832L<C<index>|/index STR,SUBSTR,POSITION> と同じように動作します。
1465314833POSITION を指定すると、その位置から始まるか、その位置より前の、
1465414834最後の位置を返します。
1465514835
1465614836=item rmdir FILENAME
1465714837X<rmdir> X<rd> X<directory, remove>
1465814838
1465914839=item rmdir
1466014840
1466114841=for Pod::Functions remove a directory
1466214842
1466314843=begin original
1466414844
1466514845Deletes the directory specified by FILENAME if that directory is
1466614846empty. If it succeeds it returns true; otherwise it returns false and
1466714847sets L<C<$!>|perlvar/$!> (errno). If FILENAME is omitted, uses
1466814848L<C<$_>|perlvar/$_>.
1466914849
1467014850=end original
1467114851
1467214852FILENAME で指定したディレクトリが空であれば、
1467314853そのディレクトリを削除します。
14674成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!> (errno) を
14854成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!>
14675設定します。
14855(errno) を設定します。
1467614856FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。
1467714857
1467814858=begin original
1467914859
1468014860To remove a directory tree recursively (C<rm -rf> on Unix) look at
1468114861the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path>
1468214862module.
1468314863
1468414864=end original
1468514865
1468614866ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、
1468714867L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を
1468814868参照してください。
1468914869
1469014870=item s///
1469114871
1469214872=for Pod::Functions replace a pattern with a string
1469314873
1469414874=begin original
1469514875
1469614876The substitution operator. See L<perlop/"Regexp Quote-Like Operators">.
1469714877
1469814878=end original
1469914879
1470014880置換演算子。
1470114881L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1470214882
1470314883=item say FILEHANDLE LIST
1470414884X<say>
1470514885
1470614886=item say FILEHANDLE
1470714887
1470814888=item say LIST
1470914889
1471014890=item say
1471114891
1471214892=for Pod::Functions +say output a list to a filehandle, appending a newline
1471314893
1471414894=begin original
1471514895
1471614896Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a
1471714897newline at the end of the LIST instead of any value L<C<$\>|perlvar/$\>
1471814898might have. To use FILEHANDLE without a LIST to
1471914899print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword
1472014900filehandle like C<FH>, not an indirect one like C<$fh>.
1472114901
1472214902=end original
1472314903
1472414904L<C<print>|/print FILEHANDLE LIST> と同様ですが、
1472514905L<C<$\>|perlvar/$\> の値の代わりに LIST の末尾に
1472614906改行が暗黙に追加されます。
1472714907L<C<$_>|perlvar/$_> の内容を表示するために LIST なしで FILEHANDLE を
1472814908使用するには、C<$fh> のような間接ファイルハンドルではなく、C<FH> のような
1472914909裸の単語のファイルハンドルを使わなければなりません。
1473014910
1473114911=begin original
1473214912
1473314913L<C<say>|/say FILEHANDLE LIST> is available only if the
1473414914L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
1473514915prefixed with C<CORE::>. The
1473614916L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
1473714917with a C<use v5.10> (or higher) declaration in the current scope.
1473814918
1473914919=end original
1474014920
1474114921L<C<say>|/say FILEHANDLE LIST> は
1474214922L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
1474314923前置されたときにのみ利用可能です。
1474414924L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
1474514925C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
1474614926
1474714927=item scalar EXPR
1474814928X<scalar> X<context>
1474914929
1475014930=for Pod::Functions force a scalar context
1475114931
1475214932=begin original
1475314933
1475414934Forces EXPR to be interpreted in scalar context and returns the value
1475514935of EXPR.
1475614936
1475714937=end original
1475814938
1475914939EXPR を強制的にスカラコンテキストで解釈されるようにして、
1476014940EXPR の値を返します。
1476114941
1476214942 my @counts = ( scalar @a, scalar @b, scalar @c );
1476314943
1476414944=begin original
1476514945
1476614946There is no equivalent operator to force an expression to
1476714947be interpolated in list context because in practice, this is never
1476814948needed. If you really wanted to do so, however, you could use
1476914949the construction C<@{[ (some expression) ]}>, but usually a simple
1477014950C<(some expression)> suffices.
1477114951
1477214952=end original
1477314953
1477414954式を強制的にリストコンテキストで解釈させるようにする演算子はありません;
1477514955理論的には不要だからです。
1477614956それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を
1477714957使えます; しかし、普通は単に C<(some expression)> とすれば十分です。
1477814958
1477914959=begin original
1478014960
1478114961Because L<C<scalar>|/scalar EXPR> is a unary operator, if you
1478214962accidentally use a
1478314963parenthesized list for the EXPR, this behaves as a scalar comma expression,
1478414964evaluating all but the last element in void context and returning the final
1478514965element evaluated in scalar context. This is seldom what you want.
1478614966
1478714967=end original
1478814968
1478914969L<C<scalar>|/scalar EXPR> は単項演算子なので、EXPR として括弧でくくった
1479014970リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては
1479114971無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った
1479214972結果が返されます。
1479314973これがあなたの望むものであることはめったにないでしょう。
1479414974
1479514975=begin original
1479614976
1479714977The following single statement:
1479814978
1479914979=end original
1480014980
1480114981以下の一つの文は:
1480214982
1480314983 print uc(scalar(foo(), $bar)), $baz;
1480414984
1480514985=begin original
1480614986
1480714987is the moral equivalent of these two:
1480814988
1480914989=end original
1481014990
1481114991以下の二つの文と等価です。
1481214992
1481314993 foo();
1481414994 print(uc($bar), $baz);
1481514995
1481614996=begin original
1481714997
1481814998See L<perlop> for more details on unary operators and the comma operator,
14819and L<perldata> for details on evaluating a hash in scalar contex.
14999and L<perldata> for details on evaluating a hash in scalar context.
1482015000
1482115001=end original
1482215002
1482315003単項演算子とカンマ演算子に関する詳細については L<perlop> を、
1482415004スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を
1482515005参照してください。
1482615006
1482715007=item seek FILEHANDLE,POSITION,WHENCE
1482815008X<seek> X<fseek> X<filehandle, position>
1482915009
1483015010=for Pod::Functions reposition file pointer for random-access I/O
1483115011
1483215012=begin original
1483315013
1483415014Sets FILEHANDLE's position, just like the L<fseek(3)> call of C C<stdio>.
1483515015FILEHANDLE may be an expression whose value gives the name of the
1483615016filehandle. The values for WHENCE are C<0> to set the new position
1483715017I<in bytes> to POSITION; C<1> to set it to the current position plus
1483815018POSITION; and C<2> to set it to EOF plus POSITION, typically
1483915019negative. For WHENCE you may use the constants C<SEEK_SET>,
1484015020C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end
1484115021of the file) from the L<Fcntl> module. Returns C<1> on success, false
1484215022otherwise.
1484315023
1484415024=end original
1484515025
1484615026C の C<stdio> ライブラリの L<fseek(3)> 関数のように、FILEHANDLE の
1484715027ファイルポインタを任意の位置に設定します。
1484815028FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1484915029WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ
1485015030設定します; C<1> ならば、現在位置から POSITION 加えた位置へ
1485115031設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を
1485215032設定します。
1485315033この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、
1485415034C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1485515035使うこともできます。
1485615036成功時には、C<1> を、失敗時にはそれ以外を返します。
1485715037
1485815038=begin original
1485915039
1486015040Note the emphasis on bytes: even if the filehandle has been set to operate
1486115041on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
1486215042L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1486315043L<C<tell>|/tell FILEHANDLE>, and
1486415044L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
1486515045family of functions use byte offsets, not character offsets,
1486615046because seeking to a character offset would be very slow in a UTF-8 file.
1486715047
1486815048=end original
1486915049
1487015050バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
1487115051ファイルハンドルが文字単位で処理するように設定されていたとしても、
1487215052L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1487315053L<C<tell>|/tell FILEHANDLE>,
1487415054L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
1487515055文字オフセットではなくバイトオフセットを使います;
1487615056文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1487715057
1487815058=begin original
1487915059
1488015060If you want to position the file for
1488115061L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or
1488215062L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use
1488315063L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its
1488415064effect on the file's read-write position unpredictable and non-portable.
1488515065Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead.
1488615066
1488715067=end original
1488815068
1488915069L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> や
1489015070L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの
1489115071位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は
1489215072使えません; なぜならバッファリングのためにファイルの読み込み位置は
1489315073動作は予測不能で移植性のないものになってしまいます。
1489415074代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。
1489515075
1489615076=begin original
1489715077
1489815078Due to the rules and rigors of ANSI C, on some systems you have to do a
1489915079seek whenever you switch between reading and writing. Amongst other
1490015080things, this may have the effect of calling stdio's L<clearerr(3)>.
1490115081A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position:
1490215082
1490315083=end original
1490415084
1490515085ANSI C の規則と困難により、システムによっては読み込みと書き込みを
1490615086切り替える度にシークしなければならない場合があります。
1490715087その他のことの中で、これは stdio の L<clearerr(3)> を呼び出す効果があります。
1490815088WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です:
1490915089
1491015090 seek($fh, 0, 1);
1491115091
1491215092=begin original
1491315093
1491415094This is also useful for applications emulating C<tail -f>. Once you hit
1491515095EOF on your read and then sleep for a while, you (probably) have to stick in a
1491615096dummy L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to reset things. The
1491715097L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position,
1491815098but it I<does> clear the end-of-file condition on the handle, so that the
1491915099next C<readline FILE> makes Perl try again to read something. (We hope.)
1492015100
1492115101=end original
1492215102
1492315103これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。
1492415104一度読み込み時に EOF に到達すると、しばらくスリープし、
1492515105(おそらく) ダミーの L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> をすることで
1492615106リセットする必要があります。
1492715107L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は現在の位置を変更しませんが、
1492815108ハンドルの EOF 状態をI<クリアします> ので、次の C<readline FILE> で Perl は
1492915109再び何かを読み込もうとします。(そのはずです。)
1493015110
1493115111=begin original
1493215112
1493315113If that doesn't work (some I/O implementations are particularly
1493415114cantankerous), you might need something like this:
1493515115
1493615116=end original
1493715117
1493815118これが動かない場合(特に意地の悪い I/O 実装もあります)、
1493915119以下のようなことをする必要があります:
1494015120
1494115121 for (;;) {
1494215122 for ($curpos = tell($fh); $_ = readline($fh);
1494315123 $curpos = tell($fh)) {
1494415124 # search for some stuff and put it into files
1494515125 }
1494615126 sleep($for_a_while);
1494715127 seek($fh, $curpos, 0);
1494815128 }
1494915129
1495015130=item seekdir DIRHANDLE,POS
1495115131X<seekdir>
1495215132
1495315133=for Pod::Functions reposition directory pointer
1495415134
1495515135=begin original
1495615136
1495715137Sets the current position for the L<C<readdir>|/readdir DIRHANDLE>
1495815138routine on DIRHANDLE. POS must be a value returned by
1495915139L<C<telldir>|/telldir DIRHANDLE>. L<C<seekdir>|/seekdir DIRHANDLE,POS>
1496015140also has the same caveats about possible directory compaction as the
1496115141corresponding system library routine.
1496215142
1496315143=end original
1496415144
1496515145DIRHANDLE での L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
1496615146設定します。
1496715147POS は、L<C<telldir>|/telldir DIRHANDLE> が返す値でなければなりません。
1496815148L<C<seekdir>|/seekdir DIRHANDLE,POS> は同名のシステムライブラリルーチンと
1496915149同じく、ディレクトリ縮小時の問題が考えられます。
1497015150
1497115151=item select FILEHANDLE
1497215152X<select> X<filehandle, default>
1497315153
1497415154=item select
1497515155
1497615156=for Pod::Functions reset default output or do I/O multiplexing
1497715157
1497815158=begin original
1497915159
1498015160Returns the currently selected filehandle. If FILEHANDLE is supplied,
1498115161sets the new current default filehandle for output. This has two
1498215162effects: first, a L<C<write>|/write FILEHANDLE> or a L<C<print>|/print
1498315163FILEHANDLE LIST> without a filehandle
1498415164default to this FILEHANDLE. Second, references to variables related to
1498515165output will refer to this output channel.
1498615166
1498715167=end original
1498815168
1498915169その時点で、選択されていたファイルハンドルを返します。
1499015170FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに
1499115171設定します。
1499215172これには、2 つの効果があります: まず、ファイルハンドルを指定しないで
1499315173L<C<write>|/write FILEHANDLE> や L<C<print>|/print FILEHANDLE LIST> を
1499415174行なった場合のデフォルトが、この FILEHANDLE になります。
1499515175もう一つは、出力関連の変数への参照は、この出力チャネルを
1499615176参照するようになります。
1499715177
1499815178=begin original
1499915179
1500015180For example, to set the top-of-form format for more than one
1500115181output channel, you might do the following:
1500215182
1500315183=end original
1500415184
1500515185例えば、複数の出力チャネルに対して、ページ先頭フォーマットを
1500615186設定するには:
1500715187
1500815188 select(REPORT1);
1500915189 $^ = 'report1_top';
1501015190 select(REPORT2);
1501115191 $^ = 'report2_top';
1501215192
1501315193=begin original
1501415194
1501515195FILEHANDLE may be an expression whose value gives the name of the
1501615196actual filehandle. Thus:
1501715197
1501815198=end original
1501915199
1502015200FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
1502115201つまり、以下のようなものです:
1502215202
1502315203 my $oldfh = select(STDERR); $| = 1; select($oldfh);
1502415204
1502515205=begin original
1502615206
1502715207Some programmers may prefer to think of filehandles as objects with
1502815208methods, preferring to write the last example as:
1502915209
1503015210=end original
1503115211
1503215212ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む
1503315213プログラマもいるかもしれません; そのような場合のための最後の例は
1503415214以下のようなものです:
1503515215
1503615216 STDERR->autoflush(1);
1503715217
1503815218=begin original
1503915219
1504015220(Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly
1504115221first.)
1504215222
1504315223=end original
1504415224
1504515225(Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする
1504615226必要があります。)
1504715227
1504815228=begin original
1504915229
1505015230Portability issues: L<perlport/select>.
1505115231
1505215232=end original
1505315233
1505415234移植性の問題: L<perlport/select>。
1505515235
1505615236=item select RBITS,WBITS,EBITS,TIMEOUT
1505715237X<select>
1505815238
1505915239=begin original
1506015240
1506115241This calls the L<select(2)> syscall with the bit masks specified, which
1506215242can be constructed using L<C<fileno>|/fileno FILEHANDLE> and
1506315243L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines:
1506415244
1506515245=end original
1506615246
1506715247これは、L<select(2)> システムコールを、指定したビットマスクで呼び出します;
1506815248ビットマスクは、L<C<fileno>|/fileno FILEHANDLE> と
1506915249L<C<vec>|/vec EXPR,OFFSET,BITS> を使って、以下のようにして作成できます:
1507015250
1507115251 my $rin = my $win = my $ein = '';
1507215252 vec($rin, fileno(STDIN), 1) = 1;
1507315253 vec($win, fileno(STDOUT), 1) = 1;
1507415254 $ein = $rin | $win;
1507515255
1507615256=begin original
1507715257
1507815258If you want to select on many filehandles, you may wish to write a
1507915259subroutine like this:
1508015260
1508115261=end original
1508215262
1508315263複数のファイルハンドルに select を行ないたいのであれば、
1508415264以下のようにします:
1508515265
1508615266 sub fhbits {
1508715267 my @fhlist = @_;
1508815268 my $bits = "";
1508915269 for my $fh (@fhlist) {
1509015270 vec($bits, fileno($fh), 1) = 1;
1509115271 }
1509215272 return $bits;
1509315273 }
1509415274 my $rin = fhbits(\*STDIN, $tty, $mysock);
1509515275
1509615276=begin original
1509715277
1509815278The usual idiom is:
1509915279
1510015280=end original
1510115281
1510215282通常は、
1510315283
1510415284 my ($nfound, $timeleft) =
1510515285 select(my $rout = $rin, my $wout = $win, my $eout = $ein,
1510615286 $timeout);
1510715287
1510815288=begin original
1510915289
1511015290or to block until something becomes ready just do this
1511115291
1511215292=end original
1511315293
1511415294のように使い、いずれかの準備が整うまでブロックするには、
1511515295以下のようにします。
1511615296
1511715297 my $nfound =
1511815298 select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef);
1511915299
1512015300=begin original
1512115301
1512215302Most systems do not bother to return anything useful in C<$timeleft>, so
1512315303calling L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context
1512415304just returns C<$nfound>.
1512515305
1512615306=end original
1512715307
1512815308ほとんどのシステムではわざわざ意味のある値を C<$timeleft> に返さないので、
1512915309L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> をスカラコンテキストで
1513015310呼び出すと、単に C<$nfound> を返します。
1513115311
1513215312=begin original
1513315313
1513415314Any of the bit masks can also be L<C<undef>|/undef EXPR>. The timeout,
1513515315if specified, is
1513615316in seconds, which may be fractional. Note: not all implementations are
1513715317capable of returning the C<$timeleft>. If not, they always return
1513815318C<$timeleft> equal to the supplied C<$timeout>.
1513915319
1514015320=end original
1514115321
1514215322どのビットマスクにも L<C<undef>|/undef EXPR> を設定することができます。
1514315323TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。
1514415324注: すべての実装で、C<$timeleft> が返せるものではありません。
1514515325その場合、C<$timeleft> には、常に指定した C<$timeout> と同じ値が返されます。
1514615326
1514715327=begin original
1514815328
1514915329You can effect a sleep of 250 milliseconds this way:
1515015330
1515115331=end original
1515215332
1515315333250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。
1515415334
1515515335 select(undef, undef, undef, 0.25);
1515615336
1515715337=begin original
1515815338
1515915339Note that whether L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> gets
1516015340restarted after signals (say, SIGALRM) is implementation-dependent. See
1516115341also L<perlport> for notes on the portability of
1516215342L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>.
1516315343
1516415344=end original
1516515345
1516615346L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> がシグナル (例えば、SIGALRM) の
1516715347後に再起動するかどうかは実装依存であることに注意してください。
1516815348L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する
1516915349注意については L<perlport> も参照してください。
1517015350
1517115351=begin original
1517215352
1517315353On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just
1517415354like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>.
1517515355
1517615356=end original
1517715357
1517815358エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は
1517915359L<select(2)> のように振舞います:
1518015360C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。
1518115361
1518215362=begin original
1518315363
1518415364On some Unixes, L<select(2)> may report a socket file descriptor as
1518515365"ready for reading" even when no data is available, and thus any
1518615366subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block.
1518715367This can be avoided if you always use C<O_NONBLOCK> on the socket. See
1518815368L<select(2)> and L<fcntl(2)> for further details.
1518915369
1519015370=end original
1519115371
1519215372Unix の中には、実際に利用可能なデータがないために引き続く
1519315373L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> が
1519415374ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が
1519515375「読み込み準備中」であると報告するものもあります。
1519615376これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。
1519715377さらなる詳細については L<select(2)> と L<fcntl(2)> を参照してください。
1519815378
1519915379=begin original
1520015380
1520115381The standard L<C<IO::Select>|IO::Select> module provides a
1520215382user-friendlier interface to
1520315383L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does
1520415384all the bit-mask work for you.
1520515385
1520615386=end original
1520715387
1520815388標準の L<C<IO::Select>|IO::Select> モジュールは
1520915389L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな
1521015390インターフェースを提供します; 主な理由はビットマスクの仕事を
1521115391してくれることです。
1521215392
1521315393=begin original
1521415394
1521515395B<WARNING>: One should not attempt to mix buffered I/O (like
1521615396L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or
1521715397L<C<readline>|/readline EXPR>) with
1521815398L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by
1521915399POSIX, and even then only on POSIX systems. You have to use
1522015400L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead.
1522115401
1522215402=end original
1522315403
1522415404B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> や
1522515405L<C<readline>|/readline EXPR>) と
1522615406L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を
1522715407混ぜて使ってはいけません(例外: POSIX で認められている形で使い、
1522815408POSIX システムでだけ動かす場合を除きます)。
1522915409代わりに L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を
1523015410使わなければなりません。
1523115411
1523215412=begin original
1523315413
1523415414Portability issues: L<perlport/select>.
1523515415
1523615416=end original
1523715417
1523815418移植性の問題: L<perlport/select>。
1523915419
1524015420=item semctl ID,SEMNUM,CMD,ARG
1524115421X<semctl>
1524215422
1524315423=for Pod::Functions SysV semaphore control operations
1524415424
1524515425=begin original
1524615426
1524715427Calls the System V IPC function L<semctl(2)>. You'll probably have to say
1524815428
1524915429=end original
1525015430
1525115431System V IPC 関数 L<semctl(2)> を呼び出します。
1525215432正しい定数定義を得るために、まず
1525315433
1525415434 use IPC::SysV;
1525515435
1525615436=begin original
1525715437
1525815438first to get the correct constant definitions. If CMD is IPC_STAT or
1525915439GETALL, then ARG must be a variable that will hold the returned
1526015440semid_ds structure or semaphore value array. Returns like
1526115441L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
1526215442the undefined value for error, "C<0 but true>" for zero, or the actual
1526315443return value otherwise. The ARG must consist of a vector of native
1526415444short integers, which may be created with C<pack("s!",(0)x$nsem)>.
1526515445See also L<perlipc/"SysV IPC"> and the documentation for
1526615446L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1526715447
1526815448=end original
1526915449
1527015450と書くことが必要でしょう。
1527115451CMD が、IPC_STAT か GETALL のときには、ARG は、返される
1527215452semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。
1527315453L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
1527415454未定義値、ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
1527515455ARG はネイティブな short int のベクターから成っていなければなりません; これは
1527615456C<pack("s!",(0)x$nsem)> で作成できます。
15277L<perlipc/"SysV IPC">
15457L<perlipc/"SysV IPC"> およびL<C<IPC::SysV>|IPC::SysV> と
15278L<C<IPC::SysV>|IPC::SysV>, L<C<IPC::Semaphore>|IPC::Semaphore> の文書も
15458L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
15279参照してください。
1528015459
1528115460=begin original
1528215461
1528315462Portability issues: L<perlport/semctl>.
1528415463
1528515464=end original
1528615465
1528715466移植性の問題: L<perlport/semctl>。
1528815467
1528915468=item semget KEY,NSEMS,FLAGS
1529015469X<semget>
1529115470
1529215471=for Pod::Functions get set of SysV semaphores
1529315472
1529415473=begin original
1529515474
1529615475Calls the System V IPC function L<semget(2)>. Returns the semaphore id, or
1529715476the undefined value on error. See also
1529815477L<perlipc/"SysV IPC"> and the documentation for
1529915478L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1530015479
1530115480=end original
1530215481
1530315482System V IPC 関数 L<semget(2)> を呼び出します。
1530415483セマフォ ID か、エラー時には未定義値を返します。
15305L<perlipc/"SysV IPC"> 、L<C<IPC::SysV>|IPC::SysV>,
15484L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
15306L<C<IPC::Semaphore>|IPC::Semaphore> 文書も参照してください。
15485L<C<IPC::Semaphore>|IPC::Semaphore> 文書も参照してください。
1530715486
1530815487=begin original
1530915488
1531015489Portability issues: L<perlport/semget>.
1531115490
1531215491=end original
1531315492
1531415493移植性の問題: L<perlport/semget>。
1531515494
1531615495=item semop KEY,OPSTRING
1531715496X<semop>
1531815497
1531915498=for Pod::Functions SysV semaphore operations
1532015499
1532115500=begin original
1532215501
1532315502Calls the System V IPC function L<semop(2)> for semaphore operations
1532415503such as signalling and waiting. OPSTRING must be a packed array of
1532515504semop structures. Each semop structure can be generated with
1532615505C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
1532715506implies the number of semaphore operations. Returns true if
1532815507successful, false on error. As an example, the
1532915508following code waits on semaphore $semnum of semaphore id $semid:
1533015509
1533115510=end original
1533215511
1533315512シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、
1533415513System V IPC 関数 L<semop(2)> を呼び出します。
1533515514OPSTRING は、semop 構造体の pack された配列でなければなりません。
1533615515semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように
1533715516作ることができます。
1533815517セマフォ操作の数は、OPSTRING の長さからわかります。
1533915518成功時には真を、エラー時には偽を返します。
1534015519以下の例は、セマフォ ID $semid のセマフォ $semnum で
1534115520待ち合わせを行ないます。
1534215521
1534315522 my $semop = pack("s!3", $semnum, -1, 0);
1534415523 die "Semaphore trouble: $!\n" unless semop($semid, $semop);
1534515524
1534615525=begin original
1534715526
1534815527To signal the semaphore, replace C<-1> with C<1>. See also
1534915528L<perlipc/"SysV IPC"> and the documentation for
1535015529L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1535115530
1535215531=end original
1535315532
1535415533セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。
15355L<perlipc/"SysV IPC"> L<C<IPC::SysV>|IPC::SysV>,
15534L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>
1535615535L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
1535715536
1535815537=begin original
1535915538
1536015539Portability issues: L<perlport/semop>.
1536115540
1536215541=end original
1536315542
1536415543移植性の問題: L<perlport/semop>。
1536515544
1536615545=item send SOCKET,MSG,FLAGS,TO
1536715546X<send>
1536815547
1536915548=item send SOCKET,MSG,FLAGS
1537015549
1537115550=for Pod::Functions send a message over a socket
1537215551
1537315552=begin original
1537415553
1537515554Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET
1537615555filehandle. Takes the same flags as the system call of the same name. On
1537715556unconnected sockets, you must specify a destination to I<send to>, in which
1537815557case it does a L<sendto(2)> syscall. Returns the number of characters sent,
1537915558or the undefined value on error. The L<sendmsg(2)> syscall is currently
1538015559unimplemented. See L<perlipc/"UDP: Message Passing"> for examples.
1538115560
1538215561=end original
1538315562
1538415563ソケットにメッセージを送ります。
1538515564スカラ MSG を ファイルハンドル SOCKET に送ろうとします。
1538615565同名のシステムコールと同じフラグが指定できます。
1538715566接続していないソケットには、I<send to> に接続先を指定しなければならず、
1538815567この場合、L<sendto(2)> を実行します。
1538915568送信した文字数か、エラー時には、未定義値を返します。
1539015569システムコール L<sendmsg(2)> は現在実装されていません。
1539115570例については L<perlipc/"UDP: Message Passing"> を参照してください。
1539215571
1539315572=begin original
1539415573
1539515574Note that if the socket has been marked as C<:utf8>, C<send> will
1539615575throw an exception. The C<:encoding(...)> layer implicitly introduces
1539715576the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>.
1539815577
1539915578=end original
1540015579
1540115580ソケットが C<:utf8> とマークされている場合、
1540215581C<send> は例外を投げることに注意してください。
1540315582C<:encoding(...)> 層は暗黙に C<:utf8> 層を導入します。
1540415583L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。
1540515584
1540615585=item setpgrp PID,PGRP
1540715586X<setpgrp> X<group>
1540815587
1540915588=for Pod::Functions set the process group of a process
1541015589
1541115590=begin original
1541215591
1541315592Sets the current process group for the specified PID, C<0> for the current
1541415593process. Raises an exception when used on a machine that doesn't
1541515594implement POSIX L<setpgid(2)> or BSD L<setpgrp(2)>. If the arguments
1541615595are omitted, it defaults to C<0,0>. Note that the BSD 4.2 version of
1541715596L<C<setpgrp>|/setpgrp PID,PGRP> does not accept any arguments, so only
1541815597C<setpgrp(0,0)> is portable. See also
1541915598L<C<POSIX::setsid()>|POSIX/C<setsid>>.
1542015599
1542115600=end original
1542215601
1542315602指定した PID (C<0> を指定するとカレントプロセス) に
1542415603対するプロセスグループを設定します。
1542515604POSIX L<setpgrp(2)> または BSD L<setpgrp(2)> が実装されていないマシンでは、
1542615605例外が発生します。
1542715606引数が省略された場合は、C<0,0>が使われます。
1542815607BSD 4.2 版の L<C<setpgrp>|/setpgrp PID,PGRP> は引数を取ることができないので、
1542915608C<setpgrp(0,0)> のみが移植性があることに注意してください。
1543015609L<C<POSIX::setsid()>|POSIX/C<setsid>> も参照してください。
1543115610
1543215611=begin original
1543315612
1543415613Portability issues: L<perlport/setpgrp>.
1543515614
1543615615=end original
1543715616
1543815617移植性の問題: L<perlport/setpgrp>。
1543915618
1544015619=item setpriority WHICH,WHO,PRIORITY
1544115620X<setpriority> X<priority> X<nice> X<renice>
1544215621
1544315622=for Pod::Functions set a process's nice value
1544415623
1544515624=begin original
1544615625
1544715626Sets the current priority for a process, a process group, or a user.
1544815627(See L<setpriority(2)>.) Raises an exception when used on a machine
1544915628that doesn't implement L<setpriority(2)>.
1545015629
1545115630=end original
1545215631
1545315632プロセス、プロセスグループ、ユーザに対する優先順位を設定します。
1545415633(L<setpriority(2)> を参照してください。)
1545515634L<setpriority(2)> が実装されていないマシンでは、例外が発生します。
1545615635
1545715636=begin original
1545815637
1545915638C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER>
1546015639imported from L<POSIX/RESOURCE CONSTANTS>.
1546115640
1546215641=end original
1546315642
1546415643C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた
1546515644C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。
1546615645
1546715646=begin original
1546815647
1546915648Portability issues: L<perlport/setpriority>.
1547015649
1547115650=end original
1547215651
1547315652移植性の問題: L<perlport/setpriority>。
1547415653
1547515654=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1547615655X<setsockopt>
1547715656
1547815657=for Pod::Functions set some socket options
1547915658
1548015659=begin original
1548115660
1548215661Sets the socket option requested. Returns L<C<undef>|/undef EXPR> on
1548315662error. Use integer constants provided by the L<C<Socket>|Socket> module
1548415663for
1548515664LEVEL and OPNAME. Values for LEVEL can also be obtained from
1548615665getprotobyname. OPTVAL might either be a packed string or an integer.
1548715666An integer OPTVAL is shorthand for pack("i", OPTVAL).
1548815667
1548915668=end original
1549015669
1549115670要求したソケットオプションを設定します。
1549215671エラー時には、L<C<undef>|/undef EXPR> を返します。
1549315672LEVEL と OPNAME には L<C<Socket>|Socket> モジュールが提供する
1549415673整数定数を使います。
1549515674LEVEL の値は getprotobyname から得ることもできます。
1549615675OPTVAL は pack された文字列か整数です。
1549715676整数の OPTVAL は pack("i", OPTVAL) の省略表現です。
1549815677
1549915678=begin original
1550015679
1550115680An example disabling Nagle's algorithm on a socket:
1550215681
1550315682=end original
1550415683
1550515684ソケットに対する Nagle のアルゴリズムを無効にする例です:
1550615685
1550715686 use Socket qw(IPPROTO_TCP TCP_NODELAY);
1550815687 setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1);
1550915688
1551015689=begin original
1551115690
1551215691Portability issues: L<perlport/setsockopt>.
1551315692
1551415693=end original
1551515694
1551615695移植性の問題: L<perlport/setsockopt>。
1551715696
1551815697=item shift ARRAY
1551915698X<shift>
1552015699
1552115700=item shift
1552215701
1552315702=for Pod::Functions remove the first element of an array, and return it
1552415703
1552515704=begin original
1552615705
1552715706Shifts the first value of the array off and returns it, shortening the
1552815707array by 1 and moving everything down. If there are no elements in the
1552915708array, returns the undefined value. If ARRAY is omitted, shifts the
1553015709L<C<@_>|perlvar/@_> array within the lexical scope of subroutines and
1553115710formats, and the L<C<@ARGV>|perlvar/@ARGV> array outside a subroutine
1553215711and also within the lexical scopes
1553315712established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
1553415713C<UNITCHECK {}>, and C<END {}> constructs.
1553515714
1553615715=end original
1553715716
1553815717配列の最初の値を取り出して、その値を返し、配列を一つ短くして、すべての要素を
1553915718前へずらします。
1554015719配列に要素がなければ、未定義値を返します。
1554115720ARRAY を省略すると、サブルーチンやフォーマットのレキシカルスコープでは
1554215721L<C<@_>|perlvar/@_> を、サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>,
1554315722C<INIT {}>, C<CHECK {}>, C<UNITCHECK {}>, C<END {}> で作成された
1554415723レキシカルスコープでは L<C<@ARGV>|perlvar/@ARGV> が用いられます。
1554515724
1554615725=begin original
1554715726
1554815727Starting with Perl 5.14, an experimental feature allowed
1554915728L<C<shift>|/shift ARRAY> to take a
1555015729scalar expression. This experiment has been deemed unsuccessful, and was
1555115730removed as of Perl 5.24.
1555215731
1555315732=end original
1555415733
1555515734Perl 5.14 から、L<C<shift>|/shift ARRAY> がスカラ式を取ることが出来るという
1555615735実験的機能がありました。
1555715736この実験は失敗と見なされ、Perl 5.24 で削除されました。
1555815737
1555915738=begin original
1556015739
1556115740See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>,
1556215741and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and
1556315742L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of
1556415743an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to
1556515744the right end.
1556615745
1556715746=end original
1556815747
1556915748L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、
1557015749L<C<pop>|/pop ARRAY> も参照してください。
1557115750L<C<shift>|/shift ARRAY> と L<C<unshift>|/unshift ARRAY,LIST> は、
1557215751L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で
1557315752行なうことを、左端で行ないます。
1557415753
1557515754=item shmctl ID,CMD,ARG
1557615755X<shmctl>
1557715756
1557815757=for Pod::Functions SysV shared memory operations
1557915758
1558015759=begin original
1558115760
1558215761Calls the System V IPC function shmctl. You'll probably have to say
1558315762
1558415763=end original
1558515764
1558615765System V IPC 関数 shmctl を呼び出します。
1558715766正しい定数定義を得るために、まず
1558815767
1558915768 use IPC::SysV;
1559015769
1559115770=begin original
1559215771
1559315772first to get the correct constant definitions. If CMD is C<IPC_STAT>,
1559415773then ARG must be a variable that will hold the returned C<shmid_ds>
1559515774structure. Returns like ioctl: L<C<undef>|/undef EXPR> for error; "C<0>
1559615775but true" for zero; and the actual return value otherwise.
1559715776See also L<perlipc/"SysV IPC"> and the documentation for
1559815777L<C<IPC::SysV>|IPC::SysV>.
1559915778
1560015779=end original
1560115780
1560215781と書くことが必要でしょう。
1560315782CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を
1560415783納める変数でなければなりません。
1560515784ioctl と同様です: エラー時には L<C<undef>|/undef EXPR>; ゼロのときは
1560615785"C<0> だが真"; それ以外なら、その値そのものを返します。
15607L<perlipc/"SysV IPC"> L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。
15786L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> の文書も
15787参照してください。
1560815788
1560915789=begin original
1561015790
1561115791Portability issues: L<perlport/shmctl>.
1561215792
1561315793=end original
1561415794
1561515795移植性の問題: L<perlport/shmctl>。
1561615796
1561715797=item shmget KEY,SIZE,FLAGS
1561815798X<shmget>
1561915799
1562015800=for Pod::Functions get SysV shared memory segment identifier
1562115801
1562215802=begin original
1562315803
1562415804Calls the System V IPC function shmget. Returns the shared memory
1562515805segment id, or L<C<undef>|/undef EXPR> on error.
1562615806See also L<perlipc/"SysV IPC"> and the documentation for
1562715807L<C<IPC::SysV>|IPC::SysV>.
1562815808
1562915809=end original
1563015810
1563115811System V IPC 関数 shmget を呼び出します。
1563215812共有メモリのセグメント ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
15633L<perlipc/"SysV IPC"> L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。
15813L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> の文書も
15814参照してください。
1563415815
1563515816=begin original
1563615817
1563715818Portability issues: L<perlport/shmget>.
1563815819
1563915820=end original
1564015821
1564115822移植性の問題: L<perlport/shmget>。
1564215823
1564315824=item shmread ID,VAR,POS,SIZE
1564415825X<shmread>
1564515826X<shmwrite>
1564615827
1564715828=for Pod::Functions read SysV shared memory
1564815829
1564915830=item shmwrite ID,STRING,POS,SIZE
1565015831
1565115832=for Pod::Functions write SysV shared memory
1565215833
1565315834=begin original
1565415835
1565515836Reads or writes the System V shared memory segment ID starting at
1565615837position POS for size SIZE by attaching to it, copying in/out, and
1565715838detaching from it. When reading, VAR must be a variable that will
1565815839hold the data read. When writing, if STRING is too long, only SIZE
1565915840bytes are used; if STRING is too short, nulls are written to fill out
1566015841SIZE bytes. Return true if successful, false on error.
1566115842L<C<shmread>|/shmread ID,VAR,POS,SIZE> taints the variable. See also
1566215843L<perlipc/"SysV IPC"> and the documentation for
1566315844L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable>
1566415845module from CPAN.
1566515846
1566615847=end original
1566715848
1566815849System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、
1566915850デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを
1567015851行ないます。
1567115852読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。
1567215853書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます; STRING が
1567315854短すぎる場合には、SIZE バイトを埋めるために、ヌル文字が書き込まれます。
1567415855成功時には真を、エラー時には偽を返します。
1567515856L<C<shmread>|/shmread ID,VAR,POS,SIZE> は変数を汚染します。
1567615857L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と CPAN の
1567715858L<C<IPC::Shareable>|IPC::Shareable> の文書も参照してください。
1567815859
1567915860=begin original
1568015861
1568115862Portability issues: L<perlport/shmread> and L<perlport/shmwrite>.
1568215863
1568315864=end original
1568415865
1568515866移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。
1568615867
1568715868=item shutdown SOCKET,HOW
1568815869X<shutdown>
1568915870
1569015871=for Pod::Functions close down just half of a socket connection
1569115872
1569215873=begin original
1569315874
1569415875Shuts down a socket connection in the manner indicated by HOW, which
1569515876has the same interpretation as in the syscall of the same name.
1569615877
1569715878=end original
1569815879
1569915880同名のシステムコールと同じように解釈される HOW によって、
1570015881指定された方法でソケット接続のシャットダウンを行ないます。
1570115882
1570215883 shutdown($socket, 0); # I/we have stopped reading data
1570315884 shutdown($socket, 1); # I/we have stopped writing data
1570415885 shutdown($socket, 2); # I/we have stopped using this socket
1570515886
1570615887=begin original
1570715888
1570815889This is useful with sockets when you want to tell the other
1570915890side you're done writing but not done reading, or vice versa.
1571015891It's also a more insistent form of close because it also
1571115892disables the file descriptor in any forked copies in other
1571215893processes.
1571315894
1571415895=end original
1571515896
1571615897これは、こちらがソケットを書き終わったが読み終わっていない、
1571715898またはその逆を相手側に伝えたいときに便利です。
1571815899これはその他のプロセスでフォークしたファイル記述子のコピーも
1571915900無効にするので、よりしつこい閉じ方です。
1572015901
1572115902=begin original
1572215903
1572315904Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if
1572415905the first argument is not a valid filehandle, or returns C<0> and sets
1572515906L<C<$!>|perlvar/$!> for any other failure.
1572615907
1572715908=end original
1572815909
1572915910成功時には C<1> を返します;
1573015911エラーの場合、最初の引数が有効なファイルハンドルでない場合は
1573115912L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して
1573215913L<C<$!>|perlvar/$!> をセットします。
1573315914
1573415915=item sin EXPR
1573515916X<sin> X<sine> X<asin> X<arcsine>
1573615917
1573715918=item sin
1573815919
1573915920=for Pod::Functions return the sine of a number
1574015921
1574115922=begin original
1574215923
1574315924Returns the sine of EXPR (expressed in radians). If EXPR is omitted,
1574415925returns sine of L<C<$_>|perlvar/$_>.
1574515926
1574615927=end original
1574715928
1574815929(ラジアンで示した) EXPR の正弦を返します。
1574915930EXPR が省略されたときには、L<C<$_>|perlvar/$_> の正弦を返します。
1575015931
1575115932=begin original
1575215933
1575315934For the inverse sine operation, you may use the C<Math::Trig::asin>
1575415935function, or use this relation:
1575515936
1575615937=end original
1575715938
1575815939逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、
1575915940以下の関係を使ってください:
1576015941
1576115942 sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
1576215943
1576315944=item sleep EXPR
1576415945X<sleep> X<pause>
1576515946
1576615947=item sleep
1576715948
1576815949=for Pod::Functions block for some number of seconds
1576915950
1577015951=begin original
1577115952
1577215953Causes the script to sleep for (integer) EXPR seconds, or forever if no
1577315954argument is given. Returns the integer number of seconds actually slept.
1577415955
1577515956=end original
1577615957
1577715958スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に)
1577815959スリープさせます。
1577915960実際にスリープした秒数を返します。
1578015961
1578115962=begin original
1578215963
15964EXPR should be a positive integer. If called with a negative integer,
15965L<C<sleep>|/sleep EXPR> does not sleep but instead emits a warning, sets
15966$! (C<errno>), and returns zero.
15967
15968=end original
15969
15970EXPR は正の整数である必要があります。
15971負の整数で呼び出すと、 L<C<sleep>|/sleep EXPR> はスリープせず、
15972警告を出力して、$! (C<errno>) を設定し、ゼロを返します。
15973
15974=begin original
15975
15976C<sleep 0> is permitted, but a function call to the underlying platform
15977implementation still occurs, with any side effects that may have.
15978C<sleep 0> is therefore not exactly identical to not sleeping at all.
15979
15980=end original
15981
15982C<sleep 0> は許されていますが、基となるプラットフォーム実装への
15983関数呼び出しはやはり行われ、どのような副作用も起こり得ます。
15984従って、C<sleep 0> は全くスリープしないのと正確に同じではありません。
15985
15986=begin original
15987
1578315988May be interrupted if the process receives a signal such as C<SIGALRM>.
1578415989
1578515990=end original
1578615991
1578715992そのプロセスが C<SIGALRM>のようなシグナルを受信すると、
1578815993割り込みがかかります。
1578915994
1579015995 eval {
1579115996 local $SIG{ALRM} = sub { die "Alarm!\n" };
1579215997 sleep;
1579315998 };
1579415999 die $@ unless $@ eq "Alarm!\n";
1579516000
1579616001=begin original
1579716002
1579816003You probably cannot mix L<C<alarm>|/alarm SECONDS> and
1579916004L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often
1580016005implemented using L<C<alarm>|/alarm SECONDS>.
1580116006
1580216007=end original
1580316008
1580416009L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って
1580516010実装されることが多いので、L<C<alarm>|/alarm SECONDS> と
1580616011L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。
1580716012
1580816013=begin original
1580916014
1581016015On some older systems, it may sleep up to a full second less than what
1581116016you requested, depending on how it counts seconds. Most modern systems
1581216017always sleep the full amount. They may appear to sleep longer than that,
1581316018however, because your process might not be scheduled right away in a
1581416019busy multitasking system.
1581516020
1581616021=end original
1581716022
1581816023古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に
1581916024満たないうちに、スリープから抜ける場合があります。
1582016025最近のシステムでは、常に完全にスリープします。
1582116026しかし、負荷の高いマルチタスクシステムでは
1582216027正しくスケジューリングされないがために
1582316028より長い時間スリープすることがあります。
1582416029
1582516030=begin original
1582616031
1582716032For delays of finer granularity than one second, the L<Time::HiRes>
1582816033module (from CPAN, and starting from Perl 5.8 part of the standard
1582916034distribution) provides L<C<usleep>|Time::HiRes/usleep ( $useconds )>.
1583016035You may also use Perl's four-argument
1583116036version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the
1583216037first three arguments undefined, or you might be able to use the
1583316038L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
1583416039if your system supports it. See L<perlfaq8> for details.
1583516040
1583616041=end original
1583716042
15838160431 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
1583916044また Perl 5.8 からは標準配布されています) が
1584016045L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。
1584116046Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
15842160473 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、
1584316048Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
1584416049アクセスすることもできます。
1584516050詳しくは L<perlfaq8> を参照してください。
1584616051
1584716052=begin original
1584816053
1584916054See also the L<POSIX> module's L<C<pause>|POSIX/C<pause>> function.
1585016055
1585116056=end original
1585216057
1585316058L<POSIX> モジュールの L<C<pause>|POSIX/C<pause>> 関数も参照してください。
1585416059
1585516060=item socket SOCKET,DOMAIN,TYPE,PROTOCOL
1585616061X<socket>
1585716062
1585816063=for Pod::Functions create a socket
1585916064
1586016065=begin original
1586116066
1586216067Opens a socket of the specified kind and attaches it to filehandle
1586316068SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for
1586416069the syscall of the same name. You should C<use Socket> first
1586516070to get the proper definitions imported. See the examples in
1586616071L<perlipc/"Sockets: Client/Server Communication">.
1586716072
1586816073=end original
1586916074
1587016075指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。
1587116076DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
1587216077適切な定義を import するために、まず、C<use Socket> とするとよいでしょう。
1587316078L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
1587416079
1587516080=begin original
1587616081
1587716082On systems that support a close-on-exec flag on files, the flag will
1587816083be set for the newly opened file descriptor, as determined by the
1587916084value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1588016085
1588116086=end original
1588216087
1588316088ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1588416089フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
1588516090ファイル記述子に対してセットされます。
1588616091L<perlvar/$^F> を参照してください。
1588716092
1588816093=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1588916094X<socketpair>
1589016095
1589116096=for Pod::Functions create a pair of sockets
1589216097
1589316098=begin original
1589416099
1589516100Creates an unnamed pair of sockets in the specified domain, of the
1589616101specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as
1589716102for the syscall of the same name. If unimplemented, raises an exception.
1589816103Returns true if successful.
1589916104
1590016105=end original
1590116106
1590216107指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。
1590316108DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
1590416109実装されていない場合には、例外が発生します。
1590516110成功時には真を返します。
1590616111
1590716112=begin original
1590816113
1590916114On systems that support a close-on-exec flag on files, the flag will
1591016115be set for the newly opened file descriptors, as determined by the value
1591116116of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1591216117
1591316118=end original
1591416119
1591516120ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1591616121フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
1591716122ファイル記述子に対してセットされます。
1591816123L<perlvar/$^F> を参照してください。
1591916124
1592016125=begin original
1592116126
1592216127Some systems define L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> in terms of
1592316128L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, in
1592416129which a call to C<pipe($rdr, $wtr)> is essentially:
1592516130
1592616131=end original
1592716132
1592816133L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
1592916134L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> を使って
1593016135定義しているシステムもあります;
1593116136C<pipe($rdr, $wtr)> は本質的には以下のようになります:
1593216137
1593316138 use Socket;
1593416139 socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
1593516140 shutdown($rdr, 1); # no more writing for reader
1593616141 shutdown($wtr, 0); # no more reading for writer
1593716142
1593816143=begin original
1593916144
1594016145See L<perlipc> for an example of socketpair use. Perl 5.8 and later will
1594116146emulate socketpair using IP sockets to localhost if your system implements
1594216147sockets but not socketpair.
1594316148
1594416149=end original
1594516150
1594616151socketpair の使用例については L<perlipc> を参照してください。
1594716152Perl 5.8 以降では、システムがソケットを実装しているが socketpair を
1594816153実装していない場合、localhost に対して IP ソケットを使うことで
1594916154socketpair をエミュレートします。
1595016155
1595116156=begin original
1595216157
1595316158Portability issues: L<perlport/socketpair>.
1595416159
1595516160=end original
1595616161
1595716162移植性の問題: L<perlport/socketpair>。
1595816163
1595916164=item sort SUBNAME LIST
1596016165X<sort>
1596116166
1596216167=item sort BLOCK LIST
1596316168
1596416169=item sort LIST
1596516170
1596616171=for Pod::Functions sort a list of values
1596716172
1596816173=begin original
1596916174
1597016175In list context, this sorts the LIST and returns the sorted list value.
1597116176In scalar context, the behaviour of L<C<sort>|/sort SUBNAME LIST> is
1597216177undefined.
1597316178
1597416179=end original
1597516180
1597616181リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。
1597716182スカラコンテキストでは、L<C<sort>|/sort SUBNAME LIST> の振る舞いは未定義です。
1597816183
1597916184=begin original
1598016185
1598116186If SUBNAME or BLOCK is omitted, L<C<sort>|/sort SUBNAME LIST>s in
1598216187standard string comparison
1598316188order. If SUBNAME is specified, it gives the name of a subroutine
1598416189that returns an integer less than, equal to, or greater than C<0>,
1598516190depending on how the elements of the list are to be ordered. (The
1598616191C<< <=> >> and C<cmp> operators are extremely useful in such routines.)
1598716192SUBNAME may be a scalar variable name (unsubscripted), in which case
1598816193the value provides the name of (or a reference to) the actual
1598916194subroutine to use. In place of a SUBNAME, you can provide a BLOCK as
1599016195an anonymous, in-line sort subroutine.
1599116196
1599216197=end original
1599316198
1599416199SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の
1599516200文字列比較の順番で行なわれます。
1599616201SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに
1599716202応じて、負の整数、C<0>、正の整数を返すサブルーチンの名前であると解釈されます。
1599816203(このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、
1599916204たいへん便利です。)
1600016205SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する
1600116206実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。
1600216207SUBNAME の代わりに、無名のインラインソートルーチンとして、BLOCK を
1600316208書くことができます。
1600416209
1600516210=begin original
1600616211
1600716212If the subroutine's prototype is C<($$)>, the elements to be compared are
1600816213passed by reference in L<C<@_>|perlvar/@_>, as for a normal subroutine.
1600916214This is slower than unprototyped subroutines, where the elements to be
1601016215compared are passed into the subroutine as the package global variables
1601116216C<$a> and C<$b> (see example below).
1601216217
1601316218=end original
1601416219
1601516220サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常のサブルーチンと
1601616221同じように L<C<@_>|perlvar/@_> の中にリファレンスとして渡されます。
1601716222これはプロトタイプなしのサブルーチンより遅いです; この場合は比較のため
1601816223サブルーチンに渡される二つの要素は、パッケージのグローバル変数 C<$a> と
1601916224C<$b> で渡されます(次の例を参照してください)。
1602016225
1602116226=begin original
1602216227
1602316228If the subroutine is an XSUB, the elements to be compared are pushed on
1602416229to the stack, the way arguments are usually passed to XSUBs. C<$a> and
1602516230C<$b> are not set.
1602616231
1602716232=end original
1602816233
1602916234サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、
1603016235スタックにプッシュされます。
1603116236C<$a> と C<$b> は設定されません。
1603216237
1603316238=begin original
1603416239
1603516240The values to be compared are always passed by reference and should not
1603616241be modified.
1603716242
1603816243=end original
1603916244
1604016245比較される値はリファレンスによって渡されるので、変更するべきではありません。
1604116246
1604216247=begin original
1604316248
1604416249You also cannot exit out of the sort block or subroutine using any of the
1604516250loop control operators described in L<perlsyn> or with
1604616251L<C<goto>|/goto LABEL>.
1604716252
1604816253=end original
1604916254
1605016255また、ソートブロックやサブルーチンから L<perlsyn> で説明されている
1605116256ループ制御子や L<C<goto>|/goto LABEL> を使って抜けてはいけません。
1605216257
1605316258=begin original
1605416259
1605516260When L<C<use locale>|locale> (but not C<use locale ':not_characters'>)
1605616261is in effect, C<sort LIST> sorts LIST according to the
1605716262current collation locale. See L<perllocale>.
1605816263
1605916264=end original
1606016265
1606116266L<C<use locale>|locale> が有効(そして C<use locale ':not_characters'> が
1606216267有効でない)の場合、C<sort LIST> は LIST を現在の比較ロケールに従って
1606316268ソートします。
1606416269L<perllocale> を参照してください。
1606516270
1606616271=begin original
1606716272
1606816273L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list,
1606916274much as a for loop's index variable aliases the list elements. That is,
1607016275modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST>
1607116276(for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or
1607216277L<C<grep>|/grep BLOCK LIST>)
1607316278actually modifies the element in the original list. This is usually
1607416279something to be avoided when writing clear code.
1607516280
1607616281=end original
1607716282
1607816283L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します;
1607916284for ループのインデックス変数がリスト要素へのエイリアスと同様です。
1608016285つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、
1608116286C<foreach> や L<C<map>|/map BLOCK LIST> や
1608216287L<C<grep>|/grep BLOCK LIST> で)変更すると、実際に元のリストの要素が
1608316288変更されます。
1608416289これはきれいなコードを書くときには普通は回避されます。
1608516290
1608616291=begin original
1608716292
1608816293Historically Perl has varied in whether sorting is stable by default.
1608916294If stability matters, it can be controlled explicitly by using the
1609016295L<sort> pragma.
1609116296
1609216297=end original
1609316298
1609416299歴史的には、ソートがデフォルトで安定かどうかは様々です。
1609516300安定性が問題になる場合は、L<sort> プラグマを使うことで明示的に制御できます。
1609616301
1609716302=begin original
1609816303
1609916304Examples:
1610016305
1610116306=end original
1610216307
1610316308例:
1610416309
1610516310 # sort lexically
1610616311 my @articles = sort @files;
1610716312
1610816313 # same thing, but with explicit sort routine
1610916314 my @articles = sort {$a cmp $b} @files;
1611016315
1611116316 # now case-insensitively
1611216317 my @articles = sort {fc($a) cmp fc($b)} @files;
1611316318
1611416319 # same thing in reversed order
1611516320 my @articles = sort {$b cmp $a} @files;
1611616321
1611716322 # sort numerically ascending
1611816323 my @articles = sort {$a <=> $b} @files;
1611916324
1612016325 # sort numerically descending
1612116326 my @articles = sort {$b <=> $a} @files;
1612216327
1612316328 # this sorts the %age hash by value instead of key
1612416329 # using an in-line function
1612516330 my @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
1612616331
1612716332 # sort using explicit subroutine name
1612816333 sub byage {
1612916334 $age{$a} <=> $age{$b}; # presuming numeric
1613016335 }
1613116336 my @sortedclass = sort byage @class;
1613216337
1613316338 sub backwards { $b cmp $a }
1613416339 my @harry = qw(dog cat x Cain Abel);
1613516340 my @george = qw(gone chased yz Punished Axed);
1613616341 print sort @harry;
1613716342 # prints AbelCaincatdogx
1613816343 print sort backwards @harry;
1613916344 # prints xdogcatCainAbel
1614016345 print sort @george, 'to', @harry;
1614116346 # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
1614216347
1614316348 # inefficiently sort by descending numeric compare using
1614416349 # the first integer after the first = sign, or the
1614516350 # whole record case-insensitively otherwise
1614616351
1614716352 my @new = sort {
1614816353 ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
1614916354 ||
1615016355 fc($a) cmp fc($b)
1615116356 } @old;
1615216357
1615316358 # same thing, but much more efficiently;
1615416359 # we'll build auxiliary indices instead
1615516360 # for speed
1615616361 my (@nums, @caps);
1615716362 for (@old) {
1615816363 push @nums, ( /=(\d+)/ ? $1 : undef );
1615916364 push @caps, fc($_);
1616016365 }
1616116366
1616216367 my @new = @old[ sort {
1616316368 $nums[$b] <=> $nums[$a]
1616416369 ||
1616516370 $caps[$a] cmp $caps[$b]
1616616371 } 0..$#old
1616716372 ];
1616816373
1616916374 # same thing, but without any temps
1617016375 my @new = map { $_->[0] }
1617116376 sort { $b->[1] <=> $a->[1]
1617216377 ||
1617316378 $a->[2] cmp $b->[2]
1617416379 } map { [$_, /=(\d+)/, fc($_)] } @old;
1617516380
1617616381 # using a prototype allows you to use any comparison subroutine
1617716382 # as a sort subroutine (including other package's subroutines)
1617816383 package Other;
1617916384 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are
1618016385 # not set here
1618116386 package main;
1618216387 my @new = sort Other::backwards @old;
1618316388
16389 ## using a prototype with function signature
16390 use feature 'signatures';
16391 sub function_with_signature :prototype($$) ($one, $two) {
16392 return $one <=> $two
16393 }
16394
16395 my @new = sort function_with_signature @old;
16396
1618416397 # guarantee stability
1618516398 use sort 'stable';
1618616399 my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
1618716400
1618816401=begin original
1618916402
1619016403Warning: syntactical care is required when sorting the list returned from
1619116404a function. If you want to sort the list returned by the function call
1619216405C<find_records(@key)>, you can use:
1619316406
1619416407=end original
1619516408
1619616409警告: 関数から返されたリストをソートするときには文法上の注意が必要です。
1619716410関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、
1619816411以下のように出来ます:
1619916412
1620016413 my @contact = sort { $a cmp $b } find_records @key;
1620116414 my @contact = sort +find_records(@key);
1620216415 my @contact = sort &find_records(@key);
1620316416 my @contact = sort(find_records(@key));
1620416417
1620516418=begin original
1620616419
1620716420If instead you want to sort the array C<@key> with the comparison routine
1620816421C<find_records()> then you can use:
1620916422
1621016423=end original
1621116424
1621216425一方、配列 C<@key> を比較ルーチン C<find_records()> でソートしたい場合は、
1621316426以下のように出来ます:
1621416427
1621516428 my @contact = sort { find_records() } @key;
1621616429 my @contact = sort find_records(@key);
1621716430 my @contact = sort(find_records @key);
1621816431 my @contact = sort(find_records (@key));
1621916432
1622016433=begin original
1622116434
1622216435C<$a> and C<$b> are set as package globals in the package the sort() is
1622316436called from. That means C<$main::a> and C<$main::b> (or C<$::a> and
1622416437C<$::b>) in the C<main> package, C<$FooPack::a> and C<$FooPack::b> in the
1622516438C<FooPack> package, etc. If the sort block is in scope of a C<my> or
1622616439C<state> declaration of C<$a> and/or C<$b>, you I<must> spell out the full
1622716440name of the variables in the sort block :
1622816441
1622916442=end original
1623016443
1623116444C<$a> と C<$b> は、sort() を呼び出したパッケージのパッケージグローバルとして
1623216445設定されます。
1623316446つまり、C<main> パッケージの C<$main::a> と C<$main::b>
1623416447(あるいは C<$::a> と C<$::b>) 、
1623516448C<FooPack> パッケージの C<$FooPack::a> と C<$FooPack::b>、などです。
1623616449ソートブロックが C<$a> や C<$b> の C<my> または C<state> のスコープ内の場合、
1623716450ソートブロックの変数の完全名を I<指定しなければなりません>:
1623816451
1623916452 package main;
1624016453 my $a = "C"; # DANGER, Will Robinson, DANGER !!!
1624116454
1624216455 print sort { $a cmp $b } qw(A C E G B D F H);
1624316456 # WRONG
1624416457 sub badlexi { $a cmp $b }
1624516458 print sort badlexi qw(A C E G B D F H);
1624616459 # WRONG
1624716460 # the above prints BACFEDGH or some other incorrect ordering
1624816461
1624916462 print sort { $::a cmp $::b } qw(A C E G B D F H);
1625016463 # OK
1625116464 print sort { our $a cmp our $b } qw(A C E G B D F H);
1625216465 # also OK
1625316466 print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H);
1625416467 # also OK
1625516468 sub lexi { our $a cmp our $b }
1625616469 print sort lexi qw(A C E G B D F H);
1625716470 # also OK
1625816471 # the above print ABCDEFGH
1625916472
1626016473=begin original
1626116474
1626216475With proper care you may mix package and my (or state) C<$a> and/or C<$b>:
1626316476
1626416477=end original
1626516478
1626616479適切に注意すれば、パッケージと my (あるいは state) C<$a> や C<$b> を
1626716480混ぜることができます:
1626816481
1626916482 my $a = {
1627016483 tiny => -2,
1627116484 small => -1,
1627216485 normal => 0,
1627316486 big => 1,
1627416487 huge => 2
1627516488 };
1627616489
1627716490 say sort { $a->{our $a} <=> $a->{our $b} }
1627816491 qw{ huge normal tiny small big};
1627916492
1628016493 # prints tinysmallnormalbighuge
1628116494
1628216495=begin original
1628316496
1628416497C<$a> and C<$b> are implicitly local to the sort() execution and regain their
1628516498former values upon completing the sort.
1628616499
1628716500=end original
1628816501
1628916502C<$a> と C<$b> は sort() の実行中は暗黙にローカル化され、ソート終了時に
1629016503元の値に戻ります。
1629116504
1629216505=begin original
1629316506
1629416507Sort subroutines written using C<$a> and C<$b> are bound to their calling
1629516508package. It is possible, but of limited interest, to define them in a
1629616509different package, since the subroutine must still refer to the calling
1629716510package's C<$a> and C<$b> :
1629816511
1629916512=end original
1630016513
1630116514C<$a> と C<$b> を使って書かれたソートサブルーチンはその呼び出しパッケージに
1630216515しなければなりません。
1630316516異なるパッケージに定義することは可能ですが、
1630416517これは可能ですが、限られた関心しかありません;
1630516518サブルーチンは呼び出しパッケージの C<$a> と C<$b> を
1630616519参照しなければならないからです:
1630716520
1630816521 package Foo;
1630916522 sub lexi { $Bar::a cmp $Bar::b }
1631016523 package Bar;
1631116524 ... sort Foo::lexi ...
1631216525
1631316526=begin original
1631416527
1631516528Use the prototyped versions (see above) for a more generic alternative.
1631616529
1631716530=end original
1631816531
1631916532より一般的な代替案としては(前述の)プロトタイプ版を使ってください。
1632016533
1632116534=begin original
1632216535
1632316536The comparison function is required to behave. If it returns
1632416537inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and
1632516538sometimes saying the opposite, for example) the results are not
1632616539well-defined.
1632716540
1632816541=end original
1632916542
1633016543比較関数は一貫した振る舞いをすることが求められます。
1633116544一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より
1633216545小さいと返し、またあるときは逆を返す)場合、結果は未定義です。
1633316546
1633416547=begin original
1633516548
1633616549Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand
1633716550is C<NaN> (not-a-number), be careful when sorting with a
1633816551comparison function like C<< $a <=> $b >> any lists that might contain a
1633916552C<NaN>. The following example takes advantage that C<NaN != NaN> to
1634016553eliminate any C<NaN>s from the input list.
1634116554
1634216555=end original
1634316556
1634416557C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに
1634516558L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数で
1634616559ソートする場合はリストに C<NaN> が含まれないように注意してください。
1634716560以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を
1634816561利用しています。
1634916562
1635016563 my @result = sort { $a <=> $b } grep { $_ == $_ } @input;
1635116564
16565=begin original
16566
16567In this version of F<perl>, the C<sort> function is implemented via the
16568mergesort algorithm.
16569
16570=end original
16571
16572このバージョンの F<perl> では、C<sort> 関数はマージソートアルゴリズムで
16573実装されています。
16574
1635216575=item splice ARRAY,OFFSET,LENGTH,LIST
1635316576X<splice>
1635416577
1635516578=item splice ARRAY,OFFSET,LENGTH
1635616579
1635716580=item splice ARRAY,OFFSET
1635816581
1635916582=item splice ARRAY
1636016583
1636116584=for Pod::Functions add or remove elements anywhere in an array
1636216585
1636316586=begin original
1636416587
1636516588Removes the elements designated by OFFSET and LENGTH from an array, and
1636616589replaces them with the elements of LIST, if any. In list context,
1636716590returns the elements removed from the array. In scalar context,
1636816591returns the last element removed, or L<C<undef>|/undef EXPR> if no
1636916592elements are
1637016593removed. The array grows or shrinks as necessary.
1637116594If OFFSET is negative then it starts that far from the end of the array.
1637216595If LENGTH is omitted, removes everything from OFFSET onward.
1637316596If LENGTH is negative, removes the elements from OFFSET onward
1637416597except for -LENGTH elements at the end of the array.
1637516598If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
1637616599past the end of the array and a LENGTH was provided, Perl issues a warning,
1637716600and splices at the end of the array.
1637816601
1637916602=end original
1638016603
1638116604ARRAY から OFFSET、LENGTH で指定される要素を取り除き、
1638216605LIST があれば、それを代わりに挿入します。
1638316606リストコンテキストでは、配列から取り除かれた要素を返します。
1638416607スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が
1638516608取り除かれなかった場合は L<C<undef>|/undef EXPR> を返します。
1638616609配列は、必要に応じて、大きくなったり、小さくなったりします。
1638716610OFFSET が負の数の場合は、配列の最後からの距離を示します。
1638816611LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。
1638916612LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を
1639016613除いて取り除きます。
1639116614OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。
1639216615OFFSET が配列の最後より後ろで、 LENGTH が指定されていると、Perl は警告を出し、
1639316616配列の最後に対して処理します。
1639416617
1639516618=begin original
1639616619
1639716620The following equivalences hold (assuming C<< $#a >= $i >> )
1639816621
1639916622=end original
1640016623
1640116624以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。
1640216625
1640316626 push(@a,$x,$y) splice(@a,@a,0,$x,$y)
1640416627 pop(@a) splice(@a,-1)
1640516628 shift(@a) splice(@a,0,1)
1640616629 unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
1640716630 $a[$i] = $y splice(@a,$i,1,$y)
1640816631
1640916632=begin original
1641016633
1641116634L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> can be used, for example,
1641216635to implement n-ary queue processing:
1641316636
1641416637=end original
1641516638
1641616639L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は、例えば、n-ary キュー処理の
1641716640実装に使えます:
1641816641
1641916642 sub nary_print {
1642016643 my $n = shift;
1642116644 while (my @next_n = splice @_, 0, $n) {
1642216645 say join q{ -- }, @next_n;
1642316646 }
1642416647 }
1642516648
1642616649 nary_print(3, qw(a b c d e f g h));
1642716650 # prints:
1642816651 # a -- b -- c
1642916652 # d -- e -- f
1643016653 # g -- h
1643116654
1643216655=begin original
1643316656
1643416657Starting with Perl 5.14, an experimental feature allowed
1643516658L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a
1643616659scalar expression. This experiment has been deemed unsuccessful, and was
1643716660removed as of Perl 5.24.
1643816661
1643916662=end original
1644016663
1644116664Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> がスカラ式を
1644216665取ることが出来るという実験的機能がありました。
1644316666この実験は失敗と見なされ、Perl 5.24 で削除されました。
1644416667
1644516668=item split /PATTERN/,EXPR,LIMIT
1644616669X<split>
1644716670
1644816671=item split /PATTERN/,EXPR
1644916672
1645016673=item split /PATTERN/
1645116674
1645216675=item split
1645316676
1645416677=for Pod::Functions split up a string using a regexp delimiter
1645516678
1645616679=begin original
1645716680
1645816681Splits the string EXPR into a list of strings and returns the
1645916682list in list context, or the size of the list in scalar context.
1646016683(Prior to Perl 5.11, it also overwrote C<@_> with the list in
1646116684void and scalar context. If you target old perls, beware.)
1646216685
1646316686=end original
1646416687
1646516688文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリストを
1646616689返し、スカラコンテキストではリストの大きさを返します。
1646716690(Perl 5.11 以前では、無効コンテキストやスカラコンテキストの場合は
1646816691C<@_> をリストで上書きします。
1646916692もし古い perl を対象にするなら、注意してください。)
1647016693
1647116694=begin original
1647216695
1647316696If only PATTERN is given, EXPR defaults to L<C<$_>|perlvar/$_>.
1647416697
1647516698=end original
1647616699
1647716700PATTERN のみが与えられた場合、EXPR のデフォルトは L<C<$_>|perlvar/$_> です。
1647816701
1647916702=begin original
1648016703
1648116704Anything in EXPR that matches PATTERN is taken to be a separator
1648216705that separates the EXPR into substrings (called "I<fields>") that
1648316706do B<not> include the separator. Note that a separator may be
1648416707longer than one character or even have no characters at all (the
1648516708empty string, which is a zero-width match).
1648616709
1648716710=end original
1648816711
1648916712EXPR の中で PATTERN にマッチングするものは何でも EXPR を("I<fields>" と
1649016713呼ばれる)セパレータを B<含まない> 部分文字列に分割するための
1649116714セパレータとなります。
1649216715セパレータは一文字より長くてもよく、全く文字がなくてもよい(空文字列は
1649316716ゼロ幅マッチングです)ということに注意してください。
1649416717
1649516718=begin original
1649616719
1649716720The PATTERN need not be constant; an expression may be used
1649816721to specify a pattern that varies at runtime.
1649916722
1650016723=end original
1650116724
1650216725PATTERN は定数である必要はありません; 実行時に変更されるパターンを
1650316726指定するために式を使えます。
1650416727
1650516728=begin original
1650616729
1650716730If PATTERN matches the empty string, the EXPR is split at the match
1650816731position (between characters). As an example, the following:
1650916732
1651016733=end original
1651116734
1651216735PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置
1651316736(文字の間)で分割されます。
1651416737例えば、以下のものは:
1651516738
16516 print join(':', split(/b/, 'abc')), "\n";
16739 my @x = split(/b/, "abc"); # ("a", "c")
1651716740
1651816741=begin original
1651916742
16520uses the C<b> in C<'abc'> as a separator to produce the output C<a:c>.
16743uses the C<b> in C<'abc'> as a separator to produce the list ("a", "c").
1652116744However, this:
1652216745
1652316746=end original
1652416747
16525C<'abc'> の C<b> をセパレータとして使って出力 C<a:c> を生成します。
16748C<'abc'> の C<b> をセパレータとして使ってリスト ("a", "c") を生成します。
1652616749しかし、これは:
1652716750
16528 print join(':', split(//, 'abc')), "\n";
16751 my @x = split(//, "abc"); # ("a", "b", "c")
1652916752
1653016753=begin original
1653116754
16532uses empty string matches as separators to produce the output
16755uses empty string matches as separators; thus, the empty string
16533C<a:b:c>; thus, the empty string may be used to split EXPR into a
16756may be used to split EXPR into a list of its component characters.
16534list of its component characters.
1653516757
1653616758=end original
1653716759
16538空文字列マッチングをセパレータとして使って出力 C<a:b:c> を生成します; 従って、
16760空文字列マッチングをセパレータとして使ます; 従って、
1653916761空文字列は EXPR を構成する文字のリストに分割するために使われます。
1654016762
1654116763=begin original
1654216764
1654316765As a special case for L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
1654416766the empty pattern given in
1654516767L<match operator|perlop/"m/PATTERN/msixpodualngc"> syntax (C<//>)
1654616768specifically matches the empty string, which is contrary to its usual
1654716769interpretation as the last successful match.
1654816770
1654916771=end original
1655016772
1655116773L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> の特殊な場合として、
1655216774L<マッチング演算子|perlop/"m/PATTERN/msixpodualngc"> 文法で与えられた
1655316775空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した
1655416776マッチングという普通の解釈と異なります。
1655516777
1655616778=begin original
1655716779
1655816780If PATTERN is C</^/>, then it is treated as if it used the
1655916781L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it
1656016782isn't much use otherwise.
1656116783
1656216784=end original
1656316785
1656416786PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS>
1656516787(C</^/m>) が使われたかのように扱われます; そうでなければほとんど
1656616788使えないからです。
1656716789
1656816790=begin original
1656916791
1657016792C<E<sol>m> and any of the other pattern modifiers valid for C<qr>
1657116793(summarized in L<perlop/qrE<sol>STRINGE<sol>msixpodualn>) may be
1657216794specified explicitly.
1657316795
1657416796=end original
1657516797
1657616798C<qr> で有効な C<E<sol>m> 及びその他のパターン修飾子
1657716799(L<perlop/qrE<sol>STRINGE<sol>msixpodualn> にまとめられています) は
1657816800明示的に定義されます。
1657916801
1658016802=begin original
1658116803
1658216804As another special case,
1658316805L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default
1658416806behavior of the
1658516807command line tool B<awk> when the PATTERN is either omitted or a
1658616808string composed of a single space character (such as S<C<' '>> or
1658716809S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading
1658816810whitespace in EXPR is removed before splitting occurs, and the PATTERN is
1658916811instead treated as if it were C</\s+/>; in particular, this means that
1659016812I<any> contiguous whitespace (not just a single space character) is used as
16591a separator. However, this special treatment can be avoided by specifying
16813a separator.
16592the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
16593only a single space character to be a separator. In earlier Perls this
16594special case was restricted to the use of a plain S<C<" ">> as the
16595pattern argument to split; in Perl 5.18.0 and later this special case is
16596triggered by any expression which evaluates to the simple string S<C<" ">>.
1659716814
1659816815=end original
1659916816
1660016817もう一つの特別な場合として、
1660116818L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> は
1660216819PATTERN が省略されるか単一のスペース文字からなる文字列 (つまり例えば
1660316820S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール
1660416821B<awk> のデフォルトの振る舞いをエミュレートします。
1660516822この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は
1660616823C</\s+/> であったかのように扱われます; 特に、これは (単に単一の
1660716824スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして
1660816825使われるということです。
16826
16827 my @x = split(" ", " Quick brown fox\n");
16828 # ("Quick", "brown", "fox")
16829
16830 my @x = split(" ", "RED\tGREEN\tBLUE");
16831 # ("RED", "GREEN", "BLUE")
16832
16833=begin original
16834
16835Using split in this fashion is very similar to how
16836L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>> works.
16837
16838=end original
16839
16840この方法で split を使うのは、
16841L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>> の動作と非常に似ています。
16842
16843=begin original
16844
16845However, this special treatment can be avoided by specifying
16846the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
16847only a single space character to be a separator. In earlier Perls this
16848special case was restricted to the use of a plain S<C<" ">> as the
16849pattern argument to split; in Perl 5.18.0 and later this special case is
16850triggered by any expression which evaluates to the simple string S<C<" ">>.
16851
16852=end original
16853
1660916854しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を
1661016855指定することで回避でき、それによってセパレータとして単一の
1661116856スペース文字のみが使われます。
1661216857以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を
1661316858使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は
1661416859単純な文字列 S<C<" ">> と評価される任意の式によって引き起こされます。
1661516860
1661616861=begin original
1661716862
1661816863As of Perl 5.28, this special-cased whitespace splitting works as expected in
16619the scope of L<< S<C<"use feature 'unicode_strings">>|feature/The
16864the scope of L<< S<C<"use feature 'unicode_strings'">>|feature/The
1662016865'unicode_strings' feature >>. In previous versions, and outside the scope of
1662116866that feature, it exhibits L<perlunicode/The "Unicode Bug">: characters that are
1662216867whitespace according to Unicode rules but not according to ASCII rules can be
1662316868treated as part of fields rather than as field separators, depending on the
1662416869string's internal encoding.
1662516870
1662616871=end original
1662716872
1662816873Perl 5.28 から、この特別な場合の空白分割は
16629L<< S<C<"use feature 'unicode_strings">>|feature/The
16874L<< S<C<"use feature 'unicode_strings'">>|feature/The
1663016875'unicode_strings' feature >> のスコープの中では想定通りに動作します。
1663116876以前のバージョンでは、そしてこの機能のスコープの外側では、
1663216877これは L<perlunicode/The "Unicode Bug"> を引き起こします:
1663316878Unicode によれば空白だけれども ASCII の規則ではそうではない文字は、
1663416879文字列の内部エンコーディングに依存して、
1663516880フィールドの区切りではなくフィールドの一部として扱われることがあります。
1663616881
1663716882=begin original
1663816883
1663916884If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering
1664016885the previously described I<awk> emulation.
1664116886
1664216887=end original
1664316888
1664416889省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、
1664516890先に記述した I<awk> エミュレーションを起動します。
1664616891
1664716892=begin original
1664816893
1664916894If LIMIT is specified and positive, it represents the maximum number
1665016895of fields into which the EXPR may be split; in other words, LIMIT is
1665116896one greater than the maximum number of times EXPR may be split. Thus,
1665216897the LIMIT value C<1> means that EXPR may be split a maximum of zero
1665316898times, producing a maximum of one field (namely, the entire value of
1665416899EXPR). For instance:
1665516900
1665616901=end original
1665716902
1665816903LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を
1665916904表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。
1666016905従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、
1666116906最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。
1666216907例えば:
1666316908
16664 print join(':', split(//, 'abc', 1)), "\n";
16909 my @x = split(//, "abc", 1); # ("abc")
16910 my @x = split(//, "abc", 2); # ("a", "bc")
16911 my @x = split(//, "abc", 3); # ("a", "b", "c")
16912 my @x = split(//, "abc", 4); # ("a", "b", "c")
1666516913
1666616914=begin original
1666716915
16668produces the output C<abc>, and this:
16669
16670=end original
16671
16672これは C<abc> を出力し、次のものは:
16673
16674 print join(':', split(//, 'abc', 2)), "\n";
16675
16676=begin original
16677
16678produces the output C<a:bc>, and each of these:
16679
16680=end original
16681
16682C<a:bc> を出力し、以下のものそれぞれは:
16683
16684 print join(':', split(//, 'abc', 3)), "\n";
16685 print join(':', split(//, 'abc', 4)), "\n";
16686
16687=begin original
16688
16689produces the output C<a:b:c>.
16690
16691=end original
16692
16693C<a:b:c> を出力します。
16694
16695=begin original
16696
1669716916If LIMIT is negative, it is treated as if it were instead arbitrarily
1669816917large; as many fields as possible are produced.
1669916918
1670016919=end original
1670116920
1670216921LIMIT が負数なら、非常に大きい数であるかのように扱われます; できるだけ多くの
1670316922フィールドが生成されます。
1670416923
1670516924=begin original
1670616925
1670716926If LIMIT is omitted (or, equivalently, zero), then it is usually
1670816927treated as if it were instead negative but with the exception that
1670916928trailing empty fields are stripped (empty leading fields are always
1671016929preserved); if all fields are empty, then all fields are considered to
1671116930be trailing (and are thus stripped in this case). Thus, the following:
1671216931
1671316932=end original
1671416933
1671516934LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように
1671616935動作しますが、末尾の空フィールドは取り除かれるという例外があります
1671716936(先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、
1671816937全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。
1671916938従って、以下のようにすると:
1672016939
16721 print join(':', split(/,/, 'a,b,c,,,')), "\n";
16940 my @x = split(/,/, "a,b,c,,,"); # ("a", "b", "c")
1672216941
1672316942=begin original
1672416943
16725produces the output C<a:b:c>, but the following:
16944produces only a three element list.
1672616945
1672716946=end original
1672816947
16729出力 C<a:b:c> を生成しますが、以下のようにすると:
169483 要素だけのリストを生成します
1673016949
16731 print join(':', split(/,/, 'a,b,c,,,', -1)), "\n";
16950 my @x = split(/,/, "a,b,c,,,", -1); # ("a", "b", "c", "", "", "")
1673216951
1673316952=begin original
1673416953
16735produces the output C<a:b:c:::>.
16954produces a six element list.
1673616955
1673716956=end original
1673816957
16739出力 C<a:b:c:::> を生成します。
169586 要素のリストを生成します。
1674016959
1674116960=begin original
1674216961
1674316962In time-critical applications, it is worthwhile to avoid splitting
1674416963into more fields than necessary. Thus, when assigning to a list,
1674516964if LIMIT is omitted (or zero), then LIMIT is treated as though it
1674616965were one larger than the number of variables in the list; for the
1674716966following, LIMIT is implicitly 3:
1674816967
1674916968=end original
1675016969
1675116970時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは
1675216971価値があります。
1675316972従って、リストに代入される場合に、LIMIT が省略される(または 0)と、
1675416973LIMIT は リストにある変数の数より一つ大きい数のように扱われます;
1675516974次の場合、LIMIT は暗黙に 3 になります:
1675616975
1675716976 my ($login, $passwd) = split(/:/);
1675816977
1675916978=begin original
1676016979
1676116980Note that splitting an EXPR that evaluates to the empty string always
1676216981produces zero fields, regardless of the LIMIT specified.
1676316982
1676416983=end original
1676516984
1676616985LIMIT の指定に関わらず、空文字列に評価される EXPR を分割すると常に 0 個の
1676716986フィールドを生成することに注意してください。
1676816987
1676916988=begin original
1677016989
1677116990An empty leading field is produced when there is a positive-width
1677216991match at the beginning of EXPR. For instance:
1677316992
1677416993=end original
1677516994
1677616995EXPR の先頭で正数幅でマッチングしたときには先頭に空のフィールドが
1677716996生成されます。
1677816997例えば:
1677916998
16780 print join(':', split(/ /, ' abc')), "\n";
16999 my @x = split(/ /, " abc"); # ("", "abc")
1678117000
1678217001=begin original
1678317002
16784produces the output C<:abc>. However, a zero-width match at the
17003splits into two elements. However, a zero-width match at the
1678517004beginning of EXPR never produces an empty field, so that:
1678617005
1678717006=end original
1678817007
16789これは出力 C<:abc> を生成します。
17008これは 2 要素に分割します。
1679017009しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので:
1679117010
16792 print join(':', split(//, ' abc'));
17011 my @x = split(//, " abc"); # (" ", "a", "b", "c")
1679317012
1679417013=begin original
1679517014
16796produces the output S<C< :a:b:c>> (rather than S<C<: :a:b:c>>).
17015splits into four elements instead of five.
1679717016
1679817017=end original
1679917018
16800これは(S<C<: :a:b:c>> ではなく)出力 S<C< :a:b:c>> を生成します。
17019これは 5 要素ではなく 4 要素に分割します。
1680117020
1680217021=begin original
1680317022
1680417023An empty trailing field, on the other hand, is produced when there is a
1680517024match at the end of EXPR, regardless of the length of the match
1680617025(of course, unless a non-zero LIMIT is given explicitly, such fields are
1680717026removed, as in the last example). Thus:
1680817027
1680917028=end original
1681017029
1681117030一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で
1681217031マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に
1681317032指定されていない場合です; このようなフィールドは前の例のように
1681417033取り除かれます)。
1681517034従って:
1681617035
16817 print join(':', split(//, ' abc', -1)), "\n";
17036 my @x = split(//, " abc", -1); # (" ", "a", "b", "c", "")
1681817037
1681917038=begin original
1682017039
16821produces the output S<C< :a:b:c:>>.
16822
16823=end original
16824
16825これは出力 S<C< :a:b:c:>> を生成します。
16826
16827=begin original
16828
1682917040If the PATTERN contains
1683017041L<capturing groups|perlretut/Grouping things and hierarchical matching>,
1683117042then for each separator, an additional field is produced for each substring
1683217043captured by a group (in the order in which the groups are specified,
1683317044as per L<backreferences|perlretut/Backreferences>); if any group does not
1683417045match, then it captures the L<C<undef>|/undef EXPR> value instead of a
1683517046substring. Also,
1683617047note that any such additional field is produced whenever there is a
1683717048separator (that is, whenever a split occurs), and such an additional field
1683817049does B<not> count towards the LIMIT. Consider the following expressions
1683917050evaluated in list context (each returned list is provided in the associated
1684017051comment):
1684117052
1684217053=end original
1684317054
1684417055PATTERN が
1684517056L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を
1684617057含んでいる場合、それぞれのセパレータについて、
1684717058(L<後方参照|perlretut/Backreferences> のようにグループが指定された)
1684817059グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが
1684917060生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに
1685017061L<C<undef>|/undef EXPR> 値を捕捉します。
1685117062また、このような追加のフィールドはセパレータがあるとき(つまり、分割が
1685217063行われるとき)はいつでも生成され、このような追加のフィールドは
1685317064LIMIT に関してはカウント B<されない> ことに注意してください。
1685417065リストコンテキストで評価される以下のような式を考えます
1685517066(それぞれの返されるリストは関連づけられたコメントで提供されます):
1685617067
16857 split(/-|,/, "1-10,20", 3)
17068 my @x = split(/-|,/ , "1-10,20", 3);
16858 # ('1', '10', '20')
17069 # ("1", "10", "20")
1685917070
16860 split(/(-|,)/, "1-10,20", 3)
17071 my @x = split(/(-|,)/ , "1-10,20", 3);
16861 # ('1', '-', '10', ',', '20')
17072 # ("1", "-", "10", ",", "20")
1686217073
16863 split(/-|(,)/, "1-10,20", 3)
17074 my @x = split(/-|(,)/ , "1-10,20", 3);
16864 # ('1', undef, '10', ',', '20')
17075 # ("1", undef, "10", ",", "20")
1686517076
16866 split(/(-)|,/, "1-10,20", 3)
17077 my @x = split(/(-)|,/ , "1-10,20", 3);
16867 # ('1', '-', '10', undef, '20')
17078 # ("1", "-", "10", undef, "20")
1686817079
16869 split(/(-)|(,)/, "1-10,20", 3)
17080 my @x = split(/(-)|(,)/, "1-10,20", 3);
16870 # ('1', '-', undef, '10', undef, ',', '20')
17081 # ("1", "-", undef, "10", undef, ",", "20")
1687117082
1687217083=item sprintf FORMAT, LIST
1687317084X<sprintf>
1687417085
1687517086=for Pod::Functions formatted print into a string
1687617087
1687717088=begin original
1687817089
1687917090Returns a string formatted by the usual
1688017091L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C
1688117092library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for
1688217093more details and see L<sprintf(3)> or L<printf(3)> on your system for an
1688317094explanation of the general principles.
1688417095
1688517096=end original
1688617097
1688717098C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST> の
1688817099普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の
1688917100整形された文字列を返します。
1689017101一般的な原則の説明については以下の説明と、システムの
1689117102L<sprintf(3)> または L<printf(3)> の説明を参照してください。
1689217103
1689317104=begin original
1689417105
1689517106For example:
1689617107
1689717108=end original
1689817109
1689917110例えば:
1690017111
1690117112 # Format number with up to 8 leading zeroes
1690217113 my $result = sprintf("%08d", $number);
1690317114
1690417115 # Round number to 3 digits after decimal point
1690517116 my $rounded = sprintf("%.3f", $number);
1690617117
1690717118=begin original
1690817119
1690917120Perl does its own L<C<sprintf>|/sprintf FORMAT, LIST> formatting: it
1691017121emulates the C
1691117122function L<sprintf(3)>, but doesn't use it except for floating-point
1691217123numbers, and even then only standard modifiers are allowed.
1691317124Non-standard extensions in your local L<sprintf(3)> are
1691417125therefore unavailable from Perl.
1691517126
1691617127=end original
1691717128
1691817129Perl は L<C<sprintf>|/sprintf FORMAT, LIST> フォーマット処理を自力で行います:
1691917130これは C の L<sprintf(3)> 関数をエミュレートしますが、C の関数は使いません
1692017131(浮動小数点を除きますが、それでも標準の記述子のみが利用できます)。
1692117132従って、ローカルな非標準の L<sprintf(3)> 拡張機能は Perl では使えません。
1692217133
1692317134=begin original
1692417135
1692517136Unlike L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
1692617137L<C<sprintf>|/sprintf FORMAT, LIST> does not do what you probably mean
1692717138when you pass it an array as your first argument.
1692817139The array is given scalar context,
1692917140and instead of using the 0th element of the array as the format, Perl will
1693017141use the count of elements in the array as the format, which is almost never
1693117142useful.
1693217143
1693317144=end original
1693417145
1693517146L<C<printf>|/printf FILEHANDLE FORMAT, LIST> と違って、
1693617147L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても
1693717148あなたが多分望むとおりには動作しません。
1693817149配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、
1693917150配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません。
1694017151
1694117152=begin original
1694217153
1694317154Perl's L<C<sprintf>|/sprintf FORMAT, LIST> permits the following
1694417155universally-known conversions:
1694517156
1694617157=end original
1694717158
1694817159Perl の L<C<sprintf>|/sprintf FORMAT, LIST> は以下の一般に知られている変換に
1694917160対応しています:
1695017161
1695117162=begin original
1695217163
1695317164 %% a percent sign
1695417165 %c a character with the given number
1695517166 %s a string
1695617167 %d a signed integer, in decimal
1695717168 %u an unsigned integer, in decimal
1695817169 %o an unsigned integer, in octal
1695917170 %x an unsigned integer, in hexadecimal
1696017171 %e a floating-point number, in scientific notation
1696117172 %f a floating-point number, in fixed decimal notation
1696217173 %g a floating-point number, in %e or %f notation
1696317174
1696417175=end original
1696517176
1696617177 %% パーセントマーク
1696717178 %c 与えられた番号の文字
1696817179 %s 文字列
1696917180 %d 符号付き 10 進数
1697017181 %u 符号なし 10 進数
1697117182 %o 符号なし 8 進数
1697217183 %x 符号なし 16 進数
1697317184 %e 科学的表記の浮動小数点数
1697417185 %f 固定 10 進数表記の浮動小数点数
1697517186 %g %e か %f の表記の浮動小数点数
1697617187
1697717188=begin original
1697817189
1697917190In addition, Perl permits the following widely-supported conversions:
1698017191
1698117192=end original
1698217193
1698317194さらに、Perl では以下のよく使われている変換に対応しています:
1698417195
1698517196=begin original
1698617197
1698717198 %X like %x, but using upper-case letters
1698817199 %E like %e, but using an upper-case "E"
1698917200 %G like %g, but with an upper-case "E" (if applicable)
1699017201 %b an unsigned integer, in binary
1699117202 %B like %b, but using an upper-case "B" with the # flag
1699217203 %p a pointer (outputs the Perl value's address in hexadecimal)
1699317204 %n special: *stores* the number of characters output so far
1699417205 into the next argument in the parameter list
1699517206 %a hexadecimal floating point
1699617207 %A like %a, but using upper-case letters
1699717208
1699817209=end original
1699917210
1700017211 %X %x と同様だが大文字を使う
1700117212 %E %e と同様だが大文字の "E" を使う
1700217213 %G %g と同様だが(適切なら)大文字の "E" を使う
1700317214 %b 符号なし 2 進数
1700417215 %B %b と同様だが、# フラグで大文字の "B" を使う
1700517216 %p ポインタ (Perl の値のアドレスを 16 進数で出力する)
1700617217 %n 特殊: 出力文字数を引数リストの次の変数に「格納」する
1700717218 %a 16 進浮動小数点
1700817219 %A %a と同様だが、大文字を使う
1700917220
1701017221=begin original
1701117222
1701217223Finally, for backward (and we do mean "backward") compatibility, Perl
1701317224permits these unnecessary but widely-supported conversions:
1701417225
1701517226=end original
1701617227
1701717228最後に、過去との互換性(これは「過去」だと考えています)のために、
1701817229Perl は以下の不要ではあるけれども広く使われている変換に対応しています。
1701917230
1702017231=begin original
1702117232
1702217233 %i a synonym for %d
1702317234 %D a synonym for %ld
1702417235 %U a synonym for %lu
1702517236 %O a synonym for %lo
1702617237 %F a synonym for %f
1702717238
1702817239=end original
1702917240
1703017241 %i %d の同義語
1703117242 %D %ld の同義語
1703217243 %U %lu の同義語
1703317244 %O %lo の同義語
1703417245 %F %f の同義語
1703517246
1703617247=begin original
1703717248
1703817249Note that the number of exponent digits in the scientific notation produced
1703917250by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
1704017251exponent less than 100 is system-dependent: it may be three or less
1704117252(zero-padded as necessary). In other words, 1.23 times ten to the
170421725399th may be either "1.23e99" or "1.23e099". Similarly for C<%a> and C<%A>:
1704317254the exponent or the hexadecimal digits may float: especially the
1704417255"long doubles" Perl configuration option may cause surprises.
1704517256
1704617257=end original
1704717258
1704817259C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の
1704917260指数部の科学的な表記法はシステム依存であることに注意してください:
17050172613 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で
1705117262パッディングされます)。
1705217263言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし
1705317264"1.23e099" かもしれません。
1705417265同様に C<%a> と C<%A> の場合:
1705517266指数部と 16 進数が浮動小数点かもしれません:
1705617267特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。
1705717268
1705817269=begin original
1705917270
1706017271Between the C<%> and the format letter, you may specify several
1706117272additional attributes controlling the interpretation of the format.
1706217273In order, these are:
1706317274
1706417275=end original
1706517276
1706617277C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、
1706717278いくつかの追加の属性を指定できます。
1706817279順番に、以下のものがあります:
1706917280
1707017281=over 4
1707117282
1707217283=item format parameter index
1707317284
1707417285(フォーマットパラメータインデックス)
1707517286
1707617287=begin original
1707717288
1707817289An explicit format parameter index, such as C<2$>. By default sprintf
1707917290will format the next unused argument in the list, but this allows you
1708017291to take the arguments out of order:
1708117292
1708217293=end original
1708317294
1708417295C<2$> のような明示的なフォーマットパラメータインデックス。
1708517296デフォルトでは sprintf はリストの次の使われていない引数を
1708617297フォーマットしますが、これによって異なった順番の引数を使えるようにします:
1708717298
1708817299 printf '%2$d %1$d', 12, 34; # prints "34 12"
1708917300 printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1"
1709017301
1709117302=item flags
1709217303
1709317304(フラグ)
1709417305
1709517306=begin original
1709617307
1709717308one or more of:
1709817309
1709917310=end original
1710017311
1710117312以下のうちの一つまたは複数指定できます:
1710217313
1710317314=begin original
1710417315
1710517316 space prefix non-negative number with a space
1710617317 + prefix non-negative number with a plus sign
1710717318 - left-justify within the field
1710817319 0 use zeros, not spaces, to right-justify
1710917320 # ensure the leading "0" for any octal,
1711017321 prefix non-zero hexadecimal with "0x" or "0X",
1711117322 prefix non-zero binary with "0b" or "0B"
1711217323
1711317324=end original
1711417325
1711517326 space 非負数の前に空白をつける
1711617327 + 非負数の前にプラス記号をつける
1711717328 - フィールド内で左詰めする
1711817329 0 右詰めに空白ではなくゼロを使う
1711917330 # 8 進数では確実に先頭に "0" をつける;
1712017331 非 0 の 16 進数では "0x" か "0X" をつける;
1712117332 非 0 の 2 進数では "0b" か "0B" をつける
1712217333
1712317334=begin original
1712417335
1712517336For example:
1712617337
1712717338=end original
1712817339
1712917340例えば:
1713017341
1713117342 printf '<% d>', 12; # prints "< 12>"
1713217343 printf '<% d>', 0; # prints "< 0>"
1713317344 printf '<% d>', -12; # prints "<-12>"
1713417345 printf '<%+d>', 12; # prints "<+12>"
1713517346 printf '<%+d>', 0; # prints "<+0>"
1713617347 printf '<%+d>', -12; # prints "<-12>"
1713717348 printf '<%6s>', 12; # prints "< 12>"
1713817349 printf '<%-6s>', 12; # prints "<12 >"
1713917350 printf '<%06s>', 12; # prints "<000012>"
1714017351 printf '<%#o>', 12; # prints "<014>"
1714117352 printf '<%#x>', 12; # prints "<0xc>"
1714217353 printf '<%#X>', 12; # prints "<0XC>"
1714317354 printf '<%#b>', 12; # prints "<0b1100>"
1714417355 printf '<%#B>', 12; # prints "<0B1100>"
1714517356
1714617357=begin original
1714717358
1714817359When a space and a plus sign are given as the flags at once,
1714917360the space is ignored.
1715017361
1715117362=end original
1715217363
1715317364空白とプラス記号がフラグとして同時に与えられると、
1715417365空白は無視されます。
1715517366
1715617367 printf '<%+ d>', 12; # prints "<+12>"
1715717368 printf '<% +d>', 12; # prints "<+12>"
1715817369
1715917370=begin original
1716017371
1716117372When the # flag and a precision are given in the %o conversion,
1716217373the precision is incremented if it's necessary for the leading "0".
1716317374
1716417375=end original
1716517376
1716617377%o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は
1716717378精度に 1 が加えられます。
1716817379
1716917380 printf '<%#.5o>', 012; # prints "<00012>"
1717017381 printf '<%#.5o>', 012345; # prints "<012345>"
1717117382 printf '<%#.0o>', 0; # prints "<0>"
1717217383
1717317384=item vector flag
1717417385
1717517386(ベクタフラグ)
1717617387
1717717388=begin original
1717817389
1717917390This flag tells Perl to interpret the supplied string as a vector of
1718017391integers, one for each character in the string. Perl applies the format to
1718117392each integer in turn, then joins the resulting strings with a separator (a
1718217393dot C<.> by default). This can be useful for displaying ordinal values of
1718317394characters in arbitrary strings:
1718417395
1718517396=end original
1718617397
1718717398このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして
1718817399解釈させます。
1718917400Perl は各数値をフォーマットし、それから結果の文字列をセパレータ
1719017401(デフォルトでは C<.>)で連結します。
1719117402これは任意の文字列の文字を順序付きの値として表示するのに便利です:
1719217403
1719317404 printf "%vd", "AB\x{100}"; # prints "65.66.256"
1719417405 printf "version is v%vd\n", $^V; # Perl's version
1719517406
1719617407=begin original
1719717408
1719817409Put an asterisk C<*> before the C<v> to override the string to
1719917410use to separate the numbers:
1720017411
1720117412=end original
1720217413
1720317414アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を
1720417415上書きします:
1720517416
1720617417 printf "address is %*vX\n", ":", $addr; # IPv6 address
1720717418 printf "bits are %0*v8b\n", " ", $bits; # random bitstring
1720817419
1720917420=begin original
1721017421
1721117422You can also explicitly specify the argument number to use for
1721217423the join string using something like C<*2$v>; for example:
1721317424
1721417425=end original
1721517426
1721617427また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に
1721717428指定できます; 例えば:
1721817429
1721917430 printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses
1722017431 @addr[1..3], ":";
1722117432
1722217433=item (minimum) width
1722317434
1722417435((最小)幅)
1722517436
1722617437=begin original
1722717438
1722817439Arguments are usually formatted to be only as wide as required to
1722917440display the given value. You can override the width by putting
1723017441a number here, or get the width from the next argument (with C<*>)
1723117442or from a specified argument (e.g., with C<*2$>):
1723217443
1723317444=end original
1723417445
1723517446引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。
1723617447ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で
1723717448幅を上書きできます。
1723817449
1723917450 printf "<%s>", "a"; # prints "<a>"
1724017451 printf "<%6s>", "a"; # prints "< a>"
1724117452 printf "<%*s>", 6, "a"; # prints "< a>"
1724217453 printf '<%*2$s>', "a", 6; # prints "< a>"
1724317454 printf "<%2s>", "long"; # prints "<long>" (does not truncate)
1724417455
1724517456=begin original
1724617457
1724717458If a field width obtained through C<*> is negative, it has the same
1724817459effect as the C<-> flag: left-justification.
1724917460
1725017461=end original
1725117462
1725217463C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと
1725317464同様の効果 (左詰め) があります。
1725417465
1725517466=item precision, or maximum width
1725617467X<precision>
1725717468
1725817469(精度あるいは最大幅)
1725917470
1726017471=begin original
1726117472
1726217473You can specify a precision (for numeric conversions) or a maximum
1726317474width (for string conversions) by specifying a C<.> followed by a number.
1726417475For floating-point formats except C<g> and C<G>, this specifies
1726517476how many places right of the decimal point to show (the default being 6).
1726617477For example:
1726717478
1726817479=end original
1726917480
1727017481C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合)
1727117482最大幅を指定できます。
1727217483小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の
1727317484桁数を指定します(デフォルトは 6 です)。
1727417485例えば:
1727517486
1727617487 # these examples are subject to system-specific variation
1727717488 printf '<%f>', 1; # prints "<1.000000>"
1727817489 printf '<%.1f>', 1; # prints "<1.0>"
1727917490 printf '<%.0f>', 1; # prints "<1>"
1728017491 printf '<%e>', 10; # prints "<1.000000e+01>"
1728117492 printf '<%.1e>', 10; # prints "<1.0e+01>"
1728217493
1728317494=begin original
1728417495
1728517496For "g" and "G", this specifies the maximum number of significant digits to
1728617497show; for example:
1728717498
1728817499=end original
1728917500
1729017501"g" と "G" の場合、これは最大有効数字を指定します; 例えば:
1729117502
1729217503 # These examples are subject to system-specific variation.
1729317504 printf '<%g>', 1; # prints "<1>"
1729417505 printf '<%.10g>', 1; # prints "<1>"
1729517506 printf '<%g>', 100; # prints "<100>"
1729617507 printf '<%.1g>', 100; # prints "<1e+02>"
1729717508 printf '<%.2g>', 100.01; # prints "<1e+02>"
1729817509 printf '<%.5g>', 100.01; # prints "<100.01>"
1729917510 printf '<%.4g>', 100.01; # prints "<100>"
1730017511 printf '<%.1g>', 0.0111; # prints "<0.01>"
1730117512 printf '<%.2g>', 0.0111; # prints "<0.011>"
1730217513 printf '<%.3g>', 0.0111; # prints "<0.0111>"
1730317514
1730417515=begin original
1730517516
1730617517For integer conversions, specifying a precision implies that the
1730717518output of the number itself should be zero-padded to this width,
1730817519where the 0 flag is ignored:
1730917520
1731017521=end original
1731117522
1731217523整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で
1731317524パッディングするべきであることを暗に示すことになり、0 フラグは
1731417525無視されます:
1731517526
1731617527 printf '<%.6d>', 1; # prints "<000001>"
1731717528 printf '<%+.6d>', 1; # prints "<+000001>"
1731817529 printf '<%-10.6d>', 1; # prints "<000001 >"
1731917530 printf '<%10.6d>', 1; # prints "< 000001>"
1732017531 printf '<%010.6d>', 1; # prints "< 000001>"
1732117532 printf '<%+10.6d>', 1; # prints "< +000001>"
1732217533
1732317534 printf '<%.6x>', 1; # prints "<000001>"
1732417535 printf '<%#.6x>', 1; # prints "<0x000001>"
1732517536 printf '<%-10.6x>', 1; # prints "<000001 >"
1732617537 printf '<%10.6x>', 1; # prints "< 000001>"
1732717538 printf '<%010.6x>', 1; # prints "< 000001>"
1732817539 printf '<%#10.6x>', 1; # prints "< 0x000001>"
1732917540
1733017541=begin original
1733117542
1733217543For string conversions, specifying a precision truncates the string
1733317544to fit the specified width:
1733417545
1733517546=end original
1733617547
1733717548文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を
1733817549切り詰めます:
1733917550
1734017551 printf '<%.5s>', "truncated"; # prints "<trunc>"
1734117552 printf '<%10.5s>', "truncated"; # prints "< trunc>"
1734217553
1734317554=begin original
1734417555
1734517556You can also get the precision from the next argument using C<.*>, or from a
1734617557specified argument (e.g., with C<.*2$>):
1734717558
1734817559=end original
1734917560
1735017561C<.*> を使って精度を次の引数から取ったり、
1735117562(C<.*2$> のように) 指定した引数から取ったりすることもできます:
1735217563
1735317564 printf '<%.6x>', 1; # prints "<000001>"
1735417565 printf '<%.*x>', 6, 1; # prints "<000001>"
1735517566
1735617567 printf '<%.*2$x>', 1, 6; # prints "<000001>"
1735717568
1735817569 printf '<%6.*2$x>', 1, 4; # prints "< 0001>"
1735917570
1736017571=begin original
1736117572
1736217573If a precision obtained through C<*> is negative, it counts
1736317574as having no precision at all.
1736417575
1736517576=end original
1736617577
1736717578C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と
1736817579同じ効果となります。
1736917580
1737017581 printf '<%.*s>', 7, "string"; # prints "<string>"
1737117582 printf '<%.*s>', 3, "string"; # prints "<str>"
1737217583 printf '<%.*s>', 0, "string"; # prints "<>"
1737317584 printf '<%.*s>', -1, "string"; # prints "<string>"
1737417585
1737517586 printf '<%.*d>', 1, 0; # prints "<0>"
1737617587 printf '<%.*d>', 0, 0; # prints "<>"
1737717588 printf '<%.*d>', -1, 0; # prints "<0>"
1737817589
1737917590=item size
1738017591
1738117592(サイズ)
1738217593
1738317594=begin original
1738417595
1738517596For numeric conversions, you can specify the size to interpret the
1738617597number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer
1738717598conversions (C<d u o x X b i D U O>), numbers are usually assumed to be
1738817599whatever the default integer size is on your platform (usually 32 or 64
1738917600bits), but you can override this to use instead one of the standard C types,
1739017601as supported by the compiler used to build Perl:
1739117602
1739217603=end original
1739317604
1739417605数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の
1739517606大きさを指定できます。
1739617607整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの
1739717608デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、
1739817609これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで
1739917610上書きできます:
1740017611
1740117612=begin original
1740217613
1740317614 hh interpret integer as C type "char" or "unsigned
1740417615 char" on Perl 5.14 or later
1740517616 h interpret integer as C type "short" or
1740617617 "unsigned short"
1740717618 j interpret integer as C type "intmax_t" on Perl
1740817619 5.14 or later; and prior to Perl 5.30, only with
1740917620 a C99 compiler (unportable)
1741017621 l interpret integer as C type "long" or
1741117622 "unsigned long"
1741217623 q, L, or ll interpret integer as C type "long long",
1741317624 "unsigned long long", or "quad" (typically
1741417625 64-bit integers)
1741517626 t interpret integer as C type "ptrdiff_t" on Perl
1741617627 5.14 or later
1741717628 z interpret integer as C types "size_t" or
1741817629 "ssize_t" on Perl 5.14 or later
1741917630
1742017631=end original
1742117632
1742217633 hh Perl 5.14 以降で整数を C の "char" または "unsigned char"
1742317634 型として解釈する
1742417635 h 整数を C の "char" または "unsigned char" 型として解釈する
1742517636 j Perl 5.14 以降 Perl 5.30 以前の C99 コンパイラのみで整数を
1742617637 C の "intmax_t" 型として解釈する (移植性なし)
1742717638 l 整数を C の "long" または "unsigned long" と解釈する
1742817639 h 整数を C の "short" または "unsigned short" と解釈する
1742917640 q, L or ll 整数を C の "long long", "unsigned long long",
1743017641 "quads"(典型的には 64 ビット整数) のどれかと解釈する
1743117642 t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する
1743217643 z Perl 5.14 以降で整数を C の "size_t" 型または "ssize_t" 型
1743317644 として解釈する
1743417645
1743517646=begin original
1743617647
17648Note that, in general, using the C<l> modifier (for example, when writing
17649C<"%ld"> or C<"%lu"> instead of C<"%d"> and C<"%u">) is unnecessary
17650when used from Perl code. Moreover, it may be harmful, for example on
17651Windows 64-bit where a long is 32-bits.
17652
17653=end original
17654
17655一般的に、C<l> 修飾子を使う (例えば、C<"%d"> と C<"%u"> ではなく
17656C<"%ld"> や C<"%lu"> と書く) ことは、Perl のコードから使われる場合は
17657不要であることに注意してください。
17658さらに、例えば long が 32 ビットのときの 64 ビット Windows のように、
17659有害な場合もあります。
17660
17661=begin original
17662
1743717663As of 5.14, none of these raises an exception if they are not supported on
1743817664your platform. However, if warnings are enabled, a warning of the
1743917665L<C<printf>|warnings> warning class is issued on an unsupported
1744017666conversion flag. Should you instead prefer an exception, do this:
1744117667
1744217668=end original
1744317669
17444176705.14 から、プラットフォームがこれらに対応していないときでも例外が
1744517671発生しなくなりました。
1744617672しかし、もし警告が有効になっているなら、
1744717673非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。
1744817674例外の方がお好みなら、以下のようにします:
1744917675
1745017676 use warnings FATAL => "printf";
1745117677
1745217678=begin original
1745317679
1745417680If you would like to know about a version dependency before you
1745517681start running the program, put something like this at its top:
1745617682
1745717683=end original
1745817684
1745917685プログラムの実行開始前にバージョン依存について知りたいなら、先頭に
1746017686以下のようなものを書きます:
1746117687
17462 use 5.014; # for hh/j/t/z/ printf modifiers
17688 use v5.14; # for hh/j/t/z/ printf modifiers
1746317689
1746417690=begin original
1746517691
1746617692You can find out whether your Perl supports quads via L<Config>:
1746717693
1746817694=end original
1746917695
1747017696Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って
1747117697調べられます:
1747217698
1747317699 use Config;
1747417700 if ($Config{use64bitint} eq "define"
1747517701 || $Config{longsize} >= 8) {
1747617702 print "Nice quads!\n";
1747717703 }
1747817704
1747917705=begin original
1748017706
1748117707For floating-point conversions (C<e f g E F G>), numbers are usually assumed
1748217708to be the default floating-point size on your platform (double or long double),
1748317709but you can force "long double" with C<q>, C<L>, or C<ll> if your
1748417710platform supports them. You can find out whether your Perl supports long
1748517711doubles via L<Config>:
1748617712
1748717713=end original
1748817714
1748917715浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの
1749017716不動小数点数のサイズ (double か long double) を仮定しますが、
1749117717プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して
1749217718"long double" を強制できます。
1749317719Perl が long double に対応しているかどうかは L<Config> を使って
1749417720調べられます:
1749517721
1749617722 use Config;
1749717723 print "long doubles\n" if $Config{d_longdbl} eq "define";
1749817724
1749917725=begin original
1750017726
1750117727You can find out whether Perl considers "long double" to be the default
1750217728floating-point size to use on your platform via L<Config>:
1750317729
1750417730=end original
1750517731
1750617732Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは
1750717733L<Config> を使って調べられます:
1750817734
1750917735 use Config;
1751017736 if ($Config{uselongdouble} eq "define") {
1751117737 print "long doubles by default\n";
1751217738 }
1751317739
1751417740=begin original
1751517741
1751617742It can also be that long doubles and doubles are the same thing:
1751717743
1751817744=end original
1751917745
1752017746long double と double が同じ場合もあります:
1752117747
1752217748 use Config;
1752317749 ($Config{doublesize} == $Config{longdblsize}) &&
1752417750 print "doubles are long doubles\n";
1752517751
1752617752=begin original
1752717753
1752817754The size specifier C<V> has no effect for Perl code, but is supported for
1752917755compatibility with XS code. It means "use the standard size for a Perl
1753017756integer or floating-point number", which is the default.
1753117757
1753217758=end original
1753317759
1753417760サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは
1753517761XS コードとの互換性のために対応しています。
1753617762これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを
1753717763意味し、これはデフォルトです。
1753817764
1753917765=item order of arguments
1754017766
1754117767(引数の順序)
1754217768
1754317769=begin original
1754417770
1754517771Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused
1754617772argument as the value to
1754717773format for each format specification. If the format specification
1754817774uses C<*> to require additional arguments, these are consumed from
1754917775the argument list in the order they appear in the format
1755017776specification I<before> the value to format. Where an argument is
1755117777specified by an explicit index, this does not affect the normal
1755217778order for the arguments, even when the explicitly specified index
1755317779would have been the next argument.
1755417780
1755517781=end original
1755617782
1755717783通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、
1755817784使われていない次の引数を
1755917785フォーマットする値として使います。
1756017786追加の引数を要求するためにフォーマット指定 C<*> を使うと、
1756117787これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に
1756217788引数リストから消費されます。
1756317789引数の位置が明示的なインデックスを使って指定された場合、
1756417790(明示的に指定したインデックスが次の引数の場合でも)
1756517791これは通常の引数の順番に影響を与えません。
1756617792
1756717793=begin original
1756817794
1756917795So:
1757017796
1757117797=end original
1757217798
1757317799それで:
1757417800
1757517801 printf "<%*.*s>", $a, $b, $c;
1757617802
1757717803=begin original
1757817804
1757917805uses C<$a> for the width, C<$b> for the precision, and C<$c>
1758017806as the value to format; while:
1758117807
1758217808=end original
1758317809
1758417810とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に
1758517811使います; 一方:
1758617812
1758717813 printf '<%*1$.*s>', $a, $b;
1758817814
1758917815=begin original
1759017816
1759117817would use C<$a> for the width and precision, and C<$b> as the
1759217818value to format.
1759317819
1759417820=end original
1759517821
1759617822とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。
1759717823
1759817824=begin original
1759917825
1760017826Here are some more examples; be aware that when using an explicit
1760117827index, the C<$> may need escaping:
1760217828
1760317829=end original
1760417830
1760517831以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は
1760617832エスケープする必要があることに注意してください:
1760717833
1760817834 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
1760917835 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
1761017836 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
1761117837 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
1761217838 printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n"
1761317839
1761417840=back
1761517841
1761617842=begin original
1761717843
1761817844If L<C<use locale>|locale> (including C<use locale ':not_characters'>)
1761917845is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
1762017846called,
1762117847the character used for the decimal separator in formatted floating-point
1762217848numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale>
1762317849and L<POSIX>.
1762417850
1762517851=end original
1762617852
1762717853(C<use locale ':not_characters'> を含む)L<C<use locale>|locale> が有効で、
1762817854L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されている場合、
1762917855フォーマットされた浮動小数点数の小数点として使われる文字は
1763017856C<LC_NUMERIC> ロケールの影響を受けます。
1763117857L<perllocale> と L<POSIX> を参照してください。
1763217858
1763317859=item sqrt EXPR
1763417860X<sqrt> X<root> X<square root>
1763517861
1763617862=item sqrt
1763717863
1763817864=for Pod::Functions square root function
1763917865
1764017866=begin original
1764117867
1764217868Return the positive square root of EXPR. If EXPR is omitted, uses
1764317869L<C<$_>|perlvar/$_>. Works only for non-negative operands unless you've
1764417870loaded the L<C<Math::Complex>|Math::Complex> module.
1764517871
1764617872=end original
1764717873
1764817874EXPR の正の平方根を返します。
1764917875EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1765017876L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は
1765117877扱えません。
1765217878
1765317879 use Math::Complex;
1765417880 print sqrt(-4); # prints 2i
1765517881
1765617882=item srand EXPR
1765717883X<srand> X<seed> X<randseed>
1765817884
1765917885=item srand
1766017886
1766117887=for Pod::Functions seed the random number generator
1766217888
1766317889=begin original
1766417890
1766517891Sets and returns the random number seed for the L<C<rand>|/rand EXPR>
1766617892operator.
1766717893
1766817894=end original
1766917895
1767017896L<C<rand>|/rand EXPR> 演算子のためのシード値を設定して返します。
1767117897
1767217898=begin original
1767317899
1767417900The point of the function is to "seed" the L<C<rand>|/rand EXPR>
1767517901function so that L<C<rand>|/rand EXPR> can produce a different sequence
1767617902each time you run your program. When called with a parameter,
1767717903L<C<srand>|/srand EXPR> uses that for the seed; otherwise it
1767817904(semi-)randomly chooses a seed. In either case, starting with Perl 5.14,
1767917905it returns the seed. To signal that your code will work I<only> on Perls
1768017906of a recent vintage:
1768117907
1768217908=end original
1768317909
1768417910この関数のポイントは、プログラムを実行するごとに L<C<rand>|/rand EXPR> 関数が
1768517911異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を
1768617912設定することです。
1768717913L<C<srand>|/srand EXPR> を引数付きで呼び出すと、これを種として使います;
1768817914さもなければ(だいたい)ランダムに種を選びます。
1768917915どちらの場合でも、Perl 5.14 からは種を返します。
1769017916特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします:
1769117917
17692 use 5.014; # so srand returns the seed
17918 use v5.14; # so srand returns the seed
1769317919
1769417920=begin original
1769517921
1769617922If L<C<srand>|/srand EXPR> is not called explicitly, it is called
1769717923implicitly without a parameter at the first use of the
1769817924L<C<rand>|/rand EXPR> operator. However, there are a few situations
1769917925where programs are likely to want to call L<C<srand>|/srand EXPR>. One
1770017926is for generating predictable results, generally for testing or
1770117927debugging. There, you use C<srand($seed)>, with the same C<$seed> each
1770217928time. Another case is that you may want to call L<C<srand>|/srand EXPR>
1770317929after a L<C<fork>|/fork> to avoid child processes sharing the same seed
1770417930value as the parent (and consequently each other).
1770517931
1770617932=end original
1770717933
1770817934L<C<srand>|/srand EXPR> が明示的に呼び出されなかった場合、最初に
1770917935L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。
1771017936しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR> を
1771117937呼び出したいであろう状況がいくつかあります。
1771217938一つはテストやデバッグのために予測可能な結果を生成するためです。
1771317939この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。
1771417940もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を
1771517941共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を
1771617942呼び出したいかもしれません。
1771717943
1771817944=begin original
1771917945
1772017946Do B<not> call C<srand()> (i.e., without an argument) more than once per
1772117947process. The internal state of the random number generator should
1772217948contain more entropy than can be provided by any seed, so calling
1772317949L<C<srand>|/srand EXPR> again actually I<loses> randomness.
1772417950
1772517951=end original
1772617952
1772717953L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回
1772817954呼び出しては B<いけません>。
1772917955乱数生成器の内部状態はどのような種によって提供されるものよりも
1773017956高いエントロピーを持っているので、C<srand()> を再び呼び出すと
1773117957ランダム性が I<失われます>。
1773217958
1773317959=begin original
1773417960
1773517961Most implementations of L<C<srand>|/srand EXPR> take an integer and will
1773617962silently
1773717963truncate decimal numbers. This means C<srand(42)> will usually
1773817964produce the same results as C<srand(42.1)>. To be safe, always pass
1773917965L<C<srand>|/srand EXPR> an integer.
1774017966
1774117967=end original
1774217968
1774317969L<C<srand>|/srand EXPR> のほとんどの実装では整数を取り、小数を暗黙に
1774417970切り捨てます。
1774517971これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。
1774617972安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。
1774717973
1774817974=begin original
1774917975
1775017976A typical use of the returned seed is for a test program which has too many
1775117977combinations to test comprehensively in the time available to it each run. It
1775217978can test a random subset each time, and should there be a failure, log the seed
1775317979used for that run so that it can later be used to reproduce the same results.
1775417980
1775517981=end original
1775617982
1775717983返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に
1775817984行うには組み合わせが多すぎるテストプログラム用です。
1775917985毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った
1776017986種をログに出力することで、後で同じ結果を再現するために使えます。
1776117987
1776217988=begin original
1776317989
1776417990B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
1776517991on it in security-sensitive situations.> As of this writing, a
1776617992number of third-party CPAN modules offer random number generators
1776717993intended by their authors to be cryptographically secure,
1776817994including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1776917995and L<Math::TrulyRandom>.
1777017996
1777117997=end original
1777217998
1777317999B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
1777418000セキュリティ的に重要な状況でこれに頼るべきではありません。>
1777518001これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
1777618002作者によって暗号学的に安全であることを目的とした乱数生成器を
1777718003提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1777818004L<Math::TrulyRandom> などです。
1777918005
1778018006=item stat FILEHANDLE
1778118007X<stat> X<file, status> X<ctime>
1778218008
1778318009=item stat EXPR
1778418010
1778518011=item stat DIRHANDLE
1778618012
1778718013=item stat
1778818014
1778918015=for Pod::Functions get a file's status information
1779018016
1779118017=begin original
1779218018
1779318019Returns a 13-element list giving the status info for a file, either
1779418020the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
1779518021omitted, it stats L<C<$_>|perlvar/$_> (not C<_>!). Returns the empty
1779618022list if L<C<stat>|/stat FILEHANDLE> fails. Typically
1779718023used as follows:
1779818024
1779918025=end original
1780018026
1780118027FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、
1780218028EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。
1780318029EXPR が省略されると、 L<C<$_>|perlvar/$_> が用いられます
1780418030(C<_> ではありません!)。
1780518031L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。
1780618032普通は、以下のようにして使います:
1780718033
1780818034 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1780918035 $atime,$mtime,$ctime,$blksize,$blocks)
1781018036 = stat($filename);
1781118037
1781218038=begin original
1781318039
1781418040Not all fields are supported on all filesystem types. Here are the
1781518041meanings of the fields:
1781618042
1781718043=end original
1781818044
1781918045全てのファイルシステムで全てのフィールドに対応しているわけではありません。
1782018046フィールドの意味は以下の通りです。
1782118047
1782218048=begin original
1782318049
1782418050 0 dev device number of filesystem
1782518051 1 ino inode number
1782618052 2 mode file mode (type and permissions)
1782718053 3 nlink number of (hard) links to the file
1782818054 4 uid numeric user ID of file's owner
1782918055 5 gid numeric group ID of file's owner
1783018056 6 rdev the device identifier (special files only)
1783118057 7 size total size of file, in bytes
1783218058 8 atime last access time in seconds since the epoch
1783318059 9 mtime last modify time in seconds since the epoch
1783418060 10 ctime inode change time in seconds since the epoch (*)
1783518061 11 blksize preferred I/O size in bytes for interacting with the
1783618062 file (may vary from file to file)
1783718063 12 blocks actual number of system-specific blocks allocated
1783818064 on disk (often, but not always, 512 bytes each)
1783918065
1784018066=end original
1784118067
1784218068 0 dev ファイルシステムのデバイス番号
1784318069 1 ino inode 番号
1784418070 2 mode ファイルモード (タイプとパーミッション)
1784518071 3 nlink ファイルへの(ハード)リンクの数
1784618072 4 uid ファイル所有者のユーザー ID の数値
1784718073 5 gid ファイル所有者のグループ ID の数値
1784818074 6 rdev デバイス識別子(特殊ファイルのみ)
1784918075 7 size ファイルサイズ(バイト単位)
1785018076 8 atime 紀元から、最後にアクセスされた時刻までの秒数
1785118077 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数
1785218078 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*)
1785318079 11 blksize ファイルとの相互作用のために適した I/O バイト数
1785418080 (ファイルごとに異なるかもしれない)
1785518081 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは
1785618082 ありませんがたいていはそれぞれ 512 バイト)の数
1785718083
1785818084=begin original
1785918085
1786018086(The epoch was at 00:00 January 1, 1970 GMT.)
1786118087
1786218088=end original
1786318089
1786418090(紀元は GMT で 1970/01/01 00:00:00。)
1786518091
1786618092=begin original
1786718093
1786818094(*) Not all fields are supported on all filesystem types. Notably, the
1786918095ctime field is non-portable. In particular, you cannot expect it to be a
1787018096"creation time"; see L<perlport/"Files and Filesystems"> for details.
1787118097
1787218098=end original
1787318099
1787418100(*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは
1787518101ありません。
1787618102明らかに、ctime のフィールドは移植性がありません。
1787718103特に、これから「作成時刻」を想定することは出来ません;
1787818104詳細については L<perlport/"Files and Filesystems"> を参照してください。
1787918105
1788018106=begin original
1788118107
1788218108If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle
1788318109consisting of an underline, no stat is done, but the current contents of
1788418110the stat structure from the last L<C<stat>|/stat FILEHANDLE>,
1788518111L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example:
1788618112
1788718113=end original
1788818114
1788918115下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE> に
1789018116渡すと、実際には stat を行なわず、stat 構造体に残っている
1789118117前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE> や
1789218118ファイルテストの情報が返されます。
1789318119例:
1789418120
1789518121 if (-x $file && (($d) = stat(_)) && $d < 0) {
1789618122 print "$file is executable NFS file\n";
1789718123 }
1789818124
1789918125=begin original
1790018126
1790118127(This works on machines only for which the device number is negative
1790218128under NFS.)
1790318129
1790418130=end original
1790518131
1790618132(これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。)
1790718133
1790818134=begin original
1790918135
1791018136On some platforms inode numbers are of a type larger than perl knows how
1791118137to handle as integer numerical values. If necessary, an inode number will
1791218138be returned as a decimal string in order to preserve the entire value.
1791318139If used in a numeric context, this will be converted to a floating-point
1791418140numerical value, with rounding, a fate that is best avoided. Therefore,
1791518141you should prefer to compare inode numbers using C<eq> rather than C<==>.
1791618142C<eq> will work fine on inode numbers that are represented numerically,
1791718143as well as those represented as strings.
1791818144
1791918145=end original
1792018146
1792118147一部のプラットフォームでは、inode 番号は perl が整数値として
1792218148扱い方を知っているものよりも大きい型になっています。
1792318149もし必要なら、inode 番号は、値全体を保存するために 10 進文字列として
1792418150返されます。
1792518151数値コンテキストで使うと、これは丸めを伴う浮動小数点数に変換され、
1792618152できるだけ避けるべき結果になります。
1792718153従って、inode 番号の比較には C<==> ではなく C<eq> を使うべきです。
1792818154C<eq> は、inode 番号が数値で表現されていても、文字列で表現されていても
1792918155うまく動作します。
1793018156
1793118157=begin original
1793218158
1793318159Because the mode contains both the file type and its permissions, you
1793418160should mask off the file type portion and (s)printf using a C<"%o">
1793518161if you want to see the real permissions.
1793618162
1793718163=end original
1793818164
1793918165モードにはファイルタイプとその権限の両方が含まれているので、
1794018166本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで
1794118167ファイルタイプをマスクするべきです。
1794218168
1794318169 my $mode = (stat($filename))[2];
1794418170 printf "Permissions are %04o\n", $mode & 07777;
1794518171
1794618172=begin original
1794718173
1794818174In scalar context, L<C<stat>|/stat FILEHANDLE> returns a boolean value
1794918175indicating success
1795018176or failure, and, if successful, sets the information associated with
1795118177the special filehandle C<_>.
1795218178
1795318179=end original
1795418180
1795518181スカラコンテキストでは、L<C<stat>|/stat FILEHANDLE> は成功か失敗を表す真偽値を
1795618182返し、成功した場合は、特別なファイルハンドル C<_> に結び付けられた
1795718183情報をセットします。
1795818184
1795918185=begin original
1796018186
1796118187The L<File::stat> module provides a convenient, by-name access mechanism:
1796218188
1796318189=end original
1796418190
1796518191L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。
1796618192
1796718193 use File::stat;
1796818194 my $sb = stat($filename);
1796918195 printf "File is %s, size is %s, perm %04o, mtime %s\n",
1797018196 $filename, $sb->size, $sb->mode & 07777,
1797118197 scalar localtime $sb->mtime;
1797218198
1797318199=begin original
1797418200
1797518201You can import symbolic mode constants (C<S_IF*>) and functions
1797618202(C<S_IS*>) from the L<Fcntl> module:
1797718203
1797818204=end original
1797918205
1798018206モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を L<Fcntl> モジュールから
1798118207インポートできます。
1798218208
1798318209 use Fcntl ':mode';
1798418210
1798518211 my $mode = (stat($filename))[2];
1798618212
1798718213 my $user_rwx = ($mode & S_IRWXU) >> 6;
1798818214 my $group_read = ($mode & S_IRGRP) >> 3;
1798918215 my $other_execute = $mode & S_IXOTH;
1799018216
1799118217 printf "Permissions are %04o\n", S_IMODE($mode), "\n";
1799218218
1799318219 my $is_setuid = $mode & S_ISUID;
1799418220 my $is_directory = S_ISDIR($mode);
1799518221
1799618222=begin original
1799718223
1799818224You could write the last two using the C<-u> and C<-d> operators.
1799918225Commonly available C<S_IF*> constants are:
1800018226
1800118227=end original
1800218228
1800318229最後の二つは C<-u> と C<-d> 演算子を使っても書けます。
1800418230一般に利用可能な C<S_IF*> 定数は以下のものです。
1800518231
1800618232 # Permissions: read, write, execute, for user, group, others.
1800718233
1800818234 S_IRWXU S_IRUSR S_IWUSR S_IXUSR
1800918235 S_IRWXG S_IRGRP S_IWGRP S_IXGRP
1801018236 S_IRWXO S_IROTH S_IWOTH S_IXOTH
1801118237
1801218238 # Setuid/Setgid/Stickiness/SaveText.
1801318239 # Note that the exact meaning of these is system-dependent.
1801418240
1801518241 S_ISUID S_ISGID S_ISVTX S_ISTXT
1801618242
1801718243 # File types. Not all are necessarily available on
1801818244 # your system.
1801918245
1802018246 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR
1802118247 S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
1802218248
1802318249 # The following are compatibility aliases for S_IRUSR,
1802418250 # S_IWUSR, and S_IXUSR.
1802518251
1802618252 S_IREAD S_IWRITE S_IEXEC
1802718253
1802818254=begin original
1802918255
1803018256and the C<S_IF*> functions are
1803118257
1803218258=end original
1803318259
1803418260一般に利用可能な C<S_IF*> 関数は以下のものです。
1803518261
1803618262 S_IMODE($mode) the part of $mode containing the permission
1803718263 bits and the setuid/setgid/sticky bits
1803818264
1803918265 S_IFMT($mode) the part of $mode containing the file type
1804018266 which can be bit-anded with (for example)
1804118267 S_IFREG or with the following functions
1804218268
1804318269 # The operators -f, -d, -l, -b, -c, -p, and -S.
1804418270
1804518271 S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
1804618272 S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)
1804718273
1804818274 # No direct -X operator counterpart, but for the first one
1804918275 # the -g operator is often equivalent. The ENFMT stands for
1805018276 # record flocking enforcement, a platform-dependent feature.
1805118277
1805218278 S_ISENFMT($mode) S_ISWHT($mode)
1805318279
1805418280=begin original
1805518281
1805618282See your native L<chmod(2)> and L<stat(2)> documentation for more details
1805718283about the C<S_*> constants. To get status info for a symbolic link
1805818284instead of the target file behind the link, use the
1805918285L<C<lstat>|/lstat FILEHANDLE> function.
1806018286
1806118287=end original
1806218288
1806318289C<S_*> 定数に関する詳細についてはネイティブの L<chmod(2)> と L<stat(2)> の
1806418290ドキュメントを参照してください。
1806518291リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を
1806618292得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。
1806718293
1806818294=begin original
1806918295
1807018296Portability issues: L<perlport/stat>.
1807118297
1807218298=end original
1807318299
1807418300移植性の問題: L<perlport/stat>。
1807518301
1807618302=item state VARLIST
1807718303X<state>
1807818304
1807918305=item state TYPE VARLIST
1808018306
1808118307=item state VARLIST : ATTRS
1808218308
1808318309=item state TYPE VARLIST : ATTRS
1808418310
1808518311=for Pod::Functions +state declare and assign a persistent lexical variable
1808618312
1808718313=begin original
1808818314
1808918315L<C<state>|/state VARLIST> declares a lexically scoped variable, just
1809018316like L<C<my>|/my VARLIST>.
1809118317However, those variables will never be reinitialized, contrary to
1809218318lexical variables that are reinitialized each time their enclosing block
1809318319is entered.
1809418320See L<perlsub/"Persistent Private Variables"> for details.
1809518321
1809618322=end original
1809718323
1809818324L<C<state>|/state VARLIST> はちょうど L<C<my>|/my VARLIST> と同様に、
1809918325レキシカルなスコープの変数を宣言します。
1810018326しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、
1810118327この変数は決して再初期化されません。
1810218328詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。
1810318329
1810418330=begin original
1810518331
1810618332If more than one variable is listed, the list must be placed in
1810718333parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be
1810818334used as a
1810918335dummy placeholder. However, since initialization of state variables in
1811018336such lists is currently not possible this would serve no purpose.
1811118337
1811218338=end original
1811318339
18114複数の変数を指定する場合、かっこで囲まなければなりません。
18340複数の変数を指定する場合リストはかっこで囲まなければなりません。
1811518341かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミーの
1811618342プレースホルダとして使えます。
1811718343しかし、そのようなリストでの state 変数の初期化は現在のところできないので、
1811818344これは無意味です。
1811918345
1812018346=begin original
1812118347
18348Redeclaring a variable in the same scope or statement will "shadow" the
18349previous declaration, creating a new instance and preventing access to
18350the previous one. This is usually undesired and, if warnings are enabled,
18351will result in a warning in the C<shadow> category.
18352
18353=end original
18354
18355同じスコープや文で変数を再宣言すると、以前の宣言を「隠し」、
18356新しい実体を作って、以前の実体にアクセスできなくなります。
18357これは普通は望まれているものではなく、警告が有効なら、
18358C<shadow> カテゴリの警告が出ます。
18359
18360=begin original
18361
1812218362L<C<state>|/state VARLIST> is available only if the
1812318363L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
1812418364prefixed with C<CORE::>. The
1812518365L<C<"state"> feature|feature/The 'state' feature> is enabled
1812618366automatically with a C<use v5.10> (or higher) declaration in the current
1812718367scope.
1812818368
1812918369=end original
1813018370
1813118371L<C<state>|/state VARLIST> は
1813218372L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を
1813318373前置した場合にのみ利用可能です。
1813418374L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
1813518375C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
1813618376
1813718377=item study SCALAR
1813818378X<study>
1813918379
1814018380=item study
1814118381
1814218382=for Pod::Functions no-op, formerly optimized input data for repeated searches
1814318383
1814418384=begin original
1814518385
1814618386At this time, C<study> does nothing. This may change in the future.
1814718387
1814818388=end original
1814918389
1815018390現時点では、C<study> は何もしません。
1815118391これは将来変更されるかもしれません。
1815218392
1815318393=begin original
1815418394
1815518395Prior to Perl version 5.16, it would create an inverted index of all characters
1815618396that occurred in the given SCALAR (or L<C<$_>|perlvar/$_> if unspecified). When
1815718397matching a pattern, the rarest character from the pattern would be looked up in
1815818398this index. Rarity was based on some static frequency tables constructed from
1815918399some C programs and English text.
1816018400
1816118401=end original
1816218402
1816318403Perl バージョン 5.16 より前では、
1816418404与えられた SCALAR (または指定されていなかった場合は L<C<$_>|perlvar/$_>)に
1816518405現れた全ての文字の転置インデックスを作ります。
1816618406パターンにマッチングしたとき、
1816718407パターン中の最も頻度の少ない文字がこのインデックスから探されます。
1816818408頻度は、C プログラムと英語の文章から構築された静的頻度テーブルを
1816918409基にしています。
1817018410
1817118411=item sub NAME BLOCK
1817218412X<sub>
1817318413
1817418414=item sub NAME (PROTO) BLOCK
1817518415
1817618416=item sub NAME : ATTRS BLOCK
1817718417
1817818418=item sub NAME (PROTO) : ATTRS BLOCK
1817918419
1818018420=for Pod::Functions declare a subroutine, possibly anonymously
1818118421
1818218422=begin original
1818318423
1818418424This is subroutine definition, not a real function I<per se>. Without a
1818518425BLOCK it's just a forward declaration. Without a NAME, it's an anonymous
1818618426function declaration, so does return a value: the CODE ref of the closure
1818718427just created.
1818818428
1818918429=end original
1819018430
1819118431これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。
1819218432BLOCK なしの場合、これは単に前方宣言です。
1819318433NAME なしの場合は、無名関数定義であり、値(作成したブロックの
1819418434コードリファレンス)を返します: 単にクロージャの CODE リファレンスが
1819518435作成されます。
1819618436
1819718437=begin original
1819818438
1819918439See L<perlsub> and L<perlref> for details about subroutines and
1820018440references; see L<attributes> and L<Attribute::Handlers> for more
1820118441information about attributes.
1820218442
1820318443=end original
1820418444
1820518445サブルーチンとリファレンスに関する詳細については、L<perlsub> と
1820618446L<perlref> を参照してください; 属性に関する更なる情報については
1820718447L<attributes> と L<Attribute::Handlers> を参照してください。
1820818448
1820918449=item __SUB__
1821018450X<__SUB__>
1821118451
1821218452=for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine
1821318453
1821418454=begin original
1821518455
1821618456A special token that returns a reference to the current subroutine, or
1821718457L<C<undef>|/undef EXPR> outside of a subroutine.
1821818458
1821918459=end original
1822018460
1822118461現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では
1822218462L<C<undef>|/undef EXPR>。
1822318463
1822418464=begin original
1822518465
1822618466The behaviour of L<C<__SUB__>|/__SUB__> within a regex code block (such
1822718467as C</(?{...})/>) is subject to change.
1822818468
1822918469=end original
1823018470
1823118471(C</(?{...})/> のような) 正規表現コードブロックの中の
1823218472L<C<__SUB__>|/__SUB__> の振る舞いは変更される予定です。
1823318473
1823418474=begin original
1823518475
1823618476This token is only available under C<use v5.16> or the
1823718477L<C<"current_sub"> feature|feature/The 'current_sub' feature>.
1823818478See L<feature>.
1823918479
1824018480=end original
1824118481
1824218482このトークンは C<use v5.16> または
1824318483L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ
1824418484利用可能です。
1824518485L<feature> を参照してください。
1824618486
1824718487=item substr EXPR,OFFSET,LENGTH,REPLACEMENT
1824818488X<substr> X<substring> X<mid> X<left> X<right>
1824918489
1825018490=item substr EXPR,OFFSET,LENGTH
1825118491
1825218492=item substr EXPR,OFFSET
1825318493
1825418494=for Pod::Functions get or alter a portion of a string
1825518495
1825618496=begin original
1825718497
1825818498Extracts a substring out of EXPR and returns it. First character is at
1825918499offset zero. If OFFSET is negative, starts
1826018500that far back from the end of the string. If LENGTH is omitted, returns
1826118501everything through the end of the string. If LENGTH is negative, leaves that
1826218502many characters off the end of the string.
1826318503
1826418504=end original
1826518505
1826618506EXPR から、部分文字列を取り出して返します。
1826718507最初の文字がオフセット 0 となります。
1826818508OFFSET に負の値を設定すると、EXPR の終わりからのオフセットとなります。
1826918509LENGTH を省略すると、EXPR の最後まですべてが返されます。
1827018510LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。
1827118511
1827218512 my $s = "The black cat climbed the green tree";
1827318513 my $color = substr $s, 4, 5; # black
1827418514 my $middle = substr $s, 4, -11; # black cat climbed the
1827518515 my $end = substr $s, 14; # climbed the green tree
1827618516 my $tail = substr $s, -4; # tree
1827718517 my $z = substr $s, -4, 2; # tr
1827818518
1827918519=begin original
1828018520
1828118521You can use the L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>
1828218522function as an lvalue, in which case EXPR
1828318523must itself be an lvalue. If you assign something shorter than LENGTH,
1828418524the string will shrink, and if you assign something longer than LENGTH,
1828518525the string will grow to accommodate it. To keep the string the same
1828618526length, you may need to pad or chop your value using
1828718527L<C<sprintf>|/sprintf FORMAT, LIST>.
1828818528
1828918529=end original
1829018530
1829118531L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として
1829218532使用することも可能で、その場合には、EXPR が自身左辺値でなければなりません。
1829318533LENGTH より短いものを代入したときには、
1829418534EXPR は短くなり、LENGTH より長いものを代入したときには、
1829518535EXPR はそれに合わせて伸びることになります。
1829618536EXPR の長さを一定に保つためには、L<C<sprintf>|/sprintf FORMAT, LIST> を
1829718537使って、代入する値の長さを調整することが、必要になるかもしれません。
1829818538
1829918539=begin original
1830018540
1830118541If OFFSET and LENGTH specify a substring that is partly outside the
1830218542string, only the part within the string is returned. If the substring
1830318543is beyond either end of the string,
1830418544L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined
1830518545value and produces a warning. When used as an lvalue, specifying a
1830618546substring that is entirely outside the string raises an exception.
1830718547Here's an example showing the behavior for boundary cases:
1830818548
1830918549=end original
1831018550
1831118551OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、
1831218552文字列の内側の部分だけが返されます。
1831318553部分文字列が文字列の両端の外側の場合、
1831418554L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、
1831518555警告が出力されます。
1831618556左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると
1831718557例外が発生します。
1831818558以下は境界条件の振る舞いを示す例です:
1831918559
1832018560 my $name = 'fred';
1832118561 substr($name, 4) = 'dy'; # $name is now 'freddy'
1832218562 my $null = substr $name, 6, 2; # returns "" (no warning)
1832318563 my $oops = substr $name, 7; # returns undef, with warning
1832418564 substr($name, 7) = 'gap'; # raises an exception
1832518565
1832618566=begin original
1832718567
1832818568An alternative to using
1832918569L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to
1833018570specify the
1833118571replacement string as the 4th argument. This allows you to replace
1833218572parts of the EXPR and return what was there before in one operation,
1833318573just as you can with
1833418574L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>.
1833518575
1833618576=end original
1833718577
1833818578L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として使う
1833918579代わりの方法は、置き換える文字列を 4 番目の引数として指定することです。
1834018580これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、
1834118581ということを(L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> と同様)
18342185821 動作で行えます。
1834318583
1834418584 my $s = "The black cat climbed the green tree";
1834518585 my $z = substr $s, 14, 7, "jumped from"; # climbed
1834618586 # $s is now "The black cat jumped from the green tree"
1834718587
1834818588=begin original
1834918589
1835018590Note that the lvalue returned by the three-argument version of
1835118591L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as
1835218592a 'magic bullet'; each time it is assigned to, it remembers which part
1835318593of the original string is being modified; for example:
1835418594
1835518595=end original
1835618596
18357185973 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された
1835818598左辺値は「魔法の弾丸」のように振舞うことに注意してください;
1835918599これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます;
1836018600例えば:
1836118601
1836218602 my $x = '1234';
1836318603 for (substr($x,1,2)) {
1836418604 $_ = 'a'; print $x,"\n"; # prints 1a4
1836518605 $_ = 'xyz'; print $x,"\n"; # prints 1xyz4
1836618606 $x = '56789';
1836718607 $_ = 'pq'; print $x,"\n"; # prints 5pq9
1836818608 }
1836918609
1837018610=begin original
1837118611
1837218612With negative offsets, it remembers its position from the end of the string
1837318613when the target string is modified:
1837418614
1837518615=end original
1837618616
1837718617負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの
1837818618位置を覚えます:
1837918619
1838018620 my $x = '1234';
1838118621 for (substr($x, -3, 2)) {
1838218622 $_ = 'a'; print $x,"\n"; # prints 1a4, as above
1838318623 $x = 'abcdefg';
1838418624 print $_,"\n"; # prints f
1838518625 }
1838618626
1838718627=begin original
1838818628
1838918629Prior to Perl version 5.10, the result of using an lvalue multiple times was
1839018630unspecified. Prior to 5.16, the result with negative offsets was
1839118631unspecified.
1839218632
1839318633=end original
1839418634
1839518635バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は
1839618636未定義でした。
18397186375.16 より前では、負のオフセットの結果は未定義です。
1839818638
1839918639=item symlink OLDFILE,NEWFILE
1840018640X<symlink> X<link> X<symbolic link> X<link, symbolic>
1840118641
1840218642=for Pod::Functions create a symbolic link to a file
1840318643
1840418644=begin original
1840518645
1840618646Creates a new filename symbolically linked to the old filename.
1840718647Returns C<1> for success, C<0> otherwise. On systems that don't support
1840818648symbolic links, raises an exception. To check for that,
1840918649use eval:
1841018650
1841118651=end original
1841218652
1841318653NEWFILE として、OLDFILE へのシンボリックリンクを生成します。
1841418654成功時には C<1> を返し、失敗時には C<0> を返します。
1841518655シンボリックリンクをサポートしていないシステムでは、
1841618656例外が発生します。
1841718657これをチェックするには、eval を使用します:
1841818658
1841918659 my $symlink_exists = eval { symlink("",""); 1 };
1842018660
1842118661=begin original
1842218662
1842318663Portability issues: L<perlport/symlink>.
1842418664
1842518665=end original
1842618666
1842718667移植性の問題: L<perlport/symlink>。
1842818668
1842918669=item syscall NUMBER, LIST
1843018670X<syscall> X<system call>
1843118671
1843218672=for Pod::Functions execute an arbitrary system call
1843318673
1843418674=begin original
1843518675
1843618676Calls the system call specified as the first element of the list,
1843718677passing the remaining elements as arguments to the system call. If
1843818678unimplemented, raises an exception. The arguments are interpreted
1843918679as follows: if a given argument is numeric, the argument is passed as
1844018680an int. If not, the pointer to the string value is passed. You are
1844118681responsible to make sure a string is pre-extended long enough to
1844218682receive any result that might be written into a string. You can't use a
1844318683string literal (or other read-only string) as an argument to
1844418684L<C<syscall>|/syscall NUMBER, LIST> because Perl has to assume that any
1844518685string pointer might be written through. If your
1844618686integer arguments are not literals and have never been interpreted in a
1844718687numeric context, you may need to add C<0> to them to force them to look
1844818688like numbers. This emulates the
1844918689L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or
1845018690vice versa):
1845118691
1845218692=end original
1845318693
1845418694LIST の最初の要素で指定するシステムコールを、残りの要素をその
1845518695システムコールの引数として呼び出します。
1845618696実装されていない場合には、例外が発生します。
1845718697引数は、以下のように解釈されます: 引数が数字であれば、int として
1845818698引数を渡します。
1845918699そうでなければ、文字列値へのポインタが渡されます。
1846018700文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、
1846118701文字列を予め伸ばしておく必要があります。
1846218702文字列リテラル(あるいはその他の読み込み専用の文字列)を
1846318703L<C<syscall>|/syscall NUMBER, LIST> の引数として使うことはできません;
1846418704Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。
1846518705整数引数が、リテラルでなく、数値コンテキストで評価されたことのない
1846618706ものであれば、数値として解釈されるように、
1846718707C<0> を足しておく必要があるかもしれません。
1846818708以下は L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> 関数(あるいは
1846918709その逆)をエミュレートします。
1847018710
1847118711 require 'syscall.ph'; # may need to run h2ph
1847218712 my $s = "hi there\n";
1847318713 syscall(SYS_write(), fileno(STDOUT), $s, length $s);
1847418714
1847518715=begin original
1847618716
1847718717Note that Perl supports passing of up to only 14 arguments to your syscall,
1847818718which in practice should (usually) suffice.
1847918719
1848018720=end original
1848118721
1848218722Perl は、システムコールに最大 14 個の引数しか渡せませんが、
1848318723(普通は)実用上問題はないでしょう。
1848418724
1848518725=begin original
1848618726
1848718727Syscall returns whatever value returned by the system call it calls.
1848818728If the system call fails, L<C<syscall>|/syscall NUMBER, LIST> returns
1848918729C<-1> and sets L<C<$!>|perlvar/$!> (errno).
1849018730Note that some system calls I<can> legitimately return C<-1>. The proper
1849118731way to handle such calls is to assign C<$! = 0> before the call, then
1849218732check the value of L<C<$!>|perlvar/$!> if
1849318733L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>.
1849418734
1849518735=end original
1849618736
1849718737syscall は、呼び出したシステムコールが返した値を返します。
1849818738システムコールが失敗すると、L<C<syscall>|/syscall NUMBER, LIST> は C<-1> を
1849918739返し、L<C<$!>|perlvar/$!>(errno) を設定します。
1850018740システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。
1850118741このようなシステムコールを正しく扱うには、
1850218742C<$! = 0> をシステムコールの前に実行し、それから
1850318743L<C<syscall>|/syscall NUMBER, LIST> が C<-1> を返した時には
1850418744L<C<$!>|perlvar/$!> の値を調べてください。
1850518745
1850618746=begin original
1850718747
1850818748There's a problem with C<syscall(SYS_pipe())>: it returns the file
1850918749number of the read end of the pipe it creates, but there is no way
1851018750to retrieve the file number of the other end. You can avoid this
1851118751problem by using L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> instead.
1851218752
1851318753=end original
1851418754
1851518755C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の
1851618756ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。
1851718757この問題を避けるためには、代わりに L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
1851818758使ってください。
1851918759
1852018760=begin original
1852118761
1852218762Portability issues: L<perlport/syscall>.
1852318763
1852418764=end original
1852518765
1852618766移植性の問題: L<perlport/syscall>。
1852718767
1852818768=item sysopen FILEHANDLE,FILENAME,MODE
1852918769X<sysopen>
1853018770
1853118771=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
1853218772
1853318773=for Pod::Functions +5.002 open a file, pipe, or descriptor
1853418774
1853518775=begin original
1853618776
1853718777Opens the file whose filename is given by FILENAME, and associates it with
1853818778FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real
1853918779filehandle wanted; an undefined scalar will be suitably autovivified. This
1854018780function calls the underlying operating system's L<open(2)> function with the
1854118781parameters FILENAME, MODE, and PERMS.
1854218782
1854318783=end original
1854418784
1854518785FILENAME で与えられたファイル名のファイルをオープンし、
1854618786FILEHANDLE と結び付けます。
1854718787FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として
1854818788扱われます; 未定義のスカラは適切に自動有効化されます。
1854918789この関数呼び出しはシステムの L<open(2)> 関数を FILENAME, MODE, PERMS の
1855018790引数で呼び出すことを基礎としています。
1855118791
1855218792=begin original
1855318793
1855418794Returns true on success and L<C<undef>|/undef EXPR> otherwise.
1855518795
1855618796=end original
1855718797
1855818798成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。
1855918799
1856018800=begin original
1856118801
1856218802L<PerlIO> layers will be applied to the handle the same way they would in an
1856318803L<C<open>|/open FILEHANDLE,MODE,EXPR> call that does not specify layers. That is,
1856418804the current value of L<C<${^OPEN}>|perlvar/${^OPEN}> as set by the L<open>
1856518805pragma in a lexical scope, or the C<-C> commandline option or C<PERL_UNICODE>
1856618806environment variable in the main program scope, falling back to the platform
1856718807defaults as described in L<PerlIO/Defaults and how to override them>. If you
1856818808want to remove any layers that may transform the byte stream, use
1856918809L<C<binmode>|/binmode FILEHANDLE, LAYER> after opening it.
1857018810
1857118811=end original
1857218812
1857318813L<PerlIO> 層は、層を指定しない L<C<open>|/open FILEHANDLE,MODE,EXPR>
1857418814呼び出しでするのと同じ方法でハンドルに適用されます。
1857518815これは、レキシカルスコープの L<open> プラグマで設定された
1857618816L<C<${^OPEN}>|perlvar/${^OPEN}> の現在の値、
1857718817またはメインプログラムスコープの C<-C> コマンドラインオプションまたは
1857818818C<PERL_UNICODE> 環境変数、L<PerlIO/Defaults and how to override them> で
1857918819記述されているようにプラットフォームのデフォルトに
1858018820フォールバックしたものです。
1858118821バイトストリームを変換する全ての層を除去したい場合は、
1858218822それを開いた後に L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。
1858318823
1858418824=begin original
1858518825
1858618826The possible values and flag bits of the MODE parameter are
1858718827system-dependent; they are available via the standard module
1858818828L<C<Fcntl>|Fcntl>. See the documentation of your operating system's
1858918829L<open(2)> syscall to see
1859018830which values and flag bits are available. You may combine several flags
1859118831using the C<|>-operator.
1859218832
1859318833=end original
1859418834
1859518835MODE パラメータに指定できるフラグビットと値はシステム依存です;
1859618836これは標準モジュール L<C<Fcntl>|Fcntl> 経由で利用可能です。
1859718837どのようなフラグビットと値が利用可能であるかについては、
1859818838OS の L<open(2)> システムコールに関する文書を参照してください。
1859918839C<|> 演算子を使って複数のフラグを結合することができます。
1860018840
1860118841=begin original
1860218842
1860318843Some of the most common values are C<O_RDONLY> for opening the file in
1860418844read-only mode, C<O_WRONLY> for opening the file in write-only mode,
1860518845and C<O_RDWR> for opening the file in read-write mode.
1860618846X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1860718847
1860818848=end original
1860918849
1861018850もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、
1861118851ファイルを書き込み専用で開く C<O_WRONLY>、
1861218852ファイルを読み書き両用で開く C<O_RDWR> です。
1861318853X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1861418854
1861518855=begin original
1861618856
1861718857For historical reasons, some values work on almost every system
1861818858supported by Perl: 0 means read-only, 1 means write-only, and 2
1861918859means read/write. We know that these values do I<not> work under
18620OS/390 and on the Macintosh; you probably don't want to
18860OS/390; you probably don't want to use them in new code.
18621use them in new code.
1862218861
1862318862=end original
1862418863
1862518864歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が
1862618865あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。
18627OS/390 と Macintosh では動作 I<しない> ことが分かっています;
18866OS/390 では動作 I<しない> ことが分かっています;
1862818867新しく書くコードではこれらは使わないほうがよいでしょう。
1862918868
1863018869=begin original
1863118870
1863218871If the file named by FILENAME does not exist and the
1863318872L<C<open>|/open FILEHANDLE,MODE,EXPR> call creates
1863418873it (typically because MODE includes the C<O_CREAT> flag), then the value of
1863518874PERMS specifies the permissions of the newly created file. If you omit
1863618875the PERMS argument to L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
1863718876Perl uses the octal value C<0666>.
1863818877These permission values need to be in octal, and are modified by your
1863918878process's current L<C<umask>|/umask EXPR>.
1864018879X<O_CREAT>
1864118880
1864218881=end original
1864318882
1864418883FILENAME という名前のファイルが存在せず、(典型的には MODE が
1864518884C<O_CREAT> フラグを含んでいたために)
1864618885L<C<open>|/open FILEHANDLE,MODE,EXPR> 呼び出しがそれを作った場合、
1864718886PERMS の値は新しく作られたファイルの権限を指定します。
1864818887L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の PERMS 引数を省略した場合、
1864918888Perl は 8 進数 C<0666> を使います。
1865018889これらの権限は 8 進数である必要があり、プロセスの現在の
1865118890L<C<umask>|/umask EXPR> で修正されます。
1865218891X<O_CREAT>
1865318892
1865418893=begin original
1865518894
1865618895In many systems the C<O_EXCL> flag is available for opening files in
1865718896exclusive mode. This is B<not> locking: exclusiveness means here that
1865818897if the file already exists,
1865918898L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> fails. C<O_EXCL> may
1866018899not work
1866118900on network filesystems, and has no effect unless the C<O_CREAT> flag
1866218901is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from
1866318902being opened if it is a symbolic link. It does not protect against
1866418903symbolic links in the file's path.
1866518904X<O_EXCL>
1866618905
1866718906=end original
1866818907
1866918908多くのシステムではファイルを排他モードで開くために C<O_EXCL> が
1867018909利用可能です。
1867118910これはロック B<ではありません>: 排他性というのは既にファイルが
1867218911存在していた場合、L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> が
1867318912失敗することを意味します。
1867418913C<O_EXCL> はネットワークファイルシステムでは動作せず、
1867518914またC<O_CREAT> フラグも有効でない限りは効果がありません。
1867618915C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は
1867718916ファイルを開くことを妨げます。
1867818917これはファイルパス中のシンボリックリンクは守りません。
1867918918X<O_EXCL>
1868018919
1868118920=begin original
1868218921
1868318922Sometimes you may want to truncate an already-existing file. This
1868418923can be done using the C<O_TRUNC> flag. The behavior of
1868518924C<O_TRUNC> with C<O_RDONLY> is undefined.
1868618925X<O_TRUNC>
1868718926
1868818927=end original
1868918928
1869018929既に存在しているファイルを切り詰めたい場合もあるかもしれません。
1869118930これは C<O_TRUNC> フラグを使うことで行えます。
1869218931C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。
1869318932X<O_TRUNC>
1869418933
1869518934=begin original
1869618935
1869718936You should seldom if ever use C<0644> as argument to
1869818937L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because
1869918938that takes away the user's option to have a more permissive umask.
1870018939Better to omit it. See L<C<umask>|/umask EXPR> for more on this.
1870118940
1870218941=end original
1870318942
1870418943めったなことでは L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の引数に
1870518944C<0644> を指定するべきではないでしょう:
1870618945ユーザーがより寛大な umask を指定する選択肢を奪うからです。
1870718946省略した方がいいです。
1870818947これに関するさらなる情報については L<C<umask>|/umask EXPR> を
1870918948参照してください。
1871018949
1871118950=begin original
1871218951
1871318952This function has no direct relation to the usage of
1871418953L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1871518954L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1871618955or L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. A handle opened with
1871718956this function can be used with buffered IO just as one opened with
1871818957L<C<open>|/open FILEHANDLE,MODE,EXPR> can be used with unbuffered IO.
1871918958
1872018959=end original
1872118960
1872218961この関数は、
1872318962L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1872418963L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1872518964L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> の使用法と
1872618965直接の関係はありません。
1872718966この関数で開かれたハンドルがバッファリングされた IO で使えるのと同様、
1872818967L<C<open>|/open FILEHANDLE,MODE,EXPR> で開かれたものは
1872918968バッファリングされない IO で使えます。
1873018969
1873118970=begin original
1873218971
1873318972Note that under Perls older than 5.8.0,
1873418973L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> depends on the
1873518974L<fdopen(3)> C library function. On many Unix systems, L<fdopen(3)> is known
1873618975to fail when file descriptors exceed a certain value, typically 255. If
1873718976you need more file descriptors than that, consider using the
1873818977L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later,
1873918978PerlIO is (most often) the default.
1874018979
1874118980=end original
1874218981
18743189825.8.0 より古い Perl では、
1874418983L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> は
1874518984C の L<fdopen(3)> ライブラリ関数に依存していることに注意してください。
1874618985多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を
1874718986超えると失敗することが知られています。
1874818987これより多くのファイル記述子が必要な場合は、
1874918988L<C<POSIX::open>|POSIX/C<open>> 関数を使うことを検討してください。
18750Perl 5.8.0 以降では、(ほぼ確実に) PerlIO がデフォルトです。
189895.8.0 以降の Perl では、(ほぼ確実に) PerlIO がデフォルトです。
1875118990
1875218991=begin original
1875318992
1875418993See L<perlopentut> for a kinder, gentler explanation of opening files.
1875518994
1875618995=end original
1875718996
1875818997ファイルを開くことに関するより親切な説明については L<perlopentut> を
1875918998参照してください。
1876018999
1876119000=begin original
1876219001
1876319002Portability issues: L<perlport/sysopen>.
1876419003
1876519004=end original
1876619005
1876719006移植性の問題: L<perlport/sysopen>。
1876819007
1876919008=item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
1877019009X<sysread>
1877119010
1877219011=item sysread FILEHANDLE,SCALAR,LENGTH
1877319012
1877419013=for Pod::Functions fixed-length unbuffered input from a filehandle
1877519014
1877619015=begin original
1877719016
1877819017Attempts to read LENGTH bytes of data into variable SCALAR from the
1877919018specified FILEHANDLE, using L<read(2)>. It bypasses any L<PerlIO> layers
1878019019including buffered IO (but is affected by the presence of the C<:utf8>
1878119020layer as described later), so mixing this with other kinds of reads,
1878219021L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1878319022L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1878419023L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> can cause
1878519024confusion because the
1878619025C<:perlio> or C<:crlf> layers usually buffer data. Returns the number of
1878719026bytes actually read, C<0> at end of file, or undef if there was an
1878819027error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will
1878919028be grown or
1879019029shrunk so that the last byte actually read is the last byte of the
1879119030scalar after the read.
1879219031
1879319032=end original
1879419033
1879519034L<read(2)> を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの
1879619035データの読み込みを試みます。
1879719036これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らないので
1879819037(しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、
1879919038L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1880019039L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
1880119040L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、入力がおかしくなるかも
1880219041しれません;
1880319042C<:perlio> 層や C<:crlf> 層は普通データをバッファリングするからです。
1880419043ファイルの最後では C<0>が、エラー時には undef が、それ以外では実際に
1880519044読み込まれたデータの長さが返されます (後者の場合は L<C<$!>|perlvar/$!> も
1880619045セットされます)。
1880719046実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、
1880819047SCALAR は伸び縮みします。
1880919048
1881019049=begin original
1881119050
1881219051An OFFSET may be specified to place the read data at some place in the
1881319052string other than the beginning. A negative OFFSET specifies
1881419053placement at that many characters counting backwards from the end of
1881519054the string. A positive OFFSET greater than the length of SCALAR
1881619055results in the string being padded to the required size with C<"\0">
1881719056bytes before the result of the read is appended.
1881819057
1881919058=end original
1882019059
1882119060OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
1882219061OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1882319062位置を指定します。
1882419063OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
1882519064追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
1882619065
1882719066=begin original
1882819067
1882919068There is no syseof() function, which is ok, since
1883019069L<C<eof>|/eof FILEHANDLE> doesn't work well on device files (like ttys)
1883119070anyway. Use L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and
1883219071check for a return value of 0 to decide whether you're done.
1883319072
1883419073=end original
1883519074
1883619075syseof() 関数はありませんが、問題ありません; どちらにしろ
1883719076L<C<eof>|/eof FILEHANDLE> は
1883819077(tty のような)デバイスファイルに対してはうまく動作しないからです。
1883919078L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を使って、
1884019079返り値が 0 かどうかで最後まで読んだかを判断してください。
1884119080
1884219081=begin original
1884319082
1884419083Note that if the filehandle has been marked as C<:utf8>, C<sysread> will
1884519084throw an exception. The C<:encoding(...)> layer implicitly
1884619085introduces the C<:utf8> layer. See
1884719086L<C<binmode>|/binmode FILEHANDLE, LAYER>,
1884819087L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma.
1884919088
1885019089=end original
1885119090
1885219091ファイルハンドルが C<:utf8> であるとマークが付けられていると、
1885319092C<sysread> は例外を投げます。
18854C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層導入されます。
19093C<:encoding(...)> 層は暗黙に C<:utf8> 層導入ます。
1885519094L<C<binmode>|/binmode FILEHANDLE, LAYER>,
1885619095L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください。
1885719096
1885819097=item sysseek FILEHANDLE,POSITION,WHENCE
1885919098X<sysseek> X<lseek>
1886019099
1886119100=for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite
1886219101
1886319102=begin original
1886419103
1886519104Sets FILEHANDLE's system position I<in bytes> using L<lseek(2)>. FILEHANDLE may
1886619105be an expression whose value gives the name of the filehandle. The values
1886719106for WHENCE are C<0> to set the new position to POSITION; C<1> to set it
1886819107to the current position plus POSITION; and C<2> to set it to EOF plus
1886919108POSITION, typically negative.
1887019109
1887119110=end original
1887219111
1887319112FILEHANDLE のシステム位置を I<バイト単位> で L<lseek(2)> を使って設定します。
1887419113FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1887519114WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します;
1887619115C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、
1887719116EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を
1887819117設定します。
1887919118
1888019119=begin original
1888119120
1888219121Note the emphasis on bytes: even if the filehandle has been set to operate
1888319122on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
1888419123L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1888519124L<C<tell>|/tell FILEHANDLE>, and
1888619125L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
1888719126family of functions use byte offsets, not character offsets,
1888819127because seeking to a character offset would be very slow in a UTF-8 file.
1888919128
1889019129=end original
1889119130
1889219131バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
1889319132ファイルハンドルが文字単位で処理するように設定されていたとしても、
1889419133L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1889519134L<C<tell>|/tell FILEHANDLE>,
1889619135L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
1889719136文字オフセットではなくバイトオフセットを使います;
1889819137文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1889919138
1890019139=begin original
1890119140
1890219141L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal
1890319142buffered IO, so mixing it with reads other than
1890419143L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example
1890519144L<C<readline>|/readline EXPR> or
1890619145L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>),
1890719146L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1890819147L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1890919148L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
1891019149confusion.
1891119150
1891219151=end original
1891319152
1891419153L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を
1891519154バイパスしますので、
1891619155L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば
1891719156L<C<readline>|/readline EXPR> や
1891819157L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、
1891919158L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1892019159L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
1892119160L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。
1892219161
1892319162=begin original
1892419163
1892519164For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>,
1892619165and C<SEEK_END> (start of the file, current position, end of the file)
1892719166from the L<Fcntl> module. Use of the constants is also more portable
1892819167than relying on 0, 1, and 2. For example to define a "systell" function:
1892919168
1893019169=end original
1893119170
1893219171WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>,
1893319172C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1893419173使うこともできます。
1893519174定数の使用は 0, 1, 2 に依存するよりも移植性があります。
1893619175例えば "systell" 関数を定義するには:
1893719176
1893819177 use Fcntl 'SEEK_CUR';
1893919178 sub systell { sysseek($_[0], 0, SEEK_CUR) }
1894019179
1894119180=begin original
1894219181
1894319182Returns the new position, or the undefined value on failure. A position
1894419183of zero is returned as the string C<"0 but true">; thus
1894519184L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns
1894619185true on success and false on failure, yet you can still easily determine
1894719186the new position.
1894819187
1894919188=end original
1895019189
1895119190新しい位置を返します; 失敗したときは未定義値を返します。
1895219191位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って
1895319192L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は成功時に真を返し、
1895419193失敗時に偽を返しますが、簡単に新しい位置を判定できます。
1895519194
1895619195=item system LIST
1895719196X<system> X<shell>
1895819197
1895919198=item system PROGRAM LIST
1896019199
1896119200=for Pod::Functions run a separate program
1896219201
1896319202=begin original
1896419203
1896519204Does exactly the same thing as L<C<exec>|/exec LIST>, except that a fork is
1896619205done first and the parent process waits for the child process to
1896719206exit. Note that argument processing varies depending on the
1896819207number of arguments. If there is more than one argument in LIST,
1896919208or if LIST is an array with more than one value, starts the program
1897019209given by the first element of the list with arguments given by the
1897119210rest of the list. If there is only one scalar argument, the argument
1897219211is checked for shell metacharacters, and if there are any, the
1897319212entire argument is passed to the system's command shell for parsing
1897419213(this is C</bin/sh -c> on Unix platforms, but varies on other
1897519214platforms). If there are no shell metacharacters in the argument,
1897619215it is split into words and passed directly to C<execvp>, which is
1897719216more efficient. On Windows, only the C<system PROGRAM LIST> syntax will
1897819217reliably avoid using the shell; C<system LIST>, even with more than one
1897919218element, will fall back to the shell if the first spawn fails.
1898019219
1898119220=end original
1898219221
1898319222L<C<exec>|/exec LIST> とほとんど同じですが、まず fork を行ない、
1898419223親プロセスではチャイルドプロセスが終了するのを wait します。
1898519224exec の項で述べたように、引数の処理は、引数の数によって異なることに
1898619225注意してください。
1898719226LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、
1898819227リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として
1898919228起動します。
1899019229スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし
1899119230あればパースのために引数全体がシステムコマンドシェル (これは
1899219231Unix プラットフォームでは C</bin/sh -c> ですが、他のプラットフォームでは
1899319232異なります)に渡されます。
1899419233シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に
1899519234渡されます; この方がより効率的です。
1899619235Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を
1899719236回避します; C<system LIST> は、2 要素以上でも、最初の spawn が失敗すると
1899819237シェルにフォールバックします。
1899919238
1900019239=begin original
1900119240
1900219241Perl will attempt to flush all files opened for
1900319242output before any operation that may do a fork, but this may not be
1900419243supported on some platforms (see L<perlport>). To be safe, you may need
1900519244to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
1900619245or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
1900719246on any open handles.
1900819247
1900919248=end original
1901019249
19011v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
19250Perl は書き込み用に開いている全てのファイルに対して
1901219251fork を行う前にフラッシュしようとしますが、これに対応していない
1901319252プラットフォームもあります(L<perlport> を参照してください)。
1901419253安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
1901519254C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
1901619255L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
1901719256呼び出す必要があるかもしれません。
1901819257
1901919258=begin original
1902019259
1902119260The return value is the exit status of the program as returned by the
1902219261L<C<wait>|/wait> call. To get the actual exit value, shift right by
1902319262eight (see below). See also L<C<exec>|/exec LIST>. This is I<not> what
1902419263you want to use to capture the output from a command; for that you
1902519264should use merely backticks or
1902619265L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, as described in
1902719266L<perlop/"`STRING`">. Return value of -1 indicates a failure to start
1902819267the program or an error of the L<wait(2)> system call (inspect
1902919268L<C<$!>|perlvar/$!> for the reason).
1903019269
1903119270=end original
1903219271
1903319272返り値は、L<C<wait>|/wait> が返すプログラムの exit 状態です。
1903419273実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。
1903519274L<C<exec>|/exec LIST> も参照してください。
1903619275これはコマンドからの出力を捕らえるために使うものI<ではありません>;
1903719276そのような用途には、L<perlop/"`STRING`"> に記述されている
1903819277逆クォートや L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>> を使用してください。
1903919278-1 の返り値はプログラムを開始させることに失敗したか、L<wait(2)>
1904019279システムコールがエラーを出したことを示します
1904119280(理由は L<C<$!>|perlvar/$!> を調べてください)。
1904219281
1904319282=begin original
1904419283
1904519284If you'd like to make L<C<system>|/system LIST> (and many other bits of
1904619285Perl) die on error, have a look at the L<autodie> pragma.
1904719286
1904819287=end original
1904919288
1905019289もし L<C<system>|/system LIST> (及び Perl のその他の多くの部分) でエラー時に
1905119290die したいなら、L<autodie> プラグマを見てみてください。
1905219291
1905319292=begin original
1905419293
1905519294Like L<C<exec>|/exec LIST>, L<C<system>|/system LIST> allows you to lie
1905619295to a program about its name if you use the C<system PROGRAM LIST>
1905719296syntax. Again, see L<C<exec>|/exec LIST>.
1905819297
1905919298=end original
1906019299
1906119300L<C<exec>|/exec LIST> と同様に、L<C<system>|/system LIST> でも
1906219301C<system PROGRAM LIST> の文法を使うことで、プログラムに対してその名前を
1906319302嘘をつくことができます。
1906419303再び、L<C<exec>|/exec LIST> を参照してください。
1906519304
1906619305=begin original
1906719306
1906819307Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of
1906919308L<C<system>|/system LIST>, if you expect your program to terminate on
1907019309receipt of these signals you will need to arrange to do so yourself
1907119310based on the return value.
1907219311
1907319312=end original
1907419313
1907519314C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、
1907619315これらのシグナルを受信して終了させることを想定したプログラムの場合、
1907719316返り値を利用するように変更する必要があります。
1907819317
1907919318 my @args = ("command", "arg1", "arg2");
1908019319 system(@args) == 0
1908119320 or die "system @args failed: $?";
1908219321
1908319322=begin original
1908419323
1908519324If you'd like to manually inspect L<C<system>|/system LIST>'s failure,
1908619325you can check all possible failure modes by inspecting
1908719326L<C<$?>|perlvar/$?> like this:
1908819327
1908919328=end original
1909019329
1909119330L<C<system>|/system LIST> の失敗を手動で検査したいなら、以下のように
1909219331L<C<$?>|perlvar/$?> を調べることで、全ての失敗の可能性をチェックできます:
1909319332
1909419333 if ($? == -1) {
1909519334 print "failed to execute: $!\n";
1909619335 }
1909719336 elsif ($? & 127) {
1909819337 printf "child died with signal %d, %s coredump\n",
1909919338 ($? & 127), ($? & 128) ? 'with' : 'without';
1910019339 }
1910119340 else {
1910219341 printf "child exited with value %d\n", $? >> 8;
1910319342 }
1910419343
1910519344=begin original
1910619345
1910719346Alternatively, you may inspect the value of
1910819347L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> with the
1910919348L<C<W*()>|POSIX/C<WIFEXITED>> calls from the L<POSIX> module.
1911019349
1911119350=end original
1911219351
1911319352または、L<POSIX> モジュールの L<C<W*()>|POSIX/C<WIFEXITED>> 呼び出しを使って
1911419353L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> の値を
1911519354調べることもできます。
1911619355
1911719356=begin original
1911819357
1911919358When L<C<system>|/system LIST>'s arguments are executed indirectly by
1912019359the shell, results and return codes are subject to its quirks.
1912119360See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details.
1912219361
1912319362=end original
1912419363
1912519364L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、
1912619365結果と返り値はシェルの癖によって変更されることがあります。
1912719366詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を
1912819367参照してください。
1912919368
1913019369=begin original
1913119370
1913219371Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and
1913319372L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for
1913419373details.
1913519374
1913619375=end original
1913719376
1913819377L<C<system>|/system LIST> は L<C<fork>|/fork> と L<C<wait>|/wait> を行うので、
1913919378C<SIGCHLD> ハンドラの影響を受けます。
1914019379詳しくは L<perlipc> を参照してください。
1914119380
1914219381=begin original
1914319382
1914419383Portability issues: L<perlport/system>.
1914519384
1914619385=end original
1914719386
1914819387移植性の問題: L<perlport/system>。
1914919388
1915019389=item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
1915119390X<syswrite>
1915219391
1915319392=item syswrite FILEHANDLE,SCALAR,LENGTH
1915419393
1915519394=item syswrite FILEHANDLE,SCALAR
1915619395
1915719396=for Pod::Functions fixed-length unbuffered output to a filehandle
1915819397
1915919398=begin original
1916019399
1916119400Attempts to write LENGTH bytes of data from variable SCALAR to the
1916219401specified FILEHANDLE, using L<write(2)>. If LENGTH is
1916319402not specified, writes whole SCALAR. It bypasses any L<PerlIO> layers
1916419403including buffered IO (but is affected by the presence of the C<:utf8>
1916519404layer as described later), so
1916619405mixing this with reads (other than C<sysread)>),
1916719406L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1916819407L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1916919408L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
1917019409confusion because the C<:perlio> and C<:crlf> layers usually buffer data.
1917119410Returns the number of bytes actually written, or L<C<undef>|/undef EXPR>
1917219411if there was an error (in this case the errno variable
1917319412L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the
1917419413data available in the SCALAR after the OFFSET, only as much data as is
1917519414available will be written.
1917619415
1917719416=end original
1917819417
1917919418L<write(2)> を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの
1918019419データの書き込みを試みます。
1918119420LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。
1918219421これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らないので
1918319422(しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、
1918419423他の入力関数 (C<sysread> 以外),
1918519424L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1918619425L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
1918719426L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、出力がおかしくなるかもしれません;
1918819427C<:perlio> 層と C<:crlf> 層は普通データをバッファリングするからです。
1918919428実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR> が
1919019429返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。
1919119430LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、
1919219431利用可能なデータのみが書き込まれます。
1919319432
1919419433=begin original
1919519434
1919619435An OFFSET may be specified to write the data from some part of the
1919719436string other than the beginning. A negative OFFSET specifies writing
1919819437that many characters counting backwards from the end of the string.
1919919438If SCALAR is of length zero, you can only use an OFFSET of 0.
1920019439
1920119440=end original
1920219441
1920319442OFFSET を指定すると、SCALAR の先頭以外の場所から、
1920419443データを取り出して、書き込みを行なうことができます。
1920519444OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて
1920619445何バイト目から書き込むかを示します。
1920719446SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。
1920819447
1920919448=begin original
1921019449
1921119450B<WARNING>: If the filehandle is marked C<:utf8>, C<syswrite> will raise an exception.
1921219451The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
1921319452Alternately, if the handle is not marked with an encoding but you
1921419453attempt to write characters with code points over 255, raises an exception.
1921519454See L<C<binmode>|/binmode FILEHANDLE, LAYER>,
1921619455L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma.
1921719456
1921819457=end original
1921919458
1922019459B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられていると、
1922119460C<syswrite> は例外を投げます。
19222C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層導入されます。
19461C<:encoding(...)> 層は暗黙に C<:utf8> 層導入ます。
1922319462または、もしハンドルにエンコーディングが記録されていない状態で
1922419463255 を超える符号位置の文字を書き込もうとすると、例外が発生します。
1922519464L<C<binmode>|/binmode FILEHANDLE, LAYER>,
1922619465L<C<open>|/open FILEHANDLE,MODE,EXPR>,
1922719466L<open> プラグマを参照してください。
1922819467
1922919468=item tell FILEHANDLE
1923019469X<tell>
1923119470
1923219471=item tell
1923319472
1923419473=for Pod::Functions get current seekpointer on a filehandle
1923519474
1923619475=begin original
1923719476
1923819477Returns the current position I<in bytes> for FILEHANDLE, or -1 on
1923919478error. FILEHANDLE may be an expression whose value gives the name of
1924019479the actual filehandle. If FILEHANDLE is omitted, assumes the file
1924119480last read.
1924219481
1924319482=end original
1924419483
1924519484FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を
1924619485返します。
1924719486FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
1924819487FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて
1924919488調べます。
1925019489
1925119490=begin original
1925219491
1925319492Note the emphasis on bytes: even if the filehandle has been set to operate
1925419493on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
1925519494L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1925619495L<C<tell>|/tell FILEHANDLE>, and
1925719496L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
1925819497family of functions use byte offsets, not character offsets,
1925919498because seeking to a character offset would be very slow in a UTF-8 file.
1926019499
1926119500=end original
1926219501
1926319502バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
1926419503ファイルハンドルが文字単位で処理するように設定されていたとしても、
1926519504L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1926619505L<C<tell>|/tell FILEHANDLE>,
1926719506L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
1926819507文字オフセットではなくバイトオフセットを使います;
1926919508文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1927019509
1927119510=begin original
1927219511
1927319512The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams
1927419513like the STDIN depends on the operating system: it may return -1 or
1927519514something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and
1927619515sockets usually returns -1.
1927719516
1927819517=end original
1927919518
1928019519STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は
1928119520OS に依存します:
1928219521-1 やその他の値が返ってくるかもしれません。
1928319522パイプ、FIFO、ソケットに対して L<C<tell>|/tell FILEHANDLE> を使うと、普通は
1928419523-1 が返ります。
1928519524
1928619525=begin original
1928719526
1928819527There is no C<systell> function. Use
1928919528L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> for that.
1929019529
1929119530=end original
1929219531
1929319532C<systell> 関数はありません。
1929419533代わりに L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> を
1929519534使ってください。
1929619535
1929719536=begin original
1929819537
1929919538Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O
1930019539operations) on a filehandle that has been manipulated by
1930119540L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1930219541L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or
1930319542L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions
1930419543ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not.
1930519544
1930619545=end original
1930719546
1930819547L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1930919548L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1931019549L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された
1931119550ファイルハンドルに L<C<tell>|/tell FILEHANDLE>
1931219551(またはその他のバッファリング I/O 操作) を使わないでください。
1931319552これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE> は
1931419553違います。
1931519554
1931619555=item telldir DIRHANDLE
1931719556X<telldir>
1931819557
1931919558=for Pod::Functions get current seekpointer on a directory handle
1932019559
1932119560=begin original
1932219561
1932319562Returns the current position of the L<C<readdir>|/readdir DIRHANDLE>
1932419563routines on DIRHANDLE. Value may be given to
1932519564L<C<seekdir>|/seekdir DIRHANDLE,POS> to access a particular location in
1932619565a directory. L<C<telldir>|/telldir DIRHANDLE> has the same caveats
1932719566about possible directory compaction as the corresponding system library
1932819567routine.
1932919568
1933019569=end original
1933119570
1933219571DIRHANDLE 上の L<C<readdir>|/readdir DIRHANDLE> ルーチンに対する現在位置を
1933319572返します。
1933419573値は、そのディレクトリで特定の位置をアクセスするため、
1933519574L<C<seekdir>|/seekdir DIRHANDLE,POS> に渡すことができます。
1933619575L<C<telldir>|/telldir DIRHANDLE> は同名のシステムライブラリルーチンと同じく、
1933719576ディレクトリ縮小時の問題が考えられます。
1933819577
1933919578=item tie VARIABLE,CLASSNAME,LIST
1934019579X<tie>
1934119580
1934219581=for Pod::Functions +5.002 bind a variable to an object class
1934319582
1934419583=begin original
1934519584
1934619585This function binds a variable to a package class that will provide the
1934719586implementation for the variable. VARIABLE is the name of the variable
1934819587to be enchanted. CLASSNAME is the name of a class implementing objects
1934919588of correct type. Any additional arguments are passed to the
1935019589appropriate constructor
1935119590method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>,
1935219591or C<TIEHASH>). Typically these are arguments such as might be passed
1935319592to the L<dbm_open(3)> function of C. The object returned by the
1935419593constructor is also returned by the
1935519594L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful
1935619595if you want to access other methods in CLASSNAME.
1935719596
1935819597=end original
1935919598
1936019599この関数は、変数を、その変数の実装を行なうクラスと結び付けます。
1936119600VARIABLE は、魔法をかける変数の名前です。
1936219601CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。
1936319602他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます
1936419603(つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。
1936519604通常、これらは、C の L<dbm_open(3)> などの関数に渡す引数となります。
1936619605コンストラクタで返されるオブジェクトはまた
1936719606L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます;
1936819607これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。
1936919608
1937019609=begin original
1937119610
1937219611Note that functions such as L<C<keys>|/keys HASH> and
1937319612L<C<values>|/values HASH> may return huge lists when used on large
1937419613objects, like DBM files. You may prefer to use the L<C<each>|/each
1937519614HASH> function to iterate over such. Example:
1937619615
1937719616=end original
1937819617
1937919618DBM ファイルのような大きなオブジェクトでは、L<C<keys>|/keys HASH> や
1938019619L<C<values>|/values HASH> のような関数は、大きなリストを返す可能性があります。
1938119620そのような場合では、L<C<each>|/each HASH> 関数を使って繰り返しを行なった方が
1938219621よいかもしれません。
1938319622例:
1938419623
1938519624 # print out history file offsets
1938619625 use NDBM_File;
1938719626 tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
1938819627 while (my ($key,$val) = each %HIST) {
1938919628 print $key, ' = ', unpack('L', $val), "\n";
1939019629 }
1939119630
1939219631=begin original
1939319632
1939419633A class implementing a hash should have the following methods:
1939519634
1939619635=end original
1939719636
1939819637ハッシュを実装するクラスでは、次のようなメソッドを用意します:
1939919638
1940019639 TIEHASH classname, LIST
1940119640 FETCH this, key
1940219641 STORE this, key, value
1940319642 DELETE this, key
1940419643 CLEAR this
1940519644 EXISTS this, key
1940619645 FIRSTKEY this
1940719646 NEXTKEY this, lastkey
1940819647 SCALAR this
1940919648 DESTROY this
1941019649 UNTIE this
1941119650
1941219651=begin original
1941319652
1941419653A class implementing an ordinary array should have the following methods:
1941519654
1941619655=end original
1941719656
1941819657通常の配列を実装するクラスでは、次のようなメソッドを用意します:
1941919658
1942019659 TIEARRAY classname, LIST
1942119660 FETCH this, key
1942219661 STORE this, key, value
1942319662 FETCHSIZE this
1942419663 STORESIZE this, count
1942519664 CLEAR this
1942619665 PUSH this, LIST
1942719666 POP this
1942819667 SHIFT this
1942919668 UNSHIFT this, LIST
1943019669 SPLICE this, offset, length, LIST
1943119670 EXTEND this, count
1943219671 DELETE this, key
1943319672 EXISTS this, key
1943419673 DESTROY this
1943519674 UNTIE this
1943619675
1943719676=begin original
1943819677
1943919678A class implementing a filehandle should have the following methods:
1944019679
1944119680=end original
1944219681
1944319682ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します:
1944419683
1944519684 TIEHANDLE classname, LIST
1944619685 READ this, scalar, length, offset
1944719686 READLINE this
1944819687 GETC this
1944919688 WRITE this, scalar, length, offset
1945019689 PRINT this, LIST
1945119690 PRINTF this, format, LIST
1945219691 BINMODE this
1945319692 EOF this
1945419693 FILENO this
1945519694 SEEK this, position, whence
1945619695 TELL this
1945719696 OPEN this, mode, LIST
1945819697 CLOSE this
1945919698 DESTROY this
1946019699 UNTIE this
1946119700
1946219701=begin original
1946319702
1946419703A class implementing a scalar should have the following methods:
1946519704
1946619705=end original
1946719706
1946819707スカラ変数を実装するクラスでは、次のようなメソッドを用意します:
1946919708
1947019709 TIESCALAR classname, LIST
1947119710 FETCH this,
1947219711 STORE this, value
1947319712 DESTROY this
1947419713 UNTIE this
1947519714
1947619715=begin original
1947719716
1947819717Not all methods indicated above need be implemented. See L<perltie>,
1947919718L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>.
1948019719
1948119720=end original
1948219721
1948319722上記の全てのメソッドを実装する必要はありません。
1948419723L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>,
1948519724L<Tie::Handle> を参照してください。
1948619725
1948719726=begin original
1948819727
1948919728Unlike L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, the
1949019729L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function will not
1949119730L<C<use>|/use Module VERSION LIST> or L<C<require>|/require VERSION> a
1949219731module for you; you need to do that explicitly yourself. See L<DB_File>
1949319732or the L<Config> module for interesting
1949419733L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations.
1949519734
1949619735=end original
1949719736
1949819737L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> と違い、
1949919738L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数はモジュールを
1950019739L<C<use>|/use Module VERSION LIST> したり
1950119740L<C<require>|/require VERSION> したりしません;
1950219741自分で明示的に行う必要があります。
1950319742L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については
1950419743L<DB_File> や L<Config> モジュールを参照してください。
1950519744
1950619745=begin original
1950719746
1950819747For further details see L<perltie>, L<C<tied>|/tied VARIABLE>.
1950919748
1951019749=end original
1951119750
1951219751更なる詳細については L<perltie> や L<C<tied>|/tied VARIABLE> を
1951319752参照してください。
1951419753
1951519754=item tied VARIABLE
1951619755X<tied>
1951719756
1951819757=for Pod::Functions get a reference to the object underlying a tied variable
1951919758
1952019759=begin original
1952119760
1952219761Returns a reference to the object underlying VARIABLE (the same value
1952319762that was originally returned by the
1952419763L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable
1952519764to a package.) Returns the undefined value if VARIABLE isn't tied to a
1952619765package.
1952719766
1952819767=end original
1952919768
1953019769VARIABLE の基となるオブジェクトへのリファレンスを返します
1953119770(変数をパッケージに結びつけるために
1953219771L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの
1953319772返り値と同じものです)。
1953419773VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。
1953519774
1953619775=item time
1953719776X<time> X<epoch>
1953819777
1953919778=for Pod::Functions return number of seconds since 1970
1954019779
1954119780=begin original
1954219781
1954319782Returns the number of non-leap seconds since whatever time the system
1954419783considers to be the epoch, suitable for feeding to
1954519784L<C<gmtime>|/gmtime EXPR> and L<C<localtime>|/localtime EXPR>. On most
1954619785systems the epoch is 00:00:00 UTC, January 1, 1970;
1954719786a prominent exception being Mac OS Classic which uses 00:00:00, January 1,
19548197871904 in the current local time zone for its epoch.
1954919788
1955019789=end original
1955119790
1955219791L<C<gmtime>|/gmtime EXPR> や L<C<localtime>|/localtime EXPR> への入力形式に
1955319792合っている、システムが紀元と考える時点からの連続秒数を返します。
1955419793ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です;
1955519794特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの
19556197951904 年 1 月 1 日 00:00:00 を紀元として使います。
1955719796
1955819797=begin original
1955919798
1956019799For measuring time in better granularity than one second, use the
1956119800L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or,
1956219801if you have L<gettimeofday(2)>, you may be able to use the
1956319802L<C<syscall>|/syscall NUMBER, LIST> interface of Perl. See L<perlfaq8>
1956419803for details.
1956519804
1956619805=end original
1956719806
19568198071 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では
1956919808CPANから)の L<Time::HiRes> モジュールを使うか、
1957019809L<gettimeofday(2)> があるなら、Perl の
1957119810L<C<syscall>|/syscall NUMBER, LIST> インターフェースを使ってください。
1957219811詳しくは L<perlfaq8> を参照してください。
1957319812
1957419813=begin original
1957519814
1957619815For date and time processing look at the many related modules on CPAN.
1957719816For a comprehensive date and time representation look at the
1957819817L<DateTime> module.
1957919818
1958019819=end original
1958119820
1958219821日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。
1958319822包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
1958419823参照してください。
1958519824
1958619825=item times
1958719826X<times>
1958819827
1958919828=for Pod::Functions return elapsed time for self and child processes
1959019829
1959119830=begin original
1959219831
1959319832Returns a four-element list giving the user and system times in
1959419833seconds for this process and any exited children of this process.
1959519834
1959619835=end original
1959719836
1959819837現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を
1959919838秒で示した、4 要素のリスト値を返します。
1960019839
1960119840 my ($user,$system,$cuser,$csystem) = times;
1960219841
1960319842=begin original
1960419843
1960519844In scalar context, L<C<times>|/times> returns C<$user>.
1960619845
1960719846=end original
1960819847
1960919848スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。
1961019849
1961119850=begin original
1961219851
1961319852Children's times are only included for terminated children.
1961419853
1961519854=end original
1961619855
1961719856子プロセスに対する times は、終了した子プロセスのみ含められます。
1961819857
1961919858=begin original
1962019859
1962119860Portability issues: L<perlport/times>.
1962219861
1962319862=end original
1962419863
1962519864移植性の問題: L<perlport/times>。
1962619865
1962719866=item tr///
1962819867
1962919868=for Pod::Functions transliterate a string
1963019869
1963119870=begin original
1963219871
1963319872The transliteration operator. Same as
1963419873L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See
1963519874L<perlop/"Quote-Like Operators">.
1963619875
1963719876=end original
1963819877
1963919878文字変換演算子です。
1964019879L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> と同じです。
1964119880L<perlop/"Quote-Like Operators"> を参照してください。
1964219881
1964319882=item truncate FILEHANDLE,LENGTH
1964419883X<truncate>
1964519884
1964619885=item truncate EXPR,LENGTH
1964719886
1964819887=for Pod::Functions shorten a file
1964919888
1965019889=begin original
1965119890
1965219891Truncates the file opened on FILEHANDLE, or named by EXPR, to the
1965319892specified length. Raises an exception if truncate isn't implemented
1965419893on your system. Returns true if successful, L<C<undef>|/undef EXPR> on
1965519894error.
1965619895
1965719896=end original
1965819897
1965919898FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、
1966019899指定した長さに切り詰めます。
1966119900システム上に truncate が実装されていなければ、例外が発生します。
1966219901成功すれば真を、エラー時には L<C<undef>|/undef EXPR> を返します。
1966319902
1966419903=begin original
1966519904
1966619905The behavior is undefined if LENGTH is greater than the length of the
1966719906file.
1966819907
1966919908=end original
1967019909
1967119910LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。
1967219911
1967319912=begin original
1967419913
1967519914The position in the file of FILEHANDLE is left unchanged. You may want to
1967619915call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the
1967719916file.
1967819917
1967919918=end original
1968019919
1968119920FILEHANDLE のファイルの位置は変わりません。
1968219921ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を
1968319922呼び出したいかもしれません。
1968419923
1968519924=begin original
1968619925
1968719926Portability issues: L<perlport/truncate>.
1968819927
1968919928=end original
1969019929
1969119930移植性の問題: L<perlport/truncate>。
1969219931
1969319932=item uc EXPR
1969419933X<uc> X<uppercase> X<toupper>
1969519934
1969619935=item uc
1969719936
1969819937=for Pod::Functions return upper-case version of a string
1969919938
1970019939=begin original
1970119940
19702Returns an uppercased version of EXPR. This is the internal function
19941Returns an uppercased version of EXPR. If EXPR is omitted, uses
19703implementing the C<\U> escape in double-quoted strings.
19942L<C<$_>|perlvar/$_>.
19704It does not attempt to do titlecase mapping on initial letters. See
19705L<C<ucfirst>|/ucfirst EXPR> for that.
1970619943
1970719944=end original
1970819945
19709EXPR 大文字に変換したものを返します。
19946EXPR 大文字を返します。
19710は、ダブルクォート文字列における、C<\U> エスケープ
19947EXPR が省略されるL<C<$_>|perlvar/$_>使います。
19711実装する内部関数です。
19712先頭文字の タイトル文字マッピングは試みません。
19713このためには L<C<ucfirst>|/ucfirst EXPR> を参照してください。
1971419948
19949 my $str = uc("Perl is GREAT"); # "PERL IS GREAT"
19950
1971519951=begin original
1971619952
19717If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
19953This function behaves the same way under various pragmas, such as in a locale,
19954as L<C<lc>|/lc EXPR> does.
1971819955
1971919956=end original
1972019957
19721EXPR が省略されるとL<C<$_>|perlvar/$_> を使いす。
19958この関数はロケールのようなさざまなプラグマの影響下では、
19959L<C<lc>|/lc EXPR> と同様に振る舞います。
1972219960
1972319961=begin original
1972419962
19725This function behaves the same way under various pragmas, such as in a locale,
19963If you want titlecase mapping on initial letters see
19726as L<C<lc>|/lc EXPR> does.
19964L<C<ucfirst>|/ucfirst EXPR> instead.
1972719965
1972819966=end original
1972919967
19730関数は、ロケールようなさまざまなプラグの影響下では、
19968最初文字タイトル文字ッピングがほしい場合は、
19731L<C<lc>|/lc EXPR> と同様に振る舞ます
19969代わりに L<C<ucfirst>|/ucfirst EXPR> を使ってください。
1973219970
19971=begin original
19972
19973B<Note:> This is the internal function implementing the
19974L<C<\U>|perlop/"Quote and Quote-like Operators"> escape in double-quoted
19975strings.
19976
19977=end original
19978
19979B<注意:> これは、ダブルクォート文字列における、
19980L<C<\U>|perlop/"Quote and Quote-like Operators"> エスケープを
19981実装する内部関数です。
19982
19983 my $str = "Perl is \Ugreat\E"; # "Perl is GREAT"
19984
1973319985=item ucfirst EXPR
1973419986X<ucfirst> X<uppercase>
1973519987
1973619988=item ucfirst
1973719989
1973819990=for Pod::Functions return a string with just the next letter in upper case
1973919991
1974019992=begin original
1974119993
1974219994Returns the value of EXPR with the first character in uppercase
1974319995(titlecase in Unicode). This is the internal function implementing
1974419996the C<\u> escape in double-quoted strings.
1974519997
1974619998=end original
1974719999
1974820000最初の文字だけを大文字にした、EXPR を返します
1974920001(Unicode では titlecase)。
1975020002これは、ダブルクォート文字列における、C<\u> エスケープを
1975120003実装する内部関数です。
1975220004
1975320005=begin original
1975420006
1975520007If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1975620008
1975720009=end original
1975820010
1975920011EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1976020012
1976120013=begin original
1976220014
1976320015This function behaves the same way under various pragmas, such as in a locale,
1976420016as L<C<lc>|/lc EXPR> does.
1976520017
1976620018=end original
1976720019
1976820020この関数は、ロケールのようなさまざまなプラグマの影響下では、
1976920021L<C<lc>|/lc EXPR> と同様に振る舞います。
1977020022
1977120023=item umask EXPR
1977220024X<umask>
1977320025
1977420026=item umask
1977520027
1977620028=for Pod::Functions set file creation mode mask
1977720029
1977820030=begin original
1977920031
1978020032Sets the umask for the process to EXPR and returns the previous value.
1978120033If EXPR is omitted, merely returns the current umask.
1978220034
1978320035=end original
1978420036
1978520037現在のプロセスの umask を EXPR に設定し、以前の値を返します。
1978620038EXPR が省略されると、単にその時点の umask の値を返します。
1978720039
1978820040=begin original
1978920041
1979020042The Unix permission C<rwxr-x---> is represented as three sets of three
1979120043bits, or three octal digits: C<0750> (the leading 0 indicates octal
1979220044and isn't one of the digits). The L<C<umask>|/umask EXPR> value is such
1979320045a number representing disabled permissions bits. The permission (or
1979420046"mode") values you pass L<C<mkdir>|/mkdir FILENAME,MODE> or
1979520047L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> are modified by your
1979620048umask, so even if you tell
1979720049L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> to create a file with
1979820050permissions C<0777>, if your umask is C<0022>, then the file will
1979920051actually be created with permissions C<0755>. If your
1980020052L<C<umask>|/umask EXPR> were C<0027> (group can't write; others can't
1980120053read, write, or execute), then passing
1980220054L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a
1980320055file with mode C<0640> (because C<0666 &~ 027> is C<0640>).
1980420056
1980520057=end original
1980620058
1980720059Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、
1980820060または 3 桁の 8 進数として表現されます:
1980920061C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。
1981020062L<C<umask>|/umask EXPR> の値は無効にするパーミッションビットのこのような
1981120063数値表現です。
1981220064L<C<mkdir>|/mkdir FILENAME,MODE> や
1981320065L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション
1981420066(または「モード」)の値は umask で修正され、たとえ
1981520067L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで
1981620068ファイルを作るように指定しても、umask が C<0022> なら、
1981720069結果としてファイルは C<0755> のパーミッションで作成されます。
1981820070L<C<umask>|/umask EXPR> が C<0027> (グループは書き込めない; その他は読み込み、
1981920071書き込み、実行できない) のとき
1982020072L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> に C<0666> を渡すと、
1982120073ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。
1982220074
1982320075=begin original
1982420076
1982520077Here's some advice: supply a creation mode of C<0666> for regular
1982620078files (in L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>) and one of
1982720079C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MODE>) and
1982820080executable files. This gives users the freedom of
1982920081choice: if they want protected files, they might choose process umasks
1983020082of C<022>, C<027>, or even the particularly antisocial mask of C<077>.
1983120083Programs should rarely if ever make policy decisions better left to
1983220084the user. The exception to this is when writing files that should be
1983320085kept private: mail files, web browser cookies, F<.rhosts> files, and
1983420086so on.
1983520087
1983620088=end original
1983720089
1983820090以下は助言です: 作成モードとして、
1983920091(L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> による)通常ファイルでは
1984020092C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MODE> による)ディレクトリでは
1984120093C<0777> を指定しましょう。
1984220094これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、
1984320095プロセスの umask として C<022>, C<027>, あるいは特に非社交的な
1984420096C<077> を選択できます。
1984520097プログラムがユーザーより適切なポリシー選択ができることは稀です。
1984620098例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、
1984720099F<.rhosts> ファイルなど)を書く場合です。
1984820100
1984920101=begin original
1985020102
1985120103If L<umask(2)> is not implemented on your system and you are trying to
1985220104restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>),
1985320105raises an exception. If L<umask(2)> is not implemented and you are
1985420106not trying to restrict access for yourself, returns
1985520107L<C<undef>|/undef EXPR>.
1985620108
1985720109=end original
1985820110
1985920111L<umask(2)> が実装されていないシステムで、I<自分自身> へのアクセスを
1986020112制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。
1986120113L<umask(2)> が実装されていないシステムで、自分自身へのアクセスは
1986220114制限しようとしなかった場合、L<C<undef>|/undef EXPR> を返します。
1986320115
1986420116=begin original
1986520117
1986620118Remember that a umask is a number, usually given in octal; it is I<not> a
1986720119string of octal digits. See also L<C<oct>|/oct EXPR>, if all you have
1986820120is a string.
1986920121
1987020122=end original
1987120123
1987220124umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の
1987320125文字列 I<ではありません>。
1987420126文字列しかない場合、 L<C<oct>|/oct EXPR> も参照してください。
1987520127
1987620128=begin original
1987720129
1987820130Portability issues: L<perlport/umask>.
1987920131
1988020132=end original
1988120133
1988220134移植性の問題: L<perlport/umask>。
1988320135
1988420136=item undef EXPR
1988520137X<undef> X<undefine>
1988620138
1988720139=item undef
1988820140
1988920141=for Pod::Functions remove a variable or function definition
1989020142
1989120143=begin original
1989220144
1989320145Undefines the value of EXPR, which must be an lvalue. Use only on a
1989420146scalar value, an array (using C<@>), a hash (using C<%>), a subroutine
1989520147(using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}>
1989620148will probably not do what you expect on most predefined variables or
1989720149DBM list values, so don't do that; see L<C<delete>|/delete EXPR>.
1989820150Always returns the undefined value.
1989920151You can omit the EXPR, in which case nothing is
1990020152undefined, but you still get an undefined value that you could, for
1990120153instance, return from a subroutine, assign to a variable, or pass as a
1990220154parameter. Examples:
1990320155
1990420156=end original
1990520157
1990620158左辺値である EXPR の値を未定義にします。
1990720159スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
1990820160サブルーチン、(C<*> を使った)型グロブだけに使用します。
1990920161特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても
1991020162おそらく期待通りの結果にはなりませんから、しないでください;
1991120163L<C<delete>|/delete EXPR> を参照してください。
1991220164常に未定義値を返します。
1991320165EXPR は省略することができ、その場合には何も未定義にされませんが
1991420166未定義値は返されますので、それをたとえば、
1991520167サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。
1991620168例:
1991720169
1991820170 undef $foo;
1991920171 undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};
1992020172 undef @ary;
1992120173 undef %hash;
1992220174 undef &mysub;
1992320175 undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc.
1992420176 return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it;
1992520177 select undef, undef, undef, 0.25;
1992620178 my ($x, $y, undef, $z) = foo(); # Ignore third value returned
1992720179
1992820180=begin original
1992920181
1993020182Note that this is a unary operator, not a list operator.
1993120183
1993220184=end original
1993320185
1993420186これはリスト演算子ではなく、単項演算子であることに注意してください。
1993520187
1993620188=item unlink LIST
1993720189X<unlink> X<delete> X<remove> X<rm> X<del>
1993820190
1993920191=item unlink
1994020192
1994120193=for Pod::Functions remove one link to a file
1994220194
1994320195=begin original
1994420196
1994520197Deletes a list of files. On success, it returns the number of files
1994620198it successfully deleted. On failure, it returns false and sets
1994720199L<C<$!>|perlvar/$!> (errno):
1994820200
1994920201=end original
1995020202
1995120203LIST に含まれるファイルを削除します。
1995220204成功時は削除に成功したファイルの数を返します。
1995320205失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします:
1995420206
1995520207 my $unlinked = unlink 'a', 'b', 'c';
1995620208 unlink @goners;
1995720209 unlink glob "*.bak";
1995820210
1995920211=begin original
1996020212
1996120213On error, L<C<unlink>|/unlink LIST> will not tell you which files it
1996220214could not remove.
1996320215If you want to know which files you could not remove, try them one
1996420216at a time:
1996520217
1996620218=end original
1996720219
1996820220エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを
1996920221知らせません。
1997020222どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください:
1997120223
1997220224 foreach my $file ( @goners ) {
1997320225 unlink $file or warn "Could not unlink $file: $!";
1997420226 }
1997520227
1997620228=begin original
1997720229
1997820230Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories
1997920231unless you are
1998020232superuser and the B<-U> flag is supplied to Perl. Even if these
1998120233conditions are met, be warned that unlinking a directory can inflict
1998220234damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on
1998320235directories is not supported on many operating systems. Use
1998420236L<C<rmdir>|/rmdir FILENAME> instead.
1998520237
1998620238=end original
1998720239
1998820240注: スーパーユーザ権限で、Perl に B<-U> を付けて実行した場合でなければ、
1998920241L<C<unlink>|/unlink LIST> はディレクトリを削除しようとすることはありません。
1999020242この条件にあう場合にも、ディレクトリの削除は、
1999120243ファイルシステムに多大な損害を与える可能性があります。
1999220244最後に、L<C<unlink>|/unlink LIST> をディレクトリに使うのはほとんどの OS では
1999320245対応していません。
1999420246代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。
1999520247
1999620248=begin original
1999720249
1999820250If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>.
1999920251
2000020252=end original
2000120253
2000220254LIST が省略されると、L<C<unlink>|/unlink LIST> は L<C<$_>|perlvar/$_> を
2000320255使います。
2000420256
2000520257=item unpack TEMPLATE,EXPR
2000620258X<unpack>
2000720259
2000820260=item unpack TEMPLATE
2000920261
2001020262=for Pod::Functions convert binary structure into normal perl variables
2001120263
2001220264=begin original
2001320265
2001420266L<C<unpack>|/unpack TEMPLATE,EXPR> does the reverse of
2001520267L<C<pack>|/pack TEMPLATE,LIST>: it takes a string
2001620268and expands it out into a list of values.
2001720269(In scalar context, it returns merely the first value produced.)
2001820270
2001920271=end original
2002020272
2002120273L<C<unpack>|/unpack TEMPLATE,EXPR> は L<C<pack>|/pack TEMPLATE,LIST> の逆を
2002220274行ないます: 構造体を表わす文字列をとり、
2002320275リスト値に展開し、その配列値を返します。
2002420276(スカラコンテキストでは、単に最初の値を返します。)
2002520277
2002620278=begin original
2002720279
2002820280If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string.
2002920281See L<perlpacktut> for an introduction to this function.
2003020282
2003120283=end original
2003220284
2003320285EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。
2003420286この関数の説明については L<perlpacktut> を参照してください。
2003520287
2003620288=begin original
2003720289
2003820290The string is broken into chunks described by the TEMPLATE. Each chunk
2003920291is converted separately to a value. Typically, either the string is a result
2004020292of L<C<pack>|/pack TEMPLATE,LIST>, or the characters of the string
2004120293represent a C structure of some kind.
2004220294
2004320295=end original
2004420296
2004520297文字列は TEMPLATE で示された固まりに分割されます。
2004620298それぞれの固まりは別々に値に変換されます。
2004720299典型的には、文字列は L<C<pack>|/pack TEMPLATE,LIST> の結果あるいはある種の
2004820300C の構造体の文字列表現の文字列です。
2004920301
2005020302=begin original
2005120303
2005220304The TEMPLATE has the same format as in the
2005320305L<C<pack>|/pack TEMPLATE,LIST> function.
2005420306Here's a subroutine that does substring:
2005520307
2005620308=end original
2005720309
2005820310TEMPLATE は、L<C<pack>|/pack TEMPLATE,LIST> 関数と同じフォーマットを使います。
2005920311部分文字列を取り出すうサブルーチンの例を示します:
2006020312
2006120313 sub substr {
2006220314 my ($what, $where, $howmuch) = @_;
2006320315 unpack("x$where a$howmuch", $what);
2006420316 }
2006520317
2006620318=begin original
2006720319
2006820320and then there's
2006920321
2007020322=end original
2007120323
2007220324これもそうです。
2007320325
2007420326 sub ordinal { unpack("W",$_[0]); } # same as ord()
2007520327
2007620328=begin original
2007720329
2007820330In addition to fields allowed in L<C<pack>|/pack TEMPLATE,LIST>, you may
2007920331prefix a field with a %<number> to indicate that
2008020332you want a <number>-bit checksum of the items instead of the items
2008120333themselves. Default is a 16-bit checksum. The checksum is calculated by
2008220334summing numeric values of expanded values (for string fields the sum of
2008320335C<ord($char)> is taken; for bit fields the sum of zeroes and ones).
2008420336
2008520337=end original
2008620338
2008720339L<C<pack>|/pack TEMPLATE,LIST> で利用可能なフィールドの他に、
2008820340フィールドの前に %<数値> というものを付けて、
2008920341項目自身の代わりに、その項目の <数値>-ビットのチェックサムを
2009020342計算させることができます。
2009120343デフォルトは、16-ビットチェックサムです。
2009220344チェックサムは展開された値の数値としての値の合計
2009320345(文字列フィールドの場合は C<ord($char)> の合計;
2009420346ビットフィールドの場合は 0 と 1 の合計) が用いられます。
2009520347
2009620348=begin original
2009720349
2009820350For example, the following
2009920351computes the same number as the System V sum program:
2010020352
2010120353=end original
2010220354
2010320355たとえば、以下のコードは
2010420356System V の sum プログラムと同じ値を計算します。
2010520357
2010620358 my $checksum = do {
2010720359 local $/; # slurp!
2010820360 unpack("%32W*", readline) % 65535;
2010920361 };
2011020362
2011120363=begin original
2011220364
2011320365The following efficiently counts the number of set bits in a bit vector:
2011420366
2011520367=end original
2011620368
2011720369以下は、効率的にビットベクターの設定されているビットを
2011820370数えるものです。
2011920371
2012020372 my $setbits = unpack("%32b*", $selectmask);
2012120373
2012220374=begin original
2012320375
2012420376The C<p> and C<P> formats should be used with care. Since Perl
2012520377has no way of checking whether the value passed to
2012620378L<C<unpack>|/unpack TEMPLATE,EXPR>
2012720379corresponds to a valid memory location, passing a pointer value that's
2012820380not known to be valid is likely to have disastrous consequences.
2012920381
2013020382=end original
2013120383
2013220384C<p> と C<P> は注意深く使うべきです。
2013320385Perl は L<C<unpack>|/unpack TEMPLATE,EXPR> に渡された値が有効なメモリ位置を
2013420386指しているかどうかを確認する方法がないので、有効かどうかわからない
2013520387ポインタ値を渡すと悲惨な結果を引き起こすかもしれません。
2013620388
2013720389=begin original
2013820390
2013920391If there are more pack codes or if the repeat count of a field or a group
2014020392is larger than what the remainder of the input string allows, the result
2014120393is not well defined: the repeat count may be decreased, or
2014220394L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros,
2014320395or it may raise an exception.
2014420396If the input string is longer than one described by the TEMPLATE,
2014520397the remainder of that input string is ignored.
2014620398
2014720399=end original
2014820400
2014920401多くの pack コードがある場合や、フィールドやグループの繰り返し回数が
2015020402入力文字列の残りより大きい場合、結果は未定義です:
2015120403繰り返し回数が減らされる場合もありますし、
2015220404L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を
2015320405返すこともありますし、例外が発生します。
2015420406もし入力文字列が TEMPLATE で表現されているものより大きい場合、
2015520407入力文字列の残りは無視されます。
2015620408
2015720409=begin original
2015820410
2015920411See L<C<pack>|/pack TEMPLATE,LIST> for more examples and notes.
2016020412
2016120413=end original
2016220414
2016320415さらなる例と注意に関しては L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
2016420416
2016520417=item unshift ARRAY,LIST
2016620418X<unshift>
2016720419
2016820420=for Pod::Functions prepend more elements to the beginning of a list
2016920421
2017020422=begin original
2017120423
2017220424Does the opposite of a L<C<shift>|/shift ARRAY>. Or the opposite of a
2017320425L<C<push>|/push ARRAY,LIST>,
2017420426depending on how you look at it. Prepends list to the front of the
2017520427array and returns the new number of elements in the array.
2017620428
2017720429=end original
2017820430
2017920431L<C<shift>|/shift ARRAY> の逆操作を行ないます。
2018020432見方を変えれば、L<C<push>|/push ARRAY,LIST> の逆操作とも考えられます。
2018120433LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。
2018220434
2018320435 unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;
2018420436
2018520437=begin original
2018620438
2018720439Note the LIST is prepended whole, not one element at a time, so the
2018820440prepended elements stay in the same order. Use
2018920441L<C<reverse>|/reverse LIST> to do the reverse.
2019020442
2019120443=end original
2019220444
2019320445LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。
2019420446逆順に登録するには、L<C<reverse>|/reverse LIST> を使ってください。
2019520447
2019620448=begin original
2019720449
2019820450Starting with Perl 5.14, an experimental feature allowed
2019920451L<C<unshift>|/unshift ARRAY,LIST> to take
2020020452a scalar expression. This experiment has been deemed unsuccessful, and was
2020120453removed as of Perl 5.24.
2020220454
2020320455=end original
2020420456
2020520457Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> がスカラ式を
2020620458取ることが出来るという実験的機能がありました。
2020720459この実験は失敗と見なされ、Perl 5.24 で削除されました。
2020820460
2020920461=item untie VARIABLE
2021020462X<untie>
2021120463
2021220464=for Pod::Functions break a tie binding to a variable
2021320465
2021420466=begin original
2021520467
2021620468Breaks the binding between a variable and a package.
2021720469(See L<tie|/tie VARIABLE,CLASSNAME,LIST>.)
2021820470Has no effect if the variable is not tied.
2021920471
2022020472=end original
2022120473
2022220474変数とパッケージの間の結合を解きます。
2022320475(L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。)
2022420476結合されていない場合は何も起きません。
2022520477
2022620478=item use Module VERSION LIST
2022720479X<use> X<module> X<import>
2022820480
2022920481=item use Module VERSION
2023020482
2023120483=item use Module LIST
2023220484
2023320485=item use Module
2023420486
20235=item use VERSION
20236
2023720487=for Pod::Functions load in a module at compile time and import its namespace
2023820488
2023920489=begin original
2024020490
2024120491Imports some semantics into the current package from the named module,
2024220492generally by aliasing certain subroutine or variable names into your
2024320493package. It is exactly equivalent to
2024420494
2024520495=end original
2024620496
2024720497指定したモジュールから、現在のパッケージにさまざまな内容をインポートします;
2024820498多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、
2024920499実現されています。
2025020500これは、以下は等価ですが:
2025120501
2025220502 BEGIN { require Module; Module->import( LIST ); }
2025320503
2025420504=begin original
2025520505
2025620506except that Module I<must> be a bareword.
2025720507The importation can be made conditional by using the L<if> module.
2025820508
2025920509=end original
2026020510
2026120511Module が I<裸の単語でなければならない> ことを除けば、です。
2026220512インポートは、L<if> を使って条件付きで行うことができます。
2026320513
2026420514=begin original
2026520515
20266In the C<use VERSION> form, VERSION may be either a v-string such as
20267v5.24.1, which will be compared to L<C<$^V>|perlvar/$^V> (aka
20268$PERL_VERSION), or a numeric argument of the form 5.024001, which will
20269be compared to L<C<$]>|perlvar/$]>. An exception is raised if VERSION
20270is greater than the version of the current Perl interpreter; Perl will
20271not attempt to parse the rest of the file. Compare with
20272L<C<require>|/require VERSION>, which can do a similar check at run
20273time. Symmetrically, C<no VERSION> allows you to specify that you
20274want a version of Perl older than the specified one.
20275
20276=end original
20277
20278C<use VERSION> の形式では、VERSION は v5.24.1 のような v-文字列
20279(L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます)
20280か、5.024001 の形の数値形式 (L<C<$]>|perlvar/$]> と比較されます) で
20281指定します。
20282VERSION が Perl の現在のバージョンより大きいと、例外が発生します;
20283Perl はファイルの残りを読み込みません。
20284L<C<require>|/require VERSION> と似ていますが、これは実行時に
20285チェックされます。
20286対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で
20287動作させたいことを意味します。
20288
20289=begin original
20290
20291Specifying VERSION as a numeric argument of the form 5.024001 should
20292generally be avoided as older less readable syntax compared to
20293v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric
20294form was the only supported syntax, which is why you might see it in
20295
20296=end original
20297
20298VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです;
20299v5.24.1 に比べてより古く読みにくい文法だからです。
20300(2002 年にリリースされた) perl 5.8.0 より前では、より冗長な
20301数値形式が唯一対応している文法でした; これが古いコードでこれを
20302見るかも知れない理由です。
20303
20304=begin original
20305
20306 use v5.24.1; # compile time version check
20307 use 5.24.1; # ditto
20308 use 5.024_001; # ditto; older syntax compatible with perl 5.6
20309
20310=end original
20311
20312 use v5.24.1; # 実行時バージョンチェック
20313 use 5.24.1; # 同様
20314 use 5.024_001; # 同様; perl 5.6 と互換性のある古い文法
20315
20316=begin original
20317
20318This is often useful if you need to check the current Perl version before
20319L<C<use>|/use Module VERSION LIST>ing library modules that won't work
20320with older versions of Perl.
20321(We try not to do this more than we have to.)
20322
20323=end original
20324
20325これは古いバージョンの Perl で動かなくなったライブラリモジュールを
20326L<C<use>|/use Module VERSION LIST> する前に、現在の Perl のバージョンを
20327調べたい場合に有用です。
20328(我々は必要な場合以外にそのようなことがないように努力していますが。)
20329
20330=begin original
20331
20332C<use VERSION> also lexically enables all features available in the requested
20333version as defined by the L<feature> pragma, disabling any features
20334not in the requested version's feature bundle. See L<feature>.
20335Similarly, if the specified Perl version is greater than or equal to
203365.12.0, strictures are enabled lexically as
20337with L<C<use strict>|strict>. Any explicit use of
20338C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes
20339before it. Later use of C<use VERSION>
20340will override all behavior of a previous
20341C<use VERSION>, possibly removing the C<strict> and C<feature> added by
20342C<use VERSION>. C<use VERSION> does not
20343load the F<feature.pm> or F<strict.pm>
20344files.
20345
20346=end original
20347
20348C<use VERSION> は、L<feature> プラグマで定義されたように、指定された
20349バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の
20350束にない機能をレキシカルに無効にします。
20351L<feature> を参照してください。
20352同様に、指定された Perl のバージョンが 5.12.0 以上の場合、
20353制限は L<C<use strict>|strict> と同様にレキシカルに有効になります。
20354明示的に C<use strict> や C<no strict> を使うと、例え先に
20355指定されていたとしても、C<use VERSION> を上書きします。
20356後から使った C<use VERSION> は先の
20357C<use VERSION> の全ての振る舞いを上書きするので、
20358C<use VERSION> によって追加された C<strict> と C<feature> を
20359削除することがあります。
20360C<use VERSION> は F<feature.pm> と F<strict.pm> ファイルは読み込みません。
20361
20362=begin original
20363
2036420516The C<BEGIN> forces the L<C<require>|/require VERSION> and
2036520517L<C<import>|/import LIST> to happen at compile time. The
2036620518L<C<require>|/require VERSION> makes sure the module is loaded into
2036720519memory if it hasn't been yet. The L<C<import>|/import LIST> is not a
2036820520builtin; it's just an ordinary static method
2036920521call into the C<Module> package to tell the module to import the list of
2037020522features back into the current package. The module can implement its
2037120523L<C<import>|/import LIST> method any way it likes, though most modules
2037220524just choose to derive their L<C<import>|/import LIST> method via
2037320525inheritance from the C<Exporter> class that is defined in the
2037420526L<C<Exporter>|Exporter> module. See L<Exporter>. If no
2037520527L<C<import>|/import LIST> method can be found, then the call is skipped,
2037620528even if there is an AUTOLOAD method.
2037720529
2037820530=end original
2037920531
2038020532C<BEGIN> によって、L<C<require>|/require VERSION> や
2038120533L<C<import>|/import LIST> は、コンパイル時に
2038220534実行されることになります。
2038320535L<C<require>|/require VERSION> は、モジュールがまだメモリに
2038420536ロードされていなければ、ロードします。
2038520537L<C<import>|/import LIST> は、組込みの関数ではありません; さまざまな機能を
2038620538現在のパッケージにインポートするように C<Module> パッケージに伝えるために
2038720539呼ばれる、通常の静的メソッドです。
2038820540モジュール側では、L<C<import>|/import LIST> メソッドをどのようにでも
2038920541実装することができますが、多くのモジュールでは、
2039020542L<C<Exporter>|Exporter> モジュールで定義された、
2039120543C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを
2039220544行なうようにしています。
2039320545L<Exporter>モジュールを参照してください。
2039420546L<C<import>|/import LIST>メソッドが見つからなかった場合、AUTOLOAD メソッドが
2039520547あったとしても呼び出しはスキップされます。
2039620548
2039720549=begin original
2039820550
2039920551If you do not want to call the package's L<C<import>|/import LIST>
2040020552method (for instance,
2040120553to stop your namespace from being altered), explicitly supply the empty list:
2040220554
2040320555=end original
2040420556
2040520557パッケージの L<C<import>|/import LIST> メソッドを呼び出したくない場合(例えば、
2040620558名前空間を変更したくない場合など)は、明示的に空リストを指定してください:
2040720559
2040820560 use Module ();
2040920561
2041020562=begin original
2041120563
2041220564That is exactly equivalent to
2041320565
2041420566=end original
2041520567
2041620568これは以下と完全に等価です:
2041720569
2041820570 BEGIN { require Module }
2041920571
2042020572=begin original
2042120573
2042220574If the VERSION argument is present between Module and LIST, then the
2042320575L<C<use>|/use Module VERSION LIST> will call the C<VERSION> method in
2042420576class Module with the given version as an argument:
2042520577
2042620578=end original
2042720579
2042820580Module と LIST の間に VERSION 引数がある場合、
2042920581L<C<use>|/use Module VERSION LIST> は Module クラスの
2043020582C<VERSION> メソッドを、与えられたバージョンを引数として呼び出します:
2043120583
2043220584 use Module 12.34;
2043320585
2043420586=begin original
2043520587
2043620588is equivalent to:
2043720589
2043820590=end original
2043920591
2044020592は以下と等価です:
2044120593
2044220594 BEGIN { require Module; Module->VERSION(12.34) }
2044320595
2044420596=begin original
2044520597
2044620598The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>,
2044720599inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given
2044820600version is larger than the value of the variable C<$Module::VERSION>.
2044920601
2045020602=end original
2045120603
2045220604デフォルトの
2045320605L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、
2045420606L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、
2045520607与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に
2045620608警告を出します。
2045720609
2045820610=begin original
2045920611
2046020612The VERSION argument cannot be an arbitrary expression. It only counts
2046120613as a VERSION argument if it is a version number literal, starting with
2046220614either a digit or C<v> followed by a digit. Anything that doesn't
2046320615look like a version literal will be parsed as the start of the LIST.
2046420616Nevertheless, many attempts to use an arbitrary expression as a VERSION
2046520617argument will appear to work, because L<Exporter>'s C<import> method
2046620618handles numeric arguments specially, performing version checks rather
2046720619than treating them as things to export.
2046820620
2046920621=end original
2047020622
2047120623VERSION 引数は任意の式ではありません。
2047220624VERSION 引数が数値または C<v> に引き続いて数値であるバージョン番号リテラルの
2047320625場合にのみ扱われます。
2047420626バージョンリテラルのように見えないものは LIST の開始としてパースされます。
2047520627それにも関わらず、VERSION 引数として任意の式を使おうとする
2047620628多くの試みは動作しているように見えます; なぜなら
2047720629L<Exporter> の C<import> メソッドは数値引数を特別に扱い、
2047820630それらをエクスポートするべきものと扱わずにバージョンチェックを
2047920631実行するからです。
2048020632
2048120633=begin original
2048220634
2048320635Again, there is a distinction between omitting LIST (L<C<import>|/import
2048420636LIST> called with no arguments) and an explicit empty LIST C<()>
2048520637(L<C<import>|/import LIST> not called). Note that there is no comma
2048620638after VERSION!
2048720639
2048820640=end original
2048920641
2049020642繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで
2049120643呼び出される)ことと明示的に空の LIST C<()> を指定する
2049220644(L<C<import>|/import LIST> は呼び出されない)ことは違います。
2049320645VERSION の後ろにカンマが不要なことに注意してください!
2049420646
2049520647=begin original
2049620648
2049720649Because this is a wide-open interface, pragmas (compiler directives)
2049820650are also implemented this way. Some of the currently implemented
2049920651pragmas are:
2050020652
2050120653=end original
2050220654
2050320655これは、広く公開されているインタフェースですので、
2050420656プラグマ (コンパイラディレクティブ) も、この方法で実装されています。
2050520657現在実装されているプラグマには、以下のようなものがあります:
2050620658
2050720659 use constant;
2050820660 use diagnostics;
2050920661 use integer;
2051020662 use sigtrap qw(SEGV BUS);
2051120663 use strict qw(subs vars refs);
2051220664 use subs qw(afunc blurfl);
2051320665 use warnings qw(all);
2051420666 use sort qw(stable);
2051520667
2051620668=begin original
2051720669
2051820670Some of these pseudo-modules import semantics into the current
2051920671block scope (like L<C<strict>|strict> or L<C<integer>|integer>, unlike
2052020672ordinary modules, which import symbols into the current package (which
2052120673are effective through the end of the file).
2052220674
2052320675=end original
2052420676
2052520677通常のモジュールが、現在のパッケージにシンボルをインポートする
2052620678(これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの
2052720679一部(L<C<strict>|strict> や L<C<integer>|integer> など)は、現在の
2052820680ブロックスコープにインポートを行ないます。
2052920681
2053020682=begin original
2053120683
2053220684Because L<C<use>|/use Module VERSION LIST> takes effect at compile time,
2053320685it doesn't respect the ordinary flow control of the code being compiled.
2053420686In particular, putting a L<C<use>|/use Module VERSION LIST> inside the
2053520687false branch of a conditional doesn't prevent it
2053620688from being processed. If a module or pragma only needs to be loaded
2053720689conditionally, this can be done using the L<if> pragma:
2053820690
2053920691=end original
2054020692
2054120693L<C<use>|/use Module VERSION LIST> はコンパイル時に有効なので、コードが
2054220694コンパイルされる際の通常の流れ制御には従いません。
2054320695特に、条件文のうち成立しない側の中に L<C<use>|/use Module VERSION LIST> を
2054420696書いても、処理を妨げられません。
2054520697モジュールやプラグマを条件付きでのみ読み込みたい場合、
2054620698L<if> プラグマを使って実現できます:
2054720699
2054820700 use if $] < 5.008, "utf8";
2054920701 use if WANT_WARNINGS, warnings => qw(all);
2055020702
2055120703=begin original
2055220704
2055320705There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration
2055420706that unimports meanings imported by L<C<use>|/use Module VERSION LIST>,
2055520707i.e., it calls C<< Module->unimport(LIST) >> instead of
2055620708L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST>
2055720709does with VERSION, an omitted or empty LIST,
2055820710or no unimport method being found.
2055920711
2056020712=end original
2056120713
2056220714これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、
2056320715L<C<use>|/use Module VERSION LIST> によってインポートされたものを、
2056420716インポートされていないことにするものがあります; つまり、
2056520717L<C<import>|/import LIST> の代わりに
2056620718C<< Module->unimport(LIST) >> を呼び出します。
2056720719これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない
2056820720場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。
2056920721
2057020722 no integer;
2057120723 no strict 'refs';
2057220724 no warnings;
2057320725
2057420726=begin original
2057520727
20576Care should be taken when using the C<no VERSION> form of L<C<no>|/no
20577MODULE VERSION LIST>. It is
20578I<only> meant to be used to assert that the running Perl is of a earlier
20579version than its argument and I<not> to undo the feature-enabling side effects
20580of C<use VERSION>.
20581
20582=end original
20583
20584L<C<no>|/no MODULE VERSION LIST> の C<no VERSION> 形式を使うときには
20585注意を払うべきです。
20586これは引数で指定されたバージョンよりも前の Perl で実行されたときに
20587アサートされることを意味する I<だけ> で、C<use VERSION> によって
20588有効にされた副作用をなかったことにするもの I<ではありません>。
20589
20590=begin original
20591
2059220728See L<perlmodlib> for a list of standard modules and pragmas. See
2059320729L<perlrun|perlrun/-m[-]module> for the C<-M> and C<-m> command-line
2059420730options to Perl that give L<C<use>|/use Module VERSION LIST>
2059520731functionality from the command-line.
2059620732
2059720733=end original
2059820734
2059920735標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。
2060020736コマンドラインから L<C<use>|/use Module VERSION LIST> 機能を
2060120737指定するための C<-M> と C<-m> の
2060220738コマンドラインオプションについては
2060320739L<perlrun|perlrun/-m[-]module> を参照してください。
2060420740
20741=item use VERSION
20742
20743=for Pod::Functions enable Perl language features and declare required version
20744
20745=begin original
20746
20747Lexically enables all features available in the requested version as
20748defined by the L<feature> pragma, disabling any features not in the
20749requested version's feature bundle. See L<feature>.
20750
20751=end original
20752
20753L<feature> プラグマで定義された、指定されたバージョンで利用可能な
20754全ての機能を有効にし、指定されたバージョンの機能の束で要求されていない
20755全ての機能を無効にします。
20756L<feature> を参照してください。
20757
20758=begin original
20759
20760VERSION may be either a v-string such as v5.24.1, which will be compared
20761to L<C<$^V>|perlvar/$^V> (aka $PERL_VERSION), or a numeric argument of the
20762form 5.024001, which will be compared to L<C<$]>|perlvar/$]>. An
20763exception is raised if VERSION is greater than the version of the current
20764Perl interpreter; Perl will not attempt to parse the rest of the file.
20765Compare with L<C<require>|/require VERSION>, which can do a similar check
20766at run time.
20767
20768=end original
20769
20770VERSION は v5.24.1 のような v-文字列
20771(L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます)
20772か、5.024001 の形の数値形式 (L<C<$]>|perlvar/$]> と比較されます) で
20773指定します。
20774VERSION が Perl の現在のバージョンより大きいと、例外が発生します;
20775Perl はファイルの残りを読み込みません。
20776L<C<require>|/require VERSION> と似ていますが、これは実行時に
20777チェックされます。
20778
20779=begin original
20780
20781If the specified Perl version is 5.12 or higher, strictures are enabled
20782lexically as with L<C<use strict>|strict>. Similarly, if the specified
20783Perl version is 5.35.0 or higher, L<warnings> are enabled. Later use of
20784C<use VERSION> will override all behavior of a previous C<use VERSION>,
20785possibly removing the C<strict>, C<warnings>, and C<feature> added by it.
20786C<use VERSION> does not load the F<feature.pm>, F<strict.pm>, or
20787F<warnings.pm> files.
20788
20789=end original
20790
20791指定された Perl のバージョンが 5.12 以上の場合、
20792L<C<use strict>|strict> と同様に、strict 機能がレキシカルに有効になります。
20793同様に、指定された Perl のバージョンが 5.35.0 以上の場合、
20794L<warnings> が有効になります。
20795後から使った C<use VERSION> は先の
20796C<use VERSION> の全ての振る舞いを上書きするので、
20797それによって追加された C<strict>, C<feature>, C<feature> を
20798削除することがあります。
20799C<use VERSION> は F<feature.pm>, F<strict.pm>, F<warnings.pm> ファイルは
20800読み込みません。
20801
20802=begin original
20803
20804In the current implementation, any explicit use of C<use strict> or
20805C<no strict> overrides C<use VERSION>, even if it comes before it.
20806However, this may be subject to change in a future release of Perl, so new
20807code should not rely on this fact. It is recommended that a
20808C<use VERSION> declaration be the first significant statement within a
20809file (possibly after a C<package> statement or any amount of whitespace or
20810comment), so that its effects happen first, and other pragmata are applied
20811after it.
20812
20813=end original
20814
20815現在の実装では、明示的に C<use strict> や C<no strict> を使うと、例え先に
20816指定されていたとしても、C<use VERSION> を上書きします。
20817しかし、これは将来のリリースの Perl で変更されるかもしれないので、
20818新しいコードはこの事実に依存するべきではありません。
20819(場合によっては C<package> 文や任意の量の空白やコメントの後の)ファイルの
20820最初の有効な文として C<use VERSION> 宣言することを勧めます;
20821この機能が最初に怒り、その他のプラグマはその後に適用されるからです。
20822
20823=begin original
20824
20825Specifying VERSION as a numeric argument of the form 5.024001 should
20826generally be avoided as older less readable syntax compared to
20827v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric
20828form was the only supported syntax, which is why you might see it in
20829older code.
20830
20831=end original
20832
20833VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです;
20834v5.24.1 に比べてより古く読みにくい文法だからです。
20835(2002 年にリリースされた) perl 5.8.0 より前では、より冗長な
20836数値形式が唯一対応している文法でした; これが古いコードでこれを
20837見るかも知れない理由です。
20838
20839=begin original
20840
20841 use v5.24.1; # compile time version check
20842 use 5.24.1; # ditto
20843 use 5.024_001; # ditto; older syntax compatible with perl 5.6
20844
20845=end original
20846
20847 use v5.24.1; # 実行時バージョンチェック
20848 use 5.24.1; # 同様
20849 use 5.024_001; # 同様; perl 5.6 と互換性のある古い文法
20850
20851=begin original
20852
20853This is often useful if you need to check the current Perl version before
20854L<C<use>|/use Module VERSION LIST>ing library modules that won't work
20855with older versions of Perl.
20856(We try not to do this more than we have to.)
20857
20858=end original
20859
20860これは古いバージョンの Perl で動かなくなったライブラリモジュールを
20861L<C<use>|/use Module VERSION LIST> する前に、現在の Perl のバージョンを
20862調べたい場合に有用です。
20863(我々は必要な場合以外にそのようなことがないように努力していますが。)
20864
20865=begin original
20866
20867Symmetrically, C<no VERSION> allows you to specify that you want a version
20868of Perl older than the specified one. Historically this was added during
20869early designs of the Raku language (formerly "Perl 6"), so that a Perl 5
20870program could begin
20871
20872=end original
20873
20874対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で
20875動作させたいことを意味します。
20876歴史的には、これは Raku 言語 (以前は "Perl 6") の初期仕様で加えられたので、
20877Perl 5 のプログラムは次のもので始めて:
20878
20879 no 6;
20880
20881=begin original
20882
20883to declare that it is not a Perl 6 program. As the two languages have
20884different implementations, file naming conventions, and other
20885infrastructure, this feature is now little used in practice and should be
20886avoided in newly-written code.
20887
20888=end original
20889
20890Perl 6 プログラムでないことを宣言できました。
20891二つの言語は異なる実装、命名規則、およびその他のインフラを持つので、
20892今ではこの機能は実際にはほとんど使われておらず、新しいコードでは
20893避けるべきです。
20894
20895=begin original
20896
20897Care should be taken when using the C<no VERSION> form, as it is I<only>
20898meant to be used to assert that the running Perl is of a earlier version
20899than its argument and I<not> to undo the feature-enabling side effects
20900of C<use VERSION>.
20901
20902=end original
20903
20904C<no VERSION> 形式を使うときには注意を払うべきです;
20905これは引数で指定されたバージョンよりも前の Perl で実行されたときに
20906アサートされることを意味する I<だけ> で、C<use VERSION> によって
20907有効にされた副作用をなかったことにするもの I<ではありません>。
20908
2060520909=item utime LIST
2060620910X<utime>
2060720911
2060820912=for Pod::Functions set a file's last access and modify times
2060920913
2061020914=begin original
2061120915
2061220916Changes the access and modification times on each file of a list of
2061320917files. The first two elements of the list must be the NUMERIC access
2061420918and modification times, in that order. Returns the number of files
2061520919successfully changed. The inode change time of each file is set
2061620920to the current time. For example, this code has the same effect as the
2061720921Unix L<touch(1)> command when the files I<already exist> and belong to
2061820922the user running the program:
2061920923
2062020924=end original
2062120925
2062220926ファイルのアクセス時刻と修正(modification) 時刻を変更します。
2062320927LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を
2062420928順に指定します。
2062520929変更に成功したファイルの数を返します。
2062620930各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。
2062720931例えば、このコードはファイルが I<既に存在して> いて、ユーザーが
2062820932実行しているプログラムに従っているなら、
2062920933Unix の L<touch(1)> コマンドと同じ効果があります。
2063020934
2063120935 #!/usr/bin/perl
2063220936 my $atime = my $mtime = time;
2063320937 utime $atime, $mtime, @ARGV;
2063420938
2063520939=begin original
2063620940
2063720941Since Perl 5.8.0, if the first two elements of the list are
2063820942L<C<undef>|/undef EXPR>,
2063920943the L<utime(2)> syscall from your C library is called with a null second
2064020944argument. On most systems, this will set the file's access and
2064120945modification times to the current time (i.e., equivalent to the example
2064220946above) and will work even on files you don't own provided you have write
2064320947permission:
2064420948
2064520949=end original
2064620950
2064720951Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である
2064820952場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として
2064920953呼び出します。
2065020954ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を
2065120955現在の時刻にセットし(つまり、上記の例と等価です)、
2065220956書き込み権限があれば他のユーザーのファイルに対しても動作します。
2065320957
2065420958 for my $file (@ARGV) {
2065520959 utime(undef, undef, $file)
2065620960 || warn "Couldn't touch $file: $!";
2065720961 }
2065820962
2065920963=begin original
2066020964
2066120965Under NFS this will use the time of the NFS server, not the time of
2066220966the local machine. If there is a time synchronization problem, the
2066320967NFS server and local machine will have different times. The Unix
2066420968L<touch(1)> command will in fact normally use this form instead of the
2066520969one shown in the first example.
2066620970
2066720971=end original
2066820972
2066920973NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が
2067020974使われます。
2067120975時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に
2067220976なっている場合があります。
2067320977実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、
2067420978この形を使います。
2067520979
2067620980=begin original
2067720981
2067820982Passing only one of the first two elements as L<C<undef>|/undef EXPR> is
2067920983equivalent to passing a 0 and will not have the effect described when
2068020984both are L<C<undef>|/undef EXPR>. This also triggers an
2068120985uninitialized warning.
2068220986
2068320987=end original
2068420988
2068520989最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その
2068620990要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR> を
2068720991渡した時と同じ効果ではありません。
2068820992この場合は、未初期化の警告が出ます。
2068920993
2069020994=begin original
2069120995
2069220996On systems that support L<futimes(2)>, you may pass filehandles among the
2069320997files. On systems that don't support L<futimes(2)>, passing filehandles raises
2069420998an exception. Filehandles must be passed as globs or glob references to be
2069520999recognized; barewords are considered filenames.
2069621000
2069721001=end original
2069821002
2069921003L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として
2070021004渡せます。
2070121005L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと
2070221006例外が発生します。
2070321007ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
2070421008渡されなければなりません; 裸の単語はファイル名として扱われます。
2070521009
2070621010=begin original
2070721011
2070821012Portability issues: L<perlport/utime>.
2070921013
2071021014=end original
2071121015
2071221016移植性の問題: L<perlport/utime>。
2071321017
2071421018=item values HASH
2071521019X<values>
2071621020
2071721021=item values ARRAY
2071821022
2071921023=for Pod::Functions return a list of the values in a hash
2072021024
2072121025=begin original
2072221026
2072321027In list context, returns a list consisting of all the values of the named
2072421028hash. In Perl 5.12 or later only, will also return a list of the values of
2072521029an array; prior to that release, attempting to use an array argument will
2072621030produce a syntax error. In scalar context, returns the number of values.
2072721031
2072821032=end original
2072921033
2073021034リストコンテキストでは、指定したハッシュのすべての値を返します。
2073121035Perl 5.12 以降でのみ、配列の全ての値からなるリストも返します;
2073221036このリリースの前では、配列要素に使おうとすると文法エラーが発生します。
2073321037スカラコンテキストでは、値の数を返します。
2073421038
2073521039=begin original
2073621040
2073721041Hash entries are returned in an apparently random order. The actual random
2073821042order is specific to a given hash; the exact same series of operations
2073921043on two hashes may result in a different order for each hash. Any insertion
2074021044into the hash may change the order, as will any deletion, with the exception
2074121045that the most recent key returned by L<C<each>|/each HASH> or
2074221046L<C<keys>|/keys HASH> may be deleted without changing the order. So
2074321047long as a given hash is unmodified you may rely on
2074421048L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
2074521049L<C<each>|/each HASH> to repeatedly return the same order
2074621050as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
2074721051details on why hash order is randomized. Aside from the guarantees
2074821052provided here the exact details of Perl's hash algorithm and the hash
2074921053traversal order are subject to change in any release of Perl. Tied hashes
2075021054may behave differently to Perl's hashes with respect to changes in order on
2075121055insertion and deletion of items.
2075221056
2075321057=end original
2075421058
2075521059ハッシュ要素は見かけ上、ランダムな順序で返されます。
2075621060実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
2075721061操作を行っても、ハッシュによって異なった順序になります。
2075821062ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
2075921063L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
2076021064最近のキーは順序を変えることなく削除できます。
2076121065ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
2076221066L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
2076321067なぜハッシュの順序がランダム化されているかの詳細については
2076421068L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
2076521069ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
2076621070正確な詳細は Perl のリリースによって変更される可能性があります。
2076721071tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
2076821072異なった振る舞いをします。
2076921073
2077021074=begin original
2077121075
2077221076As a side effect, calling L<C<values>|/values HASH> resets the HASH or
2077321077ARRAY's internal iterator (see L<C<each>|/each HASH>) before yielding the
2077421078values. In particular,
2077521079calling L<C<values>|/values HASH> in void context resets the iterator
2077621080with no other overhead.
2077721081
2077821082=end original
2077921083
2078021084副作用として、L<C<values>|/values HASH> を呼び出すと、
2078121085値を取り出す前に HASH や ARRAY の
2078221086内部反復子(L<C<each>|/each HASH> 参照)をリセットします。
2078321087特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の
2078421088オーバーヘッドなしで反復子をリセットします。
2078521089
2078621090=begin original
2078721091
2078821092Apart from resetting the iterator,
2078921093C<values @array> in list context is the same as plain C<@array>.
2079021094(We recommend that you use void context C<keys @array> for this, but
2079121095reasoned that taking C<values @array> out would require more
2079221096documentation than leaving it in.)
2079321097
2079421098=end original
2079521099
2079621100反復子をリセットするということを除けば、
2079721101リストコンテキストでの C<values @array> は単なる C<@array> と同じです。
2079821102この目的のためには無効コンテキストで C<keys @array> を使うことを
2079921103お勧めしますが、C<values @array> を取り出すにはそのままにするよりも
2080021104より多くの文書が必要だと判断しました。)
2080121105
2080221106=begin original
2080321107
2080421108Note that the values are not copied, which means modifying them will
2080521109modify the contents of the hash:
2080621110
2080721111=end original
2080821112
2080921113値はコピーされないので、返されたリストを変更すると
2081021114ハッシュの中身が変更されることに注意してください。
2081121115
2081221116 for (values %hash) { s/foo/bar/g } # modifies %hash values
2081321117 for (@hash{keys %hash}) { s/foo/bar/g } # same
2081421118
2081521119=begin original
2081621120
2081721121Starting with Perl 5.14, an experimental feature allowed
2081821122L<C<values>|/values HASH> to take a
2081921123scalar expression. This experiment has been deemed unsuccessful, and was
2082021124removed as of Perl 5.24.
2082121125
2082221126=end original
2082321127
2082421128Perl 5.14 から、L<C<values>|/values HASH> がスカラ式を取ることが出来るという
2082521129実験的機能がありました。
2082621130この実験は失敗と見なされ、Perl 5.24 で削除されました。
2082721131
2082821132=begin original
2082921133
2083021134To avoid confusing would-be users of your code who are running earlier
2083121135versions of Perl with mysterious syntax errors, put this sort of thing at
2083221136the top of your file to signal that your code will work I<only> on Perls of
2083321137a recent vintage:
2083421138
2083521139=end original
2083621140
2083721141あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
2083821142文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
2083921143I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
2084021144書いてください:
2084121145
20842 use 5.012; # so keys/values/each work on arrays
21146 use v5.12; # so keys/values/each work on arrays
2084321147
2084421148=begin original
2084521149
2084621150See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and
2084721151L<C<sort>|/sort SUBNAME LIST>.
2084821152
2084921153=end original
2085021154
2085121155L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST> も
2085221156参照してください。
2085321157
2085421158=item vec EXPR,OFFSET,BITS
2085521159X<vec> X<bit> X<bit vector>
2085621160
2085721161=for Pod::Functions test or set particular bits in a string
2085821162
2085921163=begin original
2086021164
2086121165Treats the string in EXPR as a bit vector made up of elements of
2086221166width BITS and returns the value of the element specified by OFFSET
2086321167as an unsigned integer. BITS therefore specifies the number of bits
2086421168that are reserved for each element in the bit vector. This must
2086521169be a power of two from 1 to 32 (or 64, if your platform supports
2086621170that).
2086721171
2086821172=end original
2086921173
2087021174文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、
2087121175OFFSET で指定された要素を符号なし整数として返します。
2087221176従って、 BITS はビットベクターの中の各要素について予約されるビット数です。
2087321177BIT は、1 から 32 まで(プラットホームが
2087421178対応していれば 64 まで) の 2 のべき乗でなければなりません。
2087521179
2087621180=begin original
2087721181
2087821182If BITS is 8, "elements" coincide with bytes of the input string.
2087921183
2088021184=end original
2088121185
2088221186BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。
2088321187
2088421188=begin original
2088521189
2088621190If BITS is 16 or more, bytes of the input string are grouped into chunks
2088721191of size BITS/8, and each group is converted to a number as with
2088821192L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> with
2088921193big-endian formats C<n>/C<N> (and analogously for BITS==64). See
2089021194L<C<pack>|/pack TEMPLATE,LIST> for details.
2089121195
2089221196=end original
2089321197
2089421198BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに
2089521199グループ化され、各グループは L<C<pack>|/pack TEMPLATE,LIST>/
2089621200L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン
2089721201フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。
2089821202詳細は L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
2089921203
2090021204=begin original
2090121205
2090221206If bits is 4 or less, the string is broken into bytes, then the bits
2090321207of each byte are broken into 8/BITS groups. Bits of a byte are
2090421208numbered in a little-endian-ish way, as in C<0x01>, C<0x02>,
2090521209C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example,
2090621210breaking the single input byte C<chr(0x36)> into two groups gives a list
2090721211C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>.
2090821212
2090921213=end original
2091021214
2091121215BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは
20912212168/BITS 個のグループに分割されます。
2091321217ビットはリトルエンディアン風に、C<0x01>, C<0x02>,
2091421218C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。
2091521219例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、
2091621220C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に
2091721221なります。
2091821222
2091921223=begin original
2092021224
2092121225L<C<vec>|/vec EXPR,OFFSET,BITS> may also be assigned to, in which case
2092221226parentheses are needed
2092321227to give the expression the correct precedence as in
2092421228
2092521229=end original
2092621230
2092721231L<C<vec>|/vec EXPR,OFFSET,BITS> は左辺値として、代入の
2092821232対象にすることもできます; この場合、式を正しく
2092921233先行させるために以下のように括弧が必要です:
2093021234
2093121235 vec($image, $max_x * $x + $y, 8) = 3;
2093221236
2093321237=begin original
2093421238
2093521239If the selected element is outside the string, the value 0 is returned.
2093621240If an element off the end of the string is written to, Perl will first
2093721241extend the string with sufficiently many zero bytes. It is an error
2093821242to try to write off the beginning of the string (i.e., negative OFFSET).
2093921243
2094021244=end original
2094121245
2094221246選択された要素が文字列の外側だった場合、値 0 が返されます。
2094321247文字列の最後よりも後ろの要素に書き込もうとした場合、
2094421248Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。
2094521249文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった)
2094621250場合はエラーとなります。
2094721251
2094821252=begin original
2094921253
2095021254If the string happens to be encoded as UTF-8 internally (and thus has
2095121255the UTF8 flag set), L<C<vec>|/vec EXPR,OFFSET,BITS> tries to convert it
2095221256to use a one-byte-per-character internal representation. However, if the
2095321257string contains characters with values of 256 or higher, a fatal error
2095421258will occur.
2095521259
2095621260=end original
2095721261
2095821262文字列がたまたま内部で UTF-8 でエンコードされている場合(したがって
2095921263UTF8 フラグがセットされている場合)、
2096021264L<C<vec>|/vec EXPR,OFFSET,BITS> はこれを単一バイト文字内部表現に
2096121265変換しようとします。
2096221266しかし、この文字列に値が 256 以上の文字が含まれている場合、
2096321267致命的エラーが発生します。
2096421268
2096521269=begin original
2096621270
2096721271Strings created with L<C<vec>|/vec EXPR,OFFSET,BITS> can also be
2096821272manipulated with the logical
2096921273operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit
2097021274vector operation is desired when both operands are strings.
2097121275See L<perlop/"Bitwise String Operators">.
2097221276
2097321277=end original
2097421278
2097521279L<C<vec>|/vec EXPR,OFFSET,BITS> で作られた文字列は、論理演算子 C<|>、C<&>、
2097621280C<^>, C<~> で扱うこともできます。
2097721281これらの演算子は、両方の被演算子に文字列を使うと、
2097821282ビットベクター演算を行ないます。
2097921283L<perlop/"Bitwise String Operators"> を参照してください。
2098021284
2098121285=begin original
2098221286
2098321287The following code will build up an ASCII string saying C<'PerlPerlPerl'>.
2098421288The comments show the string after each step. Note that this code works
2098521289in the same way on big-endian or little-endian machines.
2098621290
2098721291=end original
2098821292
2098921293次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。
2099021294コメントは各行の実行後の文字列を示します。
2099121295このコードはビッグエンディアンでもリトルエンディアンでも同じように
2099221296動作することに注意してください。
2099321297
2099421298 my $foo = '';
2099521299 vec($foo, 0, 32) = 0x5065726C; # 'Perl'
2099621300
2099721301 # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits
2099821302 print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P')
2099921303
2100021304 vec($foo, 2, 16) = 0x5065; # 'PerlPe'
2100121305 vec($foo, 3, 16) = 0x726C; # 'PerlPerl'
2100221306 vec($foo, 8, 8) = 0x50; # 'PerlPerlP'
2100321307 vec($foo, 9, 8) = 0x65; # 'PerlPerlPe'
2100421308 vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02"
2100521309 vec($foo, 21, 4) = 7; # 'PerlPerlPer'
2100621310 # 'r' is "\x72"
2100721311 vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c"
2100821312 vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c"
2100921313 vec($foo, 94, 1) = 1; # 'PerlPerlPerl'
2101021314 # 'l' is "\x6c"
2101121315
2101221316=begin original
2101321317
2101421318To transform a bit vector into a string or list of 0's and 1's, use these:
2101521319
2101621320=end original
2101721321
2101821322ビットベクターを、0 と 1 の文字列や配列に変換するには、
2101921323以下のようにします。
2102021324
2102121325 my $bits = unpack("b*", $vector);
2102221326 my @bits = split(//, unpack("b*", $vector));
2102321327
2102421328=begin original
2102521329
2102621330If you know the exact length in bits, it can be used in place of the C<*>.
2102721331
2102821332=end original
2102921333
2103021334ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。
2103121335
2103221336=begin original
2103321337
2103421338Here is an example to illustrate how the bits actually fall in place:
2103521339
2103621340=end original
2103721341
2103821342これはビットが実際にどのような位置に入るかを図示する例です。
2103921343
2104021344 #!/usr/bin/perl -wl
2104121345
2104221346 print <<'EOT';
2104321347 0 1 2 3
2104421348 unpack("V",$_) 01234567890123456789012345678901
2104521349 ------------------------------------------------------------------
2104621350 EOT
2104721351
2104821352 for $w (0..3) {
2104921353 $width = 2**$w;
2105021354 for ($shift=0; $shift < $width; ++$shift) {
2105121355 for ($off=0; $off < 32/$width; ++$off) {
2105221356 $str = pack("B*", "0"x32);
2105321357 $bits = (1<<$shift);
2105421358 vec($str, $off, $width) = $bits;
2105521359 $res = unpack("b*",$str);
2105621360 $val = unpack("V", $str);
2105721361 write;
2105821362 }
2105921363 }
2106021364 }
2106121365
2106221366 format STDOUT =
2106321367 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2106421368 $off, $width, $bits, $val, $res
2106521369 .
2106621370 __END__
2106721371
2106821372=begin original
2106921373
2107021374Regardless of the machine architecture on which it runs, the
2107121375example above should print the following table:
2107221376
2107321377=end original
2107421378
2107521379実行するマシンのアーキテクチャに関わらず、
2107621380上記の例は以下の表を出力します。
2107721381
2107821382 0 1 2 3
2107921383 unpack("V",$_) 01234567890123456789012345678901
2108021384 ------------------------------------------------------------------
2108121385 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
2108221386 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
2108321387 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
2108421388 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
2108521389 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
2108621390 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
2108721391 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
2108821392 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
2108921393 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
2109021394 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
2109121395 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
2109221396 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
2109321397 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
2109421398 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
2109521399 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
2109621400 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
2109721401 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
2109821402 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
2109921403 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
2110021404 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
2110121405 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
2110221406 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
2110321407 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
2110421408 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
2110521409 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
2110621410 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
2110721411 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
2110821412 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
2110921413 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
2111021414 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
2111121415 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
2111221416 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
2111321417 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
2111421418 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
2111521419 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
2111621420 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
2111721421 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
2111821422 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
2111921423 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
2112021424 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
2112121425 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
2112221426 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
2112321427 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
2112421428 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
2112521429 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
2112621430 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
2112721431 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
2112821432 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
2112921433 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
2113021434 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
2113121435 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
2113221436 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
2113321437 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
2113421438 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
2113521439 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
2113621440 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
2113721441 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
2113821442 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
2113921443 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
2114021444 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
2114121445 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
2114221446 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
2114321447 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
2114421448 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
2114521449 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
2114621450 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
2114721451 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
2114821452 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
2114921453 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
2115021454 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
2115121455 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
2115221456 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
2115321457 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
2115421458 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
2115521459 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
2115621460 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
2115721461 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
2115821462 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
2115921463 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
2116021464 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
2116121465 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
2116221466 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
2116321467 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
2116421468 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
2116521469 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
2116621470 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
2116721471 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
2116821472 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
2116921473 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
2117021474 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
2117121475 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
2117221476 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
2117321477 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
2117421478 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
2117521479 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
2117621480 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
2117721481 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
2117821482 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
2117921483 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
2118021484 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
2118121485 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
2118221486 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
2118321487 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
2118421488 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
2118521489 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
2118621490 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
2118721491 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
2118821492 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
2118921493 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
2119021494 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
2119121495 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
2119221496 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
2119321497 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
2119421498 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
2119521499 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
2119621500 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
2119721501 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
2119821502 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
2119921503 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
2120021504 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
2120121505 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
2120221506 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
2120321507 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
2120421508 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
2120521509 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
2120621510 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
2120721511 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
2120821512 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
2120921513
2121021514=item wait
2121121515X<wait>
2121221516
2121321517=for Pod::Functions wait for any child process to die
2121421518
2121521519=begin original
2121621520
2121721521Behaves like L<wait(2)> on your system: it waits for a child
2121821522process to terminate and returns the pid of the deceased process, or
2121921523C<-1> if there are no child processes. The status is returned in
2122021524L<C<$?>|perlvar/$?> and
2122121525L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
2122221526Note that a return value of C<-1> could mean that child processes are
2122321527being automatically reaped, as described in L<perlipc>.
2122421528
2122521529=end original
2122621530
2122721531L<wait(2)> と同様に振る舞います: チャイルドプロセスが終了するのを待ち、
2122821532消滅したプロセスの pid を返します; チャイルドプロセスが存在しないときには、
2122921533C<-1> を返します。
2123021534ステータスは L<C<$?>|perlvar/$?> と
2123121535L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
2123221536L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが
2123321537自動的に刈り取られたことを意味するかもしれないことに注意してください。
2123421538
2123521539=begin original
2123621540
2123721541If you use L<C<wait>|/wait> in your handler for
2123821542L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child
2123921543created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>.
2124021544See L<perlipc> for details.
2124121545
2124221546=end original
2124321547
2124421548L<C<wait>|/wait> を L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って
2124521549L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって
2124621550作られた子を待つことになるかも知れません。
2124721551詳しくは L<perlipc> を参照してください。
2124821552
2124921553=begin original
2125021554
2125121555Portability issues: L<perlport/wait>.
2125221556
2125321557=end original
2125421558
2125521559移植性の問題: L<perlport/wait>。
2125621560
2125721561=item waitpid PID,FLAGS
2125821562X<waitpid>
2125921563
2126021564=for Pod::Functions wait for a particular child process to die
2126121565
2126221566=begin original
2126321567
2126421568Waits for a particular child process to terminate and returns the pid of
2126521569the deceased process, or C<-1> if there is no such child process. A
2126621570non-blocking wait (with L<WNOHANG|POSIX/C<WNOHANG>> in FLAGS) can return 0 if
2126721571there are child processes matching PID but none have terminated yet.
2126821572The status is returned in L<C<$?>|perlvar/$?> and
2126921573L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
2127021574
2127121575=end original
2127221576
2127321577特定の子プロセスが終了するのを待ち、消滅したプロセスの pid を
2127421578返します; 指定した子プロセスが存在しないときには、C<-1> を返します。
2127521579(FLAGS に L<WNOHANG|POSIX/C<WNOHANG>> を指定した) 非ブロッキング wait は、
2127621580PID がマッチングする子プロセスがいてもまだ終了していない場合に 0 を
2127721581返すことがあります。
2127821582ステータスは L<C<$?>|perlvar/$?> と
2127921583L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
2128021584
2128121585=begin original
2128221586
2128321587A PID of C<0> indicates to wait for any child process whose process group ID is
2128421588equal to that of the current process. A PID of less than C<-1> indicates to
2128521589wait for any child process whose process group ID is equal to -PID. A PID of
2128621590C<-1> indicates to wait for any child process.
2128721591
2128821592=end original
2128921593
2129021594PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである
2129121595任意の子プロセスを wait します。
2129221596PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい
2129321597任意の子プロセスを wait します。
2129421598PID に C<-1> を指定すると任意の子プロセスを wait します。
2129521599
2129621600=begin original
2129721601
2129821602If you say
2129921603
2130021604=end original
2130121605
2130221606以下のようにするか
2130321607
2130421608 use POSIX ":sys_wait_h";
2130521609
2130621610 my $kid;
2130721611 do {
2130821612 $kid = waitpid(-1, WNOHANG);
2130921613 } while $kid > 0;
2131021614
2131121615=begin original
2131221616
2131321617or
2131421618
2131521619=end original
2131621620
2131721621または
2131821622
2131921623 1 while waitpid(-1, WNOHANG) > 0;
2132021624
2132121625=begin original
2132221626
2132321627then you can do a non-blocking wait for all pending zombie processes (see
2132421628L<POSIX/WAIT>).
2132521629Non-blocking wait is available on machines supporting either the
2132621630L<waitpid(2)> or L<wait4(2)> syscalls. However, waiting for a particular
2132721631pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the
2132821632system call by remembering the status values of processes that have
2132921633exited but have not been harvested by the Perl script yet.)
2133021634
2133121635=end original
2133221636
2133321637とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを
2133421638wait します (L<POSIX/WAIT> を参照してください)。
2133521639ブロックなしの wait は、システムコール L<wait_pid(2)> か、
2133621640システムコール L<wait4(2)> をサポートしているマシンで利用可能です。
2133721641しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも
2133821642実装されています。
2133921643(exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを
2134021644エミュレートしますが、Perl スクリプトには取り入れられていません。)
2134121645
2134221646=begin original
2134321647
2134421648Note that on some systems, a return value of C<-1> could mean that child
2134521649processes are being automatically reaped. See L<perlipc> for details,
2134621650and for other examples.
2134721651
2134821652=end original
2134921653
2135021654システムによっては、返り値が C<-1> の場合は子プロセスが自動的に
2135121655刈り取られたことを意味するかもしれないことに注意してください。
2135221656詳細やその他の例については L<perlipc> を参照してください。
2135321657
2135421658=begin original
2135521659
2135621660Portability issues: L<perlport/waitpid>.
2135721661
2135821662=end original
2135921663
2136021664移植性の問題: L<perlport/waitpid>。
2136121665
2136221666=item wantarray
2136321667X<wantarray> X<context>
2136421668
2136521669=for Pod::Functions get void vs scalar vs list context of current subroutine call
2136621670
2136721671=begin original
2136821672
2136921673Returns true if the context of the currently executing subroutine or
2137021674L<C<eval>|/eval EXPR> is looking for a list value. Returns false if the
2137121675context is
2137221676looking for a scalar. Returns the undefined value if the context is
2137321677looking for no value (void context).
2137421678
2137521679=end original
2137621680
2137721681現在実行中のサブルーチンか L<C<eval>|/eval EXPR> ブロックのコンテキストが、
2137821682リスト値を要求するものであれば、真を返します。
2137921683スカラを要求するコンテキストであれば、偽を返します。
2138021684何も値を要求しない(無効コンテキスト)場合は未定義値を返します。
2138121685
2138221686 return unless defined wantarray; # don't bother doing more
2138321687 my @a = complex_calculation();
2138421688 return wantarray ? @a : "@a";
2138521689
2138621690=begin original
2138721691
2138821692L<C<wantarray>|/wantarray>'s result is unspecified in the top level of a file,
2138921693in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or
2139021694in a C<DESTROY> method.
2139121695
2139221696=end original
2139321697
2139421698ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END>
2139521699ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は
2139621700未定義です。
2139721701
2139821702=begin original
2139921703
2140021704This function should have been named wantlist() instead.
2140121705
2140221706=end original
2140321707
2140421708この関数は wantlist() という名前にするべきでした。
2140521709
2140621710=item warn LIST
2140721711X<warn> X<warning> X<STDERR>
2140821712
2140921713=for Pod::Functions print debugging info
2141021714
2141121715=begin original
2141221716
2141321717Emits a warning, usually by printing it to C<STDERR>. C<warn> interprets
2141421718its operand LIST in the same way as C<die>, but is slightly different
2141521719in what it defaults to when LIST is empty or makes an empty string.
2141621720If it is empty and L<C<$@>|perlvar/$@> already contains an exception
2141721721value then that value is used after appending C<"\t...caught">. If it
2141821722is empty and C<$@> is also empty then the string C<"Warning: Something's
2141921723wrong"> is used.
2142021724
2142121725=end original
2142221726
2142321727(通常は C<STDERR> に表示することで) 警告を出力します。
2142421728C<warn> はそのオペランド LIST を C<die> と同様に解釈しますが、
2142521729LIST が空や空文字列を作る時に何をデフォルトとするかが少し異なります。
2142621730それが空かつ、L<C<$@>|perlvar/$@> に既に
2142721731例外値が入っている場合、C<"\t...caught"> を追加した値が
2142821732用いられます。
2142921733もしこれが空で C<$@> も空の場合は、C<"Warning: Something's wrong"> という
2143021734文字列が使われます。
2143121735
2143221736=begin original
2143321737
2143421738By default, the exception derived from the operand LIST is stringified
2143521739and printed to C<STDERR>. This behaviour can be altered by installing
2143621740a L<C<$SIG{__WARN__}>|perlvar/%SIG> handler. If there is such a
2143721741handler then no message is automatically printed; it is the handler's
2143821742responsibility to deal with the exception
2143921743as it sees fit (like, for instance, converting it into a
2144021744L<C<die>|/die LIST>). Most
2144121745handlers must therefore arrange to actually display the
2144221746warnings that they are not prepared to deal with, by calling
2144321747L<C<warn>|/warn LIST>
2144421748again in the handler. Note that this is quite safe and will not
2144521749produce an endless loop, since C<__WARN__> hooks are not called from
2144621750inside one.
2144721751
2144821752=end original
2144921753
2145021754デフォルトでは、LIST オペランドから生成された例外は
2145121755文字列化されて C<STDERR> に表示されます。
2145221756この振る舞いは、L<C<$SIG{__WARN__}>|perlvar/%SIG> ハンドラを設定することで
2145321757置き換えられます。
2145421758このようなハンドラが設定されている場合は何の
2145521759メッセージも自動的には表示されません;
2145621760例外をどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの
2145721761責任ということです。
2145821762従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、
2145921763ハンドラの中で L<C<warn>|/warn LIST> を再び呼び出します。
2146021764C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、
2146121765無限ループを引き起こすことはないということに注意してください。
2146221766
2146321767=begin original
2146421768
2146521769You will find this behavior is slightly different from that of
2146621770L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the
2146721771error text, but can instead call L<C<die>|/die LIST> again to change
2146821772it).
2146921773
2147021774=end original
2147121775
2147221776この振る舞いは L<C<$SIG{__DIE__}>|perlvar/%SIG> ハンドラ(エラーテキストは
2147321777削除しませんが、代わりに L<C<die>|/die LIST> をもう一度呼び出すことで
2147421778変更できます)とは少し違うことに気付くことでしょう。
2147521779
2147621780=begin original
2147721781
2147821782Using a C<__WARN__> handler provides a powerful way to silence all
2147921783warnings (even the so-called mandatory ones). An example:
2148021784
2148121785=end original
2148221786
2148321787C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての
2148421788警告を黙らせる強力な手段となります。
2148521789例:
2148621790
2148721791 # wipe out *all* compile-time warnings
2148821792 BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
2148921793 my $foo = 10;
2149021794 my $foo = 20; # no warning about duplicate my $foo,
2149121795 # but hey, you asked for it!
2149221796 # no compile-time or run-time warnings before here
2149321797 $DOWARN = 1;
2149421798
2149521799 # run-time warnings enabled after here
2149621800 warn "\$foo is alive and $foo!"; # does show up
2149721801
2149821802=begin original
2149921803
2150021804See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries
2150121805and for more
2150221806examples. See the L<Carp> module for other kinds of warnings using its
2150321807C<carp> and C<cluck> functions.
2150421808
2150521809=end original
2150621810
2150721811L<C<%SIG>|perlvar/%SIG> エントリのセットに関する詳細とさらなる例に関しては
2150821812L<perlvar> を参照してください。
2150921813C<carp> 関数と C<cluck> 関数を用いた警告の方法に関しては
2151021814L<Carp> モジュールを参照してください。
2151121815
2151221816=item write FILEHANDLE
2151321817X<write>
2151421818
2151521819=item write EXPR
2151621820
2151721821=item write
2151821822
2151921823=for Pod::Functions print a picture record
2152021824
2152121825=begin original
2152221826
2152321827Writes a formatted record (possibly multi-line) to the specified FILEHANDLE,
2152421828using the format associated with that file. By default the format for
2152521829a file is the one having the same name as the filehandle, but the
2152621830format for the current output channel (see the
2152721831L<C<select>|/select FILEHANDLE> function) may be set explicitly by
2152821832assigning the name of the format to the L<C<$~>|perlvar/$~> variable.
2152921833
2153021834=end original
2153121835
2153221836指定された FILEHANDLE に対して、そのファイルに対応させた
2153321837フォーマットを使って、(複数行の場合もある) 整形された
2153421838レコードを書き出します。
2153521839デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと
2153621840同じ名前のものですが、その時点の出力チャネル
2153721841(L<C<select>|/select FILEHANDLE> 関数の項を
2153821842参照してください) のフォーマットは、その名前を明示的に変数
2153921843L<C<$~>|perlvar/$~> に代入することで、変更が可能です。
2154021844
2154121845=begin original
2154221846
2154321847Top of form processing is handled automatically: if there is insufficient
2154421848room on the current page for the formatted record, the page is advanced by
2154521849writing a form feed and a special top-of-page
2154621850format is used to format the new
2154721851page header before the record is written. By default, the top-of-page
2154821852format is the name of the filehandle with C<_TOP> appended, or C<top>
2154921853in the current package if the former does not exist. This would be a
2155021854problem with autovivified filehandles, but it may be dynamically set to the
2155121855format of your choice by assigning the name to the L<C<$^>|perlvar/$^>
2155221856variable while that filehandle is selected. The number of lines
2155321857remaining on the current page is in variable L<C<$->|perlvar/$->, which
2155421858can be set to C<0> to force a new page.
2155521859
2155621860=end original
2155721861
2155821862ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された
2155921863レコードを出力するだけのスペースがない場合には、改ページを行なってページを
2156021864進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ、
2156121865その後でレコードが書かれます。
2156221866デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に
2156321867C<_TOP> をつなげたものか、前者が存在しないなら、現在のパッケージの
2156421868C<top> です。
2156521869これは自動有効化されたファイルハンドルで問題になる可能性がありますが、
2156621870ファイルハンドルが選択されている間に、
2156721871変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを
2156821872変更することができます。
2156921873そのページの残り行数は、変数 L<C<$->|perlvar/$-> に入っており、この変数を
2157021874C<0> に設定することで、強制的に改ページを行なうことができます。
2157121875
2157221876=begin original
2157321877
2157421878If FILEHANDLE is unspecified, output goes to the current default output
2157521879channel, which starts out as STDOUT but may be changed by the
2157621880L<C<select>|/select FILEHANDLE> operator. If the FILEHANDLE is an EXPR,
2157721881then the expression
2157821882is evaluated and the resulting string is used to look up the name of
2157921883the FILEHANDLE at run time. For more on formats, see L<perlform>.
2158021884
2158121885=end original
2158221886
2158321887FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して
2158421888行なわれます; これは、スクリプトの開始時点では STDOUT ですが、
2158521889L<C<select>|/select FILEHANDLE> 演算子で変更することができます。
2158621890FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が
2158721891実行時に FILEHANDLE の名前として見られます。
2158821892フォーマットについて、さらには、L<perlform> を参照してください。
2158921893
2159021894=begin original
2159121895
2159221896Note that write is I<not> the opposite of
2159321897L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately.
2159421898
2159521899=end original
2159621900
2159721901write は L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の
2159821902反対のことをするもの I<ではありません>。
2159921903残念ながら。
2160021904
2160121905=item y///
2160221906
2160321907=for Pod::Functions transliterate a string
2160421908
2160521909=begin original
2160621910
2160721911The transliteration operator. Same as
2160821912L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See
2160921913L<perlop/"Quote-Like Operators">.
2161021914
2161121915=end original
2161221916
2161321917文字変換演算子です。
2161421918L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>> と同じです。
2161521919L<perlop/"Quote-Like Operators"> を参照してください。
2161621920
2161721921=back
2161821922
2161921923=head2 Non-function Keywords by Cross-reference
2162021924
2162121925=head3 perldata
2162221926
2162321927=over
2162421928
2162521929=item __DATA__
2162621930
2162721931=item __END__
2162821932
2162921933=begin original
2163021934
2163121935These keywords are documented in L<perldata/"Special Literals">.
2163221936
2163321937=end original
2163421938
2163521939これらのキーワードは L<perldata/"Special Literals"> で文書化されています。
2163621940
2163721941=back
2163821942
2163921943=head3 perlmod
2164021944
2164121945=over
2164221946
2164321947=item BEGIN
2164421948
2164521949=item CHECK
2164621950
2164721951=item END
2164821952
2164921953=item INIT
2165021954
2165121955=item UNITCHECK
2165221956
2165321957=begin original
2165421958
2165521959These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">.
2165621960
2165721961=end original
2165821962
2165921963これらのコンパイルフェーズキーワードは
2166021964L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。
2166121965
2166221966=back
2166321967
2166421968=head3 perlobj
2166521969
2166621970=over
2166721971
2166821972=item DESTROY
2166921973
2167021974=begin original
2167121975
2167221976This method keyword is documented in L<perlobj/"Destructors">.
2167321977
2167421978=end original
2167521979
2167621980このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。
2167721981
2167821982=back
2167921983
2168021984=head3 perlop
2168121985
2168221986=over
2168321987
2168421988=item and
2168521989
2168621990=item cmp
2168721991
2168821992=item eq
2168921993
2169021994=item ge
2169121995
2169221996=item gt
2169321997
21998=item isa
21999
2169422000=item le
2169522001
2169622002=item lt
2169722003
2169822004=item ne
2169922005
2170022006=item not
2170122007
2170222008=item or
2170322009
2170422010=item x
2170522011
2170622012=item xor
2170722013
2170822014=begin original
2170922015
2171022016These operators are documented in L<perlop>.
2171122017
2171222018=end original
2171322019
2171422020これらの演算子は L<perlop> で文書化されています。
2171522021
2171622022=back
2171722023
2171822024=head3 perlsub
2171922025
2172022026=over
2172122027
2172222028=item AUTOLOAD
2172322029
2172422030=begin original
2172522031
2172622032This keyword is documented in L<perlsub/"Autoloading">.
2172722033
2172822034=end original
2172922035
2173022036このキーワードは L<perlsub/"Autoloading"> で文書化されています。
2173122037
2173222038=back
2173322039
2173422040=head3 perlsyn
2173522041
2173622042=over
2173722043
2173822044=item else
2173922045
2174022046=item elsif
2174122047
2174222048=item for
2174322049
2174422050=item foreach
2174522051
2174622052=item if
2174722053
2174822054=item unless
2174922055
2175022056=item until
2175122057
2175222058=item while
2175322059
2175422060=begin original
2175522061
2175622062These flow-control keywords are documented in L<perlsyn/"Compound Statements">.
2175722063
2175822064=end original
2175922065
2176022066これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で
2176122067文書化されています。
2176222068
2176322069=item elseif
2176422070
2176522071=begin original
2176622072
2176722073The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif>
2176822074or C<else if> either. It does parse C<elseif>, but only to warn you
2176922075about not using it.
2177022076
2177122077=end original
2177222078
2177322079"else if" キーワードは Perl では C<elsif> と綴ります。
2177422080C<elif> や C<else if> はありません。
2177522081C<elseif> はパースされますが、使わないように警告するためだけです。
2177622082
2177722083=begin original
2177822084
2177922085See the documentation for flow-control keywords in L<perlsyn/"Compound
2178022086Statements">.
2178122087
2178222088=end original
2178322089
2178422090L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を
2178522091参照してください。
2178622092
2178722093=back
2178822094
2178922095=over
2179022096
2179122097=item default
2179222098
2179322099=item given
2179422100
2179522101=item when
2179622102
2179722103=begin original
2179822104
2179922105These flow-control keywords related to the experimental switch feature are
2180022106documented in L<perlsyn/"Switch Statements">.
2180122107
2180222108=end original
2180322109
2180422110これらの実験的な switch 機能に関連するフロー制御キーワードは
2180522111L<perlsyn/"Switch Statements"> で文書化されています。
22112
22113=back
22114
22115=over
22116
22117=item try
22118
22119=item catch
22120
22121=item finally
22122
22123=begin original
22124
22125These flow-control keywords related to the experimental C<try> feature are
22126documented in L<perlsyn/"Try Catch Exception Handling">.
22127
22128=end original
22129
22130実験的な C<try> 機能に関係するこれらのフロー制御キーワードは
22131L<perlsyn/"Try Catch Exception Handling"> に文書化されています。
22132
22133=back
22134
22135=over
22136
22137=item defer
22138
22139=begin original
22140
22141This flow-control keyword related to the experimental C<defer> feature is
22142documented in L<perlsyn/"defer blocks">.
22143
22144=end original
22145
22146実験的な C<defer> 機能に関係するこれらのフロー制御キーワードは
22147L<perlsyn/"defer blocks"> に文書化されています。
2180622148
2180722149=back
2180822150
2180922151=cut
2181022152
2181122153=begin meta
2181222154
2181322155Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp>
2181422156Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
2181522157Status: completed
2181622158
2181722159=end meta