perlfunc > 5.26.1 との差分

perlfunc 5.26.1 と 5.32.0 の差分

11
22=encoding euc-jp
33
44=head1 NAME
55X<function>
66
77=begin original
88
99perlfunc - Perl builtin functions
1010
1111=end original
1212
1313perlfunc - Perl 組み込み関数
1414
1515=head1 DESCRIPTION
1616
1717=begin original
1818
1919The functions in this section can serve as terms in an expression.
2020They fall into two major categories: list operators and named unary
2121operators. These differ in their precedence relationship with a
2222following comma. (See the precedence table in L<perlop>.) List
2323operators take more than one argument, while unary operators can never
2424take more than one argument. Thus, a comma terminates the argument of
2525a unary operator, but merely separates the arguments of a list
2626operator. A unary operator generally provides 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
248than one place.
248than one place. Any warnings, including those produced by
249keywords, are described in L<perldiag> and L<warnings>.
249250
250251=end original
251252
252253以下に、カテゴリ別の関数(キーワードや名前付き演算子のような、
253254関数のように見えるものも含みます)を示します。
254255複数の場所に現れる関数もあります。
256キーワードによって生成されるものを含む全ての警告は
257L<perldiag> と L<warnings> に記述されています。
255258
256259=over 4
257260
258261=item Functions for SCALARs or strings
259262X<scalar> X<string> X<character>
260263
261264(スカラや文字列のための関数)
262265
263266=for Pod::Functions =String
264267
265268L<C<chomp>|/chomp VARIABLE>, L<C<chop>|/chop VARIABLE>,
266269L<C<chr>|/chr NUMBER>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
267270L<C<fc>|/fc EXPR>, L<C<hex>|/hex EXPR>,
268271L<C<index>|/index STR,SUBSTR,POSITION>, L<C<lc>|/lc EXPR>,
269272L<C<lcfirst>|/lcfirst EXPR>, L<C<length>|/length EXPR>,
270273L<C<oct>|/oct EXPR>, L<C<ord>|/ord EXPR>,
271274L<C<pack>|/pack TEMPLATE,LIST>,
272275L<C<qE<sol>E<sol>>|/qE<sol>STRINGE<sol>>,
273276L<C<qqE<sol>E<sol>>|/qqE<sol>STRINGE<sol>>, L<C<reverse>|/reverse LIST>,
274277L<C<rindex>|/rindex STR,SUBSTR,POSITION>,
275278L<C<sprintf>|/sprintf FORMAT, LIST>,
276279L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>,
277280L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>, L<C<uc>|/uc EXPR>,
278281L<C<ucfirst>|/ucfirst EXPR>,
279282L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>
280283
281284=begin original
282285
283286L<C<fc>|/fc EXPR> is available only if the
284287L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
285288prefixed with C<CORE::>. The
286289L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
287290with a C<use v5.16> (or higher) declaration in the current scope.
288291
289292=end original
290293
291294L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
292295C<CORE::> が前置されたときにのみ利用可能です。
293296L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
294297C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
295298
296299=item Regular expressions and pattern matching
297300X<regular expression> X<regex> X<regexp>
298301
299302(正規表現とパターンマッチング)
300303
301304=for Pod::Functions =Regexp
302305
303306L<C<mE<sol>E<sol>>|/mE<sol>E<sol>>, L<C<pos>|/pos SCALAR>,
304307L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>,
305308L<C<quotemeta>|/quotemeta EXPR>,
306309L<C<sE<sol>E<sol>E<sol>>|/sE<sol>E<sol>E<sol>>,
307310L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
308311L<C<study>|/study SCALAR>
309312
310313=item Numeric functions
311314X<numeric> X<number> X<trigonometric> X<trigonometry>
312315
313316(数値関数)
314317
315318=for Pod::Functions =Math
316319
317320L<C<abs>|/abs VALUE>, L<C<atan2>|/atan2 Y,X>, L<C<cos>|/cos EXPR>,
318321L<C<exp>|/exp EXPR>, L<C<hex>|/hex EXPR>, L<C<int>|/int EXPR>,
319322L<C<log>|/log EXPR>, L<C<oct>|/oct EXPR>, L<C<rand>|/rand EXPR>,
320323L<C<sin>|/sin EXPR>, L<C<sqrt>|/sqrt EXPR>, L<C<srand>|/srand EXPR>
321324
322325=item Functions for real @ARRAYs
323326X<array>
324327
325328(実配列のための関数)
326329
327330=for Pod::Functions =ARRAY
328331
329332L<C<each>|/each HASH>, L<C<keys>|/keys HASH>, L<C<pop>|/pop ARRAY>,
330333L<C<push>|/push ARRAY,LIST>, L<C<shift>|/shift ARRAY>,
331334L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>,
332335L<C<unshift>|/unshift ARRAY,LIST>, L<C<values>|/values HASH>
333336
334337=item Functions for list data
335338X<list>
336339
337340(リストデータのための関数)
338341
339342=for Pod::Functions =LIST
340343
341344L<C<grep>|/grep BLOCK LIST>, L<C<join>|/join EXPR,LIST>,
342345L<C<map>|/map BLOCK LIST>, L<C<qwE<sol>E<sol>>|/qwE<sol>STRINGE<sol>>,
343346L<C<reverse>|/reverse LIST>, L<C<sort>|/sort SUBNAME LIST>,
344347L<C<unpack>|/unpack TEMPLATE,EXPR>
345348
346349=item Functions for real %HASHes
347350X<hash>
348351
349352(実ハッシュのための関数)
350353
351354=for Pod::Functions =HASH
352355
353356L<C<delete>|/delete EXPR>, L<C<each>|/each HASH>,
354357L<C<exists>|/exists EXPR>, L<C<keys>|/keys HASH>,
355358L<C<values>|/values HASH>
356359
357360=item Input and output functions
358361X<I/O> X<input> X<output> X<dbm>
359362
360363(入出力関数)
361364
362365=for Pod::Functions =I/O
363366
364367L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<close>|/close FILEHANDLE>,
365368L<C<closedir>|/closedir DIRHANDLE>, L<C<dbmclose>|/dbmclose HASH>,
366369L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, L<C<die>|/die LIST>,
367370L<C<eof>|/eof FILEHANDLE>, L<C<fileno>|/fileno FILEHANDLE>,
368371L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<format>|/format>,
369372L<C<getc>|/getc FILEHANDLE>, L<C<print>|/print FILEHANDLE LIST>,
370373L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
371374L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
372375L<C<readdir>|/readdir DIRHANDLE>, L<C<readline>|/readline EXPR>,
373376L<C<rewinddir>|/rewinddir DIRHANDLE>, L<C<say>|/say FILEHANDLE LIST>,
374377L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
375378L<C<seekdir>|/seekdir DIRHANDLE,POS>,
376379L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
377380L<C<syscall>|/syscall NUMBER, LIST>,
378381L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
379382L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>,
380383L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
381384L<C<tell>|/tell FILEHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
382385L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<warn>|/warn LIST>,
383386L<C<write>|/write FILEHANDLE>
384387
385388=begin original
386389
387390L<C<say>|/say FILEHANDLE LIST> is available only if the
388391L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
389392prefixed with C<CORE::>. The
390393L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
391394with a C<use v5.10> (or higher) declaration in the current scope.
392395
393396=end original
394397
395398L<C<say>|/say FILEHANDLE LIST> は
396399L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
397400前置されたときにのみ利用可能です。
398401L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
399402C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
400403
401404=item Functions for fixed-length data or records
402405
403406(固定長データやレコードのための関数)
404407
405408=for Pod::Functions =Binary
406409
407410L<C<pack>|/pack TEMPLATE,LIST>,
408411L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
409412L<C<syscall>|/syscall NUMBER, LIST>,
410413L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
411414L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>,
412415L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
413416L<C<unpack>|/unpack TEMPLATE,EXPR>, L<C<vec>|/vec EXPR,OFFSET,BITS>
414417
415418=item Functions for filehandles, files, or directories
416419X<file> X<filehandle> X<directory> X<pipe> X<link> X<symlink>
417420
418421(ファイルハンドル、ファイル、ディレクトリのための関数)
419422
420423=for Pod::Functions =File
421424
422425L<C<-I<X>>|/-X FILEHANDLE>, L<C<chdir>|/chdir EXPR>,
423426L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
424427L<C<chroot>|/chroot FILENAME>,
425428L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>, L<C<glob>|/glob EXPR>,
426429L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
427430L<C<link>|/link OLDFILE,NEWFILE>, L<C<lstat>|/lstat FILEHANDLE>,
428L<C<mkdir>|/mkdir FILENAME,MASK>, L<C<open>|/open FILEHANDLE,EXPR>,
431L<C<mkdir>|/mkdir FILENAME,MODE>, L<C<open>|/open FILEHANDLE,MODE,EXPR>,
429432L<C<opendir>|/opendir DIRHANDLE,EXPR>, L<C<readlink>|/readlink EXPR>,
430433L<C<rename>|/rename OLDNAME,NEWNAME>, L<C<rmdir>|/rmdir FILENAME>,
431434L<C<select>|/select FILEHANDLE>, L<C<stat>|/stat FILEHANDLE>,
432435L<C<symlink>|/symlink OLDFILE,NEWFILE>,
433436L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
434437L<C<umask>|/umask EXPR>, L<C<unlink>|/unlink LIST>,
435438L<C<utime>|/utime LIST>
436439
437440=item Keywords related to the control flow of your Perl program
438441X<control flow>
439442
440443(プログラムの流れを制御することに関連するキーワード)
441444
442445=for Pod::Functions =Flow
443446
444447L<C<break>|/break>, L<C<caller>|/caller EXPR>,
445448L<C<continue>|/continue BLOCK>, L<C<die>|/die LIST>, L<C<do>|/do BLOCK>,
446449L<C<dump>|/dump LABEL>, L<C<eval>|/eval EXPR>,
447450L<C<evalbytes>|/evalbytes EXPR>, L<C<exit>|/exit EXPR>,
448451L<C<__FILE__>|/__FILE__>, L<C<goto>|/goto LABEL>,
449452L<C<last>|/last LABEL>, L<C<__LINE__>|/__LINE__>,
450453L<C<next>|/next LABEL>, L<C<__PACKAGE__>|/__PACKAGE__>,
451454L<C<redo>|/redo LABEL>, L<C<return>|/return EXPR>,
452455L<C<sub>|/sub NAME BLOCK>, L<C<__SUB__>|/__SUB__>,
453456L<C<wantarray>|/wantarray>
454457
455458=begin original
456459
457460L<C<break>|/break> is available only if you enable the experimental
458461L<C<"switch"> feature|feature/The 'switch' feature> or use the C<CORE::>
459462prefix. The L<C<"switch"> feature|feature/The 'switch' feature> also
460463enables the C<default>, C<given> and C<when> statements, which are
461464documented in L<perlsyn/"Switch Statements">.
462465The L<C<"switch"> feature|feature/The 'switch' feature> is enabled
463466automatically with a C<use v5.10> (or higher) declaration in the current
464467scope. In Perl v5.14 and earlier, L<C<continue>|/continue BLOCK>
465468required the L<C<"switch"> feature|feature/The 'switch' feature>, like
466469the other keywords.
467470
468471=end original
469472
470473L<C<break>|/break> は、実験的な
471474L<C<"switch"> 機能|feature/The 'switch' feature> が有効か C<CORE::> 接頭辞を
472475使ったときにのみ利用可能です。
473476L<C<"switch"> 機能|feature/The 'switch' feature> は、
474477L<perlsyn/"Switch Statements"> で文書化されている
475478C<default>, C<given>, C<when> 文も有効にします。
476479L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで
477480C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
478481Perl v5.14 以前では、L<C<continue>|/continue BLOCK> は他のキーワードと同様に
479482L<C<"switch"> 機能|feature/The 'switch' feature> が必要です。
480483
481484=begin original
482485
483486L<C<evalbytes>|/evalbytes EXPR> is only available with the
484487L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
485488(see L<feature>) or if prefixed with C<CORE::>. L<C<__SUB__>|/__SUB__>
486489is only available with the
487490L<C<"current_sub"> feature|feature/The 'current_sub' feature> or if
488491prefixed with C<CORE::>. Both the
489492L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features>
490493and L<C<"current_sub">|feature/The 'current_sub' feature> features are
491494enabled automatically with a C<use v5.16> (or higher) declaration in the
492495current scope.
493496
494497=end original
495498
496499L<C<evalbytes>|/evalbytes EXPR> は
497500L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features>
498501(L<feature> 参照) が有効か C<CORE::> が前置されたときにのみ利用可能です。
499502L<C<__SUB__>|/__SUB__> は
500503L<C<"current_sub"> 機能|feature/The 'current_sub' feature> が有効か
501504C<CORE::> が前置されたときにのみ利用可能です。
502505L<C<"evalbytes">|feature/The 'unicode_eval' and 'evalbytes' features> と
503506L<C<"current_sub">|feature/The 'current_sub' feature> の両方の機能は
504507現在のスコープで
505508C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
506509
507510=item Keywords related to scoping
508511
509512(スコープに関するキーワード)
510513
511514=for Pod::Functions =Namespace
512515
513516L<C<caller>|/caller EXPR>, L<C<import>|/import LIST>,
514517L<C<local>|/local EXPR>, L<C<my>|/my VARLIST>, L<C<our>|/our VARLIST>,
515518L<C<package>|/package NAMESPACE>, L<C<state>|/state VARLIST>,
516519L<C<use>|/use Module VERSION LIST>
517520
518521=begin original
519522
520523L<C<state>|/state VARLIST> is available only if the
521524L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
522525prefixed with C<CORE::>. The
523526L<C<"state"> feature|feature/The 'state' feature> is enabled
524527automatically with a C<use v5.10> (or higher) declaration in the current
525528scope.
526529
527530=end original
528531
529532L<C<state>|/state VARLIST> は
530533L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を
531534前置した場合にのみ利用可能です。
532535L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
533536C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
534537
535538=item Miscellaneous functions
536539
537540(さまざまな関数)
538541
539542=for Pod::Functions =Misc
540543
541544L<C<defined>|/defined EXPR>, L<C<formline>|/formline PICTURE,LIST>,
542545L<C<lock>|/lock THING>, L<C<prototype>|/prototype FUNCTION>,
543546L<C<reset>|/reset EXPR>, L<C<scalar>|/scalar EXPR>,
544547L<C<undef>|/undef EXPR>
545548
546549=item Functions for processes and process groups
547550X<process> X<pid> X<process id>
548551
549552(プロセスとプロセスグループのための関数)
550553
551554=for Pod::Functions =Process
552555
553556L<C<alarm>|/alarm SECONDS>, L<C<exec>|/exec LIST>, L<C<fork>|/fork>,
554557L<C<getpgrp>|/getpgrp PID>, L<C<getppid>|/getppid>,
555558L<C<getpriority>|/getpriority WHICH,WHO>, L<C<kill>|/kill SIGNAL, LIST>,
556559L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>,
557560L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>,
558561L<C<readpipe>|/readpipe EXPR>, L<C<setpgrp>|/setpgrp PID,PGRP>,
559562L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
560563L<C<sleep>|/sleep EXPR>, L<C<system>|/system LIST>, L<C<times>|/times>,
561564L<C<wait>|/wait>, L<C<waitpid>|/waitpid PID,FLAGS>
562565
563566=item Keywords related to Perl modules
564567X<module>
565568
566569(Perl モジュールに関するキーワード)
567570
568571=for Pod::Functions =Modules
569572
570573L<C<do>|/do EXPR>, L<C<import>|/import LIST>,
571574L<C<no>|/no MODULE VERSION LIST>, L<C<package>|/package NAMESPACE>,
572575L<C<require>|/require VERSION>, L<C<use>|/use Module VERSION LIST>
573576
574577=item Keywords related to classes and object-orientation
575578X<object> X<class> X<package>
576579
577580(クラスとオブジェクト指向に関するキーワード)
578581
579582=for Pod::Functions =Objects
580583
581584L<C<bless>|/bless REF,CLASSNAME>, L<C<dbmclose>|/dbmclose HASH>,
582585L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
583586L<C<package>|/package NAMESPACE>, L<C<ref>|/ref EXPR>,
584587L<C<tie>|/tie VARIABLE,CLASSNAME,LIST>, L<C<tied>|/tied VARIABLE>,
585588L<C<untie>|/untie VARIABLE>, L<C<use>|/use Module VERSION LIST>
586589
587590=item Low-level socket functions
588591X<socket> X<sock>
589592
590593(低レベルソケット関数)
591594
592595=for Pod::Functions =Socket
593596
594597L<C<accept>|/accept NEWSOCKET,GENERICSOCKET>,
595598L<C<bind>|/bind SOCKET,NAME>, L<C<connect>|/connect SOCKET,NAME>,
596599L<C<getpeername>|/getpeername SOCKET>,
597600L<C<getsockname>|/getsockname SOCKET>,
598601L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
599602L<C<listen>|/listen SOCKET,QUEUESIZE>,
600603L<C<recv>|/recv SOCKET,SCALAR,LENGTH,FLAGS>,
601604L<C<send>|/send SOCKET,MSG,FLAGS,TO>,
602605L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
603606L<C<shutdown>|/shutdown SOCKET,HOW>,
604607L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
605608L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>
606609
607610=item System V interprocess communication functions
608611X<IPC> X<System V> X<semaphore> X<shared memory> X<memory> X<message>
609612
610613(System V プロセス間通信関数)
611614
612615=for Pod::Functions =SysV
613616
614617L<C<msgctl>|/msgctl ID,CMD,ARG>, L<C<msgget>|/msgget KEY,FLAGS>,
615618L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
616619L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>,
617620L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
618621L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
619622L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
620623L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
621624L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>
622625
623626=item Fetching user and group info
624627X<user> X<group> X<password> X<uid> X<gid> X<passwd> X</etc/passwd>
625628
626629(ユーザーとグループの情報取得)
627630
628631=for Pod::Functions =User
629632
630633L<C<endgrent>|/endgrent>, L<C<endhostent>|/endhostent>,
631634L<C<endnetent>|/endnetent>, L<C<endpwent>|/endpwent>,
632635L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
633636L<C<getgrnam>|/getgrnam NAME>, L<C<getlogin>|/getlogin>,
634637L<C<getpwent>|/getpwent>, L<C<getpwnam>|/getpwnam NAME>,
635638L<C<getpwuid>|/getpwuid UID>, L<C<setgrent>|/setgrent>,
636639L<C<setpwent>|/setpwent>
637640
638641=item Fetching network info
639642X<network> X<protocol> X<host> X<hostname> X<IP> X<address> X<service>
640643
641644(ネットワーク情報取得)
642645
643646=for Pod::Functions =Network
644647
645648L<C<endprotoent>|/endprotoent>, L<C<endservent>|/endservent>,
646649L<C<gethostbyaddr>|/gethostbyaddr ADDR,ADDRTYPE>,
647650L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
648651L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
649652L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
650653L<C<getprotobyname>|/getprotobyname NAME>,
651654L<C<getprotobynumber>|/getprotobynumber NUMBER>,
652655L<C<getprotoent>|/getprotoent>,
653656L<C<getservbyname>|/getservbyname NAME,PROTO>,
654657L<C<getservbyport>|/getservbyport PORT,PROTO>,
655658L<C<getservent>|/getservent>, L<C<sethostent>|/sethostent STAYOPEN>,
656659L<C<setnetent>|/setnetent STAYOPEN>,
657660L<C<setprotoent>|/setprotoent STAYOPEN>,
658661L<C<setservent>|/setservent STAYOPEN>
659662
660663=item Time-related functions
661664X<time> X<date>
662665
663666(時刻に関する関数)
664667
665668=for Pod::Functions =Time
666669
667670L<C<gmtime>|/gmtime EXPR>, L<C<localtime>|/localtime EXPR>,
668671L<C<time>|/time>, L<C<times>|/times>
669672
670673=item Non-function keywords
671674
672675=for Pod::Functions =!Non-functions
673676
674677C<and>, C<AUTOLOAD>, C<BEGIN>, C<CHECK>, C<cmp>, C<CORE>, C<__DATA__>,
675678C<default>, C<DESTROY>, C<else>, C<elseif>, C<elsif>, C<END>, C<__END__>,
676679C<eq>, C<for>, C<foreach>, C<ge>, C<given>, C<gt>, C<if>, C<INIT>, C<le>,
677680C<lt>, C<ne>, C<not>, C<or>, C<UNITCHECK>, C<unless>, C<until>, C<when>,
678681C<while>, C<x>, C<xor>
679682
680683=back
681684
682685=head2 Portability
683686X<portability> X<Unix> X<portable>
684687
685688(移植性)
686689
687690=begin original
688691
689692Perl was born in Unix and can therefore access all common Unix
690693system calls. In non-Unix environments, the functionality of some
691694Unix system calls may not be available or details of the available
692695functionality may differ slightly. The Perl functions affected
693696by this are:
694697
695698=end original
696699
697700Perl は Unix 環境で生まれたので、全ての共通する Unix システムコールに
698701アクセスします。
699702非 Unix 環境では、いくつかの Unix システムコールの機能が使えなかったり、
700703使える機能の詳細が多少異なったりします。
701704これによる影響を受ける Perl 関数は以下のものです:
702705
703706L<C<-I<X>>|/-X FILEHANDLE>, L<C<binmode>|/binmode FILEHANDLE, LAYER>,
704707L<C<chmod>|/chmod LIST>, L<C<chown>|/chown LIST>,
705708L<C<chroot>|/chroot FILENAME>, L<C<crypt>|/crypt PLAINTEXT,SALT>,
706709L<C<dbmclose>|/dbmclose HASH>, L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>,
707710L<C<dump>|/dump LABEL>, L<C<endgrent>|/endgrent>,
708711L<C<endhostent>|/endhostent>, L<C<endnetent>|/endnetent>,
709712L<C<endprotoent>|/endprotoent>, L<C<endpwent>|/endpwent>,
710713L<C<endservent>|/endservent>, L<C<exec>|/exec LIST>,
711714L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>,
712715L<C<flock>|/flock FILEHANDLE,OPERATION>, L<C<fork>|/fork>,
713716L<C<getgrent>|/getgrent>, L<C<getgrgid>|/getgrgid GID>,
714717L<C<gethostbyname>|/gethostbyname NAME>, L<C<gethostent>|/gethostent>,
715718L<C<getlogin>|/getlogin>,
716719L<C<getnetbyaddr>|/getnetbyaddr ADDR,ADDRTYPE>,
717720L<C<getnetbyname>|/getnetbyname NAME>, L<C<getnetent>|/getnetent>,
718721L<C<getppid>|/getppid>, L<C<getpgrp>|/getpgrp PID>,
719722L<C<getpriority>|/getpriority WHICH,WHO>,
720723L<C<getprotobynumber>|/getprotobynumber NUMBER>,
721724L<C<getprotoent>|/getprotoent>, L<C<getpwent>|/getpwent>,
722725L<C<getpwnam>|/getpwnam NAME>, L<C<getpwuid>|/getpwuid UID>,
723726L<C<getservbyport>|/getservbyport PORT,PROTO>,
724727L<C<getservent>|/getservent>,
725728L<C<getsockopt>|/getsockopt SOCKET,LEVEL,OPTNAME>,
726729L<C<glob>|/glob EXPR>, L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>,
727730L<C<kill>|/kill SIGNAL, LIST>, L<C<link>|/link OLDFILE,NEWFILE>,
728731L<C<lstat>|/lstat FILEHANDLE>, L<C<msgctl>|/msgctl ID,CMD,ARG>,
729732L<C<msgget>|/msgget KEY,FLAGS>,
730733L<C<msgrcv>|/msgrcv ID,VAR,SIZE,TYPE,FLAGS>,
731L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,EXPR>,
734L<C<msgsnd>|/msgsnd ID,MSG,FLAGS>, L<C<open>|/open FILEHANDLE,MODE,EXPR>,
732735L<C<pipe>|/pipe READHANDLE,WRITEHANDLE>, L<C<readlink>|/readlink EXPR>,
733736L<C<rename>|/rename OLDNAME,NEWNAME>,
734737L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>,
735738L<C<semctl>|/semctl ID,SEMNUM,CMD,ARG>,
736739L<C<semget>|/semget KEY,NSEMS,FLAGS>, L<C<semop>|/semop KEY,OPSTRING>,
737740L<C<setgrent>|/setgrent>, L<C<sethostent>|/sethostent STAYOPEN>,
738741L<C<setnetent>|/setnetent STAYOPEN>, L<C<setpgrp>|/setpgrp PID,PGRP>,
739742L<C<setpriority>|/setpriority WHICH,WHO,PRIORITY>,
740743L<C<setprotoent>|/setprotoent STAYOPEN>, L<C<setpwent>|/setpwent>,
741744L<C<setservent>|/setservent STAYOPEN>,
742745L<C<setsockopt>|/setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL>,
743746L<C<shmctl>|/shmctl ID,CMD,ARG>, L<C<shmget>|/shmget KEY,SIZE,FLAGS>,
744747L<C<shmread>|/shmread ID,VAR,POS,SIZE>,
745748L<C<shmwrite>|/shmwrite ID,STRING,POS,SIZE>,
746749L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL>,
747750L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>,
748751L<C<stat>|/stat FILEHANDLE>, L<C<symlink>|/symlink OLDFILE,NEWFILE>,
749752L<C<syscall>|/syscall NUMBER, LIST>,
750753L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
751754L<C<system>|/system LIST>, L<C<times>|/times>,
752755L<C<truncate>|/truncate FILEHANDLE,LENGTH>, L<C<umask>|/umask EXPR>,
753756L<C<unlink>|/unlink LIST>, L<C<utime>|/utime LIST>, L<C<wait>|/wait>,
754757L<C<waitpid>|/waitpid PID,FLAGS>
755758
756759=begin original
757760
758761For more information about the portability of these functions, see
759762L<perlport> and other available platform-specific documentation.
760763
761764=end original
762765
763766これらの関数の移植性に関するさらなる情報については、
764767L<perlport> とその他のプラットホーム固有のドキュメントを参照してください。
765768
766769=head2 Alphabetical Listing of Perl Functions
767770
768771=over
769772
770773=item -X FILEHANDLE
771774X<-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>
772775X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C>
773776
774777=item -X EXPR
775778
776779=item -X DIRHANDLE
777780
778781=item -X
779782
780783=for Pod::Functions a file test (-r, -x, etc)
781784
782785=begin original
783786
784787A file test, where X is one of the letters listed below. This unary
785788operator takes one argument, either a filename, a filehandle, or a dirhandle,
786789and tests the associated file to see if something is true about it. If the
787790argument is omitted, tests L<C<$_>|perlvar/$_>, except for C<-t>, which
788791tests STDIN. Unless otherwise documented, it returns C<1> for true and
789792C<''> for false. If the file doesn't exist or can't be examined, it
790793returns L<C<undef>|/undef EXPR> and sets L<C<$!>|perlvar/$!> (errno).
791Despite the funny names, precedence is the same as any other named unary
794With the exception of the C<-l> test they all follow symbolic links
792operator. The operator may be any of:
795because they use C<stat()> and not C<lstat()> (so dangling symlinks can't
796be examined and will therefore report failure).
793797
794798=end original
795799
796800X は以下にあげる文字で、ファイルテストを行ないます。
797801この単項演算子は、ファイル名かファイルハンドルを唯一の引数として動作し、
798802「あること」について真であるか否かを判定した結果を返します。
799803引数が省略されると、C<-t> では STDIN を調べますが、その他は
800804L<C<$_>|perlvar/$_> を調べます。
801805特に記述されていなければ、真として C<1> を返し、偽として C<''> を返します。
802806ファイルが存在しないか、テスト出来なければ、L<C<undef>|/undef EXPR> を返し、
803807L<C<$!>|perlvar/$!> (errno) を設定します。
808C<-l> テストを例外として、これら全てはシンボリックリンクに従います;
809C<lstat()> ではなく C<stat()> を使っているからです
810(従って壊れたシンボリックリンクは検査されず、失敗が報告されます)。
811
812=begin original
813
814Despite the funny names, precedence is the same as any other named unary
815operator. The operator may be any of:
816
817=end original
818
804819みかけは変わっていますが、優先順位は名前付き単項演算子と同じで、
805820他の単項演算子と同じく、引数を括弧で括ることもできます。
806821演算子には以下のものがあります:
807822
808823=begin original
809824
810825 -r File is readable by effective uid/gid.
811826 -w File is writable by effective uid/gid.
812827 -x File is executable by effective uid/gid.
813828 -o File is owned by effective uid.
814829
815830=end original
816831
817832 -r ファイルが実効 uid/gid で読み出し可。
818833 -w ファイルが実効 uid/gid で書き込み可。
819834 -x ファイルが実効 uid/gid で実行可。
820835 -o ファイルが実効 uid の所有物。
821836
822837=begin original
823838
824839 -R File is readable by real uid/gid.
825840 -W File is writable by real uid/gid.
826841 -X File is executable by real uid/gid.
827842 -O File is owned by real uid.
828843
829844=end original
830845
831846 -R ファイルが実 uid/gid で読み出し可。
832847 -W ファイルが実 uid/gid で書き込み可。
833848 -X ファイルが実 uid/gid で実行可。
834849 -O ファイルが実 uid の所有物。
835850
836851=begin original
837852
838853 -e File exists.
839854 -z File has zero size (is empty).
840855 -s File has nonzero size (returns size in bytes).
841856
842857=end original
843858
844859 -e ファイルが存在する。
845860 -z ファイルの大きさがゼロ(空)。
846861 -s ファイルの大きさがゼロ以外 (バイト単位での大きさを返す)。
847862
848863=begin original
849864
850865 -f File is a plain file.
851866 -d File is a directory.
852867 -l File is a symbolic link (false if symlinks aren't
853868 supported by the file system).
854869 -p File is a named pipe (FIFO), or Filehandle is a pipe.
855870 -S File is a socket.
856871 -b File is a block special file.
857872 -c File is a character special file.
858873 -t Filehandle is opened to a tty.
859874
860875=end original
861876
862877 -f ファイルは通常ファイル。
863878 -d ファイルはディレクトリ。
864879 -l ファイルはシンボリックリンク(ファイルシステムが非対応なら偽)。
865880 -p ファイルは名前付きパイプ (FIFO) またはファイルハンドルはパイプ。
866881 -S ファイルはソケット。
867882 -b ファイルはブロック特殊ファイル。
868883 -c ファイルはキャラクタ特殊ファイル。
869884 -t ファイルハンドルは tty にオープンされている。
870885
871886=begin original
872887
873888 -u File has setuid bit set.
874889 -g File has setgid bit set.
875890 -k File has sticky bit set.
876891
877892=end original
878893
879894 -u ファイルの setuid ビットがセットされている。
880895 -g ファイルの setgid ビットがセットされている。
881896 -k ファイルの sticky ビットがセットされている。
882897
883898=begin original
884899
885900 -T File is an ASCII or UTF-8 text file (heuristic guess).
886901 -B File is a "binary" file (opposite of -T).
887902
888903=end original
889904
890905 -T ファイルは ASCII または UTF-8 テキストファイル (発見的に推測します)。
891906 -B ファイルは「バイナリ」ファイル (-T の反対)。
892907
893908=begin original
894909
895910 -M Script start time minus file modification time, in days.
896911 -A Same for access time.
897912 -C Same for inode change time (Unix, may differ for other
898913 platforms)
899914
900915=end original
901916
902917 -M スクリプト実行開始時刻からファイル修正時刻を引いたもの(日単位)。
903918 -A 同様にアクセスがあってからの日数。
904919 -C 同様に(Unix では) inode が変更されてからの日数(それ以外の
905920 プラットフォームでは違うかもしれません)。
906921
907922=begin original
908923
909924Example:
910925
911926=end original
912927
913928例:
914929
915930 while (<>) {
916931 chomp;
917932 next unless -f $_; # ignore specials
918933 #...
919934 }
920935
921936=begin original
922937
923938Note that C<-s/a/b/> does not do a negated substitution. Saying
924939C<-exp($foo)> still works as expected, however: only single letters
925940following a minus are interpreted as file tests.
926941
927942=end original
928943
929944C<-s/a/b> は、置換演算 (s///) の符号反転ではありません。
930945しかし、C<-exp($foo)> は期待どおりに動作します; しかし、マイナス記号の後に
931946英字が 1 字続くときにのみ、ファイルテストと解釈されます。
932947
933948=begin original
934949
935950These operators are exempt from the "looks like a function rule" described
936951above. That is, an opening parenthesis after the operator does not affect
937952how much of the following code constitutes the argument. Put the opening
938953parentheses before the operator to separate it from code that follows (this
939954applies only to operators with higher precedence than unary operators, of
940955course):
941956
942957=end original
943958
944959これらの演算子は上述の「関数のように見えるルール」から免除されます。
945960つまり、演算子の後の開きかっこは、引き続くコードのどこまでが引数を
946961構成するかに影響を与えません。
947962演算子を引き続くコードから分離するには、演算子の前に開きかっこを
948963置いてください (これはもちろん、単項演算子より高い優先順位を持つ
949964演算子にのみ適用されます):
950965
951966 -s($file) + 1024 # probably wrong; same as -s($file + 1024)
952967 (-s $file) + 1024 # correct
953968
954969=begin original
955970
956971The interpretation of the file permission operators C<-r>, C<-R>,
957972C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the mode
958973of the file and the uids and gids of the user. There may be other
959974reasons you can't actually read, write, or execute the file: for
960975example network filesystem access controls, ACLs (access control lists),
961976read-only filesystems, and unrecognized executable formats. Note
962977that the use of these six specific operators to verify if some operation
963978is possible is usually a mistake, because it may be open to race
964979conditions.
965980
966981=end original
967982
968983ファイルのパーミッション演算子 C<-r>, C<-R>, C<-w>, C<-W>, C<-x>,
969984C<-X> の解釈は、ファイルのモードとユーザの実効/実 uid と
970985実効/実 gid のみから判断されます。
971986実際にファイルが読めたり、書けたり、実行できたりするためには、
972987別の条件が必要かもしれません:
973988例えば、ネットワークファイルシステムアクセスコントロール、
974989ACL(アクセスコントロールリスト)、読み込み専用ファイルシステム、
975990認識できない実行ファイルフォーマット、などです。
976991これらの 6 つの演算子を、特定の操作が可能かどうかを確認するために使うのは
977992通常は誤りであることに注意してください; なぜなら、これらは競合条件を
978993招きやすいからです。
979994
980995=begin original
981996
982997Also note that, for the superuser on the local filesystems, the C<-r>,
983998C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1
984999if any execute bit is set in the mode. Scripts run by the superuser
9851000may thus need to do a L<C<stat>|/stat FILEHANDLE> to determine the
9861001actual mode of the file, or temporarily set their effective uid to
9871002something else.
9881003
9891004=end original
9901005
9911006ローカルファイルシステムのスーパーユーザには、
9921007C<-r>, C<-R>, C<-w>, C<-W> に対して、常に 1 が返り、モード中の
9931008いずれかの実行許可ビットが立っていれば、C<-x>, C<-X> にも 1 が
9941009返ることにも注意してください。
9951010スーパーユーザが実行するスクリプトでは、ファイルのモードを調べるためには、
9961011L<C<stat>|/stat FILEHANDLE> を行なうか、実効 uid を一時的に別のものにする
9971012必要があるでしょう。
9981013
9991014=begin original
10001015
10011016If you are using ACLs, there is a pragma called L<C<filetest>|filetest>
10021017that may produce more accurate results than the bare
10031018L<C<stat>|/stat FILEHANDLE> mode bits.
10041019When under C<use filetest 'access'>, the above-mentioned filetests
10051020test whether the permission can(not) be granted using the L<access(2)>
10061021family of system calls. Also note that the C<-x> and C<-X> tests may
10071022under this pragma return true even if there are no execute permission
10081023bits set (nor any extra execute permission ACLs). This strangeness is
10091024due to the underlying system calls' definitions. Note also that, due to
10101025the implementation of C<use filetest 'access'>, the C<_> special
10111026filehandle won't cache the results of the file tests when this pragma is
10121027in effect. Read the documentation for the L<C<filetest>|filetest>
10131028pragma for more information.
10141029
10151030=end original
10161031
10171032ACL を使っている場合は、生の L<C<stat>|/stat FILEHANDLE> モードビットより
10181033精度の高い結果を作成する L<C<filetest>|filetest> プラグマがあります。
10191034C<use filetest 'access'> とした場合、上述したファイルテストは
10201035システムコールの L<access(2)> ファミリーを使って権限が与えられているか
10211036どうかをテストします。
10221037また、このプラグマが指定されている場合、C<-x> と C<-X> テストは
10231038たとえ実行許可ビット(または追加の実行許可 ACL)がセットされていない
10241039場合でも真を返すことに注意してください。
10251040この挙動は使用するシステムコールの定義によるものです。
10261041C<use filetest 'access'> の実装により、このプラグマが有効の場合は
10271042C<_> 特殊ファイルハンドルはファイルテストの結果をキャッシュしないことに
10281043注意してください。
10291044さらなる情報については L<C<filetest>|filetest> プラグマのドキュメントを
10301045参照してください。
10311046
10321047=begin original
10331048
10341049The C<-T> and C<-B> tests work as follows. The first block or so of
10351050the file is examined to see if it is valid UTF-8 that includes non-ASCII
10361051characters. If so, it's a C<-T> file. Otherwise, that same portion of
10371052the file is examined for odd characters such as strange control codes or
10381053characters with the high bit set. If more than a third of the
10391054characters are strange, it's a C<-B> file; otherwise it's a C<-T> file.
10401055Also, any file containing a zero byte in the examined portion is
10411056considered a binary file. (If executed within the scope of a L<S<use
10421057locale>|perllocale> which includes C<LC_CTYPE>, odd characters are
10431058anything that isn't a printable nor space in the current locale.) If
10441059C<-T> or C<-B> is used on a filehandle, the current IO buffer is
10451060examined
10461061rather than the first block. Both C<-T> and C<-B> return true on an empty
10471062file, or a file at EOF when testing a filehandle. Because you have to
10481063read a file to do the C<-T> test, on most occasions you want to use a C<-f>
10491064against the file first, as in C<next unless -f $file && -T $file>.
10501065
10511066=end original
10521067
10531068ファイルテスト C<-T> と C<-B> の動作原理は、次のようになっています。
10541069ファイルの最初の数ブロックを調べて、非 ASCII 文字を含む妥当な UTF-8 かどうかを
10551070調べます。
10561071もしそうなら、それは C<-T> ファイルです。
10571072さもなければ、ファイルの同じ位置から、変わった制御コードや
10581073上位ビットがセットされているような、通常のテキストには現れない文字を探します。
10591074三分の一以上がおかしな文字なら、それは C<-B> ファイルでです;
10601075さもなければ C<-T> ファイルです。
10611076また、調べた位置にヌル文字が含まれるファイルも、バイナリファイルと
10621077みなされます。
10631078(C<LC_CTYPE> を含む L<S<use locale>|perllocale> のスコープの中で実行されると、
10641079おかしな文字というのは現在のロケールで表示可能でもスペースでもないものです。)
10651080C<-T> や C<-B> をファイルハンドルに対して用いると、
10661081最初のブロックを調べる代わりに、IO バッファを調べます。
10671082調べたファイルの中身が何もないときや、
10681083ファイルハンドルを調べたときに EOF に達して
10691084いたときには、C<-T> も C<-B> も「真」を返します。
10701085C<-T> テストをするためにはファイルを読み込まないといけないので、
10711086たいていは C<next unless -f $file && -T $file> というような形で
10721087まず調べたいファイルに対して C<-f> を使いたいはずです。
10731088
10741089=begin original
10751090
10761091If any of the file tests (or either the L<C<stat>|/stat FILEHANDLE> or
10771092L<C<lstat>|/lstat FILEHANDLE> operator) is given the special filehandle
10781093consisting of a solitary underline, then the stat structure of the
10791094previous file test (or L<C<stat>|/stat FILEHANDLE> operator) is used,
10801095saving a system call. (This doesn't work with C<-t>, and you need to
10811096remember that L<C<lstat>|/lstat FILEHANDLE> and C<-l> leave values in
10821097the stat structure for the symbolic link, not the real file.) (Also, if
10831098the stat buffer was filled by an L<C<lstat>|/lstat FILEHANDLE> call,
10841099C<-T> and C<-B> will reset it with the results of C<stat _>).
10851100Example:
10861101
10871102=end original
10881103
10891104どのファイルテスト (あるいは、L<C<stat>|/stat FILEHANDLE> や
10901105L<C<lstat>|/lstat FILEHANDLE>) 演算子にも、
10911106下線だけから成る特別なファイルハンドルを与えると、
10921107前回のファイルテスト (や L<C<stat>|/stat FILEHANDLE> 演算子) の
10931108stat 構造体が使われ、システムコールを省きます。
10941109(C<-t> には使えませんし、L<C<lstat>|/lstat FILEHANDLE> や C<-l> は
10951110実ファイルではなく、シンボリックリンクの情報を stat 構造体に残すことを
10961111覚えておく必要があります。)
10971112(また、stat バッファが L<C<lstat>|/lstat FILEHANDLE> 呼び出しで埋まった場合、
10981113C<-T> と C<-B> の結果は C<stat _> の結果でリセットされます。
10991114例:
11001115
11011116 print "Can do.\n" if -r $a || -w _ || -x _;
11021117
11031118 stat($filename);
11041119 print "Readable\n" if -r _;
11051120 print "Writable\n" if -w _;
11061121 print "Executable\n" if -x _;
11071122 print "Setuid\n" if -u _;
11081123 print "Setgid\n" if -g _;
11091124 print "Sticky\n" if -k _;
11101125 print "Text\n" if -T _;
11111126 print "Binary\n" if -B _;
11121127
11131128=begin original
11141129
11151130As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file
11161131test operators, in a way that C<-f -w -x $file> is equivalent to
11171132C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use
11181133the return value of C<-f $file> as an argument to another filetest
11191134operator, no special magic will happen.)
11201135
11211136=end original
11221137
11231138Perl 5.10.0 から、純粋にシンタックスシュガーとして、ファイルテスト演算子を
11241139スタックさせることができるので、C<-f -w -x $file> は
11251140C<-x $file && -w _ && -f _> と等価です。
11261141(これは文法上だけの話です; もし C<-f $file> の返り値を他のファイルテスト
11271142演算子の引数として使う場合は、何の特別なことも起きません。)
11281143
11291144=begin original
11301145
11311146Portability issues: L<perlport/-X>.
11321147
11331148=end original
11341149
11351150移植性の問題: L<perlport/-X>。
11361151
11371152=begin original
11381153
11391154To avoid confusing would-be users of your code with mysterious
11401155syntax errors, put something like this at the top of your script:
11411156
11421157=end original
11431158
11441159あなたのコードのユーザーが不思議な文法エラーで混乱することを
11451160避けるために、スクリプトの先頭に以下のようなことを書いてください:
11461161
11471162 use 5.010; # so filetest ops can stack
11481163
11491164=item abs VALUE
11501165X<abs> X<absolute>
11511166
11521167=item abs
11531168
11541169=for Pod::Functions absolute value function
11551170
11561171=begin original
11571172
11581173Returns the absolute value of its argument.
11591174If VALUE is omitted, uses L<C<$_>|perlvar/$_>.
11601175
11611176=end original
11621177
11631178引数の絶対値を返します。
11641179VALUE が省略された場合は、L<C<$_>|perlvar/$_> を使います。
11651180
11661181=item accept NEWSOCKET,GENERICSOCKET
11671182X<accept>
11681183
11691184=for Pod::Functions accept an incoming socket connect
11701185
11711186=begin original
11721187
11731188Accepts an incoming socket connect, just as L<accept(2)>
11741189does. Returns the packed address if it succeeded, false otherwise.
11751190See the example in L<perlipc/"Sockets: Client/Server Communication">.
11761191
11771192=end original
11781193
11791194L<accept(2)> システムコールと同様に、着信するソケットの接続を受け付けます。
11801195成功時にはパックされたアドレスを返し、失敗すれば偽を返します。
11811196L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
11821197
11831198=begin original
11841199
11851200On systems that support a close-on-exec flag on files, the flag will
11861201be set for the newly opened file descriptor, as determined by the
11871202value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
11881203
11891204=end original
11901205
11911206ファイルに対する close-on-exec フラグをサポートしているシステムでは、
11921207フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
11931208ファイル記述子に対してセットされます。
11941209L<perlvar/$^F> を参照してください。
11951210
11961211=item alarm SECONDS
11971212X<alarm>
11981213X<SIGALRM>
11991214X<timer>
12001215
12011216=item alarm
12021217
12031218=for Pod::Functions schedule a SIGALRM
12041219
12051220=begin original
12061221
12071222Arranges to have a SIGALRM delivered to this process after the
12081223specified number of wallclock seconds has elapsed. If SECONDS is not
12091224specified, the value stored in L<C<$_>|perlvar/$_> is used. (On some
12101225machines, unfortunately, the elapsed time may be up to one second less
12111226or more than you specified because of how seconds are counted, and
12121227process scheduling may delay the delivery of the signal even further.)
12131228
12141229=end original
12151230
12161231指定した壁時計秒数が経過した後に、自プロセスに SIGALRM が
12171232送られてくるようにします。
12181233SECONDS が指定されていない場合は、L<C<$_>|perlvar/$_> に格納されている値を
12191234使います。
12201235(マシンによっては、秒の数え方が異なるため、指定した秒数よりも最大で
122112361 秒ずれます。)
12221237
12231238=begin original
12241239
12251240Only one timer may be counting at once. Each call disables the
12261241previous timer, and an argument of C<0> may be supplied to cancel the
12271242previous timer without starting a new one. The returned value is the
12281243amount of time remaining on the previous timer.
12291244
12301245=end original
12311246
12321247一度には一つのタイマだけが設定可能です。
12331248呼び出しを行なう度に、以前のタイマを無効にしますし、
12341249新しくタイマを起動しないで以前のタイマをキャンセルするために
12351250引数に C<0> を指定して呼び出すことができます。
12361251以前のタイマの残り時間が、返り値となります。
12371252
12381253=begin original
12391254
12401255For delays of finer granularity than one second, the L<Time::HiRes> module
12411256(from CPAN, and starting from Perl 5.8 part of the standard
12421257distribution) provides
12431258L<C<ualarm>|Time::HiRes/ualarm ( $useconds [, $interval_useconds ] )>.
12441259You may also use Perl's four-argument version of
12451260L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the first three
12461261arguments undefined, or you might be able to use the
12471262L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
12481263if your system supports it. See L<perlfaq8> for details.
12491264
12501265=end original
12511266
125212671 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
12531268また Perl 5.8 からは標準配布されています) が
12541269L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。
12551270Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
125612713 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、
12571272Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
12581273アクセスすることもできます。
12591274詳しくは L<perlfaq8> を参照してください。
12601275
12611276=begin original
12621277
12631278It is usually a mistake to intermix L<C<alarm>|/alarm SECONDS> and
12641279L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> may be
12651280internally implemented on your system with L<C<alarm>|/alarm SECONDS>.
12661281
12671282=end original
12681283
12691284L<C<alarm>|/alarm SECONDS> と L<C<sleep>|/sleep EXPR> を混ぜて使うのは
12701285普通は間違いです; なぜなら、L<C<sleep>|/sleep EXPR> は内部的に
12711286L<C<alarm>|/alarm SECONDS> を使って内部的に実装されているかも
12721287しれないからです。
12731288
12741289=begin original
12751290
12761291If you want to use L<C<alarm>|/alarm SECONDS> to time out a system call
12771292you need to use an L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> pair. You
12781293can't rely on the alarm causing the system call to fail with
12791294L<C<$!>|perlvar/$!> set to C<EINTR> because Perl sets up signal handlers
12801295to restart system calls on some systems. Using
12811296L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the
12821297caveats given in L<perlipc/"Signals">.
12831298
12841299=end original
12851300
12861301L<C<alarm>|/alarm SECONDS> をシステムコールの時間切れのために使いたいなら、
12871302L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> のペアで使う必要があります。
12881303システムコールが失敗したときに L<C<$!>|perlvar/$!> に C<EINTR> が
12891304セットされることに頼ってはいけません; なぜならシステムによっては Perl は
12901305システムコールを再開するためにシグナルハンドラを設定するからです。
12911306L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> は常にうまく動きます;
12921307注意点については L<perlipc/"Signals"> を参照してください。
12931308
12941309 eval {
12951310 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
12961311 alarm $timeout;
12971312 my $nread = sysread $socket, $buffer, $size;
12981313 alarm 0;
12991314 };
13001315 if ($@) {
13011316 die unless $@ eq "alarm\n"; # propagate unexpected errors
13021317 # timed out
13031318 }
13041319 else {
13051320 # didn't
13061321 }
13071322
13081323=begin original
13091324
13101325For more information see L<perlipc>.
13111326
13121327=end original
13131328
13141329さらなる情報については L<perlipc> を参照してください。
13151330
13161331=begin original
13171332
13181333Portability issues: L<perlport/alarm>.
13191334
13201335=end original
13211336
13221337移植性の問題: L<perlport/alarm>。
13231338
13241339=item atan2 Y,X
13251340X<atan2> X<arctangent> X<tan> X<tangent>
13261341
13271342=for Pod::Functions arctangent of Y/X in the range -PI to PI
13281343
13291344=begin original
13301345
13311346Returns the arctangent of Y/X in the range -PI to PI.
13321347
13331348=end original
13341349
13351350-πからπの範囲で Y/X の逆正接を返します。
13361351
13371352=begin original
13381353
13391354For the tangent operation, you may use the
13401355L<C<Math::Trig::tan>|Math::Trig/B<tan>> function, or use the familiar
13411356relation:
13421357
13431358=end original
13441359
13451360正接を求めたいときは、L<C<Math::Trig::tan>|Math::Trig/B<tan>> を使うか、
13461361以下のよく知られた関係を使ってください。
13471362
13481363 sub tan { sin($_[0]) / cos($_[0]) }
13491364
13501365=begin original
13511366
13521367The return value for C<atan2(0,0)> is implementation-defined; consult
13531368your L<atan2(3)> manpage for more information.
13541369
13551370=end original
13561371
13571372C<atan2(0,0)> の返り値は実装依存です; さらなる情報については
13581373L<atan2(3)> man ページを参照してください。
13591374
13601375=begin original
13611376
13621377Portability issues: L<perlport/atan2>.
13631378
13641379=end original
13651380
13661381移植性の問題: L<perlport/atan2>。
13671382
13681383=item bind SOCKET,NAME
13691384X<bind>
13701385
13711386=for Pod::Functions binds an address to a socket
13721387
13731388=begin original
13741389
13751390Binds a network address to a socket, just as L<bind(2)>
13761391does. Returns true if it succeeded, false otherwise. NAME should be a
13771392packed address of the appropriate type for the socket. See the examples in
13781393L<perlipc/"Sockets: Client/Server Communication">.
13791394
13801395=end original
13811396
13821397L<bind(2)> システムコールと同様に、ネットワークアドレスをソケットに
13831398結び付けます。
13841399成功時には真を、さもなければ偽を返します。
13851400NAME は、ソケットに対する、適切な型のパックされた
13861401アドレスでなければなりません。
13871402L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
13881403
13891404=item binmode FILEHANDLE, LAYER
13901405X<binmode> X<binary> X<text> X<DOS> X<Windows>
13911406
13921407=item binmode FILEHANDLE
13931408
13941409=for Pod::Functions prepare binary files for I/O
13951410
13961411=begin original
13971412
13981413Arranges for FILEHANDLE to be read or written in "binary" or "text"
13991414mode on systems where the run-time libraries distinguish between
14001415binary and text files. If FILEHANDLE is an expression, the value is
14011416taken as the name of the filehandle. Returns true on success,
14021417otherwise it returns L<C<undef>|/undef EXPR> and sets
14031418L<C<$!>|perlvar/$!> (errno).
14041419
14051420=end original
14061421
14071422バイナリファイルとテキストファイルを区別する OS において、
14081423FILEHANDLE を「バイナリ」または「テキスト」で読み書きするように
14091424指定します。
14101425FILEHANDLE が式である場合には、その式の値がファイルハンドルの
14111426名前として使われます。
14121427成功時には真を返し、失敗時には L<C<undef>|/undef EXPR> を返して
14131428L<C<$!>|perlvar/$!> (errno) を設定します。
14141429
14151430=begin original
14161431
14171432On some systems (in general, DOS- and Windows-based systems)
14181433L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
14191434working with a text file. For the sake of portability it is a good idea
14201435always to use it when appropriate, and never to use it when it isn't
14211436appropriate. Also, people can set their I/O to be by default
14221437UTF8-encoded Unicode, not bytes.
14231438
14241439=end original
14251440
14261441テキストファイルでないものを扱う場合に
14271442L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
14281443システムもあります(一般的には DOS と Windows ベースのシステムです)。
14291444移植性のために、適切なときには常にこれを使い、適切でないときには
14301445決して使わないというのは良い考えです。
14311446また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
14321447Unicode にセットすることも出来ます。
14331448
14341449=begin original
14351450
14361451In other words: regardless of platform, use
14371452L<C<binmode>|/binmode FILEHANDLE, LAYER> on binary data, like images,
14381453for example.
14391454
14401455=end original
14411456
14421457言い換えると: プラットフォームに関わらず、
14431458例えばイメージのようなバイナリファイルに対しては
14441459L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。
14451460
14461461=begin original
14471462
14481463If LAYER is present it is a single string, but may contain multiple
14491464directives. The directives alter the behaviour of the filehandle.
14501465When LAYER is present, using binmode on a text file makes sense.
14511466
14521467=end original
14531468
14541469LAYER が存在すると、それは単一の文字列ですが、複数の指示子を
14551470含むことができます。
14561471指示子はファイルハンドルの振る舞いを変更します。
14571472LAYER が存在すると、テキストファイルでの binmode が意味を持ちます。
14581473
14591474=begin original
14601475
14611476If LAYER is omitted or specified as C<:raw> the filehandle is made
14621477suitable for passing binary data. This includes turning off possible CRLF
14631478translation and marking it as bytes (as opposed to Unicode characters).
14641479Note that, despite what may be implied in I<"Programming Perl"> (the
14651480Camel, 3rd edition) or elsewhere, C<:raw> is I<not> simply the inverse of C<:crlf>.
14661481Other layers that would affect the binary nature of the stream are
1467I<also> disabled. See L<PerlIO>, L<perlrun>, and the discussion about the
1482I<also> disabled. See L<PerlIO>, and the discussion about the PERLIO
1468PERLIO environment variable.
1483environment variable in L<perlrun|perlrun/PERLIO>.
14691484
14701485=end original
14711486
14721487LAYER が省略されたり、C<:raw> が指定されると、ファイルハンドルはバイナリ
14731488データの通過に適するように設定されます。
14741489これには CRLF 変換をオフにしたり、それぞれを(Unicode 文字ではなく)
14751490バイトであるとマークしたりすることを含みます。
14761491I<"プログラミング Perl">(ラクダ本第三版) やその他で暗示されているにも関わらず、
14771492C<:raw> は単なる C<:crlf> の I<逆ではありません>。
14781493ストリームのバイナリとしての性質に影響を与える
14791494I<その他の層も無効にされます>。
1480L<PerlIO>, L<perlrun> およびPERLIO 環境変数に関する議論を参照してください。
1495L<PerlIO>, および L<perlrun|perlrun/PERLIO> PERLIO 環境変数に関する議論を
1496参照してください。
14811497
14821498=begin original
14831499
14841500The C<:bytes>, C<:crlf>, C<:utf8>, and any other directives of the
14851501form C<:...>, are called I/O I<layers>. The L<open> pragma can be used to
14861502establish default I/O layers.
14871503
14881504=end original
14891505
14901506C<:bytes>, C<:crlf>, and C<:utf8>, 及びその他の C<:...> 形式の指示子は
14911507I/O I<層> が呼び出されます。
14921508L<open> プラグマはデフォルト I/O 層を指定するために使われます。
14931509
14941510=begin original
14951511
14961512I<The LAYER parameter of the L<C<binmode>|/binmode FILEHANDLE, LAYER>
14971513function is described as "DISCIPLINE" in "Programming Perl, 3rd
14981514Edition". However, since the publishing of this book, by many known as
14991515"Camel III", the consensus of the naming of this functionality has moved
15001516from "discipline" to "layer". All documentation of this version of Perl
15011517therefore refers to "layers" rather than to "disciplines". Now back to
15021518the regularly scheduled documentation...>
15031519
15041520=end original
15051521
15061522I<L<C<binmode>|/binmode FILEHANDLE, LAYER> 関数の LAYER パラメータは
15071523「プログラミングPerl 第 3 版」では
15081524「ディシプリン(DISCIPLINE)」と表現されていました。
15091525しかし、「ラクダ本第 3 版」として知られているこの本の出版後、この機能の名前は
15101526「ディシプリン」から「層」に変更することで合意されました。
15111527従って、このバージョンの Perl の全ての文書では「ディシプリン」ではなく
15121528「層」と記述されています。では通常の解説に戻ります…>
15131529
15141530=begin original
15151531
15161532To mark FILEHANDLE as UTF-8, use C<:utf8> or C<:encoding(UTF-8)>.
15171533C<:utf8> just marks the data as UTF-8 without further checking,
15181534while C<:encoding(UTF-8)> checks the data for actually being valid
15191535UTF-8. More details can be found in L<PerlIO::encoding>.
15201536
15211537=end original
15221538
15231539FILEHANDLE が UTF-8 であるというマークをつけるには、C<:utf8> か
15241540C<:encoding(UTF-8)> を使ってください。
15251541C<:utf8> は、さらなるチェックなしにデータが UTF-8 としてマークしますが、
15261542C<:encoding(UTF-8)> はデータが実際に有効な UTF-8 かどうかをチェックします。
15271543さらなる詳細は L<PerlIO::encoding> にあります。
15281544
15291545=begin original
15301546
15311547In general, L<C<binmode>|/binmode FILEHANDLE, LAYER> should be called
1532after L<C<open>|/open FILEHANDLE,EXPR> but before any I/O is done on the
1548after L<C<open>|/open FILEHANDLE,MODE,EXPR> but before any I/O is done on the
15331549filehandle. Calling L<C<binmode>|/binmode FILEHANDLE, LAYER> normally
15341550flushes any pending buffered output data (and perhaps pending input
15351551data) on the handle. An exception to this is the C<:encoding> layer
15361552that changes the default character encoding of the handle.
15371553The C<:encoding> layer sometimes needs to be called in
15381554mid-stream, and it doesn't flush the stream. C<:encoding>
15391555also implicitly pushes on top of itself the C<:utf8> layer because
15401556internally Perl operates on UTF8-encoded Unicode characters.
15411557
15421558=end original
15431559
15441560一般的に L<C<binmode>|/binmode FILEHANDLE, LAYER> は
1545L<C<open>|/open FILEHANDLE,EXPR> を呼び出した後、このファイルハンドルに対する
1561L<C<open>|/open FILEHANDLE,MODE,EXPR> を呼び出した後、このファイルハンドルに
1546I/O 操作をする前に呼び出すべきです。
1562対するI/O 操作をする前に呼び出すべきです。
15471563L<C<binmode>|/binmode FILEHANDLE, LAYER> を呼び出すと、普通はこの
15481564ファイルハンドルに対してバッファリングされている全ての出力データ
15491565(およびおそらくは入力データ)をフラッシュします。
15501566例外は、このハンドルに対するデフォルト文字エンコーディングを変更する
15511567C<:encoding> 層です。
15521568C<:encoding> 層はストリームの途中で呼び出す必要があることがあり、
15531569それによってストリームはフラッシュされません。
15541570Perl は内部で UTF-8 エンコードされた Unicode 文字を操作しているので、
15551571C<:encoding> は暗黙のうちに自身を C<:utf8> 層の上に押し上げます。
15561572
15571573=begin original
15581574
15591575The operating system, device drivers, C libraries, and Perl run-time
15601576system all conspire to let the programmer treat a single
15611577character (C<\n>) as the line terminator, irrespective of external
15621578representation. On many operating systems, the native text file
15631579representation matches the internal representation, but on some
15641580platforms the external representation of C<\n> is made up of more than
15651581one character.
15661582
15671583=end original
15681584
15691585オペレーティングシステム、デバイスドライバ、C ライブラリ、
15701586Perl ランタイムシステムは全て、プログラマが外部表現に関わらず
157115871 文字 (C<\n>) を行終端として扱えるように協調作業します。
15721588多くのオペレーティングシステムでは、ネイティブテキストファイル表現は
15731589内部表現と同じですが、C<\n> の外部表現が複数文字になる
15741590プラットフォームもあります。
15751591
15761592=begin original
15771593
15781594All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use
15791595a single character to end each line in the external representation of text
15801596(even though that single character is CARRIAGE RETURN on old, pre-Darwin
15811597flavors of Mac OS, and is LINE FEED on Unix and most VMS files). In other
15821598systems like OS/2, DOS, and the various flavors of MS-Windows, your program
15831599sees a C<\n> as a simple C<\cJ>, but what's stored in text files are the
15841600two characters C<\cM\cJ>. That means that if you don't use
15851601L<C<binmode>|/binmode FILEHANDLE, LAYER> on these systems, C<\cM\cJ>
15861602sequences on disk will be converted to C<\n> on input, and any C<\n> in
15871603your program will be converted back to C<\cM\cJ> on output. This is
15881604what you want for text files, but it can be disastrous for binary files.
15891605
15901606=end original
15911607
15921608全ての Unix 系、(新旧の)Mac OS、VMS の Stream_LF ファイルは
15931609テキストの外部表現として各行の末尾に一つの文字を
15941610使っています(しかしその文字は古い Darwin 以前の Mac OS では復帰で、
15951611Unix とほとんどのVMS のファイルでは改行です)。
15961612VMS, MS-DOS, MS-Windows 系といったその他のシステムでは、
15971613プログラムからは C<\n> は単純に C<\cJ> に見えますが、
15981614テキストファイルとして保存される場合は C<\cM\cJ> の 2 文字になります。
15991615つまり、もしこれらのシステムで L<C<binmode>|/binmode FILEHANDLE, LAYER> を
16001616使わないと、ディスク上の C<\cM\cJ> という並びは入力時に C<\n> に変換され、
16011617プログラムが出力した全ての C<\n> は C<\cM\cJ> に逆変換されます。
16021618これはテキストファイルの場合は思い通りの結果でしょうが、
16031619バイナリファイルの場合は悲惨です。
16041620
16051621=begin original
16061622
16071623Another consequence of using L<C<binmode>|/binmode FILEHANDLE, LAYER>
16081624(on some systems) is that special end-of-file markers will be seen as
16091625part of the data stream. For systems from the Microsoft family this
16101626means that, if your binary data contain C<\cZ>, the I/O subsystem will
16111627regard it as the end of the file, unless you use
16121628L<C<binmode>|/binmode FILEHANDLE, LAYER>.
16131629
16141630=end original
16151631
16161632L<C<binmode>|/binmode FILEHANDLE, LAYER> を(いくつかのシステムで)
16171633使うことによるその他の作用としては、特別なファイル終端マーカーが
16181634データストリームの一部として見られることです。
16191635Microsoft ファミリーのシステムでは、
16201636L<C<binmode>|/binmode FILEHANDLE, LAYER> を使っていないと、
16211637もしバイナリデータに C<\cZ> が含まれていたときに、
16221638I/O サブシステムがこれをファイル終端とみなすことを意味します。
16231639
16241640=begin original
16251641
16261642L<C<binmode>|/binmode FILEHANDLE, LAYER> is important not only for
16271643L<C<readline>|/readline EXPR> and L<C<print>|/print FILEHANDLE LIST>
16281644operations, but also when using
16291645L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16301646L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
16311647L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16321648L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> and
16331649L<C<tell>|/tell FILEHANDLE> (see L<perlport> for more details). See the
16341650L<C<$E<sol>>|perlvar/$E<sol>> and L<C<$\>|perlvar/$\> variables in
16351651L<perlvar> for how to manually set your input and output
16361652line-termination sequences.
16371653
16381654=end original
16391655
16401656L<C<binmode>|/binmode FILEHANDLE, LAYER> は L<C<readline>|/readline EXPR> と
16411657L<C<print>|/print FILEHANDLE LIST> 操作にだけではなく、
16421658L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16431659L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
16441660L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16451661L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
16461662L<C<tell>|/tell FILEHANDLE> を使うときにも重要です
16471663(詳細は L<perlport> を参照してください)。
16481664入出力の行端末シーケンスを手動でセットする方法については
16491665L<perlvar> の L<C<$E<sol>>|perlvar/$E<sol>> 変数と
16501666L<C<$\>|perlvar/$\> 変数を参照してください。
16511667
16521668=begin original
16531669
16541670Portability issues: L<perlport/binmode>.
16551671
16561672=end original
16571673
16581674移植性の問題: L<perlport/binmode>。
16591675
16601676=item bless REF,CLASSNAME
16611677X<bless>
16621678
16631679=item bless REF
16641680
16651681=for Pod::Functions create an object
16661682
16671683=begin original
16681684
16691685This function tells the thingy referenced by REF that it is now an object
1670in the CLASSNAME package. If CLASSNAME is omitted, the current package
1686in the CLASSNAME package. If CLASSNAME is an empty string, it is
1687interpreted as referring to the C<main> package.
1688If CLASSNAME is omitted, the current package
16711689is used. Because a L<C<bless>|/bless REF,CLASSNAME> is often the last
16721690thing in a constructor, it returns the reference for convenience.
16731691Always use the two-argument version if a derived class might inherit the
16741692method doing the blessing. See L<perlobj> for more about the blessing
16751693(and blessings) of objects.
16761694
16771695=end original
16781696
16791697この関数は、REF で渡された オブジェクトに対し、
16801698CLASSNAME 内のオブジェクトとなったことを伝えます。
1699CLASSNAME が空文字列の場合、C<main> パッケージを参照しているものと
1700解釈されます。
16811701CLASSNAME が省略された場合には、その時点のパッケージとなります。
16821702L<C<bless>|/bless REF,CLASSNAME> は通常、コンストラクタの最後に
16831703置かれますので、簡便のためにそのリファレンスを返します。
16841704派生クラスが bless されるメソッドを継承する場合は、
16851705常に 2 引数版を使ってください。
16861706オブジェクトの bless (や再 bless) について、詳しくは と L<perlobj> を
16871707参照してください。
16881708
16891709=begin original
16901710
16911711Consider always blessing objects in CLASSNAMEs that are mixed case.
16921712Namespaces with all lowercase names are considered reserved for
16931713Perl pragmas. Builtin types have all uppercase names. To prevent
1694confusion, you may wish to avoid such package names as well. Make sure
1714confusion, you may wish to avoid such package names as well.
1695that CLASSNAME is a true value.
1715It is advised to avoid the class name C<0>, because much code erroneously
1716uses the result of L<C<ref>|/ref EXPR> as a truth value.
16961717
16971718=end original
16981719
16991720大文字小文字が混じっている CLASSNAME のオブジェクトは常に bless することを
17001721考慮してください。
17011722全て小文字の名前を持つ名前空間は Perl プラグマのために予約されています。
17021723組み込みの型は全て大文字の名前を持ちます。
17031724混乱を避けるために、
17041725パッケージ名としてこのような名前は避けるべきです。
17051726CLASSNAME は真の値を持つようにしてください。
1727クラス名として C<0> は避けてください; 多くのコードが誤って
1728L<C<ref>|/ref EXPR> の結果を真の値として使っているからです。
17061729
17071730=begin original
17081731
17091732See L<perlmod/"Perl Modules">.
17101733
17111734=end original
17121735
17131736L<perlmod/"Perl Modules"> を参照してください。
17141737
17151738=item break
17161739
17171740=for Pod::Functions +switch break out of a C<given> block
17181741
17191742=begin original
17201743
17211744Break out of a C<given> block.
17221745
17231746=end original
17241747
17251748C<given> ブロックから脱出します。
17261749
17271750=begin original
17281751
17291752L<C<break>|/break> is available only if the
17301753L<C<"switch"> feature|feature/The 'switch' feature> is enabled or if it
17311754is prefixed with C<CORE::>. The
17321755L<C<"switch"> feature|feature/The 'switch' feature> is enabled
17331756automatically with a C<use v5.10> (or higher) declaration in the current
17341757scope.
17351758
17361759=end original
17371760
17381761L<C<break>|/break> は、L<C<"switch"> 機能|feature/The 'switch' feature> が
17391762有効か、C<CORE::> 接頭辞を使ったときにのみ利用可能です。
17401763L<C<"switch"> 機能|feature/The 'switch' feature> は、現在のスコープで
17411764C<use v5.10> (またはそれ以上) 宣言があると自動的に有効になります。
17421765
17431766=item caller EXPR
17441767X<caller> X<call stack> X<stack> X<stack trace>
17451768
17461769=item caller
17471770
17481771=for Pod::Functions get context of the current subroutine call
17491772
17501773=begin original
17511774
17521775Returns the context of the current pure perl subroutine call. In scalar
17531776context, returns the caller's package name if there I<is> a caller (that is, if
17541777we're in a subroutine or L<C<eval>|/eval EXPR> or
17551778L<C<require>|/require VERSION>) and the undefined value otherwise.
17561779caller never returns XS subs and they are skipped. The next pure perl
17571780sub will appear instead of the XS sub in caller's return values. In
17581781list context, caller returns
17591782
17601783=end original
17611784
17621785その時点のピュア perl サブルーチン呼び出しのコンテキストを返します。
17631786スカラコンテキストでは、呼び元が I<ある> 場合
17641787(サブルーチン、L<C<eval>|/eval EXPR>、L<C<require>|/require VERSION> の中に
17651788いるとき) には呼び出し元のパッケージ名を返し、
17661789その他のときには未定義値を返します。
17671790caller は XS サブルーチンを返すことはなく、それらは飛ばされます。
17681791XS サブルーチンの代わりに次のピュア perl サブルーチンが caller の返り値に
17691792なります。
17701793リストコンテキストでは、caller は以下を返します:
17711794
17721795 # 0 1 2
17731796 my ($package, $filename, $line) = caller;
17741797
17751798=begin original
17761799
1800Like L<C<__FILE__>|/__FILE__> and L<C<__LINE__>|/__LINE__>, the filename and
1801line number returned here may be altered by the mechanism described at
1802L<perlsyn/"Plain Old Comments (Not!)">.
1803
1804=end original
1805
1806L<C<__FILE__>|/__FILE__> と L<C<__LINE__>|/__LINE__> 同様、
1807ここで返されるファイル名と行番号は
1808L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構によって
1809置き換えられます。
1810
1811=begin original
1812
17771813With EXPR, it returns some extra information that the debugger uses to
17781814print a stack trace. The value of EXPR indicates how many call frames
17791815to go back before the current one.
17801816
17811817=end original
17821818
17831819EXPR を付けると、デバッガがスタックトレースを表示するために使う情報を返します。
17841820EXPR の値は、現状から数えて、
17851821いくつ前のコールフレームまで戻るかを示します。
17861822
17871823 # 0 1 2 3 4
17881824 my ($package, $filename, $line, $subroutine, $hasargs,
17891825
17901826 # 5 6 7 8 9 10
17911827 $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
17921828 = caller($i);
17931829
17941830=begin original
17951831
17961832Here, $subroutine is the function that the caller called (rather than the
17971833function containing the caller). Note that $subroutine may be C<(eval)> if
17981834the frame is not a subroutine call, but an L<C<eval>|/eval EXPR>. In
17991835such a case additional elements $evaltext and C<$is_require> are set:
18001836C<$is_require> is true if the frame is created by a
18011837L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>
18021838statement, $evaltext contains the text of the C<eval EXPR> statement.
18031839In particular, for an C<eval BLOCK> statement, $subroutine is C<(eval)>,
18041840but $evaltext is undefined. (Note also that each
18051841L<C<use>|/use Module VERSION LIST> statement creates a
18061842L<C<require>|/require VERSION> frame inside an C<eval EXPR> frame.)
18071843$subroutine may also be C<(unknown)> if this particular subroutine
18081844happens to have been deleted from the symbol table. C<$hasargs> is true
18091845if a new instance of L<C<@_>|perlvar/@_> was set up for the frame.
18101846C<$hints> and C<$bitmask> contain pragmatic hints that the caller was
18111847compiled with. C<$hints> corresponds to L<C<$^H>|perlvar/$^H>, and
18121848C<$bitmask> corresponds to
18131849L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}>. The C<$hints> and
18141850C<$bitmask> values are subject to change between versions of Perl, and
18151851are not meant for external use.
18161852
18171853=end original
18181854
18191855ここで、$subroutine は、(caller を含む関数ではなく) caller が呼び出した
18201856関数です。
18211857フレームがサブルーチン呼び出しではなく L<C<eval>|/eval EXPR> だった場合、この
18221858$subroutine は C<(eval)> になることに注意してください。
18231859この場合、追加の要素である $evaltext と C<$is_require> がセットされます:
18241860C<$is_require> はフレームが L<C<require>|/require VERSION> または
18251861L<C<use>|/use Module VERSION LIST> で作られた場合に真になり、
18261862$evaltext は C<eval EXPR> のテキストが入ります。
18271863特に、C<eval BLOCK> の場合、$subroutine は C<(eval)> になりますが、
18281864$evaltext は未定義値になります。
18291865(それぞれの L<C<use>|/use Module VERSION LIST> は C<eval EXPR> の中で
18301866L<C<require>|/require VERSION> フレームを作ることに注意してください。)
18311867$subroutine は、そのサブルーチンがシンボルテーブルから削除された場合は
18321868C<(unknown)> になります。
18331869C<$hasargs> はこのフレーム用に L<C<@_>|perlvar/@_> の新しい実体が
18341870設定された場合に真となります。
18351871C<$hints> と C<$bitmask> は caller がコンパイルされたときの
18361872実際的なヒントを含みます。
18371873C<$hints> は L<C<$^H>|perlvar/$^H> に対応し、C<$bitmask> は
18381874L<C<${^WARNING_BITS}>|perlvar/${^WARNING_BITS}> に
18391875対応します。
18401876C<$hints> は C<$bitmask> は Perl のバージョンによって変更される
18411877可能性があるので、外部での使用を想定していません。
18421878
18431879=begin original
18441880
18451881C<$hinthash> is a reference to a hash containing the value of
18461882L<C<%^H>|perlvar/%^H> when the caller was compiled, or
18471883L<C<undef>|/undef EXPR> if L<C<%^H>|perlvar/%^H> was empty. Do not
18481884modify the values of this hash, as they are the actual values stored in
18491885the optree.
18501886
18511887=end original
18521888
18531889C<$hinthash> は、caller がコンパイルされた時の L<C<%^H>|perlvar/%^H> の値を
18541890含むハッシュへのリファレンスか、あるいは L<C<%^H>|perlvar/%^H> が空の場合は
18551891L<C<undef>|/undef EXPR> です。
18561892このハッシュの値は構文木に保管されている実際の値なので、変更しないで下さい。
18571893
18581894=begin original
18591895
18601896Furthermore, when called from within the DB package in
18611897list context, and with an argument, caller returns more
18621898detailed information: it sets the list variable C<@DB::args> to be the
18631899arguments with which the subroutine was invoked.
18641900
18651901=end original
18661902
18671903さらに、DB パッケージの中からリストコンテキストで引数付きで呼ばれた場合は、
18681904caller はより詳細な情報を返します; サブルーチンが起動されたときの引数を
18691905変数 C<@DB::args> に設定します。
18701906
18711907=begin original
18721908
18731909Be aware that the optimizer might have optimized call frames away before
18741910L<C<caller>|/caller EXPR> had a chance to get the information. That
18751911means that C<caller(N)> might not return information about the call
18761912frame you expect it to, for C<< N > 1 >>. In particular, C<@DB::args>
18771913might have information from the previous time L<C<caller>|/caller EXPR>
18781914was called.
18791915
18801916=end original
18811917
18821918L<C<caller>|/caller EXPR> が情報を得る前にオプティマイザが呼び出しフレームを
18831919最適化してしまうかもしれないことに注意してください。
18841920これは、C<caller(N)> が C<< N > 1 >> のとき、
18851921あなたが予測した呼び出しフレームの情報を返さないかもしれないことを意味します。
18861922特に、C<@DB::args> は L<C<caller>|/caller EXPR> が前回呼び出された時の情報を
18871923持っているかもしれません。
18881924
18891925=begin original
18901926
18911927Be aware that setting C<@DB::args> is I<best effort>, intended for
18921928debugging or generating backtraces, and should not be relied upon. In
18931929particular, as L<C<@_>|perlvar/@_> contains aliases to the caller's
18941930arguments, Perl does not take a copy of L<C<@_>|perlvar/@_>, so
18951931C<@DB::args> will contain modifications the subroutine makes to
18961932L<C<@_>|perlvar/@_> or its contents, not the original values at call
18971933time. C<@DB::args>, like L<C<@_>|perlvar/@_>, does not hold explicit
18981934references to its elements, so under certain cases its elements may have
18991935become freed and reallocated for other variables or temporary values.
19001936Finally, a side effect of the current implementation is that the effects
19011937of C<shift @_> can I<normally> be undone (but not C<pop @_> or other
19021938splicing, I<and> not if a reference to L<C<@_>|perlvar/@_> has been
19031939taken, I<and> subject to the caveat about reallocated elements), so
19041940C<@DB::args> is actually a hybrid of the current state and initial state
19051941of L<C<@_>|perlvar/@_>. Buyer beware.
19061942
19071943=end original
19081944
19091945C<@DB::args> の設定は I<ベストエフォート> で、デバッグやバックトレースの
19101946生成を目的としていて、これに依存するべきではないということにも
19111947注意してください。
19121948特に、L<C<@_>|perlvar/@_> は呼び出し元の引数へのエイリアスを含んでいるので、
19131949Perl は L<C<@_>|perlvar/@_> のコピーを取らず、従って C<@DB::args> は
19141950サブルーチンが L<C<@_>|perlvar/@_> やその内容に行った変更を含んでいて、
19151951呼び出し時の元の値ではありません。
19161952C<@DB::args> は、L<C<@_>|perlvar/@_> と同様、その要素への明示的な
19171953リファレンスを保持しないので、ある種の状況では、解放されて他の変数や
19181954一時的な値のために再割り当てされているかもしれません。
19191955最後に、現在の実装の副作用は、C<shift @_> の効果は I<普通は> 行われない
19201956(しかし C<pop @_> やその他の splice は違い、I<そして> もし
19211957L<C<@_>|perlvar/@_> のリファレンスが取られると違い、I<そして> 再割り当てされた
19221958要素に関する問題になりやすいです)ことなので、C<@DB::args> は実際には現在の
19231959状態と L<C<@_>|perlvar/@_> の初期状態との合成物となります。
19241960ご用心を。
19251961
19261962=item chdir EXPR
19271963X<chdir>
19281964X<cd>
19291965X<directory, change>
19301966
19311967=item chdir FILEHANDLE
19321968
19331969=item chdir DIRHANDLE
19341970
19351971=item chdir
19361972
19371973=for Pod::Functions change your current working directory
19381974
19391975=begin original
19401976
19411977Changes the working directory to EXPR, if possible. If EXPR is omitted,
19421978changes to the directory specified by C<$ENV{HOME}>, if set; if not,
19431979changes to the directory specified by C<$ENV{LOGDIR}>. (Under VMS, the
19441980variable C<$ENV{'SYS$LOGIN'}> is also checked, and used if it is set.) If
19451981neither is set, L<C<chdir>|/chdir EXPR> does nothing and fails. It
19461982returns true on success, false otherwise. See the example under
19471983L<C<die>|/die LIST>.
19481984
19491985=end original
19501986
19511987(可能であれば、) カレントディレクトリを EXPR に移します。
19521988EXPR を指定しないと、C<$ENV{HOME}> が設定されていれば、そのディレクトリに
19531989移ります; そうでなく、C<$ENV{LOGDIR}>が設定されていれば、そのディレクトリに
19541990移ります。
19551991(VMS では C<$ENV{'SYS$LOGIN'}> もチェックされ、もしセットされていれば
19561992使われます。)
19571993どちらも設定されていなければ、L<C<chdir>|/chdir EXPR> は何もせずに失敗します。
19581994成功時には真を返し、そうでなければ偽を返します。
19591995L<C<die>|/die LIST> の項の例を参照してください。
19601996
19611997=begin original
19621998
19631999On systems that support L<fchdir(2)>, you may pass a filehandle or
19642000directory handle as the argument. On systems that don't support L<fchdir(2)>,
19652001passing handles raises an exception.
19662002
19672003=end original
19682004
19692005L<fchdir(2)> に対応しているシステムでは、ファイルハンドルや
19702006ディレクトリハンドルを引数として渡せます。
19712007L<fchdir(2)> に対応していないシステムでは、ハンドルを渡すと例外が発生します。
19722008
19732009=item chmod LIST
19742010X<chmod> X<permission> X<mode>
19752011
19762012=for Pod::Functions changes the permissions on a list of files
19772013
19782014=begin original
19792015
19802016Changes the permissions of a list of files. The first element of the
19812017list must be the numeric mode, which should probably be an octal
19822018number, and which definitely should I<not> be a string of octal digits:
19832019C<0644> is okay, but C<"0644"> is not. Returns the number of files
19842020successfully changed. See also L<C<oct>|/oct EXPR> if all you have is a
19852021string.
19862022
19872023=end original
19882024
19892025LIST に含まれるファイルの、パーミッションを変更します。
19902026LIST の最初の要素は、数値表現のモードでなければなりません;
19912027恐らく 8 進表記の数であるべきでしょう: しかし、8 進表記の
19922028文字列では I<いけません>: C<0644> は OK ですが、 C<"0644"> は
19932029だめ、ということです。
19942030変更に成功したファイルの数を返します。
19952031文字列を使いたい場合は、L<C<oct>|/oct EXPR> を参照してください。
19962032
19972033 my $cnt = chmod 0755, "foo", "bar";
19982034 chmod 0755, @executables;
19992035 my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to
20002036 # --w----r-T
20012037 my $mode = "0644"; chmod oct($mode), "foo"; # this is better
20022038 my $mode = 0644; chmod $mode, "foo"; # this is best
20032039
20042040=begin original
20052041
20062042On systems that support L<fchmod(2)>, you may pass filehandles among the
20072043files. On systems that don't support L<fchmod(2)>, passing filehandles raises
20082044an exception. Filehandles must be passed as globs or glob references to be
20092045recognized; barewords are considered filenames.
20102046
20112047=end original
20122048
20132049L<fchmod(2)> に対応しているシステムでは、ファイルハンドルを引数として
20142050渡せます。
20152051L<fchmod(2)> に対応していないシステムでは、ファイルハンドルを渡すと
20162052例外が発生します。
20172053ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
20182054渡されなければなりません;
20192055裸の単語はファイル名として扱われます。
20202056
20212057 open(my $fh, "<", "foo");
20222058 my $perm = (stat $fh)[2] & 07777;
20232059 chmod($perm | 0600, $fh);
20242060
20252061=begin original
20262062
20272063You can also import the symbolic C<S_I*> constants from the
20282064L<C<Fcntl>|Fcntl> module:
20292065
20302066=end original
20312067
20322068L<C<Fcntl>|Fcntl> モジュールから C<S_I*> シンボル定数を
20332069インポートすることもできます:
20342070
20352071 use Fcntl qw( :mode );
20362072 chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables;
20372073 # Identical to the chmod 0755 of the example above.
20382074
20392075=begin original
20402076
20412077Portability issues: L<perlport/chmod>.
20422078
20432079=end original
20442080
20452081移植性の問題: L<perlport/chmod>。
20462082
20472083=item chomp VARIABLE
20482084X<chomp> X<INPUT_RECORD_SEPARATOR> X<$/> X<newline> X<eol>
20492085
20502086=item chomp( LIST )
20512087
20522088=item chomp
20532089
20542090=for Pod::Functions remove a trailing record separator from a string
20552091
20562092=begin original
20572093
20582094This safer version of L<C<chop>|/chop VARIABLE> removes any trailing
20592095string that corresponds to the current value of
20602096L<C<$E<sol>>|perlvar/$E<sol>> (also known as C<$INPUT_RECORD_SEPARATOR>
20612097in the L<C<English>|English> module). It returns the total
20622098number of characters removed from all its arguments. It's often used to
20632099remove the newline from the end of an input record when you're worried
20642100that the final record may be missing its newline. When in paragraph
20652101mode (C<$/ = ''>), it removes all trailing newlines from the string.
20662102When in slurp mode (C<$/ = undef>) or fixed-length record mode
20672103(L<C<$E<sol>>|perlvar/$E<sol>> is a reference to an integer or the like;
20682104see L<perlvar>), L<C<chomp>|/chomp VARIABLE> won't remove anything.
20692105If VARIABLE is omitted, it chomps L<C<$_>|perlvar/$_>. Example:
20702106
20712107=end original
20722108
20732109より安全な L<C<chop>|/chop VARIABLE> (以下を参照してください) です;
20742110L<C<$E<sol>>|perlvar/$E<sol>> (L<C<English>|English> モジュールでは、
20752111C<$INPUT_RECORD_SEPARATOR> とも言う) のその時点の
20762112値に対応する行末文字を削除します。
20772113全ての引数から削除した文字数の合計を返します。
20782114入力レコードから、改行を削除したいのだけれど、最後のレコードには改行が
20792115入っているのかわからないような場合に、使用できます。
20802116段落モード (C<$/ = ''>) では、レコードの最後の改行をすべて取り除きます。
20812117吸い込みモード (C<$/ = undef>) や 固定長レコードモード
20822118(L<C<$E<sol>>|perlvar/$E<sol>> が整数へのリファレンスや類似のものの場合;
20832119L<perlvar>を参照してください)では、L<C<chomp>|/chomp VARIABLE> は
20842120何も取り除きません。
20852121VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chomp します。
20862122例:
20872123
20882124 while (<>) {
20892125 chomp; # avoid \n on last field
20902126 my @array = split(/:/);
20912127 # ...
20922128 }
20932129
20942130=begin original
20952131
20962132If VARIABLE is a hash, it chomps the hash's values, but not its keys,
20972133resetting the L<C<each>|/each HASH> iterator in the process.
20982134
20992135=end original
21002136
21012137VARIABLE がハッシュなら、ハッシュのキーではなく値について chomp し、
21022138このプロセスの L<C<each>|/each HASH> 反復子をリセットします。
21032139
21042140=begin original
21052141
21062142You can actually chomp anything that's an lvalue, including an assignment:
21072143
21082144=end original
21092145
21102146左辺値であれば、代入を含めて、任意のものを chomp できます:
21112147
21122148 chomp(my $cwd = `pwd`);
21132149 chomp(my $answer = <STDIN>);
21142150
21152151=begin original
21162152
21172153If you chomp a list, each element is chomped, and the total number of
21182154characters removed is returned.
21192155
21202156=end original
21212157
21222158リストを chomp すると、個々の要素が chomp され、
21232159削除された文字数の合計が返されます。
21242160
21252161=begin original
21262162
21272163Note that parentheses are necessary when you're chomping anything
21282164that is not a simple variable. This is because C<chomp $cwd = `pwd`;>
21292165is interpreted as C<(chomp $cwd) = `pwd`;>, rather than as
21302166C<chomp( $cwd = `pwd` )> which you might expect. Similarly,
21312167C<chomp $a, $b> is interpreted as C<chomp($a), $b> rather than
21322168as C<chomp($a, $b)>.
21332169
21342170=end original
21352171
21362172単純な変数以外のものを chomp する場合はかっこが必要であることに
21372173注意してください。
21382174これは、C<chomp $cwd = `pwd`;> は、予測している
21392175C<chomp( $cwd = `pwd` )> ではなく、C<(chomp $cwd) = `pwd`;> と
21402176解釈されるからです。
21412177同様に、C<chomp $a, $b> は C<chomp($a, $b)> ではなく C<chomp($a), $b>
21422178と解釈されます。
21432179
21442180=item chop VARIABLE
21452181X<chop>
21462182
21472183=item chop( LIST )
21482184
21492185=item chop
21502186
21512187=for Pod::Functions remove the last character from a string
21522188
21532189=begin original
21542190
21552191Chops off the last character of a string and returns the character
21562192chopped. It is much more efficient than C<s/.$//s> because it neither
21572193scans nor copies the string. If VARIABLE is omitted, chops
21582194L<C<$_>|perlvar/$_>.
21592195If VARIABLE is a hash, it chops the hash's values, but not its keys,
21602196resetting the L<C<each>|/each HASH> iterator in the process.
21612197
21622198=end original
21632199
21642200文字列の最後の文字を切り捨てて、その切り取った文字を返します。
21652201文字列の検索もコピーも行ないませんので
21662202C<s/.$//s> よりも、ずっと効率的です。
21672203VARIABLE が省略されると、L<C<$_>|perlvar/$_> を対象として chop します。
21682204VARIABLE がハッシュの場合、ハッシュのキーではなく値について chop し、
21692205このプロセスの L<C<each>|/each HASH> 反復子をリセットします。
21702206
21712207=begin original
21722208
21732209You can actually chop anything that's an lvalue, including an assignment.
21742210
21752211=end original
21762212
21772213実際のところ、代入を含む左辺値となりうるなんでも chop できます。
21782214
21792215=begin original
21802216
21812217If you chop a list, each element is chopped. Only the value of the
21822218last L<C<chop>|/chop VARIABLE> is returned.
21832219
21842220=end original
21852221
21862222リストを chop すると、個々の要素が chop されます。
21872223最後の L<C<chop>|/chop VARIABLE> の値だけが返されます。
21882224
21892225=begin original
21902226
21912227Note that L<C<chop>|/chop VARIABLE> returns the last character. To
21922228return all but the last character, use C<substr($string, 0, -1)>.
21932229
21942230=end original
21952231
21962232L<C<chop>|/chop VARIABLE> は最後の文字を返すことに注意してください。
21972233最後以外の全ての文字を返すためには、C<substr($string, 0, -1)> を
21982234使ってください。
21992235
22002236=begin original
22012237
22022238See also L<C<chomp>|/chomp VARIABLE>.
22032239
22042240=end original
22052241
22062242L<C<chomp>|/chomp VARIABLE> も参照してください。
22072243
22082244=item chown LIST
22092245X<chown> X<owner> X<user> X<group>
22102246
22112247=for Pod::Functions change the ownership on a list of files
22122248
22132249=begin original
22142250
22152251Changes the owner (and group) of a list of files. The first two
22162252elements of the list must be the I<numeric> uid and gid, in that
22172253order. A value of -1 in either position is interpreted by most
22182254systems to leave that value unchanged. Returns the number of files
22192255successfully changed.
22202256
22212257=end original
22222258
22232259LIST に含まれるファイルの所有者 (とグループ) を変更します。
22242260LIST の最初の二つの要素には、I<数値表現> の uid と gid を
22252261この順序で与えなければなりません。
22262262どちらかの値を -1 にすると、ほとんどのシステムではその値は
22272263変更しないと解釈します。
22282264変更に成功したファイルの数を返します。
22292265
22302266 my $cnt = chown $uid, $gid, 'foo', 'bar';
22312267 chown $uid, $gid, @filenames;
22322268
22332269=begin original
22342270
22352271On systems that support L<fchown(2)>, you may pass filehandles among the
22362272files. On systems that don't support L<fchown(2)>, passing filehandles raises
22372273an exception. Filehandles must be passed as globs or glob references to be
22382274recognized; barewords are considered filenames.
22392275
22402276=end original
22412277
22422278L<fchown(2)> に対応しているシステムでは、ファイルハンドルを引数として渡せます。
22432279L<fchown(2)> に対応していないシステムでは、ファイルハンドルを渡すと
22442280例外が発生します。
22452281ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
22462282渡されなければなりません; 裸の単語はファイル名として扱われます。
22472283
22482284=begin original
22492285
22502286Here's an example that looks up nonnumeric uids in the passwd file:
22512287
22522288=end original
22532289
22542290passwd ファイルから数値表現でない uid を検索する例を
22552291示します:
22562292
22572293 print "User: ";
22582294 chomp(my $user = <STDIN>);
22592295 print "Files: ";
22602296 chomp(my $pattern = <STDIN>);
22612297
22622298 my ($login,$pass,$uid,$gid) = getpwnam($user)
22632299 or die "$user not in passwd file";
22642300
22652301 my @ary = glob($pattern); # expand filenames
22662302 chown $uid, $gid, @ary;
22672303
22682304=begin original
22692305
22702306On most systems, you are not allowed to change the ownership of the
22712307file unless you're the superuser, although you should be able to change
22722308the group to any of your secondary groups. On insecure systems, these
22732309restrictions may be relaxed, but this is not a portable assumption.
22742310On POSIX systems, you can detect this condition this way:
22752311
22762312=end original
22772313
22782314ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を
22792315変更できますが、グループは実行者の副グループに変更できるべきです。
22802316安全でないシステムでは、この制限はゆるめられています; しかしこれは
22812317移植性のある仮定ではありません。
22822318POSIX システムでは、以下のようにしてこの条件を検出できます:
22832319
22842320 use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
22852321 my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED);
22862322
22872323=begin original
22882324
22892325Portability issues: L<perlport/chown>.
22902326
22912327=end original
22922328
22932329移植性の問題: L<perlport/chown>。
22942330
22952331=item chr NUMBER
22962332X<chr> X<character> X<ASCII> X<Unicode>
22972333
22982334=item chr
22992335
23002336=for Pod::Functions get character this number represents
23012337
23022338=begin original
23032339
23042340Returns the character represented by that NUMBER in the character set.
23052341For example, C<chr(65)> is C<"A"> in either ASCII or Unicode, and
23062342chr(0x263a) is a Unicode smiley face.
23072343
23082344=end original
23092345
23102346特定の文字セットでの NUMBER で表わされる文字を返します。
23112347たとえば、C<chr(65)> は ASCII と Unicode の両方で C<"A"> となります;
23122348chr(0x263a) は Unicode のスマイリーフェイスです。
23132349
23142350=begin original
23152351
23162352Negative values give the Unicode replacement character (chr(0xfffd)),
23172353except under the L<bytes> pragma, where the low eight bits of the value
23182354(truncated to an integer) are used.
23192355
23202356=end original
23212357
23222358負の数は Unicode の置換文字 (chr(0xfffd)) を与えますが、
23232359L<bytes> プラグマの影響下では、(integer に切り詰められた)値の下位 8 ビットが
23242360使われます。
23252361
23262362=begin original
23272363
23282364If NUMBER is omitted, uses L<C<$_>|perlvar/$_>.
23292365
23302366=end original
23312367
23322368NUMBER が省略された場合、L<C<$_>|perlvar/$_> を使います。
23332369
23342370=begin original
23352371
23362372For the reverse, use L<C<ord>|/ord EXPR>.
23372373
23382374=end original
23392375
23402376逆を行うためには、L<C<ord>|/ord EXPR> を参照してください。
23412377
23422378=begin original
23432379
23442380Note that characters from 128 to 255 (inclusive) are by default
23452381internally not encoded as UTF-8 for backward compatibility reasons.
23462382
23472383=end original
23482384
23492385128 から 255 までの文字は過去との互換性のために
23502386デフォルトでは UTF-8 Unicode にエンコードされません。
23512387
23522388=begin original
23532389
23542390See L<perlunicode> for more about Unicode.
23552391
23562392=end original
23572393
23582394Unicode については L<perlunicode> を参照してください。
23592395
23602396=item chroot FILENAME
23612397X<chroot> X<root>
23622398
23632399=item chroot
23642400
23652401=for Pod::Functions make directory new root for path lookups
23662402
23672403=begin original
23682404
23692405This function works like the system call by the same name: it makes the
23702406named directory the new root directory for all further pathnames that
23712407begin with a C</> by your process and all its children. (It doesn't
23722408change your current working directory, which is unaffected.) For security
23732409reasons, this call is restricted to the superuser. If FILENAME is
23742410omitted, does a L<C<chroot>|/chroot FILENAME> to L<C<$_>|perlvar/$_>.
23752411
23762412=end original
23772413
23782414同じ名前のシステムコールと同じことをします: 現在のプロセス及び子プロセスに
23792415対して、C</>で始まるパス名に関して指定されたディレクトリを新しい
23802416ルートディレクトリとして扱います。
23812417(これはカレントディレクトリを変更しません; カレントディレクトリは
23822418そのままです。)
23832419セキュリティ上の理由により、この呼び出しはスーパーユーザーしか行えません。
23842420FILENAME を省略すると、L<C<$_>|perlvar/$_> へ
23852421L<C<chroot>|/chroot FILENAME> します。
23862422
23872423=begin original
23882424
2389B<NOTE:> It is good security practice to do C<chdir("/")>
2425B<NOTE:> It is mandatory for security to C<chdir("/")>
23902426(L<C<chdir>|/chdir EXPR> to the root directory) immediately after a
2391L<C<chroot>|/chroot FILENAME>.
2427L<C<chroot>|/chroot FILENAME>, otherwise the current working directory
2428may be outside of the new root.
23922429
23932430=end original
23942431
23952432B<注意:> L<C<chroot>|/chroot FILENAME> の直後に (ルートディレクトリに
23962433L<C<chdir>|/chdir EXPR> する)
2397C<chdir("/")> するのはセキュリティ上の良い習慣です
2434C<chdir("/")> するのはセキュリティ上必須です;
2435さもなければ現在の作業ディレクトリは新しいルートの外側かもしれません。
23982436
23992437=begin original
24002438
24012439Portability issues: L<perlport/chroot>.
24022440
24032441=end original
24042442
24052443移植性の問題: L<perlport/chroot>。
24062444
24072445=item close FILEHANDLE
24082446X<close>
24092447
24102448=item close
24112449
24122450=for Pod::Functions close file (or pipe or socket) handle
24132451
24142452=begin original
24152453
24162454Closes the file or pipe associated with the filehandle, flushes the IO
24172455buffers, and closes the system file descriptor. Returns true if those
24182456operations succeed and if no error was reported by any PerlIO
24192457layer. Closes the currently selected filehandle if the argument is
24202458omitted.
24212459
24222460=end original
24232461
24242462FILEHANDLE に対応したファイルまたはパイプをクローズして、
24252463IO バッファをフラッシュし、システムファイル記述子をクローズします。
24262464操作が成功し、PerlIO 層からエラーが報告されなかった場合に真を返します。
24272465引数が省略された場合、現在選択されているファイルハンドルをクローズします。
24282466
24292467=begin original
24302468
24312469You don't have to close FILEHANDLE if you are immediately going to do
2432another L<C<open>|/open FILEHANDLE,EXPR> on it, because
2470another L<C<open>|/open FILEHANDLE,MODE,EXPR> on it, because
2433L<C<open>|/open FILEHANDLE,EXPR> closes it for you. (See
2471L<C<open>|/open FILEHANDLE,MODE,EXPR> closes it for you. (See
2434L<C<open>|/open FILEHANDLE,EXPR>.) However, an explicit
2472L<C<open>|/open FILEHANDLE,MODE,EXPR>.) However, an explicit
24352473L<C<close>|/close FILEHANDLE> on an input file resets the line counter
24362474(L<C<$.>|perlvar/$.>), while the implicit close done by
2437L<C<open>|/open FILEHANDLE,EXPR> does not.
2475L<C<open>|/open FILEHANDLE,MODE,EXPR> does not.
24382476
24392477=end original
24402478
24412479クローズしてすぐにまた、同じファイルハンドルに対してオープンを行なう
2442場合には、L<C<open>|/open FILEHANDLE,EXPR> が自動的に
2480場合には、L<C<open>|/open FILEHANDLE,MODE,EXPR> が自動的に
24432481L<C<close>|/close FILEHANDLE> を行ないますので、
24442482close FILEHANDLE する必要はありません。
2445(L<C<open>|/open FILEHANDLE,EXPR> を参照してください。)
2483(L<C<open>|/open FILEHANDLE,MODE,EXPR> を参照してください。)
24462484ただし、明示的にクローズを行なったときにのみ入力ファイルの
24472485行番号 (L<C<$.>|perlvar/$.>) のリセットが行なわれ、
2448L<C<open>|/open FILEHANDLE,EXPR> によって行なわれる
2486L<C<open>|/open FILEHANDLE,MODE,EXPR> によって行なわれる
24492487暗黙の L<C<close>|/close FILEHANDLE> では行なわれません。
24502488
24512489=begin original
24522490
24532491If the filehandle came from a piped open, L<C<close>|/close FILEHANDLE>
24542492returns false if one of the other syscalls involved fails or if its
24552493program exits with non-zero status. If the only problem was that the
24562494program exited non-zero, L<C<$!>|perlvar/$!> will be set to C<0>.
24572495Closing a pipe also waits for the process executing on the pipe to
24582496exit--in case you wish to look at the output of the pipe afterwards--and
24592497implicitly puts the exit status value of that command into
24602498L<C<$?>|perlvar/$?> and
24612499L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
24622500
24632501=end original
24642502
24652503ファイルハンドルがパイプつきオープンなら、L<C<close>|/close FILEHANDLE> は
24662504その他のシステムコールが失敗したりプログラムが非ゼロのステータスで終了した
24672505場合にも偽を返します。
24682506プログラムが非ゼロで終了しただけの場合は、L<C<$!>|perlvar/$!> が C<0> に
24692507セットされます。
24702508後でパイプの出力を見たい場合のために、パイプのクローズでは、パイプ上で
24712509実行されているプロセスの終了を待ち、また自動的にコマンドのステータス値を
24722510L<C<$?>|perlvar/$?> と
24732511L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に設定します。
24742512
24752513=begin original
24762514
24772515If there are multiple threads running, L<C<close>|/close FILEHANDLE> on
24782516a filehandle from a piped open returns true without waiting for the
24792517child process to terminate, if the filehandle is still open in another
24802518thread.
24812519
24822520=end original
24832521
24842522複数のスレッドがある場合、パイプで開かれたファイルハンドルに対する
24852523L<C<close>|/close FILEHANDLE> は、そのファイルハンドルが他のスレッドで
24862524まだ開かれている場合、子プロセスの終了を待たずに真を返します。
24872525
24882526=begin original
24892527
24902528Closing the read end of a pipe before the process writing to it at the
24912529other end is done writing results in the writer receiving a SIGPIPE. If
24922530the other end can't handle that, be sure to read all the data before
24932531closing the pipe.
24942532
24952533=end original
24962534
24972535書き込み側が閉じる前に途中でパイプの読み込み側が閉じた場合、
24982536書き込み側に SIGPIPE が配送されます。
24992537書き込み側がこれを扱えない場合、パイプを閉じる前に
25002538確実に全てのデータが読み込まれるようにする必要があります。
25012539
25022540=begin original
25032541
25042542Example:
25052543
25062544=end original
25072545
25082546例:
25092547
25102548 open(OUTPUT, '|sort >foo') # pipe to sort
25112549 or die "Can't start sort: $!";
25122550 #... # print stuff to output
25132551 close OUTPUT # wait for sort to finish
25142552 or warn $! ? "Error closing sort pipe: $!"
25152553 : "Exit status $? from sort";
25162554 open(INPUT, 'foo') # get sort's results
25172555 or die "Can't open 'foo' for input: $!";
25182556
25192557=begin original
25202558
25212559FILEHANDLE may be an expression whose value can be used as an indirect
25222560filehandle, usually the real filehandle name or an autovivified handle.
25232561
25242562=end original
25252563
25262564FILEHANDLE は式でもかまいません; この場合、値は間接ファイルハンドルと
25272565して扱われ、普通は実際のファイルハンドル名か自動有効化されたハンドルです。
25282566
25292567=item closedir DIRHANDLE
25302568X<closedir>
25312569
25322570=for Pod::Functions close directory handle
25332571
25342572=begin original
25352573
25362574Closes a directory opened by L<C<opendir>|/opendir DIRHANDLE,EXPR> and
25372575returns the success of that system call.
25382576
25392577=end original
25402578
25412579L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリをクローズし、
25422580システムコールの返り値を返します。
25432581
25442582=item connect SOCKET,NAME
25452583X<connect>
25462584
25472585=for Pod::Functions connect to a remote socket
25482586
25492587=begin original
25502588
25512589Attempts to connect to a remote socket, just like L<connect(2)>.
25522590Returns true if it succeeded, false otherwise. NAME should be a
25532591packed address of the appropriate type for the socket. See the examples in
25542592L<perlipc/"Sockets: Client/Server Communication">.
25552593
25562594=end original
25572595
25582596L<connect(2)> システムコールと同様に、リモートソケットへの接続を試みます。
25592597成功時には真を、さもなければ偽を返します。
25602598NAME は、ソケットに対する、適切な型のパックされた
25612599アドレスでなければなりません。
25622600L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
25632601
25642602=item continue BLOCK
25652603X<continue>
25662604
25672605=item continue
25682606
25692607=for Pod::Functions optional trailing block in a while or foreach
25702608
25712609=begin original
25722610
25732611When followed by a BLOCK, L<C<continue>|/continue BLOCK> is actually a
25742612flow control statement rather than a function. If there is a
25752613L<C<continue>|/continue BLOCK> BLOCK attached to a BLOCK (typically in a
25762614C<while> or C<foreach>), it is always executed just before the
25772615conditional is about to be evaluated again, just like the third part of
25782616a C<for> loop in C. Thus it can be used to increment a loop variable,
25792617even when the loop has been continued via the L<C<next>|/next LABEL>
25802618statement (which is similar to the C L<C<continue>|/continue BLOCK>
25812619statement).
25822620
25832621=end original
25842622
25852623BLOCK が引き続く場合、L<C<continue>|/continue BLOCK> は実際には関数ではなく、
25862624実行制御文です。
25872625L<C<continue>|/continue BLOCK> BLOCK が BLOCK (典型的には C<while> または
25882626C<foreach> の中)にあると、これは条件文が再評価される直前に常に実行されます;
25892627これは C における C<for> ループの 3 番目の部分と同様です。
25902628従って、これは L<C<next>|/next LABEL> 文 (これは C の
25912629L<C<continue>|/continue BLOCK> 文と似ています) を使って
25922630ループが繰り返されるときでもループ変数を増やしたいときに使えます。
25932631
25942632=begin original
25952633
25962634L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, or
25972635L<C<redo>|/redo LABEL> may appear within a
25982636L<C<continue>|/continue BLOCK> block; L<C<last>|/last LABEL> and
25992637L<C<redo>|/redo LABEL> behave as if they had been executed within the
26002638main block. So will L<C<next>|/next LABEL>, but since it will execute a
26012639L<C<continue>|/continue BLOCK> block, it may be more entertaining.
26022640
26032641=end original
26042642
26052643L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
26062644L<C<continue>|/continue BLOCK> ブロック内に現れる可能性があります;
26072645L<C<last>|/last LABEL> と L<C<redo>|/redo LABEL> はメインブロックの中で
26082646実行されたのと同じように振舞います。
26092647L<C<next>|/next LABEL> の場合は、L<C<continue>|/continue BLOCK> ブロックを
26102648実行することになるので、より面白いことになります。
26112649
26122650 while (EXPR) {
26132651 ### redo always comes here
26142652 do_something;
26152653 } continue {
26162654 ### next always comes here
26172655 do_something_else;
26182656 # then back the top to re-check EXPR
26192657 }
26202658 ### last always comes here
26212659
26222660=begin original
26232661
26242662Omitting the L<C<continue>|/continue BLOCK> section is equivalent to
26252663using an empty one, logically enough, so L<C<next>|/next LABEL> goes
26262664directly back to check the condition at the top of the loop.
26272665
26282666=end original
26292667
26302668L<C<continue>|/continue BLOCK> 節を省略するのは、空の節を指定したのと同じで、
26312669論理的には十分なので、この場合、L<C<next>|/next LABEL> は直接ループ先頭の
26322670条件チェックに戻ります。
26332671
26342672=begin original
26352673
26362674When there is no BLOCK, L<C<continue>|/continue BLOCK> is a function
26372675that falls through the current C<when> or C<default> block instead of
26382676iterating a dynamically enclosing C<foreach> or exiting a lexically
26392677enclosing C<given>. In Perl 5.14 and earlier, this form of
26402678L<C<continue>|/continue BLOCK> was only available when the
26412679L<C<"switch"> feature|feature/The 'switch' feature> was enabled. See
26422680L<feature> and L<perlsyn/"Switch Statements"> for more information.
26432681
26442682=end original
26452683
26462684BLOCK がなければ、L<C<continue>|/continue BLOCK> は動的に囲まれた C<foreach> や
26472685レキシカルに囲まれた C<given> で反復するのではなく、現在の C<when> または
26482686C<default> のブロックを通り抜けるための文です。
26492687Perl 5.14 以前では、この形式の L<C<continue>|/continue BLOCK> は
26502688L<C<"switch"> 機能|feature/The 'switch' feature> が有効の場合にのみ
26512689利用可能です。
26522690さらなる情報については L<feature> と L<perlsyn/"Switch Statements"> を
26532691参照してください。
26542692
26552693=item cos EXPR
26562694X<cos> X<cosine> X<acos> X<arccosine>
26572695
26582696=item cos
26592697
26602698=for Pod::Functions cosine function
26612699
26622700=begin original
26632701
26642702Returns the cosine of EXPR (expressed in radians). If EXPR is omitted,
26652703takes the cosine of L<C<$_>|perlvar/$_>.
26662704
26672705=end original
26682706
26692707(ラジアンで示した) EXPR の余弦を返します。
26702708EXPR が省略されたときには、L<C<$_>|perlvar/$_> の余弦を取ります。
26712709
26722710=begin original
26732711
26742712For the inverse cosine operation, you may use the
26752713L<C<Math::Trig::acos>|Math::Trig> function, or use this relation:
26762714
26772715=end original
26782716
26792717逆余弦を求めるためには、L<C<Math::Trig::acos>|Math::Trig> 関数を使うか、
26802718以下の関係を使ってください。
26812719
26822720 sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
26832721
26842722=item crypt PLAINTEXT,SALT
26852723X<crypt> X<digest> X<hash> X<salt> X<plaintext> X<password>
26862724X<decrypt> X<cryptography> X<passwd> X<encrypt>
26872725
26882726=for Pod::Functions one-way passwd-style encryption
26892727
26902728=begin original
26912729
26922730Creates a digest string exactly like the L<crypt(3)> function in the C
26932731library (assuming that you actually have a version there that has not
26942732been extirpated as a potential munition).
26952733
26962734=end original
26972735
26982736C ライブラリの L<crypt(3)> 関数と全く同じように、ダイジェスト文字列を
26992737作成します(一時的な必需品として、まだ絶滅していないバージョンを
27002738持っていると仮定しています)。
27012739
27022740=begin original
27032741
27042742L<C<crypt>|/crypt PLAINTEXT,SALT> is a one-way hash function. The
27052743PLAINTEXT and SALT are turned
27062744into a short string, called a digest, which is returned. The same
27072745PLAINTEXT and SALT will always return the same string, but there is no
27082746(known) way to get the original PLAINTEXT from the hash. Small
27092747changes in the PLAINTEXT or SALT will result in large changes in the
27102748digest.
27112749
27122750=end original
27132751
27142752L<C<crypt>|/crypt PLAINTEXT,SALT> は一方向ハッシュ関数です。
27152753PLAINTEXT と SALT はダイジェストと呼ばれる短い文字列に変えられて、
27162754それが返されます。
27172755PLAINTEXT と SALT が同じ場合は常に同じ文字列を返しますが、ハッシュから
27182756元の PLAINTEXT を得る(既知の)方法はありません。
27192757PLAINTEXT や SALT を少し変更してもダイジェストは大きく変更されます。
27202758
27212759=begin original
27222760
27232761There is no decrypt function. This function isn't all that useful for
27242762cryptography (for that, look for F<Crypt> modules on your nearby CPAN
27252763mirror) and the name "crypt" is a bit of a misnomer. Instead it is
27262764primarily used to check if two pieces of text are the same without
27272765having to transmit or store the text itself. An example is checking
27282766if a correct password is given. The digest of the password is stored,
27292767not the password itself. The user types in a password that is
27302768L<C<crypt>|/crypt PLAINTEXT,SALT>'d with the same salt as the stored
27312769digest. If the two digests match, the password is correct.
27322770
27332771=end original
27342772
27352773復号化関数はありません。
27362774この関数は暗号化のためにはまったく役に立ちません(このためには、
27372775お近くの CPAN ミラーで F<Crypt> モジュールを探してください)ので、
27382776"crypt" という名前は少し間違った名前です。
27392777その代わりに、一般的には二つのテキスト片が同じかどうかをテキストそのものを
27402778転送したり保管したりせずにチェックするために使います。
27412779例としては、正しいパスワードが与えられたかどうかをチェックがあります。
27422780パスワード自身ではなく、パスワードのダイジェストが保管されます。
27432781ユーザーがパスワードを入力すると、保管されているダイジェストと同じ
27442782salt で L<C<crypt>|/crypt PLAINTEXT,SALT> します。
27452783二つのダイジェストが同じなら、パスワードは正しいです。
27462784
27472785=begin original
27482786
27492787When verifying an existing digest string you should use the digest as
27502788the salt (like C<crypt($plain, $digest) eq $digest>). The SALT used
27512789to create the digest is visible as part of the digest. This ensures
27522790L<C<crypt>|/crypt PLAINTEXT,SALT> will hash the new string with the same
27532791salt as the digest. This allows your code to work with the standard
27542792L<C<crypt>|/crypt PLAINTEXT,SALT> and with more exotic implementations.
27552793In other words, assume nothing about the returned string itself nor
27562794about how many bytes of SALT may matter.
27572795
27582796=end original
27592797
27602798すでにあるダイジェスト文字列を検証するには、ダイジェストを
27612799(C<crypt($plain, $digest) eq $digest> のようにして)salt として使います。
27622800ダイジェストを作るのに使われた SALT はダイジェストの一部として見えます。
27632801これにより、L<C<crypt>|/crypt PLAINTEXT,SALT> は同じ salt で新しい文字列を
27642802ダイジェストとしてハッシュ化できるようにします。
27652803これによって標準的な L<C<crypt>|/crypt PLAINTEXT,SALT> や、より風変わりな
27662804実装でも動作します。
27672805言い換えると、返される文字列や、SALT が何バイトあるかといったことに対して、
27682806どのような仮定もしてはいけません。
27692807
27702808=begin original
27712809
27722810Traditionally the result is a string of 13 bytes: two first bytes of
27732811the salt, followed by 11 bytes from the set C<[./0-9A-Za-z]>, and only
27742812the first eight bytes of PLAINTEXT mattered. But alternative
27752813hashing schemes (like MD5), higher level security schemes (like C2),
27762814and implementations on non-Unix platforms may produce different
27772815strings.
27782816
27792817=end original
27802818
27812819伝統的には結果は 13 バイトの文字列です: 最初の 2 バイトは salt、引き続いて
27822820集合 C<[./0-9A-Za-z]> からの 11 バイトで、PLAINTEXT の最初の
278328218 バイトだけが意味があります。
27842822しかし、(MD5 のように) 異なったハッシュ手法、
27852823(C2 のような) 高レベルセキュリティ手法、非 Unix プラットフォームでの
27862824実装などでは異なった文字列が生成されることがあります。
27872825
27882826=begin original
27892827
27902828When choosing a new salt create a random two character string whose
27912829characters come from the set C<[./0-9A-Za-z]> (like C<join '', ('.',
27922830'/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]>). This set of
27932831characters is just a recommendation; the characters allowed in
27942832the salt depend solely on your system's crypt library, and Perl can't
27952833restrict what salts L<C<crypt>|/crypt PLAINTEXT,SALT> accepts.
27962834
27972835=end original
27982836
27992837新しい salt を選択する場合は、集合 C<[./0-9A-Za-z]> から
28002838(C<join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]> の
28012839ようにして)ランダムに2 つの文字を選びます。
28022840この文字集合は単なる推薦です; salt として許される文字はシステムの暗号化
28032841ライブラリだけに依存し、Perl は L<C<crypt>|/crypt PLAINTEXT,SALT> が
28042842どのような salt を受け付けるかについて制限しません。
28052843
28062844=begin original
28072845
28082846Here's an example that makes sure that whoever runs this program knows
28092847their password:
28102848
28112849=end original
28122850
28132851プログラムを実行する人が、
28142852自分のパスワードを知っていることを確認する例です:
28152853
28162854 my $pwd = (getpwuid($<))[1];
28172855
28182856 system "stty -echo";
28192857 print "Password: ";
28202858 chomp(my $word = <STDIN>);
28212859 print "\n";
28222860 system "stty echo";
28232861
28242862 if (crypt($word, $pwd) ne $pwd) {
28252863 die "Sorry...\n";
28262864 } else {
28272865 print "ok\n";
28282866 }
28292867
28302868=begin original
28312869
28322870Of course, typing in your own password to whoever asks you
28332871for it is unwise.
28342872
28352873=end original
28362874
28372875もちろん、自分自身のパスワードを誰にでも入力するのは賢明ではありません。
28382876
28392877=begin original
28402878
28412879The L<C<crypt>|/crypt PLAINTEXT,SALT> function is unsuitable for hashing
28422880large quantities of data, not least of all because you can't get the
28432881information back. Look at the L<Digest> module for more robust
28442882algorithms.
28452883
28462884=end original
28472885
28482886L<C<crypt>|/crypt PLAINTEXT,SALT> 関数は大量のデータのハッシュ化には
28492887向いていません; これは情報を戻せないという理由だけではありません。
28502888より頑強なアルゴリズムについては L<Digest> モジュールを参照してください。
28512889
28522890=begin original
28532891
28542892If using L<C<crypt>|/crypt PLAINTEXT,SALT> on a Unicode string (which
28552893I<potentially> has characters with codepoints above 255), Perl tries to
28562894make sense of the situation by trying to downgrade (a copy of) the
28572895string back to an eight-bit byte string before calling
28582896L<C<crypt>|/crypt PLAINTEXT,SALT> (on that copy). If that works, good.
28592897If not, L<C<crypt>|/crypt PLAINTEXT,SALT> dies with
28602898L<C<Wide character in crypt>|perldiag/Wide character in %s>.
28612899
28622900=end original
28632901
28642902Unicode 文字列(I<潜在的には> 255 を越えるコードポイントを持つ文字を
28652903含みます)に L<C<crypt>|/crypt PLAINTEXT,SALT> を使った場合、Perl は
28662904L<C<crypt>|/crypt PLAINTEXT,SALT> を呼び出す前に与えられた
28672905文字列を8 ビットバイト文字列にダウングレードする(文字列のコピーを作る)
28682906ことで状況のつじつまを合わせようとします。
28692907うまく動けば、それでよし。
28702908動かなければ、L<C<crypt>|/crypt PLAINTEXT,SALT> は
28712909L<C<Wide character in crypt>|perldiag/Wide character in %s> という
28722910メッセージと共に die します。
28732911
28742912=begin original
28752913
28762914Portability issues: L<perlport/crypt>.
28772915
28782916=end original
28792917
28802918移植性の問題: L<perlport/crypt>。
28812919
28822920=item dbmclose HASH
28832921X<dbmclose>
28842922
28852923=for Pod::Functions breaks binding on a tied dbm file
28862924
28872925=begin original
28882926
28892927[This function has been largely superseded by the
28902928L<C<untie>|/untie VARIABLE> function.]
28912929
28922930=end original
28932931
28942932[この関数は、L<C<untie>|/untie VARIABLE> 関数に大きくとって代わられました。]
28952933
28962934=begin original
28972935
28982936Breaks the binding between a DBM file and a hash.
28992937
29002938=end original
29012939
29022940DBM ファイルとハッシュの連結をはずします。
29032941
29042942=begin original
29052943
29062944Portability issues: L<perlport/dbmclose>.
29072945
29082946=end original
29092947
29102948移植性の問題: L<perlport/dbmclose>。
29112949
29122950=item dbmopen HASH,DBNAME,MASK
29132951X<dbmopen> X<dbm> X<ndbm> X<sdbm> X<gdbm>
29142952
29152953=for Pod::Functions create binding on a tied dbm file
29162954
29172955=begin original
29182956
29192957[This function has been largely superseded by the
29202958L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function.]
29212959
29222960=end original
29232961
29242962[この関数は、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数に
29252963大きくとって代わられました。]
29262964
29272965=begin original
29282966
29292967This binds a L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)>, or Berkeley
29302968DB file to a hash. HASH is the name of the hash. (Unlike normal
2931L<C<open>|/open FILEHANDLE,EXPR>, the first argument is I<not> a
2969L<C<open>|/open FILEHANDLE,MODE,EXPR>, the first argument is I<not> a
29322970filehandle, even though it looks like one). DBNAME is the name of the
29332971database (without the F<.dir> or F<.pag> extension if any). If the
29342972database does not exist, it is created with protection specified by MASK
29352973(as modified by the L<C<umask>|/umask EXPR>). To prevent creation of
29362974the database if it doesn't exist, you may specify a MODE of 0, and the
29372975function will return a false value if it can't find an existing
29382976database. If your system supports only the older DBM functions, you may
29392977make only one L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> call in your
29402978program. In older versions of Perl, if your system had neither DBM nor
29412979ndbm, calling L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> produced a fatal
29422980error; it now falls back to L<sdbm(3)>.
29432981
29442982=end original
29452983
29462984L<dbm(3)>, L<ndbm(3)>, L<sdbm(3)>, L<gdbm(3)> ファイルまたは
29472985Berkeley DB ファイルを連想配列に結び付けます。
29482986HASH は、その連想配列の名前です。
2949(普通の L<C<open>|/open FILEHANDLE,EXPR> とは違って、最初の引数は
2987(普通の L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違って、最初の引数は
29502988ファイルハンドル I<ではありません>; まあ、似たようなものですが)。
29512989DBNAME は、データベースの名前です (拡張子の .dir や .pag はもしあっても
29522990つけません)。
29532991データベースが存在しなければ、MODE MASK (を L<C<umask>|/umask EXPR> で
29542992修正したもの) で指定されたモードで作られます。
29552993存在しないときにデータベースを作成しないようにするには、MODE に 0 を
29562994設定でき、データベースを見つけられなかった場合は関数は偽を返します。
29572995古い DBM 関数のみをサポートしているシステムでは、プログラム中で 1 度だけ
29582996L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を実行することができます。
29592997昔のバージョンの Perl では、DBM も ndbm も持っていないシステムでは、
29602998L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出すと致命的エラーになります;
29612999現在では L<sdbm(3)> にフォールバックします。
29623000
29633001=begin original
29643002
29653003If you don't have write access to the DBM file, you can only read hash
29663004variables, not set them. If you want to test whether you can write,
29673005either use file tests or try setting a dummy hash entry inside an
29683006L<C<eval>|/eval EXPR> to trap the error.
29693007
29703008=end original
29713009
29723010DBM ファイルに対して、書き込み権が無いときには、ハッシュ
29733011配列を読みだすことだけができ、設定することはできません。
29743012書けるか否かを調べたい場合には、ファイルテスト
29753013演算子を使うか、エラーをトラップするための L<C<eval>|/eval EXPR> の中で、
29763014ダミーのハッシュエントリを設定してみることになります。
29773015
29783016=begin original
29793017
29803018Note that functions such as L<C<keys>|/keys HASH> and
29813019L<C<values>|/values HASH> may return huge lists when used on large DBM
29823020files. You may prefer to use the L<C<each>|/each HASH> function to
29833021iterate over large DBM files. Example:
29843022
29853023=end original
29863024
29873025大きな DBM ファイルを扱うときには、L<C<keys>|/keys HASH> や
29883026L<C<values>|/values HASH> のような関数は、巨大なリストを返します。
29893027大きな DBM ファイルでは、L<C<each>|/each HASH> 関数を使って繰り返しを
29903028行なった方が良いかもしれません。
29913029例:
29923030
29933031 # print out history file offsets
29943032 dbmopen(%HIST,'/usr/lib/news/history',0666);
29953033 while (($key,$val) = each %HIST) {
29963034 print $key, ' = ', unpack('L',$val), "\n";
29973035 }
29983036 dbmclose(%HIST);
29993037
30003038=begin original
30013039
30023040See also L<AnyDBM_File> for a more general description of the pros and
30033041cons of the various dbm approaches, as well as L<DB_File> for a particularly
30043042rich implementation.
30053043
30063044=end original
30073045
30083046様々な dbm 手法に対する利点欠点に関するより一般的な記述および
30093047特にリッチな実装である L<DB_File> に関しては
30103048L<AnyDBM_File> も参照してください。
30113049
30123050=begin original
30133051
30143052You can control which DBM library you use by loading that library
30153053before you call L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>:
30163054
30173055=end original
30183056
30193057L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> を呼び出す前にライブラリを
30203058読み込むことで、どの DBM ライブラリを使うかを制御できます:
30213059
30223060 use DB_File;
30233061 dbmopen(%NS_Hist, "$ENV{HOME}/.netscape/history.db")
30243062 or die "Can't open netscape history file: $!";
30253063
30263064=begin original
30273065
30283066Portability issues: L<perlport/dbmopen>.
30293067
30303068=end original
30313069
30323070移植性の問題: L<perlport/dbmopen>。
30333071
30343072=item defined EXPR
30353073X<defined> X<undef> X<undefined>
30363074
30373075=item defined
30383076
30393077=for Pod::Functions test whether a value, variable, or function is defined
30403078
30413079=begin original
30423080
30433081Returns a Boolean value telling whether EXPR has a value other than the
30443082undefined value L<C<undef>|/undef EXPR>. If EXPR is not present,
30453083L<C<$_>|perlvar/$_> is checked.
30463084
30473085=end original
30483086
30493087左辺値 EXPR が未定義値 L<C<undef>|/undef EXPR> 以外の値を持つか否かを示す、
30503088ブール値を返します。
30513089EXPR がない場合は、L<C<$_>|perlvar/$_> がチェックされます。
30523090
30533091=begin original
30543092
30553093Many operations return L<C<undef>|/undef EXPR> to indicate failure, end
30563094of file, system error, uninitialized variable, and other exceptional
30573095conditions. This function allows you to distinguish
30583096L<C<undef>|/undef EXPR> from other values. (A simple Boolean test will
30593097not distinguish among L<C<undef>|/undef EXPR>, zero, the empty string,
30603098and C<"0">, which are all equally false.) Note that since
30613099L<C<undef>|/undef EXPR> is a valid scalar, its presence doesn't
30623100I<necessarily> indicate an exceptional condition: L<C<pop>|/pop ARRAY>
30633101returns L<C<undef>|/undef EXPR> when its argument is an empty array,
30643102I<or> when the element to return happens to be L<C<undef>|/undef EXPR>.
30653103
30663104=end original
30673105
30683106多くの演算子が、EOF や未初期化変数、システムエラーといった、
30693107例外的な条件で L<C<undef>|/undef EXPR> を返すようになっています。
30703108この関数は、他の値と L<C<undef>|/undef EXPR> とを区別するために使えます。
30713109(単純な真偽値テストでは、L<C<undef>|/undef EXPR>、0、C<"0"> のいずれも偽を
30723110返すので、区別することができません。)
30733111L<C<undef>|/undef EXPR> は有効なスカラ値なので、その存在が I<必ずしも>
30743112例外的な状況を表すとは限らないということに注意してください:
30753113L<C<pop>|/pop ARRAY> は引数が空の配列だったときに L<C<undef>|/undef EXPR> を
30763114返しますが、I<あるいは> 返すべき要素がたまたま
30773115L<C<undef>|/undef EXPR> だったのかもしれません。
30783116
30793117=begin original
30803118
30813119You may also use C<defined(&func)> to check whether subroutine C<func>
30823120has ever been defined. The return value is unaffected by any forward
30833121declarations of C<func>. A subroutine that is not defined
30843122may still be callable: its package may have an C<AUTOLOAD> method that
30853123makes it spring into existence the first time that it is called; see
30863124L<perlsub>.
30873125
30883126=end original
30893127
30903128C<defined(&func)> とすることでサブルーチン C<func> の存在を、
30913129確かめることもできます。
30923130返り値は C<func> の前方定義には影響されません。
30933131定義されていないサブルーチンも呼び出し可能です:
30943132最初に呼び出されたときに存在するようにするための
30953133C<AUTOLOAD> メソッドを持ったパッケージかもしれません;
30963134L<perlsub> を参照してください。
30973135
30983136=begin original
30993137
31003138Use of L<C<defined>|/defined EXPR> on aggregates (hashes and arrays) is
31013139no longer supported. It used to report whether memory for that
31023140aggregate had ever been allocated. You should instead use a simple
31033141test for size:
31043142
31053143=end original
31063144
31073145集合(ハッシュや配列)への L<C<defined>|/defined EXPR> の使用は
31083146もはや対応していません。
31093147これはその集合にメモリが割り当てられたかを報告するのに用いられていました。
31103148代わりにサイズに対する簡単なテストを使うべきです。
31113149
31123150 if (@an_array) { print "has array elements\n" }
31133151 if (%a_hash) { print "has hash members\n" }
31143152
31153153=begin original
31163154
31173155When used on a hash element, it tells you whether the value is defined,
31183156not whether the key exists in the hash. Use L<C<exists>|/exists EXPR>
31193157for the latter purpose.
31203158
31213159=end original
31223160
31233161ハッシュの要素に対して用いると、value が定義されているか否かを
31243162返すものであって、ハッシュに key が存在するか否かを返すのではありません。
31253163この用途には、L<C<exists>|/exists EXPR> を使ってください。
31263164
31273165=begin original
31283166
31293167Examples:
31303168
31313169=end original
31323170
31333171例:
31343172
31353173 print if defined $switch{D};
31363174 print "$val\n" while defined($val = pop(@ary));
31373175 die "Can't readlink $sym: $!"
31383176 unless defined($value = readlink $sym);
31393177 sub foo { defined &$bar ? $bar->(@_) : die "No bar"; }
31403178 $debugging = 0 unless defined $debugging;
31413179
31423180=begin original
31433181
31443182Note: Many folks tend to overuse L<C<defined>|/defined EXPR> and are
31453183then surprised to discover that the number C<0> and C<""> (the
31463184zero-length string) are, in fact, defined values. For example, if you
31473185say
31483186
31493187=end original
31503188
31513189注意: 多くの人々が L<C<defined>|/defined EXPR> を使いすぎて、C<0> と
31523190C<"">(空文字列) が実際のところ定義された値であることに驚くようです。
31533191例えば、以下のように書くと:
31543192
31553193 "ab" =~ /a(.*)b/;
31563194
31573195=begin original
31583196
31593197The pattern match succeeds and C<$1> is defined, although it
31603198matched "nothing". It didn't really fail to match anything. Rather, it
31613199matched something that happened to be zero characters long. This is all
31623200very above-board and honest. When a function returns an undefined value,
31633201it's an admission that it couldn't give you an honest answer. So you
31643202should use L<C<defined>|/defined EXPR> only when questioning the
31653203integrity of what you're trying to do. At other times, a simple
31663204comparison to C<0> or C<""> is what you want.
31673205
31683206=end original
31693207
31703208パターンマッチングが成功し、C<$1> が定義されても、実際には
31713209「なし」にマッチしています。
31723210しかしこれは何にもマッチしていないわけではありません。
31733211何かにはマッチしているのですが、たまたまそれが長さ 0 だっただけです。
31743212これは非常に率直で正直なことです。
31753213関数が未定義値を返すとき、正直な答えを返すことができないことを
31763214告白しています。
31773215ですので、あなたが自分がしようとしていることの完全性を確認するときにだけ
31783216L<C<defined>|/defined EXPR> を使うべきです。
31793217その他の場合では、単に C<0> または C<""> と比較するというのがあなたの
31803218求めているものです。
31813219
31823220=begin original
31833221
31843222See also L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>,
31853223L<C<ref>|/ref EXPR>.
31863224
31873225=end original
31883226
31893227L<C<undef>|/undef EXPR>, L<C<exists>|/exists EXPR>, L<C<ref>|/ref EXPR> も
31903228参照してください。
31913229
31923230=item delete EXPR
31933231X<delete>
31943232
31953233=for Pod::Functions deletes a value from a hash
31963234
31973235=begin original
31983236
31993237Given an expression that specifies an element or slice of a hash,
32003238L<C<delete>|/delete EXPR> deletes the specified elements from that hash
32013239so that L<C<exists>|/exists EXPR> on that element no longer returns
32023240true. Setting a hash element to the undefined value does not remove its
32033241key, but deleting it does; see L<C<exists>|/exists EXPR>.
32043242
32053243=end original
32063244
32073245ハッシュの要素やスライスを指定する式を取り、L<C<delete>|/delete EXPR> は
32083246指定された要素をハッシュから削除するので、
32093247その要素に対する L<C<exists>|/exists EXPR> はもはや真を返さなくなります。
32103248ハッシュ要素に未定義値をセットしてもそのキーは削除されませんが、
32113249delete では削除されます; L<C<exists>|/exists EXPR> を参照してください。
32123250
32133251=begin original
32143252
3215In list context, returns the value or values deleted, or the last such
3253In list context, usually returns the value or values deleted, or the last such
3216element in scalar context. The return list's length always matches that of
3254element in scalar context. The return list's length corresponds to that of
32173255the argument list: deleting non-existent elements returns the undefined value
3218in their corresponding positions.
3256in their corresponding positions. When a
3257L<keyE<sol>value hash slice|perldata/KeyE<sol>Value Hash Slices> is passed to
3258C<delete>, the return value is a list of key/value pairs (two elements for each
3259item deleted from the hash).
32193260
32203261=end original
32213262
3222リストコンテキストでは削除された要素を返し、スカラコンテキストでは
3263リストコンテキストでは通常は削除された要素を返し、スカラコンテキストでは
32233264削除された要素のうち最後のものを返します。
3224返されたリストの長さは常に引数リストの長さと一致します:
3265返されたリストの長さは常に引数リストの長さに対応します:
32253266存在しない要素を削除すると、対応する位置に未定義値をセットして返します。
3267L<キーE<sol>値ハッシュスライス|perldata/KeyE<sol>Value Hash Slices> が
3268C<delete> に渡されると、返り値はキー/値の組(それぞれのアイテムについて
3269二つの要素が元のハッシュから削除されたもの)です。
32263270
32273271=begin original
32283272
32293273L<C<delete>|/delete EXPR> may also be used on arrays and array slices,
32303274but its behavior is less straightforward. Although
32313275L<C<exists>|/exists EXPR> will return false for deleted entries,
32323276deleting array elements never changes indices of existing values; use
32333277L<C<shift>|/shift ARRAY> or L<C<splice>|/splice
32343278ARRAY,OFFSET,LENGTH,LIST> for that. However, if any deleted elements
32353279fall at the end of an array, the array's size shrinks to the position of
32363280the highest element that still tests true for L<C<exists>|/exists EXPR>,
32373281or to 0 if none do. In other words, an array won't have trailing
32383282nonexistent elements after a delete.
32393283
32403284=end original
32413285
32423286L<C<delete>|/delete EXPR> は配列や配列のスライスに対しても使えますが、その
32433287振る舞いはあまり直感的ではありません。
32443288削除されたエントリに対しては L<C<exists>|/exists EXPR> は偽を返しますが、
32453289配列要素を削除しても、存在する値の添え字は変わりません; このためには
32463290L<C<shift>|/shift ARRAY> や L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> を
32473291使ってください。
32483292しかし、削除された要素が配列の末尾であった場合、配列のサイズは
32493293L<C<exists>|/exists EXPR> が真となる最大位置の要素(それがない場合は 0)に
32503294切り詰められます。
32513295言い換えると、delete の後には配列の末尾に値のない要素はありません。
32523296
32533297=begin original
32543298
32553299B<WARNING:> Calling L<C<delete>|/delete EXPR> on array values is
32563300strongly discouraged. The
32573301notion of deleting or checking the existence of Perl array elements is not
32583302conceptually coherent, and can lead to surprising behavior.
32593303
32603304=end original
32613305
32623306B<警告:> 配列の値に対して L<C<delete>|/delete EXPR> を呼び出すことは強く
32633307非推奨です。
32643308Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
32653309驚くべき振る舞いを引き起こすことがあります。
32663310
32673311=begin original
32683312
32693313Deleting from L<C<%ENV>|perlvar/%ENV> modifies the environment.
32703314Deleting from a hash tied to a DBM file deletes the entry from the DBM
32713315file. Deleting from a L<C<tied>|/tied VARIABLE> hash or array may not
32723316necessarily return anything; it depends on the implementation of the
32733317L<C<tied>|/tied VARIABLE> package's DELETE method, which may do whatever
32743318it pleases.
32753319
32763320=end original
32773321
32783322L<C<%ENV>|perlvar/%ENV> から削除を行なうと、実際に環境変数を変更します。
32793323DBM ファイルに tie された配列からの削除は、その DBM ファイルからエントリを
32803324削除します。
32813325しかし、L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたハッシュや配列からの
32823326削除は、値を返すとは限りません; これは
32833327L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> されたパッケージの DELETE
32843328メソッドの実装に依存するので、どんなことでも起こります。
32853329
32863330=begin original
32873331
32883332The C<delete local EXPR> construct localizes the deletion to the current
32893333block at run time. Until the block exits, elements locally deleted
32903334temporarily no longer exist. See L<perlsub/"Localized deletion of elements
32913335of composite types">.
32923336
32933337=end original
32943338
32953339C<delete local EXPR> 構文は、現在のブロックの削除を実行時にローカル化します。
32963340ブロックから出るまで、ローカルで削除された要素は存在しなくなります。
32973341L<perlsub/"Localized deletion of elements of composite types"> を
32983342参照してください。
32993343
33003344 my %hash = (foo => 11, bar => 22, baz => 33);
33013345 my $scalar = delete $hash{foo}; # $scalar is 11
33023346 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
33033347 my @array = delete @hash{qw(foo baz)}; # @array is (undef,33)
33043348
33053349=begin original
33063350
33073351The following (inefficiently) deletes all the values of %HASH and @ARRAY:
33083352
33093353=end original
33103354
33113355以下は、%HASH と @ARRAY のすべての値を(非効率的に)削除します:
33123356
33133357 foreach my $key (keys %HASH) {
33143358 delete $HASH{$key};
33153359 }
33163360
33173361 foreach my $index (0 .. $#ARRAY) {
33183362 delete $ARRAY[$index];
33193363 }
33203364
33213365=begin original
33223366
33233367And so do these:
33243368
33253369=end original
33263370
33273371そして以下のようにもできます:
33283372
33293373 delete @HASH{keys %HASH};
33303374
33313375 delete @ARRAY[0 .. $#ARRAY];
33323376
33333377=begin original
33343378
33353379But both are slower than assigning the empty list
33363380or undefining %HASH or @ARRAY, which is the customary
33373381way to empty out an aggregate:
33383382
33393383=end original
33403384
33413385しかし、これら二つは両方とも、構造を空にするための慣習的な方法である、
33423386単に空リストを代入するか、%HASH や @ARRAY を
33433387undef するより遅いです:
33443388
33453389 %HASH = (); # completely empty %HASH
33463390 undef %HASH; # forget %HASH ever existed
33473391
33483392 @ARRAY = (); # completely empty @ARRAY
33493393 undef @ARRAY; # forget @ARRAY ever existed
33503394
33513395=begin original
33523396
33533397The EXPR can be arbitrarily complicated provided its
33543398final operation is an element or slice of an aggregate:
33553399
33563400=end original
33573401
33583402最終的な操作が集合の要素かスライスである限りは、
33593403いずれかである限りは、EXPR には任意の複雑な式を置くことができます:
33603404
33613405 delete $ref->[$x][$y]{$key};
33623406 delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};
33633407
33643408 delete $ref->[$x][$y][$index];
33653409 delete @{$ref->[$x][$y]}[$index1, $index2, @moreindices];
33663410
33673411=item die LIST
33683412X<die> X<throw> X<exception> X<raise> X<$@> X<abort>
33693413
33703414=for Pod::Functions raise an exception or bail out
33713415
33723416=begin original
33733417
3374L<C<die>|/die LIST> raises an exception. Inside an
3418L<C<die>|/die LIST> raises an exception. Inside an L<C<eval>|/eval EXPR>
3375L<C<eval>|/eval EXPR> the error message is stuffed into
3419the exception is stuffed into L<C<$@>|perlvar/$@> and the L<C<eval>|/eval
3376L<C<$@>|perlvar/$@> and the L<C<eval>|/eval EXPR> is terminated with the
3420EXPR> is terminated with the undefined value. If the exception is
3377undefined value. If the exception is outside of all enclosing
3421outside of all enclosing L<C<eval>|/eval EXPR>s, then the uncaught
3378L<C<eval>|/eval EXPR>s, then the uncaught exception prints LIST to
3422exception is printed to C<STDERR> and perl exits with an exit code
3379C<STDERR> and exits with a non-zero value. If you need to exit the
3423indicating failure. If you need to exit the process with a specific
3380process with a specific exit code, see L<C<exit>|/exit EXPR>.
3424exit code, see L<C<exit>|/exit EXPR>.
33813425
33823426=end original
33833427
33843428L<C<die>|/die LIST> は例外を発生させます。
3385L<C<eval>|/eval EXPR> の中で使用すると、エラーメッセージ
3429L<C<eval>|/eval EXPR> の中で使用すると、例外
33863430L<C<$@>|perlvar/$@> に入り、L<C<eval>|/eval EXPR> は
33873431未定義値を返して終了します。
33883432例外が全ての L<C<eval>|/eval EXPR> の外側の場合は、捕捉されなかった例外は
3389LIST を C<STDERR> に表示して 0 の値で終了します。
3433C<STDERR> に表示されperl は失敗を示す終了コードで終了します。
33903434特定の終了コードでプロセスを終了させる必要がある場合は、
33913435L<C<exit>|/exit EXPR> を参照してください。
33923436
33933437=begin original
33943438
33953439Equivalent examples:
33963440
33973441=end original
33983442
33993443等価な例:
34003444
34013445 die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
34023446 chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
34033447
34043448=begin original
34053449
3406If the last element of LIST does not end in a newline, the current
3450Most of the time, C<die> is called with a string to use as the exception.
3407script line number and input line number (if any) are also printed,
3451You may either give a single non-reference operand to serve as the
3408and a newline is supplied. Note that the "input line number" (also
3452exception, or a list of two or more items, which will be stringified
3453and concatenated to make the exception.
3454
3455=end original
3456
3457ほとんどの場合、C<die> は例外として使うための文字列と共に呼び出されます。
3458例外として圧から割れる単一の非リファレンスオペランドか、
3459例外を作るために文字列化されて連結される、二つ以上のアイテムのリストを
3460指定することができます。
3461
3462=begin original
3463
3464If the string exception does not end in a newline, the current
3465script line number and input line number (if any) and a newline
3466are appended to it. Note that the "input line number" (also
34093467known as "chunk") is subject to whatever notion of "line" happens to
34103468be currently in effect, and is also available as the special variable
34113469L<C<$.>|perlvar/$.>. See L<perlvar/"$/"> and L<perlvar/"$.">.
34123470
34133471=end original
34143472
3415LIST の最後の要素が改行で終わっていなければ、その時点のスクリプト名と
3473文字列例外が改行で終わっていなければ、その時点のスクリプト名と
3416スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が、続けて
3474スクリプトの行番号、(もしあれば) 入力ファイルの行番号と改行文字が
3417表示されます。
3475それに追加されます。
34183476「入力行番号」("chunk" とも呼ばれます)は「行」という概念が現在有効であると
34193477仮定しています; また特殊変数 L<C<$.>|perlvar/$.> でも利用可能です。
34203478L<perlvar/"$/"> と L<perlvar/"$."> も参照してください。
34213479
34223480=begin original
34233481
34243482Hint: sometimes appending C<", stopped"> to your message will cause it
34253483to make better sense when the string C<"at foo line 123"> is appended.
34263484Suppose you are running script "canasta".
34273485
34283486=end original
34293487
34303488ヒント: メッセージの最後を C<", stopped"> のようなもので
34313489終わるようにしておけば、C<"at foo line 123"> のように
34323490追加されて、わかりやすくなります。
34333491"canasta" というスクリプトを実行しているとします。
34343492
34353493 die "/etc/games is no good";
34363494 die "/etc/games is no good, stopped";
34373495
34383496=begin original
34393497
34403498produce, respectively
34413499
34423500=end original
34433501
34443502これは、それぞれ以下のように表示します。
34453503
34463504 /etc/games is no good at canasta line 123.
34473505 /etc/games is no good, stopped at canasta line 123.
34483506
34493507=begin original
34503508
3451If the output is empty and L<C<$@>|perlvar/$@> already contains a value
3509If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@>
3452(typically from a previous L<C<eval>|/eval EXPR>) that value is reused after
3510already contains an exception value (typically from a previous
3511L<C<eval>|/eval EXPR>), then that value is reused after
34533512appending C<"\t...propagated">. This is useful for propagating exceptions:
34543513
34553514=end original
34563515
3457出力が空L<C<$@>|perlvar/$@> が(典型的には前回の L<C<eval>|/eval EXPR> で)
3516出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が
3458値を持っている場合、値は C<"\t...propagated"> を追加した後再利用されます。
3517(典型的には前回の L<C<eval>|/eval EXPR> で)
3518既に例外値を持っている場合、
3519値は C<"\t...propagated"> を追加した後再利用されます。
34593520これは例外を伝播させる場合に有効です:
34603521
34613522 eval { ... };
34623523 die unless $@ =~ /Expected exception/;
34633524
34643525=begin original
34653526
3466If the output is empty and L<C<$@>|perlvar/$@> contains an object
3527If LIST was empty or made an empty string,
3528and L<C<$@>|perlvar/$@> contains an object
34673529reference that has a C<PROPAGATE> method, that method will be called
34683530with additional file and line number parameters. The return value
34693531replaces the value in L<C<$@>|perlvar/$@>; i.e., as if
34703532C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> were called.
34713533
34723534=end original
34733535
3474出力が空、L<C<$@>|perlvar/$@> が C<PROPAGATE> メソッドを含むオブジェクトへの
3536出力が空か空文字列を作り、L<C<$@>|perlvar/$@> が C<PROPAGATE> メソッドを
3475リファレンスを含む場合、このメソッドが追加ファイルと行番号を引数として
3537含むオブジェクトへのリファレンスを含む場合、
3476呼び出されます。
3538このメソッドが追加ファイルと行番号を引数として呼び出されます。
34773539返り値は L<C<$@>|perlvar/$@> の値を置き換えます;
34783540つまり、C<< $@ = eval { $@->PROPAGATE(__FILE__, __LINE__) }; >> が
34793541呼び出されたかのようになります。
34803542
34813543=begin original
34823544
3483If L<C<$@>|perlvar/$@> is empty, then the string C<"Died"> is used.
3545If LIST was empty or made an empty string, and L<C<$@>|perlvar/$@>
3546is also empty, then the string C<"Died"> is used.
34843547
34853548=end original
34863549
3487L<C<$@>|perlvar/$@> 空の場合、C<"Died"> が使われます。
3550LIST が空か空文字列を作り、L<C<$@>|perlvar/$@> 空の場合、
3551C<"Died"> が使われます。
34883552
34893553=begin original
34903554
3555You can also call L<C<die>|/die LIST> with a reference argument, and if
3556this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@>
3557contains that reference. This permits more elaborate exception handling
3558using objects that maintain arbitrary state about the exception. Such a
3559scheme is sometimes preferable to matching particular string values of
3560L<C<$@>|perlvar/$@> with regular expressions.
3561
3562=end original
3563
3564L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これが
3565L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は
3566そのリファレンスを持ちます。
3567これは、例外の性質について任意の状態を管理するオブジェクトを使った
3568より複雑な例外処理の実装を可能にします。
3569このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って
3570マッチングするときに時々好まれます。
3571
3572=begin original
3573
3574Because Perl stringifies uncaught exception messages before display,
3575you'll probably want to overload stringification operations on
3576exception objects. See L<overload> for details about that.
3577The stringified message should be non-empty, and should end in a newline,
3578in order to fit in with the treatment of string exceptions.
3579Also, because an exception object reference cannot be stringified
3580without destroying it, Perl doesn't attempt to append location or other
3581information to a reference exception. If you want location information
3582with a complex exception object, you'll have to arrange to put the
3583location information into the object yourself.
3584
3585=end original
3586
3587perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、
3588このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと
3589思うかもしれません。
3590これに関する詳細は L<overload> を参照してください。
3591文字列化されたメッセージは、文字列例外の扱いに合わせるために、
3592空ではなく、末尾は改行であるべきです。
3593また、例外オブジェクトリファレンスはそれを破壊することなく
3594文字列化することができないので、Perl はリファレンス例外に位置や
3595その他の情報を追加しようとしません。
3596複雑な例外オブジェクトに位置情報が欲しい場合、
3597オブジェクト自身に位置情報を設定するように用意する必要があります。
3598
3599=begin original
3600
3601Because L<C<$@>|perlvar/$@> is a global variable, be careful that
3602analyzing an exception caught by C<eval> doesn't replace the reference
3603in the global variable. It's
3604easiest to make a local copy of the reference before any manipulations.
3605Here's an example:
3606
3607=end original
3608
3609L<C<$@>|perlvar/$@> はグローバル変数なので、
3610C<eval> により補足された例外の解析はグローバル変数の
3611リファレンスを置き換えないことに注意を払わなければなりません。
3612他の操作をする前にリファレンスのローカルコピーを
3613作るのが一番簡単です。
3614以下に例を示します:
3615
3616 use Scalar::Util "blessed";
3617
3618 eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) };
3619 if (my $ev_err = $@) {
3620 if (blessed($ev_err)
3621 && $ev_err->isa("Some::Module::Exception")) {
3622 # handle Some::Module::Exception
3623 }
3624 else {
3625 # handle all other possible exceptions
3626 }
3627 }
3628
3629=begin original
3630
34913631If an uncaught exception results in interpreter exit, the exit code is
34923632determined from the values of L<C<$!>|perlvar/$!> and
34933633L<C<$?>|perlvar/$?> with this pseudocode:
34943634
34953635=end original
34963636
34973637例外が捕捉されないとインタプリタは終了し、終了コードは以下の
34983638擬似コードのように、L<C<$!>|perlvar/$!> と L<C<$?>|perlvar/$?> の値から
34993639決定されます:
35003640
35013641 exit $! if $!; # errno
35023642 exit $? >> 8 if $? >> 8; # child exit status
35033643 exit 255; # last resort
35043644
35053645=begin original
35063646
35073647As with L<C<exit>|/exit EXPR>, L<C<$?>|perlvar/$?> is set prior to
35083648unwinding the call stack; any C<DESTROY> or C<END> handlers can then
35093649alter this value, and thus Perl's exit code.
35103650
35113651=end original
35123652
35133653L<C<exit>|/exit EXPR> と同様に、コールスタックを巻き戻す前に
35143654L<C<$?>|perlvar/$?> が設定されます; C<DESTROY> と C<END> のハンドラが
35153655それからこの値を変更して、これが Perl の終了コードになります。
35163656
35173657=begin original
35183658
35193659The intent is to squeeze as much possible information about the likely cause
35203660into the limited space of the system exit code. However, as
35213661L<C<$!>|perlvar/$!> is the value of C's C<errno>, which can be set by
35223662any system call, this means that the value of the exit code used by
35233663L<C<die>|/die LIST> can be non-predictable, so should not be relied
35243664upon, other than to be non-zero.
35253665
35263666=end original
35273667
35283668この意図は、できるだけ多くの似たような原因に関する情報を、システム終了
35293669コードという限られた領域に圧縮することです。
35303670しかし、L<C<$!>|perlvar/$!> はシステムコールによって設定される可能性がある C の
35313671C<errno> の値であり、L<C<die>|/die LIST> によって使われる終了コードの値は
35323672予測不能であることを意味するので、非 0 ということ以上にこの値に
35333673依存するべきではありません。
35343674
35353675=begin original
35363676
3537You can also call L<C<die>|/die LIST> with a reference argument, and if
3538this is trapped within an L<C<eval>|/eval EXPR>, L<C<$@>|perlvar/$@>
3539contains that reference. This permits more elaborate exception handling
3540using objects that maintain arbitrary state about the exception. Such a
3541scheme is sometimes preferable to matching particular string values of
3542L<C<$@>|perlvar/$@> with regular expressions. Because
3543L<C<$@>|perlvar/$@> is a global variable and L<C<eval>|/eval EXPR> may
3544be used within object implementations, be careful that analyzing the
3545error object doesn't replace the reference in the global variable. It's
3546easiest to make a local copy of the reference before any manipulations.
3547Here's an example:
3548
3549=end original
3550
3551L<C<die>|/die LIST> はリファレンス引数と共に呼び出すこともでき、これが
3552L<C<eval>|/eval EXPR> 内部でトラップされた場合、L<C<$@>|perlvar/$@> は
3553そのリファレンスを持ちます。
3554これは、例外の性質について任意の状態を管理するオブジェクトを使った
3555より複雑な例外処理の実装を可能にします。
3556このようなスキームは L<C<$@>|perlvar/$@> の特定の文字列値を正規表現を使って
3557マッチングするときに時々好まれます。
3558L<C<$@>|perlvar/$@> はグローバル変数で、L<C<eval>|/eval EXPR> はオブジェクト
3559実装の内部で使われることがあるので、エラーオブジェクトの解析はグローバル変数の
3560リファレンスを置き換えないことに注意を払わなければなりません。
3561他の操作をする前にリファレンスのローカルコピーを
3562作るのが一番簡単です。
3563以下に例を示します:
3564
3565 use Scalar::Util "blessed";
3566
3567 eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) };
3568 if (my $ev_err = $@) {
3569 if (blessed($ev_err)
3570 && $ev_err->isa("Some::Module::Exception")) {
3571 # handle Some::Module::Exception
3572 }
3573 else {
3574 # handle all other possible exceptions
3575 }
3576 }
3577
3578=begin original
3579
3580Because Perl stringifies uncaught exception messages before display,
3581you'll probably want to overload stringification operations on
3582exception objects. See L<overload> for details about that.
3583
3584=end original
3585
3586perl は捕らえられなかった例外のメッセージを表示する前に文字列化するので、
3587このようなカスタム例外オブジェクトの文字列化をオーバーロードしたいと
3588思うかもしれません。
3589これに関する詳細は L<overload> を参照してください。
3590
3591=begin original
3592
35933677You can arrange for a callback to be run just before the
35943678L<C<die>|/die LIST> does its deed, by setting the
35953679L<C<$SIG{__DIE__}>|perlvar/%SIG> hook. The associated handler is called
3596with the error text and can change the error message, if it sees fit, by
3680with the exception as an argument, and can change the exception,
3681if it sees fit, by
35973682calling L<C<die>|/die LIST> again. See L<perlvar/%SIG> for details on
35983683setting L<C<%SIG>|perlvar/%SIG> entries, and L<C<eval>|/eval EXPR> for some
35993684examples. Although this feature was to be run only right before your
36003685program was to exit, this is not currently so: the
36013686L<C<$SIG{__DIE__}>|perlvar/%SIG> hook is currently called even inside
36023687L<C<eval>|/eval EXPR>ed blocks/strings! If one wants the hook to do
36033688nothing in such situations, put
36043689
36053690=end original
36063691
36073692L<C<$SIG{__DIE__}>|perlvar/%SIG> フックをセットすることで、
36083693L<C<die>|/die LIST> がその行動を行う
36093694直前に実行されるコールバックを設定できます。
3610結び付けられたハンドラはエラーテキスト共に呼び出され、
3695結び付けられたハンドラは例外を引数して呼び出され、
3611必要なら再び L<C<die>|/die LIST> を呼び出すことでエラーテキスト
3696必要なら再び L<C<die>|/die LIST> を呼び出すことで例外変更できます。
3612変更できます。
36133697L<C<%SIG>|perlvar/%SIG> のエントリをセットする詳細については、
36143698L<perlvar/%SIG> を、例については L<C<eval>|/eval EXPR> を参照してください。
36153699この機能はプログラムが終了しようとする前に 1 回だけ実行していましたが、
36163700現在ではそうではありません:
36173701L<C<$SIG{__DIE__}>|perlvar/%SIG> フックは L<C<eval>|/eval EXPR> された
36183702ブロック/文字列の中でも呼ばれるのです!
36193703もしそのような状況で何もしなくない時は:
36203704
36213705 die @_ if $^S;
36223706
36233707=begin original
36243708
36253709as the first line of the handler (see L<perlvar/$^S>). Because
36263710this promotes strange action at a distance, this counterintuitive
36273711behavior may be fixed in a future release.
36283712
36293713=end original
36303714
36313715をハンドラの最初の行に置いてください(L<perlvar/$^S> を参照してください)。
36323716これは離れたところで不思議な行動を引き起こすので、
36333717この直感的でない振る舞いは将来のリリースで修正されるかもしれません。
36343718
36353719=begin original
36363720
36373721See also L<C<exit>|/exit EXPR>, L<C<warn>|/warn LIST>, and the L<Carp>
36383722module.
36393723
36403724=end original
36413725
36423726L<C<exit>|/exit EXPR> と L<C<warn>|/warn LIST> と L<Carp> モジュールも
36433727参照してください。
36443728
36453729=item do BLOCK
36463730X<do> X<block>
36473731
36483732=for Pod::Functions turn a BLOCK into a TERM
36493733
36503734=begin original
36513735
36523736Not really a function. Returns the value of the last command in the
36533737sequence of commands indicated by BLOCK. When modified by the C<while> or
36543738C<until> loop modifier, executes the BLOCK once before testing the loop
36553739condition. (On other statements the loop modifiers test the conditional
36563740first.)
36573741
36583742=end original
36593743
36603744実際は関数ではありません。
36613745BLOCK で示されるコマンド列の最後の値を返します。
36623746C<while> や C<until> ループ修飾子で修飾すると、
36633747ループ条件を調べる前に 1 度、BLOCK を実行します。
36643748(これ以外の実行文は、ループ修飾子により、条件が最初に
36653749調べられます。)
36663750
36673751=begin original
36683752
36693753C<do BLOCK> does I<not> count as a loop, so the loop control statements
36703754L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
36713755L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
36723756See L<perlsyn> for alternative strategies.
36733757
36743758=end original
36753759
36763760C<do BLOCK> はループとしては I<扱われません>; 従って、L<C<next>|/next LABEL>,
36773761L<C<last>|/last LABEL>,L<C<redo>|/redo LABEL> といったループ制御文は
36783762ブロックから抜けたり再開することはできません。
36793763その他の戦略については L<perlsyn> を参照してください。
36803764
36813765=item do EXPR
36823766X<do>
36833767
36843768=begin original
36853769
36863770Uses the value of EXPR as a filename and executes the contents of the
36873771file as a Perl script:
36883772
36893773=end original
36903774
36913775EXPR の値をファイル名として用い、そのファイルの中身を
36923776Perl のスクリプトとして実行します:
36933777
36943778 # load the exact specified file (./ and ../ special-cased)
36953779 do '/foo/stat.pl';
36963780 do './stat.pl';
36973781 do '../foo/stat.pl';
36983782
36993783 # search for the named file within @INC
37003784 do 'stat.pl';
37013785 do 'foo/stat.pl';
37023786
37033787=begin original
37043788
37053789C<do './stat.pl'> is largely like
37063790
37073791=end original
37083792
37093793C<do './stat.pl'> はだいたい以下のものと同じようなものですが、
37103794
37113795 eval `cat stat.pl`;
37123796
37133797=begin original
37143798
37153799except that it's more concise, runs no external processes, and keeps
37163800track of the current filename for error messages. It also differs in that
37173801code evaluated with C<do FILE> cannot see lexicals in the enclosing
37183802scope; C<eval STRING> does. It's the same, however, in that it does
37193803reparse the file every time you call it, so you probably don't want
37203804to do this inside a loop.
37213805
37223806=end original
37233807
37243808より簡潔で、外部プログラムを起動せず、エラーメッセージでファイル名がわかる、
37253809といったことがあります。
37263810C<do FILE> で評価されたコードは、入れ子のスコープにある
37273811レキシカル変数を見ることができないのに対し、C<eval STRING>ではできる、
37283812という違いがあります。
37293813しかし、呼び出すたびにファイルを解析し直すという点では同じですから、
37303814ループ内でこれを使おうなどとは、間違っても思ったりしないように。
37313815
37323816=begin original
37333817
37343818Using C<do> with a relative path (except for F<./> and F<../>), like
37353819
37363820=end original
37373821
37383822次のように、C<do> に (F<./> と F<../> 以外の) 相対パスを使うと:
37393823
37403824 do 'foo/stat.pl';
37413825
37423826=begin original
37433827
37443828will search the L<C<@INC>|perlvar/@INC> directories, and update
37453829L<C<%INC>|perlvar/%INC> if the file is found. See L<perlvar/@INC>
37463830and L<perlvar/%INC> for these variables. In particular, note that
37473831whilst historically L<C<@INC>|perlvar/@INC> contained '.' (the
37483832current directory) making these two cases equivalent, that is no
37493833longer necessarily the case, as '.' is not included in C<@INC> by default
37503834in perl versions 5.26.0 onwards. Instead, perl will now warn:
37513835
37523836=end original
37533837
37543838L<C<@INC>|perlvar/@INC> ディレクトリを検索し、ファイルが見つかれば
37553839L<C<%INC>|perlvar/%INC> を更新します。
37563840これらの変数については L<perlvar/@INC> と L<perlvar/%INC> を参照してください。
37573841特に、歴史的には L<C<@INC>|perlvar/@INC> に '.' (カレントディレクトリ) を
37583842含んでいたのでこの二つの場合は等価でしたが、
37593843perl バージョン 5.26.0 以降ではデフォルトでは C<@INC> に '.' を
37603844含んでいないので、もはやそうではないことに注意してください。
37613845代わりに、perl は次のような警告を出します:
37623846
37633847 do "stat.pl" failed, '.' is no longer in @INC;
37643848 did you mean do "./stat.pl"?
37653849
37663850=begin original
37673851
37683852If L<C<do>|/do EXPR> can read the file but cannot compile it, it
37693853returns L<C<undef>|/undef EXPR> and sets an error message in
37703854L<C<$@>|perlvar/$@>. If L<C<do>|/do EXPR> cannot read the file, it
37713855returns undef and sets L<C<$!>|perlvar/$!> to the error. Always check
37723856L<C<$@>|perlvar/$@> first, as compilation could fail in a way that also
37733857sets L<C<$!>|perlvar/$!>. If the file is successfully compiled,
37743858L<C<do>|/do EXPR> returns the value of the last expression evaluated.
37753859
37763860=end original
37773861
37783862L<C<do>|/do EXPR> がファイルを読み込めたがコンパイルできなかった場合、
37793863L<C<undef>|/undef EXPR> を返して L<C<$@>|perlvar/$@> にエラーメッセージを
37803864設定します。
37813865L<C<do>|/do EXPR>がファイルを読み込めなかった場合、undef を返して
37823866L<C<$!>|perlvar/$!> にエラーを設定します。
37833867コンパイルに失敗したときにも L<C<$!>|perlvar/$!> が設定されるので、
37843868常に L<C<$@>|perlvar/$@> を先にチェックします。
37853869ファイルのコンパイルに成功した場合、L<C<do>|/do EXPR> は最後に評価した表現の
37863870値を返します。
37873871
37883872=begin original
37893873
37903874Inclusion of library modules is better done with the
37913875L<C<use>|/use Module VERSION LIST> and L<C<require>|/require VERSION>
37923876operators, which also do automatic error checking and raise an exception
37933877if there's a problem.
37943878
37953879=end original
37963880
37973881ライブラリモジュールのインクルードには、
37983882L<C<use>|/use Module VERSION LIST> 演算子や
37993883L<C<require>|/require VERSION> 演算子を使った方がよいです;
38003884これらは自動的にエラーをチェックして、問題があれば例外を発生させます。
38013885
38023886=begin original
38033887
38043888You might like to use L<C<do>|/do EXPR> to read in a program
38053889configuration file. Manual error checking can be done this way:
38063890
38073891=end original
38083892
38093893L<C<do>|/do EXPR> をプログラム設定ファイルを読み込むのに
38103894使いたいかもしれません。
38113895手動のエラーチェックは以下のようにして行えます:
38123896
38133897 # Read in config files: system first, then user.
38143898 # Beware of using relative pathnames here.
38153899 for $file ("/share/prog/defaults.rc",
38163900 "$ENV{HOME}/.someprogrc")
38173901 {
38183902 unless ($return = do $file) {
38193903 warn "couldn't parse $file: $@" if $@;
38203904 warn "couldn't do $file: $!" unless defined $return;
38213905 warn "couldn't run $file" unless $return;
38223906 }
38233907 }
38243908
38253909=item dump LABEL
38263910X<dump> X<core> X<undump>
38273911
38283912=item dump EXPR
38293913
38303914=item dump
38313915
38323916=for Pod::Functions create an immediate core dump
38333917
38343918=begin original
38353919
38363920This function causes an immediate core dump. See also the B<-u>
3837command-line switch in L<perlrun>, which does the same thing.
3921command-line switch in L<perlrun|perlrun/-u>, which does the same thing.
38383922Primarily this is so that you can use the B<undump> program (not
38393923supplied) to turn your core dump into an executable binary after
38403924having initialized all your variables at the beginning of the
38413925program. When the new binary is executed it will begin by executing
38423926a C<goto LABEL> (with all the restrictions that L<C<goto>|/goto LABEL>
38433927suffers).
38443928Think of it as a goto with an intervening core dump and reincarnation.
38453929If C<LABEL> is omitted, restarts the program from the top. The
38463930C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be
38473931computed at run time, being otherwise identical to C<dump LABEL>.
38483932
38493933=end original
38503934
38513935この関数は即座にコアダンプを行ないます。
3852同様のことを行う L<perlrun> の B<-u> オプションも参照してください。
3936同様のことを行う <perlrun|perlrun/-u> の B<-u> オプションも参照してください。
38533937プログラムの先頭で、
38543938すべての変数を初期化したあとのコアダンプを B<undump>
38553939プログラム(提供していません)を使って実行ファイルに返ることができます。
38563940この新しいバイナリが実行されると、C<goto LABEL> から始めます
38573941(L<C<goto>|/goto LABEL> に関する制限はすべて適用されます)。
38583942コアダンプをはさんで再生する goto と考えてください。
38593943C<LABEL> が省略されると、プログラムを先頭から再開します。
38603944Perl 5.18.0 から利用可能な C<dump EXPR> 形式では、実行時に計算される
38613945名前が使えます; その他は C<dump LABEL> と同一です。
38623946
38633947=begin original
38643948
38653949B<WARNING>: Any files opened at the time of the dump will I<not>
38663950be open any more when the program is reincarnated, with possible
38673951resulting confusion by Perl.
38683952
38693953=end original
38703954
38713955B<警告>: dump 時点でオープンされていたファイルは、プログラムが
38723956再生されたときには、もはやオープンされて I<いません>; Perl を
38733957混乱させる可能性があります。
38743958
38753959=begin original
38763960
38773961This function is now largely obsolete, mostly because it's very hard to
3878convert a core file into an executable. That's why you should now invoke
3962convert a core file into an executable. As of Perl 5.30, it must be invoked
3879it as C<CORE::dump()> if you don't want to be warned against a possible
3963as C<CORE::dump()>.
3880typo.
38813964
38823965=end original
38833966
38843967この関数は大幅に時代遅れのものです; 主な理由としては、コアファイルを
38853968実行形式に変換するのが非常に困難であることです。
3886これが、今でタイプミスの可能性を警告さたくいなら
3969Perl 5.30 から、これは C<CORE::dump()> として起動しなけりません。
3887C<CORE::dump> として起動するべき理由です。
38883970
38893971=begin original
38903972
38913973Unlike most named operators, this has the same precedence as assignment.
38923974It is also exempt from the looks-like-a-function rule, so
38933975C<dump ("foo")."bar"> will cause "bar" to be part of the argument to
38943976L<C<dump>|/dump LABEL>.
38953977
38963978=end original
38973979
38983980ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
38993981また、関数のように見えるものの規則からも免れるので、C<dump ("foo")."bar"> と
39003982すると "bar" は L<C<dump>|/dump LABEL> への引数の一部になります。
39013983
39023984=begin original
39033985
39043986Portability issues: L<perlport/dump>.
39053987
39063988=end original
39073989
39083990移植性の問題: L<perlport/dump>。
39093991
39103992=item each HASH
39113993X<each> X<hash, iterator>
39123994
39133995=item each ARRAY
39143996X<array, iterator>
39153997
39163998=for Pod::Functions retrieve the next key/value pair from a hash
39173999
39184000=begin original
39194001
39204002When called on a hash in list context, returns a 2-element list
39214003consisting of the key and value for the next element of a hash. In Perl
392240045.12 and later only, it will also return the index and value for the next
39234005element of an array so that you can iterate over it; older Perls consider
39244006this a syntax error. When called in scalar context, returns only the key
39254007(not the value) in a hash, or the index in an array.
39264008
39274009=end original
39284010
39294011ハッシュに対してリストコンテキストで呼び出した場合は、次の要素に対する、
39304012ハッシュのキーと値を返します。
39314013Perl 5.12 以降でのみ、配列のインデックスと値からなる
393240142 要素のリストを返すので、反復を行えます; より古い Perl ではこれは
39334015文法エラーと考えられます。
39344016スカラコンテキストで呼び出した場合は、
39354017ハッシュの場合は(値ではなく)キー、配列の場合はインデックスを返します。
39364018
39374019=begin original
39384020
39394021Hash entries are returned in an apparently random order. The actual random
39404022order is specific to a given hash; the exact same series of operations
39414023on two hashes may result in a different order for each hash. Any insertion
39424024into the hash may change the order, as will any deletion, with the exception
39434025that the most recent key returned by L<C<each>|/each HASH> or
39444026L<C<keys>|/keys HASH> may be deleted without changing the order. So
39454027long as a given hash is unmodified you may rely on
39464028L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
39474029L<C<each>|/each HASH> to repeatedly return the same order
39484030as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
39494031details on why hash order is randomized. Aside from the guarantees
39504032provided here the exact details of Perl's hash algorithm and the hash
39514033traversal order are subject to change in any release of Perl.
39524034
39534035=end original
39544036
39554037ハッシュ要素は見かけ上、ランダムな順序で返されます。
39564038実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
39574039操作を行っても、ハッシュによって異なった順序になります。
39584040ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
39594041L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
39604042最近のキーは順序を変えることなく削除できます。
39614043ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
39624044L<C<each>|/each HASH> が繰り返し同じ順序で
39634045返すことに依存してもかまいません。
39644046なぜハッシュの順序がランダム化されているかの詳細については
39654047L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
39664048ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
39674049正確な詳細は Perl のリリースによって変更される可能性があります。
39684050
39694051=begin original
39704052
39714053After L<C<each>|/each HASH> has returned all entries from the hash or
39724054array, the next call to L<C<each>|/each HASH> returns the empty list in
39734055list context and L<C<undef>|/undef EXPR> in scalar context; the next
39744056call following I<that> one restarts iteration. Each hash or array has
39754057its own internal iterator, accessed by L<C<each>|/each HASH>,
39764058L<C<keys>|/keys HASH>, and L<C<values>|/values HASH>. The iterator is
39774059implicitly reset when L<C<each>|/each HASH> has reached the end as just
39784060described; it can be explicitly reset by calling L<C<keys>|/keys HASH>
3979or L<C<values>|/values HASH> on the hash or array. If you add or delete
4061or L<C<values>|/values HASH> on the hash or array, or by referencing
4062the hash (but not array) in list context. If you add or delete
39804063a hash's elements while iterating over it, the effect on the iterator is
39814064unspecified; for example, entries may be skipped or duplicated--so don't
39824065do that. Exception: It is always safe to delete the item most recently
39834066returned by L<C<each>|/each HASH>, so the following code works properly:
39844067
39854068=end original
39864069
39874070L<C<each>|/each HASH> がハッシュをすべて読み込んでしまった後、
39884071次の L<C<each>|/each HASH> 呼び出しでは、リストコンテキストでは空リストが
39894072返され、スカラコンテキストでは L<C<undef>|/undef EXPR> が返されます;
39904073I<そのあと> もう一度呼び出すと、再び反復を始めます。
39914074ハッシュや配列毎にそれぞれ反復子があり、L<C<each>|/each HASH>、
39924075L<C<keys>|/keys HASH>、L<C<values>|/values HASH> でアクセスされます。
39934076反復子は、前述したように L<C<each>|/each HASH> が要素をすべて読むことによって
39944077暗黙にリセットされます; また、ハッシュや配列に対して L<C<keys>|/keys HASH>,
3995L<C<values>|/values HASH> を呼び出すことで明示的にセットできます。
4078L<C<values>|/values HASH> を呼び出すか、コンテキスト
4079(配列ではなく)ハッシュを参照ことで明示的にリセットできます。
39964080繰り返しを行なっている間に、ハッシュに要素を追加したり削除したりすると、
39974081反復子の動作は未定義です; 例えば、要素が飛ばされたり重複したりします--
39984082従って、してはいけません。
39994083例外: 一番最近に L<C<each>|/each HASH> から返されたものを削除するのは常に
40004084安全です; これは以下のようなコードが正しく動くことを意味します:
40014085
40024086 while (my ($key, $value) = each %hash) {
40034087 print $key, "\n";
40044088 delete $hash{$key}; # This is safe
40054089 }
40064090
40074091=begin original
40084092
40094093Tied hashes may have a different ordering behaviour to perl's hash
40104094implementation.
40114095
40124096=end original
40134097
40144098tie されたハッシュは、順序に関して Perl のハッシュと異なった振る舞いをします。
40154099
40164100=begin original
40174101
4102The iterator used by C<each> is attached to the hash or array, and is
4103shared between all iteration operations applied to the same hash or array.
4104Thus all uses of C<each> on a single hash or array advance the same
4105iterator location. All uses of C<each> are also subject to having the
4106iterator reset by any use of C<keys> or C<values> on the same hash or
4107array, or by the hash (but not array) being referenced in list context.
4108This makes C<each>-based loops quite fragile: it is easy to arrive at
4109such a loop with the iterator already part way through the object, or to
4110accidentally clobber the iterator state during execution of the loop body.
4111It's easy enough to explicitly reset the iterator before starting a loop,
4112but there is no way to insulate the iterator state used by a loop from
4113the iterator state used by anything else that might execute during the
4114loop body. To avoid these problems, use a C<foreach> loop rather than
4115C<while>-C<each>.
4116
4117=end original
4118
4119C<each> で使われる反復子はハッシュや配列に付随し、
4120同じハッシュや配列に適用される全ての反復操作の間で共有されます。
4121従って、一つのハッシュや配列での C<each> の全ての使用は同じ反復位置を
4122進めます。
4123また、全ての C<each> は、同じハッシュまたはキーに対する
4124C<keys> や C<values> の使用によって、または
4125(リストではなく)ハッシュがリストコンテキストで参照されることによって、
4126反復子がリセットされることになります。
4127これは、C<each> を基にしたループをかなり不安定にします:
4128そのようなループが既にオブジェクトを部分的に通りぬけた反復子で行われたり、
4129ループ本体の実行中に誤って反復子の状態を壊すことは容易です。
4130ループを始める前に反復子を明示的にリセットするのは十分容易ですが、
4131ループ本体の間に実行しているかもしれない他の何かによって使われている
4132反復子の状態から、
4133ループによって使われている反復子の状態を分離する方法はありません。
4134これらの問題を避けるには、C<while>-C<each> ではなく
4135C<foreach> ループを使ってください。
4136
4137=begin original
4138
40184139This prints out your environment like the L<printenv(1)> program,
40194140but in a different order:
40204141
40214142=end original
40224143
40234144これは、L<printenv(1)> プログラムのように環境変数を表示しますが、
40244145順序は異なっています:
40254146
40264147 while (my ($key,$value) = each %ENV) {
40274148 print "$key=$value\n";
40284149 }
40294150
40304151=begin original
40314152
40324153Starting with Perl 5.14, an experimental feature allowed
40334154L<C<each>|/each HASH> to take a scalar expression. This experiment has
40344155been deemed unsuccessful, and was removed as of Perl 5.24.
40354156
40364157=end original
40374158
40384159Perl 5.14 から、L<C<each>|/each HASH> がスカラ式を取ることが出来るという
40394160実験的機能がありました。
40404161この実験は失敗と見なされ、Perl 5.24 で削除されました。
40414162
40424163=begin original
40434164
40444165As of Perl 5.18 you can use a bare L<C<each>|/each HASH> in a C<while>
40454166loop, which will set L<C<$_>|perlvar/$_> on every iteration.
4167If either an C<each> expression or an explicit assignment of an C<each>
4168expression to a scalar is used as a C<while>/C<for> condition, then
4169the condition actually tests for definedness of the expression's value,
4170not for its regular truth value.
40464171
40474172=end original
40484173
40494174Perl 5.18 から C<while> ループの中に裸の L<C<each>|/each HASH> を書けます;
40504175これは繰り返し毎に L<C<$_>|perlvar/$_> を設定します。
4176C<each> 式または C<each> 式からスカラへの明示的な代入が
4177C<while>/C<for> の条件部として使われた場合、
4178条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
4179テストします。
40514180
40524181 while (each %ENV) {
40534182 print "$_=$ENV{$_}\n";
40544183 }
40554184
40564185=begin original
40574186
40584187To avoid confusing would-be users of your code who are running earlier
40594188versions of Perl with mysterious syntax errors, put this sort of thing at
40604189the top of your file to signal that your code will work I<only> on Perls of
40614190a recent vintage:
40624191
40634192=end original
40644193
40654194あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
40664195文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
40674196I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
40684197書いてください:
40694198
40704199 use 5.012; # so keys/values/each work on arrays
40714200 use 5.018; # so each assigns to $_ in a lone while test
40724201
40734202=begin original
40744203
40754204See also L<C<keys>|/keys HASH>, L<C<values>|/values HASH>, and
40764205L<C<sort>|/sort SUBNAME LIST>.
40774206
40784207=end original
40794208
40804209L<C<keys>|/keys HASH> や L<C<values>|/values HASH> や
40814210L<C<sort>|/sort SUBNAME LIST> も参照してください。
40824211
40834212=item eof FILEHANDLE
40844213X<eof>
40854214X<end of file>
40864215X<end-of-file>
40874216
40884217=item eof ()
40894218
40904219=item eof
40914220
40924221=for Pod::Functions test a filehandle for its end
40934222
40944223=begin original
40954224
40964225Returns 1 if the next read on FILEHANDLE will return end of file I<or> if
40974226FILEHANDLE is not open. FILEHANDLE may be an expression whose value
40984227gives the real filehandle. (Note that this function actually
40994228reads a character and then C<ungetc>s it, so isn't useful in an
41004229interactive context.) Do not read from a terminal file (or call
41014230C<eof(FILEHANDLE)> on it) after end-of-file is reached. File types such
41024231as terminals may lose the end-of-file condition if you do.
41034232
41044233=end original
41054234
41064235次に FILEHANDLE 上で読み込みを行なったときに、EOF が返されるときか、
41074236I<または> FILEHANDLE がオープンされていないと、1 を返します。
41084237FILEHANDLE は、値が実際のファイルハンドルを示す式であってもかまいません。
41094238(この関数は、実際に文字を読み、C<ungetc> を行ないますので、
41104239対話型の場合には有用ではありません。)
41114240端末ファイルは EOF に達した後にさらに読み込んだり C<eof(FILEHANDLE)> を
41124241呼び出したりしてはいけません。
41134242そのようなことをすると、端末のようなファイルタイプは
41144243EOF 状態を失ってしまうかもしれません。
41154244
41164245=begin original
41174246
41184247An L<C<eof>|/eof FILEHANDLE> without an argument uses the last file
41194248read. Using L<C<eof()>|/eof FILEHANDLE> with empty parentheses is
41204249different. It refers to the pseudo file formed from the files listed on
41214250the command line and accessed via the C<< <> >> operator. Since
41224251C<< <> >> isn't explicitly opened, as a normal filehandle is, an
41234252L<C<eof()>|/eof FILEHANDLE> before C<< <> >> has been used will cause
41244253L<C<@ARGV>|perlvar/@ARGV> to be examined to determine if input is
41254254available. Similarly, an L<C<eof()>|/eof FILEHANDLE> after C<< <> >>
41264255has returned end-of-file will assume you are processing another
41274256L<C<@ARGV>|perlvar/@ARGV> list, and if you haven't set
41284257L<C<@ARGV>|perlvar/@ARGV>, will read input from C<STDIN>; see
41294258L<perlop/"I/O Operators">.
41304259
41314260=end original
41324261
41334262引数を省略した L<C<eof>|/eof FILEHANDLE> は、最後に読み込みを行なった
41344263ファイルを使います。
41354264空の括弧をつけた L<C<eof()>|/eof FILEHANDLE> は異なります。
41364265これはコマンドラインのファイルリストで構成され、C<< <> >> 演算子経由で
41374266アクセスされる擬似ファイルを示すために用いられます。
41384267通常のファイルハンドルと違って C<< <> >> は明示的にオープンされないので、
41394268C<< <> >> を使う前に L<C<eof()>|/eof FILEHANDLE> を使うと、
41404269入力が正常か確認するために L<C<@ARGV>|perlvar/@ARGV> がテストされます。
41414270同様に、C<< <> >> が EOF を返した後の L<C<eof()>|/eof FILEHANDLE> は、
41424271他の L<C<@ARGV>|perlvar/@ARGV> リストを処理していると仮定し、もし
41434272L<C<@ARGV>|perlvar/@ARGV> をセットしていないときは C<STDIN> から読み込みます;
41444273L<perlop/"I/O Operators"> を参照してください。
41454274
41464275=begin original
41474276
41484277In a C<< while (<>) >> loop, L<C<eof>|/eof FILEHANDLE> or C<eof(ARGV)>
41494278can be used to detect the end of each file, whereas
41504279L<C<eof()>|/eof FILEHANDLE> will detect the end of the very last file
41514280only. Examples:
41524281
41534282=end original
41544283
41554284C<< while (<>) >> ループの中では、個々のファイルの終わりを調べるには、
41564285L<C<eof>|/eof FILEHANDLE> か C<eof(ARGV)> を用いるのに対して
41574286L<C<eof()>|/eof FILEHANDLE> は最後のファイルの終わりのみを調べます。
41584287例:
41594288
41604289 # reset line numbering on each input file
41614290 while (<>) {
41624291 next if /^\s*#/; # skip comments
41634292 print "$.\t$_";
41644293 } continue {
41654294 close ARGV if eof; # Not eof()!
41664295 }
41674296
41684297 # insert dashes just before last line of last file
41694298 while (<>) {
41704299 if (eof()) { # check for end of last file
41714300 print "--------------\n";
41724301 }
41734302 print;
41744303 last if eof(); # needed if we're reading from a terminal
41754304 }
41764305
41774306=begin original
41784307
41794308Practical hint: you almost never need to use L<C<eof>|/eof FILEHANDLE>
41804309in Perl, because the input operators typically return L<C<undef>|/undef
41814310EXPR> when they run out of data or encounter an error.
41824311
41834312=end original
41844313
41854314現実的なヒント: Perl で L<C<eof>|/eof FILEHANDLE> が必要となることは、
41864315ほとんどありません;
41874316基本的には、データがなくなったときやエラーがあったときに、入力演算子が
41884317L<C<undef>|/undef EXPR> を返してくれるからです。
41894318
41904319=item eval EXPR
41914320X<eval> X<try> X<catch> X<evaluate> X<parse> X<execute>
41924321X<error, handling> X<exception, handling>
41934322
41944323=item eval BLOCK
41954324
41964325=item eval
41974326
41984327=for Pod::Functions catch exceptions or compile and run code
41994328
42004329=begin original
42014330
42024331C<eval> in all its forms is used to execute a little Perl program,
42034332trapping any errors encountered so they don't crash the calling program.
42044333
42054334=end original
42064335
42074336どの型式の C<eval> も、小さな Perl のプログラムであるかのように実行され、
42084337遭遇した全てのエラーをトラップするので、呼び出したプログラムが
42094338クラッシュすることはありません。
42104339
42114340=begin original
42124341
42134342Plain C<eval> with no argument is just C<eval EXPR>, where the
42144343expression is understood to be contained in L<C<$_>|perlvar/$_>. Thus
42154344there are only two real C<eval> forms; the one with an EXPR is often
42164345called "string eval". In a string eval, the value of the expression
42174346(which is itself determined within scalar context) is first parsed, and
42184347if there were no errors, executed as a block within the lexical context
42194348of the current Perl program. This form is typically used to delay
42204349parsing and subsequent execution of the text of EXPR until run time.
42214350Note that the value is parsed every time the C<eval> executes.
42224351
42234352=end original
42244353
42254354引数なしの C<eval> は単に C<eval EXPR> で、式は L<C<$_>|perlvar/$_> に
42264355含まれているものとして考えられます。
42274356従って実際には二つだけの C<eval> 形式があります:
42284357EXPR のものはしばしば「文字列 eval」(string eval) と呼ばれます。
42294358「文字列 eval」では、
42304359式の値(それ自身スカラコンテキストの中で決定されます)はまずパースされ、
42314360エラーがなければ Perl プログラムのレキシカルコンテキストの中のブロックとして
42324361実行されます。
42334362この形は主に EXPR のテキストのパースと実行を実行時にまで
42344363遅延させるのに用います。
42354364返される値は C<eval> が実行されるごとにパースされることに注意してください。
42364365
42374366=begin original
42384367
42394368The other form is called "block eval". It is less general than string
42404369eval, but the code within the BLOCK is parsed only once (at the same
42414370time the code surrounding the C<eval> itself was parsed) and executed
42424371within the context of the current Perl program. This form is typically
42434372used to trap exceptions more efficiently than the first, while also
42444373providing the benefit of checking the code within BLOCK at compile time.
42454374BLOCK is parsed and compiled just once. Since errors are trapped, it
42464375often is used to check if a given feature is available.
42474376
42484377=end original
42494378
42504379もう一つの型式は「ブロック eval」と呼ばれます。
42514380これは文字列 eval ほど一般的ではありませんが、
42524381BLOCK 内部のコードは一度だけパースされ (コードを
42534382囲む C<eval> 自身がパースされるのと同じ時点です) 現在の
42544383Perl プログラムのコンテキストで実行されます。
42554384この形式は典型的には第一の形式より効率的に例外をトラップします;
42564385また BLOCK 内部のコードはコンパイル時にチェックされるという利点を提供します。
42574386BLOCK は一度だけパース及びコンパイルされます。
42584387エラーはトラップされてるので、しばしば与えられた機能が利用可能かを
42594388チェックするために使われます。
42604389
42614390=begin original
42624391
42634392In both forms, the value returned is the value of the last expression
42644393evaluated inside the mini-program; a return statement may also be used, just
42654394as with subroutines. The expression providing the return value is evaluated
42664395in void, scalar, or list context, depending on the context of the
42674396C<eval> itself. See L<C<wantarray>|/wantarray> for more
42684397on how the evaluation context can be determined.
42694398
42704399=end original
42714400
42724401どちらの形式でも、返される値はミニプログラムの内部で最後に評価された
42734402表現の値です; サブルーチンと同様、return 文も使えます。
42744403返り値として提供される表現は、C<eval> 自身のコンテキストに
42754404依存して無効・スカラ・リストのいずれかのコンテキストで評価されます。
42764405評価コンテキストの決定方法についての詳細は L<C<wantarray>|/wantarray> を
42774406参照してください。
42784407
42794408=begin original
42804409
42814410If there is a syntax error or runtime error, or a L<C<die>|/die LIST>
42824411statement is executed, C<eval> returns
42834412L<C<undef>|/undef EXPR> in scalar context, or an empty list in list
42844413context, and L<C<$@>|perlvar/$@> is set to the error message. (Prior to
428544145.16, a bug caused L<C<undef>|/undef EXPR> to be returned in list
42864415context for syntax errors, but not for runtime errors.) If there was no
42874416error, L<C<$@>|perlvar/$@> is set to the empty string. A control flow
42884417operator like L<C<last>|/last LABEL> or L<C<goto>|/goto LABEL> can
42894418bypass the setting of L<C<$@>|perlvar/$@>. Beware that using
42904419C<eval> neither silences Perl from printing warnings to
42914420STDERR, nor does it stuff the text of warning messages into
42924421L<C<$@>|perlvar/$@>. To do either of those, you have to use the
42934422L<C<$SIG{__WARN__}>|perlvar/%SIG> facility, or turn off warnings inside
42944423the BLOCK or EXPR using S<C<no warnings 'all'>>. See
42954424L<C<warn>|/warn LIST>, L<perlvar>, and L<warnings>.
42964425
42974426=end original
42984427
42994428構文エラーや実行エラーが発生するか、L<C<die>|/die LIST> 文が実行されると、
43004429C<eval> はスカラコンテキストでは L<C<undef>|/undef EXPR> が、
43014430リストコンテキストでは空リストが設定され、
43024431L<C<$@>|perlvar/$@> にエラーメッセージが設定されます。
43034432(5.16 以前では、バグによって、リストコンテキストで構文エラーの時には
43044433L<C<undef>|/undef EXPR> を返していましたが、実行エラーの時には
43054434返していませんでした。)
43064435エラーがなければ、L<C<$@>|perlvar/$@> は空文字列に設定されます。
43074436L<C<last>|/last LABEL> や L<C<goto>|/goto LABEL> のようなフロー制御演算子は
43084437L<C<$@>|perlvar/$@> の設定を回避できます。
43094438C<eval> を、STDERR に警告メッセージを表示させない目的や、
43104439警告メッセージを L<C<$@>|perlvar/$@> に格納する目的では使わないでください。
43114440そのような用途では、L<C<$SIG{__WARN__}>|perlvar/%SIG> 機能を使うか、
43124441S<C<no warnings 'all'>> を使って BLOCK か EXPR の内部での警告を
43134442オフにする必要があります。
43144443L<C<warn>|/warn LIST>, L<perlvar>, L<warnings> を参照してください。
43154444
43164445=begin original
43174446
43184447Note that, because C<eval> traps otherwise-fatal errors,
43194448it is useful for determining whether a particular feature (such as
43204449L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> or
43214450L<C<symlink>|/symlink OLDFILE,NEWFILE>) is implemented. It is also
43224451Perl's exception-trapping mechanism, where the L<C<die>|/die LIST>
43234452operator is used to raise exceptions.
43244453
43254454=end original
43264455
43274456C<eval> は、致命的エラーとなるようなものを
43284457トラップすることができるので、
43294458(L<C<socket>|/socket SOCKET,DOMAIN,TYPE,PROTOCOL> や
43304459L<C<symlink>|/symlink OLDFILE,NEWFILE> といった) 特定の機能が
43314460実装されているかを、
43324461調べるために使うことができることに注意してください。
43334462L<C<die>|/die LIST> 演算子が例外を発生させるものとすれば、これはまた、
43344463Perl の例外捕捉機能と捉えることもできます。
43354464
43364465=begin original
43374466
43384467Before Perl 5.14, the assignment to L<C<$@>|perlvar/$@> occurred before
43394468restoration
43404469of localized variables, which means that for your code to run on older
43414470versions, a temporary is required if you want to mask some, but not all
43424471errors:
43434472
43444473=end original
43454474
43464475Perl 5.14 より前では、L<C<$@>|perlvar/$@> への代入はローカル化された変数の
43474476復帰の前に起きるので、古いバージョンで実行される場合は、全てではなく一部だけの
43484477エラーをマスクしたい場合には一時変数が必要です:
43494478
43504479 # alter $@ on nefarious repugnancy only
43514480 {
43524481 my $e;
43534482 {
43544483 local $@; # protect existing $@
43554484 eval { test_repugnancy() };
43564485 # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
43574486 $@ =~ /nefarious/ and $e = $@;
43584487 }
43594488 die $e if defined $e
43604489 }
43614490
43624491=begin original
43634492
43644493There are some different considerations for each form:
43654494
43664495=end original
43674496
43684497それぞれの型式について、異なった考慮事項があります:
43694498
43704499=over 4
43714500
43724501=item String eval
43734502
43744503(文字列 eval)
43754504
43764505=begin original
43774506
43784507Since the return value of EXPR is executed as a block within the lexical
43794508context of the current Perl program, any outer lexical variables are
43804509visible to it, and any package variable settings or subroutine and
43814510format definitions remain afterwards.
43824511
43834512=end original
43844513
43854514EXPR の返り値は現在の Perl プログラムのレキシカルコンテキストの中で
43864515実行されるので、外側のレキシカルスコープはそこから見え、
43874516パッケージ変数設定やサブルーチンとフォーマット設定は後に残ります。
43884517
43894518=over 4
43904519
43914520=item Under the L<C<"unicode_eval"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
43924521
43934522=begin original
43944523
43954524If this feature is enabled (which is the default under a C<use 5.16> or
43964525higher declaration), EXPR is considered to be
43974526in the same encoding as the surrounding program. Thus if
43984527S<L<C<use utf8>|utf8>> is in effect, the string will be treated as being
43994528UTF-8 encoded. Otherwise, the string is considered to be a sequence of
44004529independent bytes. Bytes that correspond to ASCII-range code points
44014530will have their normal meanings for operators in the string. The
44024531treatment of the other bytes depends on if the
44034532L<C<'unicode_strings"> feature|feature/The 'unicode_strings' feature> is
44044533in effect.
44054534
44064535=end original
44074536
44084537この機能が有効の場合(これは C<use 5.16> またはそれ以上が
44094538宣言されている場合はデフォルトです)、
44104539EXPR は周りのプログラムと同じエンコーディングであるとして扱われます。
44114540従って、S<L<C<use utf8>|utf8>> が有効の場合、
44124541文字列は UTF-8 エンコードされているものとして扱われます。
44134542さもなければ、この文字列は個々のバイト列として扱われます。
44144543ASCII の範囲の符号位置に対応するバイトは、
44154544文字列の操作に関して通常の意味を持ちます。
44164545その他のバイトの扱いは、
44174546<C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か
44184547どうかに依存します。
44194548
44204549=begin original
44214550
44224551In a plain C<eval> without an EXPR argument, being in S<C<use utf8>> or
44234552not is irrelevant; the UTF-8ness of C<$_> itself determines the
44244553behavior.
44254554
44264555=end original
44274556
44284557EXPR 引数のない単なる C<eval> の場合、S<C<use utf8>> の有無は無関係です;
44294558C<$_> 自身の UTF-8 性が振る舞いを決定します。
44304559
44314560=begin original
44324561
44334562Any S<C<use utf8>> or S<C<no utf8>> declarations within the string have
44344563no effect, and source filters are forbidden. (C<unicode_strings>,
44354564however, can appear within the string.) See also the
44364565L<C<evalbytes>|/evalbytes EXPR> operator, which works properly with
44374566source filters.
44384567
44394568=end original
44404569
44414570文字列中の S<C<use utf8>> や S<C<no utf8>> 宣言は無効で、ソースフィルタは
44424571禁止されます。
44434572(しかし、C<unicode_strings> は文字列の中に現れます。)
44444573ソースフィルタが適切に動作する
44454574L<C<evalbytes>|/evalbytes EXPR> 演算子も参照してください。
44464575
44474576=begin original
44484577
44494578Variables defined outside the C<eval> and used inside it retain their
44504579original UTF-8ness. Everything inside the string follows the normal
44514580rules for a Perl program with the given state of S<C<use utf8>>.
44524581
44534582=end original
44544583
44554584Variables defined outside the
44564585C<eval> の外側で定義され、内側で使われた変数は、
44574586元の UTF-8 性を維持します。
44584587内側の文字列は、S<C<use utf8>> の状態によって Perl プログラムに適用される
44594588通常の規則に従います。
44604589
44614590=item Outside the C<"unicode_eval"> feature
44624591
44634592=begin original
44644593
44654594In this case, the behavior is problematic and is not so easily
44664595described. Here are two bugs that cannot easily be fixed without
44674596breaking existing programs:
44684597
44694598=end original
44704599
44714600この場合、振る舞いには問題があり、それほど簡単には説明できません。
44724601既存のプログラムを壊さずに簡単に修正することが出来ない二つのバグがあります:
44734602
44744603=over 4
44754604
44764605=item *
44774606
44784607=begin original
44794608
44804609It can lose track of whether something should be encoded as UTF-8 or
44814610not.
44824611
44834612=end original
44844613
44854614あるものが UTF-8 でエンコードされているかどうかを見失うことがあります。
44864615
44874616=item *
44884617
44894618=begin original
44904619
44914620Source filters activated within C<eval> leak out into whichever file
44924621scope is currently being compiled. To give an example with the CPAN module
44934622L<Semi::Semicolons>:
44944623
44954624=end original
44964625
44974626C<eval> の中で有効にされたソースフィルタは、現在どちらのファイルスコープで
44984627コンパイルされているかをリークさせます。
44994628CPAN モジュール L<Semi::Semicolons> を使った例は:
45004629
45014630 BEGIN { eval "use Semi::Semicolons; # not filtered" }
45024631 # filtered here!
45034632
45044633=begin original
45054634
45064635L<C<evalbytes>|/evalbytes EXPR> fixes that to work the way one would
45074636expect:
45084637
45094638=end original
45104639
45114640L<C<evalbytes>|/evalbytes EXPR> は、人が想定するだろう手法で動作するように
45124641これを修正します:
45134642
45144643 use feature "evalbytes";
45154644 BEGIN { evalbytes "use Semi::Semicolons; # filtered" }
45164645 # not filtered
45174646
45184647=back
45194648
45204649=back
45214650
45224651=begin original
45234652
45244653Problems can arise if the string expands a scalar containing a floating
45254654point number. That scalar can expand to letters, such as C<"NaN"> or
45264655C<"Infinity">; or, within the scope of a L<C<use locale>|locale>, the
45274656decimal point character may be something other than a dot (such as a
45284657comma). None of these are likely to parse as you are likely expecting.
45294658
45304659=end original
45314660
45324661文字列をが小数点を含むスカラを展開するときに問題が起こることがあります。
45334662そのようなスカラは C<"NaN"> や C<"Infinity"> のような文字に
45344663展開されることがあります; または、L<C<use locale>|locale> のスコープの中では、
45354664小数点文字は (カンマのような) ドット以外の文字かもしれません。
45364665これらはどれもあなたがおそらく予測しているようにはパースされません。
45374666
45384667=begin original
45394668
45404669You should be especially careful to remember what's being looked at
45414670when:
45424671
45434672=end original
45444673
45454674以下のような場合に、何が調べられるかに特に注意しておくことが必要です:
45464675
45474676 eval $x; # CASE 1
45484677 eval "$x"; # CASE 2
45494678
45504679 eval '$x'; # CASE 3
45514680 eval { $x }; # CASE 4
45524681
45534682 eval "\$$x++"; # CASE 5
45544683 $$x++; # CASE 6
45554684
45564685=begin original
45574686
45584687Cases 1 and 2 above behave identically: they run the code contained in
45594688the variable $x. (Although case 2 has misleading double quotes making
45604689the reader wonder what else might be happening (nothing is).) Cases 3
45614690and 4 likewise behave in the same way: they run the code C<'$x'>, which
45624691does nothing but return the value of $x. (Case 4 is preferred for
45634692purely visual reasons, but it also has the advantage of compiling at
45644693compile-time instead of at run-time.) Case 5 is a place where
45654694normally you I<would> like to use double quotes, except that in this
45664695particular situation, you can just use symbolic references instead, as
45674696in case 6.
45684697
45694698=end original
45704699
45714700上記の CASE 1 と CASE 2 の動作は同一で、変数 $x 内の
45724701コードを実行します。
45734702(ただし、CASE 2 では、必要のないダブルクォートによって、
45744703読む人が何が起こるか混乱することでしょう (何も起こりませんが)。)
45754704同様に CASE 3 と CASE 4 の動作も等しく、$x の値を返す以外に
45764705何もしない C<$x> というコードを実行します
45774706(純粋に見た目の問題で、CASE 4 が好まれますが、
45784707実行時でなくコンパイル時にコンパイルされるという利点もあります)。
45794708CASE 5 の場合は、通常ダブルクォートを使用 I<します>;
45804709この状況を除けば、CASE 6 のように、単に
45814710シンボリックリファレンスを使えば良いでしょう。
45824711
45834712=begin original
45844713
45854714An C<eval ''> executed within a subroutine defined
45864715in the C<DB> package doesn't see the usual
45874716surrounding lexical scope, but rather the scope of the first non-DB piece
45884717of code that called it. You don't normally need to worry about this unless
45894718you are writing a Perl debugger.
45904719
45914720=end original
45924721
45934722C<DB> パッケージで定義されたサブルーチン内で C<eval ''> を実行すると、通常の
45944723レキシカルスコープではなく、これを呼び出した最初の非 DB コード片の
45954724スコープになります。
45964725Perl デバッガを書いているのでない限り、普通はこれについて心配する必要は
45974726ありません。
45984727
45994728=begin original
46004729
46014730The final semicolon, if any, may be omitted from the value of EXPR.
46024731
46034732=end original
46044733
46054734最後のセミコロンは、もしあれば、EXPR の値から省くことができます。
46064735
46074736=item Block eval
46084737
46094738=begin original
46104739
46114740If the code to be executed doesn't vary, you may use the eval-BLOCK
46124741form to trap run-time errors without incurring the penalty of
46134742recompiling each time. The error, if any, is still returned in
46144743L<C<$@>|perlvar/$@>.
46154744Examples:
46164745
46174746=end original
46184747
46194748実行するコードが変わらないのであれば、毎回多量の再コンパイルすることなしに、
46204749実行時エラーのトラップを行なうために、
46214750eval-BLOCK 形式を使うことができます。
46224751エラーがあれば、やはり L<C<$@>|perlvar/$@> に返されます。
46234752例:
46244753
46254754 # make divide-by-zero nonfatal
46264755 eval { $answer = $a / $b; }; warn $@ if $@;
46274756
46284757 # same thing, but less efficient
46294758 eval '$answer = $a / $b'; warn $@ if $@;
46304759
46314760 # a compile-time error
46324761 eval { $answer = }; # WRONG
46334762
46344763 # a run-time error
46354764 eval '$answer ='; # sets $@
46364765
46374766=begin original
46384767
46394768If you want to trap errors when loading an XS module, some problems with
46404769the binary interface (such as Perl version skew) may be fatal even with
46414770C<eval> unless C<$ENV{PERL_DL_NONLAZY}> is set. See
4642L<perlrun>.
4771L<perlrun|perlrun/PERL_DL_NONLAZY>.
46434772
46444773=end original
46454774
46464775XS モジュールのロード中のエラーをトラップしたいなら、
46474776(Perl バージョンの違いのような) バイナリインターフェースに関する問題に
46484777ついては C<$ENV{PERL_DL_NONLAZY}> がセットされていない
46494778C<eval> でも致命的エラーになるかもしれません。
4650L<perlrun> を参照してください。
4779L<perlrun|perlrun/PERL_DL_NONLAZY> を参照してください。
46514780
46524781=begin original
46534782
46544783Using the C<eval {}> form as an exception trap in libraries does have some
46554784issues. Due to the current arguably broken state of C<__DIE__> hooks, you
46564785may wish not to trigger any C<__DIE__> hooks that user code may have installed.
46574786You can use the C<local $SIG{__DIE__}> construct for this purpose,
46584787as this example shows:
46594788
46604789=end original
46614790
46624791C<eval{}> 形式をライブラリの例外を捕捉するために使うときには
46634792問題があります。
46644793現在の C<__DIE__> フックの状態はほぼ確実に壊れているという理由で、
46654794ユーザーのコードが設定した C<__DIE__> フックを実行したくないかもしれません。
46664795この目的には以下の例のように、C<local $SIG{__DIE__}> 構造が使えます。
46674796
46684797 # a private exception trap for divide-by-zero
46694798 eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
46704799 warn $@ if $@;
46714800
46724801=begin original
46734802
46744803This is especially significant, given that C<__DIE__> hooks can call
46754804L<C<die>|/die LIST> again, which has the effect of changing their error
46764805messages:
46774806
46784807=end original
46794808
46804809これは特に顕著です; 与えられた C<__DIE__> フックは L<C<die>|/die LIST> を
46814810もう一度呼び出すことができ、これによってエラーメッセージを変える
46824811効果があります:
46834812
46844813 # __DIE__ hooks may modify error messages
46854814 {
46864815 local $SIG{'__DIE__'} =
46874816 sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
46884817 eval { die "foo lives here" };
46894818 print $@ if $@; # prints "bar lives here"
46904819 }
46914820
46924821=begin original
46934822
46944823Because this promotes action at a distance, this counterintuitive behavior
46954824may be fixed in a future release.
46964825
46974826=end original
46984827
46994828これは距離の離れた行動であるため、この直感的でない振る舞いは
47004829将来のリリースでは修正されるかもしれません。
47014830
47024831=begin original
47034832
47044833C<eval BLOCK> does I<not> count as a loop, so the loop control statements
47054834L<C<next>|/next LABEL>, L<C<last>|/last LABEL>, or
47064835L<C<redo>|/redo LABEL> cannot be used to leave or restart the block.
47074836
47084837=end original
47094838
47104839C<eval BLOCK> はループとして I<扱われません>; 従って、L<C<next>|/next LABEL>,
47114840L<C<last>|/last LABEL>, L<C<redo>|/redo LABEL> といったループ制御文で
47124841ブロックから離れたり再実行したりはできません。
47134842
47144843=begin original
47154844
47164845The final semicolon, if any, may be omitted from within the BLOCK.
47174846
47184847=end original
47194848
47204849最後のセミコロンは、もしあれば、BLOCK の中から削除されます。
47214850
47224851=back
47234852
47244853=item evalbytes EXPR
47254854X<evalbytes>
47264855
47274856=item evalbytes
47284857
47294858=for Pod::Functions +evalbytes similar to string eval, but intend to parse a bytestream
47304859
47314860=begin original
47324861
47334862This function is similar to a L<string eval|/eval EXPR>, except it
47344863always parses its argument (or L<C<$_>|perlvar/$_> if EXPR is omitted)
47354864as a string of independent bytes.
47364865
47374866=end original
47384867
47394868この関数は L<文字列 eval|/eval EXPR> に似ていますが、引数(EXPR が
47404869省略された場合はL<C<$_>|perlvar/$_>) を常にバイト単位のの文字列として
47414870扱います。
47424871
47434872=begin original
47444873
47454874If called when S<C<use utf8>> is in effect, the string will be assumed
47464875to be encoded in UTF-8, and C<evalbytes> will make a temporary copy to
47474876work from, downgraded to non-UTF-8. If this is not possible
47484877(because one or more characters in it require UTF-8), the C<evalbytes>
47494878will fail with the error stored in C<$@>.
47504879
47514880=end original
47524881
47534882S<C<use utf8>> が有効のときに呼び出されると、
47544883文字列は UTF-8 でエンコードされていると仮定され、
47554884C<evalbytes> は、非 UTF-8 にダウングレードした一時的なコピーを作ります。
47564885(UTF-8 が必要な文字があるために) これが不可能な場合、
47574886C<evalbytes> は失敗し、エラーは C<$@> に保管されます。
47584887
47594888=begin original
47604889
47614890Bytes that correspond to ASCII-range code points will have their normal
47624891meanings for operators in the string. The treatment of the other bytes
47634892depends on if the L<C<'unicode_strings"> feature|feature/The
47644893'unicode_strings' feature> is in effect.
47654894
47664895=end original
47674896
47684897ASCII の範囲の符号位置に対応するバイトは、
47694898文字列の操作に関して通常の意味を持ちます。
47704899その他のバイトの扱いは、
47714900<C<'unicode_strings"> feature|feature/'unicode_strings' 機能> が有効の場合か
47724901どうかに依存します。
47734902
47744903=begin original
47754904
47764905Of course, variables that are UTF-8 and are referred to in the string
47774906retain that:
47784907
47794908=end original
47804909
47814910もちろん、UTF-8 で文字列の中で参照されている変数はそのままです:
47824911
47834912 my $a = "\x{100}";
47844913 evalbytes 'print ord $a, "\n"';
47854914
47864915=begin original
47874916
47884917prints
47894918
47904919=end original
47914920
47924921というのは、次を表示し、
47934922
47944923 256
47954924
47964925=begin original
47974926
47984927and C<$@> is empty.
47994928
48004929=end original
48014930
48024931C<$@> は空になります。
48034932
48044933=begin original
48054934
48064935Source filters activated within the evaluated code apply to the code
48074936itself.
48084937
48094938=end original
48104939
48114940eval されたコード内で有効になったソースフィルタはコード自体に適用されます。
48124941
48134942=begin original
48144943
48154944L<C<evalbytes>|/evalbytes EXPR> is available starting in Perl v5.16. To
48164945access it, you must say C<CORE::evalbytes>, but you can omit the
48174946C<CORE::> if the
48184947L<C<"evalbytes"> feature|feature/The 'unicode_eval' and 'evalbytes' features>
48194948is enabled. This is enabled automatically with a C<use v5.16> (or
48204949higher) declaration in the current scope.
48214950
48224951=end original
48234952
48244953L<C<evalbytes>|/evalbytes EXPR> は Perl v5.16 から利用可能です。
48254954これにアクセスするには C<CORE::evalbytes> とする必要がありますが、
48264955L<C<"evalbytes"> 機能|feature/The 'unicode_eval' and 'evalbytes' features> が
48274956有効なら C<CORE::> を省略できます。
48284957これは現在のスコープで C<use v5.16> (またはそれ以上) 宣言があると
48294958自動的に有効になります。
48304959
48314960=item exec LIST
48324961X<exec> X<execute>
48334962
48344963=item exec PROGRAM LIST
48354964
48364965=for Pod::Functions abandon this program to run another
48374966
48384967=begin original
48394968
48404969The L<C<exec>|/exec LIST> function executes a system command I<and never
48414970returns>; use L<C<system>|/system LIST> instead of L<C<exec>|/exec LIST>
48424971if you want it to return. It fails and
48434972returns false only if the command does not exist I<and> it is executed
48444973directly instead of via your system's command shell (see below).
48454974
48464975=end original
48474976
48484977L<C<exec>|/exec LIST> 関数は、システムのコマンドを実行し、I<戻ってはきません>;
48494978戻って欲しい場合には、L<C<exec>|/exec LIST>ではなく
48504979L<C<system>|/system LIST> 関数を使ってください。
48514980コマンドが存在せず、I<しかも> システムのコマンドシェル経由でなく
48524981直接コマンドを実行しようとした場合にのみこの関数は失敗して偽を返します。
48534982
48544983=begin original
48554984
48564985Since it's a common mistake to use L<C<exec>|/exec LIST> instead of
48574986L<C<system>|/system LIST>, Perl warns you if L<C<exec>|/exec LIST> is
48584987called in void context and if there is a following statement that isn't
48594988L<C<die>|/die LIST>, L<C<warn>|/warn LIST>, or L<C<exit>|/exit EXPR> (if
48604989L<warnings> are enabled--but you always do that, right?). If you
48614990I<really> want to follow an L<C<exec>|/exec LIST> with some other
48624991statement, you can use one of these styles to avoid the warning:
48634992
48644993=end original
48654994
48664995L<C<system>|/system LIST> の代わりに L<C<exec>|/exec LIST> を使うという
48674996よくある間違いを防ぐために、L<C<exec>|/exec LIST> が無効コンテキストで
48684997呼び出されて、引き続く文が L<C<die>|/die LIST>, L<C<warn>|/warn LIST>,
48694998L<C<exit>|/exit EXPR> 以外の場合、Perl は警告を出します(L<warnings> が
48704999有効の場合 -- でもいつもセットしてますよね?)。
48715000もし I<本当に> L<C<exec>|/exec LIST> の後に他の文を書きたい場合、以下の
48725001どちらかのスタイルを使うことで警告を回避できます:
48735002
48745003 exec ('foo') or print STDERR "couldn't exec foo: $!";
48755004 { exec ('foo') }; print STDERR "couldn't exec foo: $!";
48765005
48775006=begin original
48785007
48795008If there is more than one argument in LIST, this calls L<execvp(3)> with the
48805009arguments in LIST. If there is only one element in LIST, the argument is
48815010checked for shell metacharacters, and if there are any, the entire
48825011argument is passed to the system's command shell for parsing (this is
48835012C</bin/sh -c> on Unix platforms, but varies on other platforms). If
48845013there are no shell metacharacters in the argument, it is split into words
48855014and passed directly to C<execvp>, which is more efficient. Examples:
48865015
48875016=end original
48885017
48895018LIST に複数の引数がある場合は、LIST の引数を使って L<execvp(3)> を
48905019呼び出します。
48915020LIST に要素が一つのみの場合には、その引数からシェルのメタ文字をチェックし、
48925021もしメタ文字があれば、引数全体をシステムのコマンドシェル(これはUnix では
48935022C</bin/sh -c> ですが、システムによって異なります)に渡して解析させます。
48945023シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に
48955024渡されます; この方がより効率的です。
48965025例:
48975026
48985027 exec '/bin/echo', 'Your arguments are: ', @ARGV;
48995028 exec "sort $outfile | uniq";
49005029
49015030=begin original
49025031
49035032If you don't really want to execute the first argument, but want to lie
49045033to the program you are executing about its own name, you can specify
49055034the program you actually want to run as an "indirect object" (without a
49065035comma) in front of the LIST, as in C<exec PROGRAM LIST>. (This always
49075036forces interpretation of the LIST as a multivalued list, even if there
49085037is only a single scalar in the list.) Example:
49095038
49105039=end original
49115040
49125041第一引数に指定するものを本当に実行したいが、実行するプログラムに対して別の
49135042名前を教えたい場合には、C<exec PROGRAM LIST> のように、LIST の前に
49145043「間接オブジェクト」(コンマなし) として実際に実行したいプログラムを
49155044指定することができます。
49165045(これによって、LIST に単一のスカラしかなくても、複数値のリストであるように、
49175046LIST の解釈を行ないます。)
49185047例:
49195048
49205049 my $shell = '/bin/csh';
49215050 exec $shell '-sh'; # pretend it's a login shell
49225051
49235052=begin original
49245053
49255054or, more directly,
49265055
49275056=end original
49285057
49295058あるいは、より直接的に、
49305059
49315060 exec {'/bin/csh'} '-sh'; # pretend it's a login shell
49325061
49335062=begin original
49345063
49355064When the arguments get executed via the system shell, results are
49365065subject to its quirks and capabilities. See L<perlop/"`STRING`">
49375066for details.
49385067
49395068=end original
49405069
49415070引数がシステムシェルで実行されるとき、結果はシェルの奇癖と能力によって
49425071変わります。
49435072詳細については L<perlop/"`STRING`"> を参照してください。
49445073
49455074=begin original
49465075
49475076Using an indirect object with L<C<exec>|/exec LIST> or
49485077L<C<system>|/system LIST> is also more secure. This usage (which also
49495078works fine with L<C<system>|/system LIST>) forces
49505079interpretation of the arguments as a multivalued list, even if the
49515080list had just one argument. That way you're safe from the shell
49525081expanding wildcards or splitting up words with whitespace in them.
49535082
49545083=end original
49555084
49565085L<C<exec>|/exec LIST> や L<C<system>|/system LIST> で間接オブジェクトを
49575086使うのもより安全です。
49585087この使い方(L<C<system>|/system LIST> でも同様にうまく動きます)は、たとえ
49595088引数が一つだけの場合も、複数の値を持つリストとして引数を解釈することを
49605089強制します。
49615090この方法で、シェルによるワイルドカード展開や、空白による単語の分割から
49625091守られます。
49635092
49645093 my @args = ( "echo surprise" );
49655094
49665095 exec @args; # subject to shell escapes
49675096 # if @args == 1
49685097 exec { $args[0] } @args; # safe even with one-arg list
49695098
49705099=begin original
49715100
49725101The first version, the one without the indirect object, ran the I<echo>
49735102program, passing it C<"surprise"> an argument. The second version didn't;
49745103it tried to run a program named I<"echo surprise">, didn't find it, and set
49755104L<C<$?>|perlvar/$?> to a non-zero value indicating failure.
49765105
49775106=end original
49785107
49795108間接オブジェクトなしの一つ目のバージョンでは、I<echo> プログラムが実行され、
49805109C<"surprise"> が引数として渡されます。
49815110二つ目のバージョンでは違います; I<"echo surprise"> という名前の
49825111プログラムを実行しようとして、見つからないので、失敗したことを示すために
49835112L<C<$?>|perlvar/$?> に非 0 がセットされます。
49845113
49855114=begin original
49865115
49875116On Windows, only the C<exec PROGRAM LIST> indirect object syntax will
49885117reliably avoid using the shell; C<exec LIST>, even with more than one
49895118element, will fall back to the shell if the first spawn fails.
49905119
49915120=end original
49925121
49935122Windows では、C<exec PROGRAM LIST> 間接オブジェクト構文のみが、シェルを
49945123使うのを回避するための信頼できる方法です; C<exec LIST> は、複数の要素が
49955124あっても、最初の spawn が失敗したときにシェルに
49965125フォールバックすることがあります。
49975126
49985127=begin original
49995128
50005129Perl attempts to flush all files opened for output before the exec,
50015130but this may not be supported on some platforms (see L<perlport>).
50025131To be safe, you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
50035132(C<$AUTOFLUSH> in L<English>) or call the C<autoflush> method of
50045133L<C<IO::Handle>|IO::Handle/METHODS> on any open handles to avoid lost
50055134output.
50065135
50075136=end original
50085137
50095138v5.6.0 から、Perl は exec の前に出力用に開かれている全てのファイルを
50105139フラッシュしようとしますが、これに対応していないプラットフォームもあります
50115140(L<perlport> を参照してください)。
50125141安全のためには、出力が重複するのを避けるために、全てのオープンしている
50135142ハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
50145143(L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、
50155144L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
50165145呼ぶ必要があるかもしれません。
50175146
50185147=begin original
50195148
50205149Note that L<C<exec>|/exec LIST> will not call your C<END> blocks, nor
50215150will it invoke C<DESTROY> methods on your objects.
50225151
50235152=end original
50245153
50255154L<C<exec>|/exec LIST> は C<END> ブロックや、オブジェクトの
50265155C<DESTROY> メソッドを起動しないことに注意してください。
50275156
50285157=begin original
50295158
50305159Portability issues: L<perlport/exec>.
50315160
50325161=end original
50335162
50345163移植性の問題: L<perlport/exec>。
50355164
50365165=item exists EXPR
50375166X<exists> X<autovivification>
50385167
50395168=for Pod::Functions test whether a hash key is present
50405169
50415170=begin original
50425171
50435172Given an expression that specifies an element of a hash, returns true if the
50445173specified element in the hash has ever been initialized, even if the
50455174corresponding value is undefined.
50465175
50475176=end original
50485177
50495178ハッシュ要素を示す表現が与えられ、指定された要素が、ハッシュに存在すれば、
50505179たとえ対応する値が未定義でも真を返します。
50515180
50525181 print "Exists\n" if exists $hash{$key};
50535182 print "Defined\n" if defined $hash{$key};
50545183 print "True\n" if $hash{$key};
50555184
50565185=begin original
50575186
50585187exists may also be called on array elements, but its behavior is much less
50595188obvious and is strongly tied to the use of L<C<delete>|/delete EXPR> on
50605189arrays.
50615190
50625191=end original
50635192
50645193exists は配列の要素に対しても呼び出せますが、その振る舞いははるかに
50655194不明確で、配列に対する L<C<delete>|/delete EXPR> の使用と強く
50665195結びついています。
50675196
50685197=begin original
50695198
50705199B<WARNING:> Calling L<C<exists>|/exists EXPR> on array values is
50715200strongly discouraged. The
50725201notion of deleting or checking the existence of Perl array elements is not
50735202conceptually coherent, and can lead to surprising behavior.
50745203
50755204=end original
50765205
50775206B<警告:> 配列の値に対して L<C<exists>|/exists EXPR> を呼び出すことは強く
50785207非推奨です。
50795208Perl の配列要素を削除したり存在を調べたりする記法は概念的に一貫しておらず、
50805209驚くべき振る舞いを引き起こすことがあります。
50815210
50825211 print "Exists\n" if exists $array[$index];
50835212 print "Defined\n" if defined $array[$index];
50845213 print "True\n" if $array[$index];
50855214
50865215=begin original
50875216
50885217A hash or array element can be true only if it's defined and defined only if
50895218it exists, but the reverse doesn't necessarily hold true.
50905219
50915220=end original
50925221
50935222ハッシュまたは配列要素は、定義されているときにのみ真となり、
50945223存在しているときにのみ定義されますが、逆は必ずしも真ではありません。
50955224
50965225=begin original
50975226
50985227Given an expression that specifies the name of a subroutine,
50995228returns true if the specified subroutine has ever been declared, even
51005229if it is undefined. Mentioning a subroutine name for exists or defined
51015230does not count as declaring it. Note that a subroutine that does not
51025231exist may still be callable: its package may have an C<AUTOLOAD>
51035232method that makes it spring into existence the first time that it is
51045233called; see L<perlsub>.
51055234
51065235=end original
51075236
51085237引数としてサブルーチンの名前が指定された場合、
51095238指定されたサブルーチンが宣言されていれば(たとえ未定義でも)
51105239真を返します。
51115240exists や defined のために言及されているサブルーチン名は
51125241宣言としてのカウントに入りません。
51135242存在しないサブルーチンでも呼び出し可能かもしれないことに注意してください:
51145243パッケージが C<AUTOLOAD> メソッドを持っていて、最初に呼び出された時に
51155244存在を作り出すかもしれません; L<perlsub> を参照してください。
51165245
51175246 print "Exists\n" if exists &subroutine;
51185247 print "Defined\n" if defined &subroutine;
51195248
51205249=begin original
51215250
51225251Note that the EXPR can be arbitrarily complicated as long as the final
51235252operation is a hash or array key lookup or subroutine name:
51245253
51255254=end original
51265255
51275256最終的な操作がハッシュや配列の key による検索または
51285257サブルーチン名である限りは、EXPR には任意の複雑な式を置くことができます:
51295258
51305259 if (exists $ref->{A}->{B}->{$key}) { }
51315260 if (exists $hash{A}{B}{$key}) { }
51325261
51335262 if (exists $ref->{A}->{B}->[$ix]) { }
51345263 if (exists $hash{A}{B}[$ix]) { }
51355264
51365265 if (exists &{$ref->{A}{B}{$key}}) { }
51375266
51385267=begin original
51395268
51405269Although the most deeply nested array or hash element will not spring into
51415270existence just because its existence was tested, any intervening ones will.
51425271Thus C<< $ref->{"A"} >> and C<< $ref->{"A"}->{"B"} >> will spring
51435272into existence due to the existence test for the C<$key> element above.
51445273This happens anywhere the arrow operator is used, including even here:
51455274
51465275=end original
51475276
51485277最も深くネストした配列やハッシュの要素は、その存在をテストしただけでは
51495278存在するようにはなりませんが、途中のものは存在するようになります。
51505279従って C<< $ref->{"A"} >> と C<< $ref->{"A"}->{"B"} >> は上記の C<$key> の
51515280存在をテストしたことによって存在するようになります。
51525281これは、矢印演算子が使われるところでは、以下のようなものを含むどこででも
51535282起こります。
51545283
51555284 undef $ref;
51565285 if (exists $ref->{"Some key"}) { }
51575286 print $ref; # prints HASH(0x80d3d5c)
51585287
51595288=begin original
51605289
5161This surprising autovivification in what does not at first--or even
5162second--glance appear to be an lvalue context may be fixed in a future
5163release.
5164
5165=end original
5166
5167一目見ただけでは -- あるいは二目見ても -- 驚かされる、左辺値コンテキストでの
5168自動有効化は将来のリリースでは修正されるでしょう。
5169
5170=begin original
5171
51725290Use of a subroutine call, rather than a subroutine name, as an argument
51735291to L<C<exists>|/exists EXPR> is an error.
51745292
51755293=end original
51765294
51775295L<C<exists>|/exists EXPR> の引数としてサブルーチン名でなくサブルーチン
51785296呼び出しを使うと、エラーになります。
51795297
51805298 exists &sub; # OK
51815299 exists &sub(); # Error
51825300
51835301=item exit EXPR
51845302X<exit> X<terminate> X<abort>
51855303
51865304=item exit
51875305
51885306=for Pod::Functions terminate this program
51895307
51905308=begin original
51915309
51925310Evaluates EXPR and exits immediately with that value. Example:
51935311
51945312=end original
51955313
51965314EXPR を評価し、即座にその値を持って終了します。
51975315例:
51985316
51995317 my $ans = <STDIN>;
52005318 exit 0 if $ans =~ /^[Xx]/;
52015319
52025320=begin original
52035321
52045322See also L<C<die>|/die LIST>. If EXPR is omitted, exits with C<0>
52055323status. The only
52065324universally recognized values for EXPR are C<0> for success and C<1>
52075325for error; other values are subject to interpretation depending on the
52085326environment in which the Perl program is running. For example, exiting
5209532769 (EX_UNAVAILABLE) from a I<sendmail> incoming-mail filter will cause
52105328the mailer to return the item undelivered, but that's not true everywhere.
52115329
52125330=end original
52135331
52145332L<C<die>|/die LIST> も参照してください。
52155333EXPR が省略された場合には、ステータスを C<0> として終了します。
52165334EXPR の値として広く利用可能なのは C<0> が成功で C<1> が
52175335エラーということだけです; その他の値は、 Perl が実行される環境によって異なる
52185336解釈がされる可能性があります。
52195337例えば、I<sendmail> 到着メールフィルタから 69 (EX_UNAVAILABLE) で終了すると
52205338メーラーはアイテムを配達せずに差し戻しますが、
52215339これはいつでも真ではありません。
52225340
52235341=begin original
52245342
52255343Don't use L<C<exit>|/exit EXPR> to abort a subroutine if there's any
52265344chance that someone might want to trap whatever error happened. Use
52275345L<C<die>|/die LIST> instead, which can be trapped by an
52285346L<C<eval>|/eval EXPR>.
52295347
52305348=end original
52315349
52325350誰かが発生したエラーをトラップしようと考えている可能性がある場合は、
52335351サブルーチンの中断に L<C<exit>|/exit EXPR> を使わないでください。
52345352代わりに L<C<eval>|/eval EXPR> でトラップできる L<C<die>|/die LIST> を
52355353使ってください。
52365354
52375355=begin original
52385356
52395357The L<C<exit>|/exit EXPR> function does not always exit immediately. It
52405358calls any defined C<END> routines first, but these C<END> routines may
52415359not themselves abort the exit. Likewise any object destructors that
52425360need to be called are called before the real exit. C<END> routines and
52435361destructors can change the exit status by modifying L<C<$?>|perlvar/$?>.
52445362If this is a problem, you can call
52455363L<C<POSIX::_exit($status)>|POSIX/C<_exit>> to avoid C<END> and destructor
52465364processing. See L<perlmod> for details.
52475365
52485366=end original
52495367
52505368L<C<exit>|/exit EXPR> 関数は常に直ちに終了するわけではありません。
52515369まず、定義されている C<END> ルーチンを呼び出しますが、
52525370C<END> ルーチン自身は exit を止められません。
52535371同様に、呼び出す必要のあるオブジェクトデストラクタは
52545372すべて、実際の終了前に呼び出されます。
52555373C<END> ルーチンとデストラクタは L<C<$?>|perlvar/$?> を修正することで
52565374終了コードを変更できます。
52575375これが問題になる場合は、C<END> やデストラクタが実行されることを
52585376防ぐために L<C<POSIX::_exit($status)>|POSIX/C<_exit>> を呼び出してください。
52595377詳しくは L<perlmod> を参照してください。
52605378
52615379=begin original
52625380
52635381Portability issues: L<perlport/exit>.
52645382
52655383=end original
52665384
52675385移植性の問題: L<perlport/exit>。
52685386
52695387=item exp EXPR
52705388X<exp> X<exponential> X<antilog> X<antilogarithm> X<e>
52715389
52725390=item exp
52735391
52745392=for Pod::Functions raise I<e> to a power
52755393
52765394=begin original
52775395
52785396Returns I<e> (the natural logarithm base) to the power of EXPR.
52795397If EXPR is omitted, gives C<exp($_)>.
52805398
52815399=end original
52825400
52835401I<e> (自然対数の底) の EXPR 乗を返します。
52845402EXPR を省略した場合には、C<exp($_)> を返します。
52855403
52865404=item fc EXPR
52875405X<fc> X<foldcase> X<casefold> X<fold-case> X<case-fold>
52885406
52895407=item fc
52905408
52915409=for Pod::Functions +fc return casefolded version of a string
52925410
52935411=begin original
52945412
52955413Returns the casefolded version of EXPR. This is the internal function
52965414implementing the C<\F> escape in double-quoted strings.
52975415
52985416=end original
52995417
53005418EXPR の畳み込み版を返します。
53015419これは、ダブルクォート文字列における、C<\F> エスケープを
53025420実装する内部関数です。
53035421
53045422=begin original
53055423
53065424Casefolding is the process of mapping strings to a form where case
53075425differences are erased; comparing two strings in their casefolded
53085426form is effectively a way of asking if two strings are equal,
53095427regardless of case.
53105428
53115429=end original
53125430
53135431畳み込みは大文字小文字の違いを消した形式に文字列をマッピングする処理です;
53145432畳み込み形式で二つの文字列を比較するのは二つの文字列が大文字小文字に
53155433関わらず等しいかどうかを比較する効率的な方法です。
53165434
53175435=begin original
53185436
53195437Roughly, if you ever found yourself writing this
53205438
53215439=end original
53225440
53235441おおよそ、自分自身で以下のように書いていたとしても
53245442
53255443 lc($this) eq lc($that) # Wrong!
53265444 # or
53275445 uc($this) eq uc($that) # Also wrong!
53285446 # or
53295447 $this =~ /^\Q$that\E\z/i # Right!
53305448
53315449=begin original
53325450
53335451Now you can write
53345452
53355453=end original
53365454
53375455今では以下のように書けます
53385456
53395457 fc($this) eq fc($that)
53405458
53415459=begin original
53425460
53435461And get the correct results.
53445462
53455463=end original
53465464
53475465そして正しい結果を得られます。
53485466
53495467=begin original
53505468
53515469Perl only implements the full form of casefolding, but you can access
53525470the simple folds using L<Unicode::UCD/B<casefold()>> and
53535471L<Unicode::UCD/B<prop_invmap()>>.
53545472For further information on casefolding, refer to
53555473the Unicode Standard, specifically sections 3.13 C<Default Case Operations>,
535654744.2 C<Case-Normative>, and 5.18 C<Case Mappings>,
5357available at L<http://www.unicode.org/versions/latest/>, as well as the
5475available at L<https://www.unicode.org/versions/latest/>, as well as the
5358Case Charts available at L<http://www.unicode.org/charts/case/>.
5476Case Charts available at L<https://www.unicode.org/charts/case/>.
53595477
53605478=end original
53615479
53625480Perl は完全な形式の畳み込みのみを実装していますが、
53635481L<Unicode::UCD/B<casefold()>> と L<Unicode::UCD/B<prop_invmap()>> を使って
53645482単純なたたみ込みにアクセスできます。
53655483畳み込みに関するさらなる情報については、
5366L<http://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に
5484L<https://www.unicode.org/versions/latest/> で利用可能な Unicode 標準、特に
536754853.13 C<Default Case Operations>, 4.2 C<Case-Normative>, 5.18
5368C<Case Mappings> および、L<http://www.unicode.org/charts/case/> で
5486C<Case Mappings> および、L<https://www.unicode.org/charts/case/> で
53695487利用可能なケース表を参照してください。
53705488
53715489=begin original
53725490
53735491If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
53745492
53755493=end original
53765494
53775495EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
53785496
53795497=begin original
53805498
53815499This function behaves the same way under various pragmas, such as within
53825500L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>,
53835501as L<C<lc>|/lc EXPR> does, with the single exception of
53845502L<C<fc>|/fc EXPR> of I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) within the
53855503scope of L<S<C<use locale>>|locale>. The foldcase of this character
53865504would normally be C<"ss">, but as explained in the L<C<lc>|/lc EXPR>
53875505section, case
53885506changes that cross the 255/256 boundary are problematic under locales,
53895507and are hence prohibited. Therefore, this function under locale returns
53905508instead the string C<"\x{17F}\x{17F}">, which is the I<LATIN SMALL LETTER
53915509LONG S>. Since that character itself folds to C<"s">, the string of two
53925510of them together should be equivalent to a single U+1E9E when foldcased.
53935511
53945512=end original
53955513
53965514この関数は、
53975515L<S<C<"use feature 'unicode_strings">>|feature/The 'unicode_strings' feature>
53985516のようなさまざまなプラグマの影響下では、L<C<lc>|/lc EXPR> と同様に
53995517振る舞います;
54005518但し、L<S<C<use locale>>|locale> のスコープ内での
54015519I<LATIN CAPITAL LETTER SHARP S> (U+1E9E) の L<C<fc>|/fc EXPR> は例外です。
54025520この文字の畳み込み文字は普通は C<"ss"> ですが、L<C<lc>|/lc EXPR> の節で
54035521説明しているように、ロケールの基での255/256 境界をまたぐ大文字小文字の変更は
54045522問題があるので、禁止されています。
54055523従って、ロケールの基ではこの関数は代わりに I<LATIN SMALL LETTER LONG S> である
54065524C<"\x{17F}\x{17F}"> を返します。
54075525この文字自体は C<"s"> の畳み込みなので、これら二つを合わせた文字列は
54085526畳み込まれた場合は単一の U+1E9E と等価になります。
54095527
54105528=begin original
54115529
54125530While the Unicode Standard defines two additional forms of casefolding,
54135531one for Turkic languages and one that never maps one character into multiple
54145532characters, these are not provided by the Perl core. However, the CPAN module
54155533L<C<Unicode::Casing>|Unicode::Casing> may be used to provide an implementation.
54165534
54175535=end original
54185536
54195537Unicode 標準はさらに二つの畳み込み形式、一つはツルキ語、もう一つは決して
54205538一つの文字が複数の文字にマッピングされないもの、を定義していますが、
54215539これらは Perl コアでは提供されません。
54225540しかし、CPAN モジュール L<C<Unicode::Casing>|Unicode::Casing> が実装を
54235541提供しています。
54245542
54255543=begin original
54265544
54275545L<C<fc>|/fc EXPR> is available only if the
54285546L<C<"fc"> feature|feature/The 'fc' feature> is enabled or if it is
54295547prefixed with C<CORE::>. The
54305548L<C<"fc"> feature|feature/The 'fc' feature> is enabled automatically
54315549with a C<use v5.16> (or higher) declaration in the current scope.
54325550
54335551=end original
54345552
54355553L<C<fc>|/fc EXPR> は L<C<"fc"> 機能|feature/The 'fc' feature> が有効か
54365554C<CORE::> が前置されたときにのみ利用可能です。
54375555L<C<"fc"> 機能|feature/The 'fc' feature> は現在のスコープで
54385556C<use v5.16> (またはそれ以上) が宣言されると自動的に有効になります。
54395557
54405558=item fcntl FILEHANDLE,FUNCTION,SCALAR
54415559X<fcntl>
54425560
54435561=for Pod::Functions file control system call
54445562
54455563=begin original
54465564
54475565Implements the L<fcntl(2)> function. You'll probably have to say
54485566
54495567=end original
54505568
54515569L<fcntl(2)> 関数を実装します。
54525570正しい定数定義を得るために、まず
54535571
54545572 use Fcntl;
54555573
54565574=begin original
54575575
54585576first to get the correct constant definitions. Argument processing and
54595577value returned work just like L<C<ioctl>|/ioctl
54605578FILEHANDLE,FUNCTION,SCALAR> below. For example:
54615579
54625580=end original
54635581
54645582と書くことが必要でしょう。
54655583引数の処理と返り値については、下記の
54665584L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同様に動作します。
54675585例えば:
54685586
54695587 use Fcntl;
54705588 my $flags = fcntl($filehandle, F_GETFL, 0)
54715589 or die "Can't fcntl F_GETFL: $!";
54725590
54735591=begin original
54745592
54755593You don't have to check for L<C<defined>|/defined EXPR> on the return
54765594from L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>. Like
54775595L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>, it maps a C<0> return
54785596from the system call into C<"0 but true"> in Perl. This string is true
54795597in boolean context and C<0> in numeric context. It is also exempt from
54805598the normal
54815599L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
54825600L<warnings> on improper numeric conversions.
54835601
54845602=end original
54855603
54865604L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> からの返り値のチェックに
54875605L<C<defined>|/defined EXPR> を使う必要はありません。
54885606L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と違って、これは
54895607システムコールの結果が C<0> だった場合は C<"0 だが真"> を返します。
54905608この文字列は真偽値コンテキストでは真となり、
54915609数値コンテキストでは C<0> になります。
54925610これはまた、不適切な数値変換に関する通常の
54935611L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
54945612L<warnings> を回避します。
54955613
54965614=begin original
54975615
54985616Note that L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> raises an
54995617exception if used on a machine that doesn't implement L<fcntl(2)>. See
55005618the L<Fcntl> module or your L<fcntl(2)> manpage to learn what functions
55015619are available on your system.
55025620
55035621=end original
55045622
55055623L<fcntl(2)> が実装されていないマシンでは、
55065624L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> は例外を
55075625引き起こすことに注意してください。
55085626システムでどの関数が利用可能かについては L<Fcntl> モジュールや
55095627L<fcntl(2)> man ページを参照してください。
55105628
55115629=begin original
55125630
55135631Here's an example of setting a filehandle named C<$REMOTE> to be
55145632non-blocking at the system level. You'll have to negotiate
55155633L<C<$E<verbar>>|perlvar/$E<verbar>> on your own, though.
55165634
55175635=end original
55185636
55195637これは C<$REMOTE> というファイルハンドルをシステムレベルで
55205638非ブロックモードにセットする例です。
55215639ただし、 L<C<$E<verbar>>|perlvar/$E<verbar>> を自分で管理しなければなりません。
55225640
55235641 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
55245642
55255643 my $flags = fcntl($REMOTE, F_GETFL, 0)
55265644 or die "Can't get flags for the socket: $!\n";
55275645
55285646 fcntl($REMOTE, F_SETFL, $flags | O_NONBLOCK)
55295647 or die "Can't set flags for the socket: $!\n";
55305648
55315649=begin original
55325650
55335651Portability issues: L<perlport/fcntl>.
55345652
55355653=end original
55365654
55375655移植性の問題: L<perlport/fcntl>。
55385656
55395657=item __FILE__
55405658X<__FILE__>
55415659
55425660=for Pod::Functions the name of the current source file
55435661
55445662=begin original
55455663
55465664A special token that returns the name of the file in which it occurs.
5665It can be altered by the mechanism described at
5666L<perlsyn/"Plain Old Comments (Not!)">.
55475667
55485668=end original
55495669
55505670これが書いてあるファイルの名前を返す特殊トークン。
5671L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って
5672置き換えられます。
55515673
55525674=item fileno FILEHANDLE
55535675X<fileno>
55545676
5677=item fileno DIRHANDLE
5678
55555679=for Pod::Functions return file descriptor from filehandle
55565680
55575681=begin original
55585682
5559Returns the file descriptor for a filehandle, or undefined if the
5683Returns the file descriptor for a filehandle or directory handle,
5684or undefined if the
55605685filehandle is not open. If there is no real file descriptor at the OS
55615686level, as can happen with filehandles connected to memory objects via
5562L<C<open>|/open FILEHANDLE,EXPR> with a reference for the third
5687L<C<open>|/open FILEHANDLE,MODE,EXPR> with a reference for the third
55635688argument, -1 is returned.
55645689
55655690=end original
55665691
5567ファイルハンドルに対するファイル記述子を返します; ファイルハンドルが
5692ファイルハンドルやディレクトリハンドルに対するファイル記述子を返します;
5568オープンしていない場合は未定義値を返します。
5693ファイルハンドルがオープンしていない場合は未定義値を返します。
5569OS レベルで実際のファイル記述子がない(L<C<open>|/open FILEHANDLE,EXPR> の
5694OS レベルで実際のファイル記述子がない(
5570第 3 引数にリファレンスを
5695L<C<open>|/open FILEHANDLE,MODE,EXPR> の第 3 引数にリファレンスを
55715696指定してファイルハンドルがメモリオブジェクトと結びつけられたときに
55725697起こります)場合、-1 が返されます。
55735698
55745699=begin original
55755700
55765701This is mainly useful for constructing bitmaps for
55775702L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> and low-level POSIX
55785703tty-handling operations.
55795704If FILEHANDLE is an expression, the value is taken as an indirect
55805705filehandle, generally its name.
55815706
55825707=end original
55835708
55845709これは主に L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> や低レベル
55855710POSIX tty 操作に対する、ビットマップを構成するときに便利です。
55865711FILEHANDLE が式であれば、
55875712その値が間接ファイルハンドル(普通は名前)として使われます。
55885713
55895714=begin original
55905715
55915716You can use this to find out whether two handles refer to the
55925717same underlying descriptor:
55935718
55945719=end original
55955720
55965721これを、二つのハンドルが同じ識別子を参照しているかどうかを見つけるのに
55975722使えます:
55985723
55995724 if (fileno($this) != -1 && fileno($this) == fileno($that)) {
56005725 print "\$this and \$that are dups\n";
56015726 } elsif (fileno($this) != -1 && fileno($that) != -1) {
56025727 print "\$this and \$that have different " .
56035728 "underlying file descriptors\n";
56045729 } else {
56055730 print "At least one of \$this and \$that does " .
56065731 "not have a real file descriptor\n";
56075732 }
56085733
56095734=begin original
56105735
56115736The behavior of L<C<fileno>|/fileno FILEHANDLE> on a directory handle
56125737depends on the operating system. On a system with L<dirfd(3)> or
56135738similar, L<C<fileno>|/fileno FILEHANDLE> on a directory
56145739handle returns the underlying file descriptor associated with the
56155740handle; on systems with no such support, it returns the undefined value,
56165741and sets L<C<$!>|perlvar/$!> (errno).
56175742
56185743=end original
56195744
56205745ディレクトリハンドルに対する L<C<fileno>|/fileno FILEHANDLE> の振る舞いは
56215746オペレーティングシステムに依存します。
56225747L<dirfd(3)> のようなものがあるシステムでは、ディレクトリハンドルに対する
56235748L<C<fileno>|/fileno FILEHANDLE> はハンドルに関連付けられた基となる
56245749ファイル記述子を返します;
56255750そのような対応がないシステムでは、未定義値を返し、
56265751L<C<$!>|perlvar/$!> (errno) を設定します。
56275752
56285753=item flock FILEHANDLE,OPERATION
56295754X<flock> X<lock> X<locking>
56305755
56315756=for Pod::Functions lock an entire file with an advisory lock
56325757
56335758=begin original
56345759
56355760Calls L<flock(2)>, or an emulation of it, on FILEHANDLE. Returns true
56365761for success, false on failure. Produces a fatal error if used on a
56375762machine that doesn't implement L<flock(2)>, L<fcntl(2)> locking, or
56385763L<lockf(3)>. L<C<flock>|/flock FILEHANDLE,OPERATION> is Perl's portable
56395764file-locking interface, although it locks entire files only, not
56405765records.
56415766
56425767=end original
56435768
56445769FILEHANDLE に対して L<flock(2)>、またはそのエミュレーションを呼び出します。
56455770成功時には真を、失敗時には偽を返します。
56465771L<flock(2)>, L<fcntl(2)> ロック, L<lockf(3)> のいずれかを実装していない
56475772マシンで使うと、致命的エラーが発生します。
56485773L<C<flock>|/flock FILEHANDLE,OPERATION> は Perl の移植性のある
56495774ファイルロックインターフェースです;
56505775しかしレコードではなく、ファイル全体のみをロックします。
56515776
56525777=begin original
56535778
56545779Two potentially non-obvious but traditional L<C<flock>|/flock
56555780FILEHANDLE,OPERATION> semantics are
56565781that it waits indefinitely until the lock is granted, and that its locks
56575782are B<merely advisory>. Such discretionary locks are more flexible, but
56585783offer fewer guarantees. This means that programs that do not also use
56595784L<C<flock>|/flock FILEHANDLE,OPERATION> may modify files locked with
56605785L<C<flock>|/flock FILEHANDLE,OPERATION>. See L<perlport>,
56615786your port's specific documentation, and your system-specific local manpages
56625787for details. It's best to assume traditional behavior if you're writing
56635788portable programs. (But if you're not, you should as always feel perfectly
56645789free to write for your own system's idiosyncrasies (sometimes called
56655790"features"). Slavish adherence to portability concerns shouldn't get
56665791in the way of your getting your job done.)
56675792
56685793=end original
56695794
56705795明白ではないものの、伝統的な L<C<flock>|/flock FILEHANDLE,OPERATION> の
56715796動作としては、ロックが得られるまで
56725797無限に待ち続けるものと、B<単に勧告的に> ロックするものの二つがあります。
56735798このような自由裁量のロックはより柔軟ですが、保障されるものはより少ないです。
56745799これは、L<C<flock>|/flock FILEHANDLE,OPERATION> を使わないプログラムが
56755800L<C<flock>|/flock FILEHANDLE,OPERATION> でロックされたファイルを
56765801書き換えるかもしれないことを意味します。
56775802詳細については、L<perlport>、システム固有のドキュメント、システム固有の
56785803ローカルの man ページを参照してください。
56795804移植性のあるプログラムを書く場合は、伝統的な振る舞いを仮定するのが
56805805ベストです。
56815806(しかし移植性のないプログラムを書く場合は、自身のシステムの性癖(しばしば
56825807「仕様」と呼ばれます)に合わせて書くことも完全に自由です。
56835808盲目的に移植性に固執することで、あなたの作業を仕上げるのを邪魔するべきでは
56845809ありません。)
56855810
56865811=begin original
56875812
56885813OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with
56895814LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but
56905815you can use the symbolic names if you import them from the L<Fcntl> module,
56915816either individually, or as a group using the C<:flock> tag. LOCK_SH
56925817requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN
56935818releases a previously requested lock. If LOCK_NB is bitwise-or'ed with
56945819LOCK_SH or LOCK_EX, then L<C<flock>|/flock FILEHANDLE,OPERATION> returns
56955820immediately rather than blocking waiting for the lock; check the return
56965821status to see if you got it.
56975822
56985823=end original
56995824
57005825OPERATION は LOCK_SH, LOCK_EX, LOCK_UN のいずれかで、LOCK_NB と
57015826組み合わされることもあります。
57025827これらの定数は伝統的には 1, 2, 8, 4 の値を持ちますが、L<Fcntl> モジュールから
57035828シンボル名を独立してインポートするか、C<:flock> タグを使うグループとして、
57045829シンボル名をを使うことができます。
57055830LOCK_SH は共有ロックを要求し、LOCK_EX は排他ロックを要求し、LOCK_UN は
57065831前回要求したロックを開放します。
57075832LOCK_NB と LOCK_SH か LOCK_EX がビット単位の論理和されると、
57085833L<C<flock>|/flock FILEHANDLE,OPERATION> は
57095834ロックを取得するまで待つのではなく、すぐに返ります;
57105835ロックが取得できたかどうかは返り値を調べます。
57115836
57125837=begin original
57135838
57145839To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE
57155840before locking or unlocking it.
57165841
57175842=end original
57185843
57195844不一致の可能性を避けるために、Perl はファイルをロック、アンロックする前に
57205845FILEHANDLE をフラッシュします。
57215846
57225847=begin original
57235848
57245849Note that the emulation built with L<lockf(3)> doesn't provide shared
57255850locks, and it requires that FILEHANDLE be open with write intent. These
57265851are the semantics that L<lockf(3)> implements. Most if not all systems
57275852implement L<lockf(3)> in terms of L<fcntl(2)> locking, though, so the
57285853differing semantics shouldn't bite too many people.
57295854
57305855=end original
57315856
57325857L<lockf(3)> で作成されたエミュレーションは共有ロックを提供せず、
57335858FILEHANDLE が書き込みモードで開いていることを必要とすることに
57345859注意してください。
57355860これは L<lockf(3)> が実装している動作です。
57365861しかし、全てではないにしてもほとんどのシステムでは L<fcntl(2)> を使って
57375862L<lockf(3)> を実装しているので、異なった動作で多くの人々を混乱させることは
57385863ないはずです。
57395864
57405865=begin original
57415866
57425867Note that the L<fcntl(2)> emulation of L<flock(3)> requires that FILEHANDLE
57435868be open with read intent to use LOCK_SH and requires that it be open
57445869with write intent to use LOCK_EX.
57455870
57465871=end original
57475872
57485873L<flock(3)> の L<fcntl(2)> エミュレーションは、 LOCK_SH を使うためには
57495874FILEHANDLE を読み込みで開いている必要があり、LOCK_EX を使うためには
57505875書き込みで開いている必要があることに注意してください。
57515876
57525877=begin original
57535878
57545879Note also that some versions of L<C<flock>|/flock FILEHANDLE,OPERATION>
57555880cannot lock things over the network; you would need to use the more
57565881system-specific L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> for
57575882that. If you like you can force Perl to ignore your system's L<flock(2)>
57585883function, and so provide its own L<fcntl(2)>-based emulation, by passing
57595884the switch C<-Ud_flock> to the F<Configure> program when you configure
57605885and build a new Perl.
57615886
57625887=end original
57635888
57645889ネットワーク越しにはロックできない L<C<flock>|/flock FILEHANDLE,OPERATION> も
57655890あることに注意してください;
57665891このためには、よりシステム依存な
57675892L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR> を使う必要があります。
57685893Perl にシステムの L<flock(2)> 関数を無視させ、自身の L<fcntl(2)> ベースの
57695894エミュレーションを使う場合は、新しい Perl を設定およびビルドするときに
57705895F<Configure> プログラムに C<-Ud_flock> オプションを渡してください。
57715896
57725897=begin original
57735898
57745899Here's a mailbox appender for BSD systems.
57755900
57765901=end original
57775902
57785903BSD システムでのメールボックスへの追加処理の例を示します。
57795904
57805905 # import LOCK_* and SEEK_END constants
57815906 use Fcntl qw(:flock SEEK_END);
57825907
57835908 sub lock {
57845909 my ($fh) = @_;
57855910 flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
5911 # and, in case we're running on a very old UNIX
5787 # and, in case someone appended while we were waiting...
5912 # variant without the modern O_APPEND semantics...
57885913 seek($fh, 0, SEEK_END) or die "Cannot seek - $!\n";
57895914 }
57905915
57915916 sub unlock {
57925917 my ($fh) = @_;
57935918 flock($fh, LOCK_UN) or die "Cannot unlock mailbox - $!\n";
57945919 }
57955920
57965921 open(my $mbox, ">>", "/usr/spool/mail/$ENV{'USER'}")
57975922 or die "Can't open mailbox: $!";
57985923
57995924 lock($mbox);
58005925 print $mbox $msg,"\n\n";
58015926 unlock($mbox);
58025927
58035928=begin original
58045929
58055930On systems that support a real L<flock(2)>, locks are inherited across
58065931L<C<fork>|/fork> calls, whereas those that must resort to the more
58075932capricious L<fcntl(2)> function lose their locks, making it seriously
58085933harder to write servers.
58095934
58105935=end original
58115936
58125937真の L<flock(2)> に対応しているシステムではロックは L<C<fork>|/fork> を通して
58135938継承されるのに対して、より不安定な L<fcntl(2)> に頼らなければならない場合、
58145939サーバを書くのは本当により難しくなります。
58155940
58165941=begin original
58175942
58185943See also L<DB_File> for other L<C<flock>|/flock FILEHANDLE,OPERATION>
58195944examples.
58205945
58215946=end original
58225947
58235948その他の L<C<flock>|/flock FILEHANDLE,OPERATION> の例としては L<DB_File> も
58245949参照してください。
58255950
58265951=begin original
58275952
58285953Portability issues: L<perlport/flock>.
58295954
58305955=end original
58315956
58325957移植性の問題: L<perlport/flock>。
58335958
58345959=item fork
58355960X<fork> X<child> X<parent>
58365961
58375962=for Pod::Functions create a new process just like this one
58385963
58395964=begin original
58405965
58415966Does a L<fork(2)> system call to create a new process running the
58425967same program at the same point. It returns the child pid to the
58435968parent process, C<0> to the child process, or L<C<undef>|/undef EXPR> if
58445969the fork is
58455970unsuccessful. File descriptors (and sometimes locks on those descriptors)
58465971are shared, while everything else is copied. On most systems supporting
58475972L<fork(2)>, great care has gone into making it extremely efficient (for
58485973example, using copy-on-write technology on data pages), making it the
58495974dominant paradigm for multitasking over the last few decades.
58505975
58515976=end original
58525977
58535978同じプログラムの同じ地点から開始する新しいプロセスを作成するために
58545979システムコール L<fork(2)> を行ないます。
58555980親プロセスには、チャイルドプロセスの pid を、
58565981チャイルドプロセスに C<0> を返しますが、
58575982fork に失敗したときには、L<C<undef>|/undef EXPR>を返します。
58585983ファイル記述子(および記述子に関連するロック)は共有され、
58595984その他の全てはコピーされます。
58605985L<fork(2)> に対応するほとんどのシステムでは、
58615986これを極めて効率的にするために多大な努力が払われてきました
58625987(例えば、データページへの copy-on-write テクノロジーなどです);
58635988これはここ 20 年にわたるマルチタスクに関する主要なパラダイムとなっています。
58645989
58655990=begin original
58665991
58675992Perl attempts to flush all files opened for output before forking the
58685993child process, but this may not be supported on some platforms (see
58695994L<perlport>). To be safe, you may need to set
58705995L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>) or
58715996call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS> on
58725997any open handles to avoid duplicate output.
58735998
58745999=end original
58756000
58766001v5.6.0 から、Perl は子プロセスを fork する前に出力用にオープンしている全ての
58776002ファイルをフラッシュしようとしますが、これに対応していないプラットフォームも
58786003あります(L<perlport> を参照してください)。
58796004安全のためには、出力が重複するのを避けるために、
58806005全てのオープンしているハンドルに対して L<C<$E<verbar>>|perlvar/$E<verbar>>
58816006(L<English> モジュールでは C<$AUTOFLUSH>) を設定するか、
58826007L<C<IO::Handle>|IO::Handle/METHODS> モジュールの C<autoflush> メソッドを
58836008呼ぶ必要があるかもしれません。
58846009
58856010=begin original
58866011
58876012If you L<C<fork>|/fork> without ever waiting on your children, you will
58886013accumulate zombies. On some systems, you can avoid this by setting
58896014L<C<$SIG{CHLD}>|perlvar/%SIG> to C<"IGNORE">. See also L<perlipc> for
58906015more examples of forking and reaping moribund children.
58916016
58926017=end original
58936018
58946019チャイルドプロセスの終了を待たずに、L<C<fork>|/fork> を繰り返せば、
58956020ゾンビをためこむことになります。
58966021L<C<$SIG{CHLD}>|perlvar/%SIG> に C<"IGNORE"> を指定することでこれを
58976022回避できるシステムもあります。
58986023fork と消滅しかけている子プロセスを回収するための更なる例については
58996024L<perlipc> も参照してください。
59006025
59016026=begin original
59026027
59036028Note that if your forked child inherits system file descriptors like
59046029STDIN and STDOUT that are actually connected by a pipe or socket, even
59056030if you exit, then the remote server (such as, say, a CGI script or a
59066031backgrounded job launched from a remote shell) won't think you're done.
59076032You should reopen those to F</dev/null> if it's any issue.
59086033
59096034=end original
59106035
59116036fork した子プロセスが STDIN や STDOUT といったシステムファイル記述子を
59126037継承する場合、(CGI スクリプトやリモートシェルといった
59136038バックグラウンドジョブのような)リモートサーバは考え通りに
59146039動かないであろうことに注意してください。
59156040このような場合ではこれらを F</dev/null> として再オープンするべきです。
59166041
59176042=begin original
59186043
59196044On some platforms such as Windows, where the L<fork(2)> system call is
59206045not available, Perl can be built to emulate L<C<fork>|/fork> in the Perl
59216046interpreter. The emulation is designed, at the level of the Perl
59226047program, to be as compatible as possible with the "Unix" L<fork(2)>.
59236048However it has limitations that have to be considered in code intended
59246049to be portable. See L<perlfork> for more details.
59256050
59266051=end original
59276052
59286053Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
59296054L<C<fork>|/fork> を Perl インタプリタでエミュレートします。
59306055エミュレーションは Perl プログラムのレベルではできるだけ "Unix" L<fork(2)> と
59316056互換性があるように設計されています。
59326057しかしコードが移植性があると考えられるように制限があります。
59336058さらなる詳細については L<perlfork> を参照してください。
59346059
59356060=begin original
59366061
59376062Portability issues: L<perlport/fork>.
59386063
59396064=end original
59406065
59416066移植性の問題: L<perlport/fork>。
59426067
59436068=item format
59446069X<format>
59456070
59466071=for Pod::Functions declare a picture format with use by the write() function
59476072
59486073=begin original
59496074
59506075Declare a picture format for use by the L<C<write>|/write FILEHANDLE>
59516076function. For example:
59526077
59536078=end original
59546079
59556080L<C<write>|/write FILEHANDLE> 関数で使うピクチャーフォーマットを宣言します。
59566081例えば:
59576082
59586083 format Something =
59596084 Test: @<<<<<<<< @||||| @>>>>>
59606085 $str, $%, '$' . int($num)
59616086 .
59626087
59636088 $str = "widget";
59646089 $num = $cost/$quantity;
59656090 $~ = 'Something';
59666091 write;
59676092
59686093=begin original
59696094
59706095See L<perlform> for many details and examples.
59716096
59726097=end original
59736098
59746099詳細と例については L<perlform> を参照してください。
59756100
59766101=item formline PICTURE,LIST
59776102X<formline>
59786103
59796104=for Pod::Functions internal function used for formats
59806105
59816106=begin original
59826107
59836108This is an internal function used by L<C<format>|/format>s, though you
59846109may call it, too. It formats (see L<perlform>) a list of values
59856110according to the contents of PICTURE, placing the output into the format
59866111output accumulator, L<C<$^A>|perlvar/$^A> (or C<$ACCUMULATOR> in
59876112L<English>). Eventually, when a L<C<write>|/write FILEHANDLE> is done,
59886113the contents of L<C<$^A>|perlvar/$^A> are written to some filehandle.
59896114You could also read L<C<$^A>|perlvar/$^A> and then set
59906115L<C<$^A>|perlvar/$^A> back to C<"">. Note that a format typically does
59916116one L<C<formline>|/formline PICTURE,LIST> per line of form, but the
59926117L<C<formline>|/formline PICTURE,LIST> function itself doesn't care how
59936118many newlines are embedded in the PICTURE. This means that the C<~> and
59946119C<~~> tokens treat the entire PICTURE as a single line. You may
59956120therefore need to use multiple formlines to implement a single record
59966121format, just like the L<C<format>|/format> compiler.
59976122
59986123=end original
59996124
60006125これは、L<C<format>|/format> が使用する内部関数ですが、直接呼び出すことも
60016126できます。
60026127これは、PICTURE の内容にしたがって、LIST の値を整形し (L<perlform> を
60036128参照してください)、結果をフォーマット出力アキュムレータL<C<$^A>|perlvar/$^A>
60046129(L<English> モジュールでは C<$ACCUMULATOR>) に納めます。
60056130最終的に、L<C<write>|/write FILEHANDLE> が実行されると、
60066131L<C<$^A>|perlvar/$^A> の中身が、何らかのファイルハンドルに書き出されます。
60076132また、自分で L<C<$^A>|perlvar/$^A> を読んで、L<C<$^A>|perlvar/$^A> の内容を
60086133C<""> に戻してもかまいません。
60096134format は通常、1 行ごとに L<C<formline>|/formline PICTURE,LIST> を
60106135行ないますが、L<C<formline>|/formline PICTURE,LIST> 関数自身は、PICTURE の中に
60116136いくつの改行が入っているかは、関係がありません。
60126137これは、C<~> と C<~~>トークンは PICTURE 全体を一行として扱うことを意味します。
60136138従って、1 レコードフォーマットを実装するためには
60146139L<C<format>|/format> コンパイラのような複数 formline を使う必要があります。
60156140
60166141=begin original
60176142
60186143Be careful if you put double quotes around the picture, because an C<@>
60196144character may be taken to mean the beginning of an array name.
60206145L<C<formline>|/formline PICTURE,LIST> always returns true. See
60216146L<perlform> for other examples.
60226147
60236148=end original
60246149
60256150ダブルクォートで PICTURE を囲む場合には、C<@> という文字が
60266151配列名の始まりと解釈されますので、注意してください。
60276152L<C<formline>|/formline PICTURE,LIST> は常に真を返します。
60286153その他の例については L<perlform> を参照してください。
60296154
60306155=begin original
60316156
60326157If you are trying to use this instead of L<C<write>|/write FILEHANDLE>
60336158to capture the output, you may find it easier to open a filehandle to a
60346159scalar (C<< open my $fh, ">", \$output >>) and write to that instead.
60356160
60366161=end original
60376162
60386163出力を捕捉するために L<C<write>|/write FILEHANDLE> の代わりにこれを
60396164使おうとした場合、スカラにファイルハンドルを開いて
60406165(C<< open my $fh, ">", \$output >>)、
60416166代わりにここに出力する方が簡単であることに気付くでしょう。
60426167
60436168=item getc FILEHANDLE
60446169X<getc> X<getchar> X<character> X<file, read>
60456170
60466171=item getc
60476172
60486173=for Pod::Functions get the next character from the filehandle
60496174
60506175=begin original
60516176
60526177Returns the next character from the input file attached to FILEHANDLE,
60536178or the undefined value at end of file or if there was an error (in
60546179the latter case L<C<$!>|perlvar/$!> is set). If FILEHANDLE is omitted,
60556180reads from
60566181STDIN. This is not particularly efficient. However, it cannot be
60576182used by itself to fetch single characters without waiting for the user
60586183to hit enter. For that, try something more like:
60596184
60606185=end original
60616186
60626187FILEHANDLE につながれている入力ファイルから、次の一文字を返します;
60636188ファイルの最後、またはエラーが発生した場合は、未定義値を返します
60646189(後者の場合は L<C<$!>|perlvar/$!> がセットされます)。
60656190FILEHANDLE が省略された場合には、STDIN から読み込みを行ないます。
60666191これは特に効率的ではありません。
60676192しかし、これはユーザーがリターンキーを押すのを待つことなく
60686193一文字を読み込む用途には使えません。
60696194そのような場合には、以下のようなものを試して見てください:
60706195
60716196 if ($BSD_STYLE) {
60726197 system "stty cbreak </dev/tty >/dev/tty 2>&1";
60736198 }
60746199 else {
60756200 system "stty", '-icanon', 'eol', "\001";
60766201 }
60776202
60786203 my $key = getc(STDIN);
60796204
60806205 if ($BSD_STYLE) {
60816206 system "stty -cbreak </dev/tty >/dev/tty 2>&1";
60826207 }
60836208 else {
60846209 system 'stty', 'icanon', 'eol', '^@'; # ASCII NUL
60856210 }
60866211 print "\n";
60876212
60886213=begin original
60896214
60906215Determination of whether C<$BSD_STYLE> should be set is left as an
60916216exercise to the reader.
60926217
60936218=end original
60946219
60956220C<$BSD_STYLE> をセットするべきかどうかを決定する方法については
60966221読者への宿題として残しておきます。
60976222
60986223=begin original
60996224
61006225The L<C<POSIX::getattr>|POSIX/C<getattr>> function can do this more
61016226portably on systems purporting POSIX compliance. See also the
61026227L<C<Term::ReadKey>|Term::ReadKey> module on CPAN.
61036228
61046229=end original
61056230
61066231L<C<POSIX::getattr>|POSIX/C<getattr>> 関数は POSIX 準拠を主張するシステムで
61076232これをより移植性のある形で行います。
61086233CPAN にある L<C<Term::ReadKey>|Term::ReadKey> モジュールも
61096234参照してください。
61106235
61116236=item getlogin
61126237X<getlogin> X<login>
61136238
61146239=for Pod::Functions return who logged in at this tty
61156240
61166241=begin original
61176242
61186243This implements the C library function of the same name, which on most
61196244systems returns the current login from F</etc/utmp>, if any. If it
61206245returns the empty string, use L<C<getpwuid>|/getpwuid UID>.
61216246
61226247=end original
61236248
61246249これは同じ名前の C ライブラリ関数を実装していて、
61256250多くのシステムでは、もしあれば、F</etc/utmp> から現在のログイン名を返します。
61266251もし空文字列が返ってきた場合は、L<C<getpwuid>|/getpwuid UID> を
61276252使ってください。
61286253
61296254 my $login = getlogin || getpwuid($<) || "Kilroy";
61306255
61316256=begin original
61326257
61336258Do not consider L<C<getlogin>|/getlogin> for authentication: it is not
61346259as secure as L<C<getpwuid>|/getpwuid UID>.
61356260
61366261=end original
61376262
61386263L<C<getlogin>|/getlogin> を認証に使ってはいけません: これは
61396264L<C<getpwuid>|/getpwuid UID> のように安全ではありません。
61406265
61416266=begin original
61426267
61436268Portability issues: L<perlport/getlogin>.
61446269
61456270=end original
61466271
61476272移植性の問題: L<perlport/getlogin>。
61486273
61496274=item getpeername SOCKET
61506275X<getpeername> X<peer>
61516276
61526277=for Pod::Functions find the other end of a socket connection
61536278
61546279=begin original
61556280
61566281Returns the packed sockaddr address of the other end of the SOCKET
61576282connection.
61586283
61596284=end original
61606285
61616286SOCKET コネクションの向こう側のパックされた aockaddr アドレスを返します。
61626287
61636288 use Socket;
61646289 my $hersockaddr = getpeername($sock);
61656290 my ($port, $iaddr) = sockaddr_in($hersockaddr);
61666291 my $herhostname = gethostbyaddr($iaddr, AF_INET);
61676292 my $herstraddr = inet_ntoa($iaddr);
61686293
61696294=item getpgrp PID
61706295X<getpgrp> X<group>
61716296
61726297=for Pod::Functions get process group
61736298
61746299=begin original
61756300
61766301Returns the current process group for the specified PID. Use
61776302a PID of C<0> to get the current process group for the
61786303current process. Will raise an exception if used on a machine that
61796304doesn't implement L<getpgrp(2)>. If PID is omitted, returns the process
61806305group of the current process. Note that the POSIX version of
61816306L<C<getpgrp>|/getpgrp PID> does not accept a PID argument, so only
61826307C<PID==0> is truly portable.
61836308
61846309=end original
61856310
61866311指定された PID の現在のプロセスグループを返します。
61876312PID に C<0> を与えるとカレントプロセスの指定となります。
61886313L<getpgrp(2)> を実装していないマシンで実行した場合には、例外が発生します。
61896314PID を省略するとカレントプロセスのプロセスグループを返します。
61906315POSIX 版の L<C<getpgrp>|/getpgrp PID> は PID 引数を受け付けないので、
61916316C<PID==0> のみが完全に移植性があります。
61926317
61936318=begin original
61946319
61956320Portability issues: L<perlport/getpgrp>.
61966321
61976322=end original
61986323
61996324移植性の問題: L<perlport/getpgrp>。
62006325
62016326=item getppid
62026327X<getppid> X<parent> X<pid>
62036328
62046329=for Pod::Functions get parent process ID
62056330
62066331=begin original
62076332
62086333Returns the process id of the parent process.
62096334
62106335=end original
62116336
62126337親プロセスのプロセス id を返します。
62136338
62146339=begin original
62156340
62166341Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
62176342around non-POSIX thread semantics the minority of Linux systems (and
62186343Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
62196344has since been removed. See the documentation for L<$$|perlvar/$$> for
62206345details.
62216346
62226347=end original
62236348
62246349Linux ユーザーへの注意: v5.8.1 から v5.16.0 の間 Perl は
62256350LinuxThreads という非 POSIX なスレッド文法を使っているマイナーな
62266351Linux システム (および Debian GNU/kFreeBSD システム) に対応していました。
62276352このエミュレーションは削除されました;
62286353詳しくは L<$$|perlvar/$$> の文書を参照してください。
62296354
62306355=begin original
62316356
62326357Portability issues: L<perlport/getppid>.
62336358
62346359=end original
62356360
62366361移植性の問題: L<perlport/getppid>。
62376362
62386363=item getpriority WHICH,WHO
62396364X<getpriority> X<priority> X<nice>
62406365
62416366=for Pod::Functions get current nice value
62426367
62436368=begin original
62446369
62456370Returns the current priority for a process, a process group, or a user.
62466371(See L<getpriority(2)>.) Will raise a fatal exception if used on a
62476372machine that doesn't implement L<getpriority(2)>.
62486373
62496374=end original
62506375
62516376プロセス、プロセスグループ、ユーザに対する現在の優先度を返します。
62526377(L<getpriority(2)> を参照してください。)
62536378L<getpriority(2)> を実装していない
62546379マシンで実行した場合には、致命的例外が発生します。
62556380
62566381=begin original
62576382
6383C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER>
6384imported from L<POSIX/RESOURCE CONSTANTS>.
6385
6386=end original
6387
6388C<WHICH> は L<POSIX/RESOURCE CONSTANTS> からインポートされた
6389C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。
6390
6391=begin original
6392
62586393Portability issues: L<perlport/getpriority>.
62596394
62606395=end original
62616396
62626397移植性の問題: L<perlport/getpriority>。
62636398
62646399=item getpwnam NAME
62656400X<getpwnam> X<getgrnam> X<gethostbyname> X<getnetbyname> X<getprotobyname>
62666401X<getpwuid> X<getgrgid> X<getservbyname> X<gethostbyaddr> X<getnetbyaddr>
62676402X<getprotobynumber> X<getservbyport> X<getpwent> X<getgrent> X<gethostent>
62686403X<getnetent> X<getprotoent> X<getservent> X<setpwent> X<setgrent> X<sethostent>
62696404X<setnetent> X<setprotoent> X<setservent> X<endpwent> X<endgrent> X<endhostent>
62706405X<endnetent> X<endprotoent> X<endservent>
62716406
62726407=for Pod::Functions get passwd record given user login name
62736408
62746409=item getgrnam NAME
62756410
62766411=for Pod::Functions get group record given group name
62776412
62786413=item gethostbyname NAME
62796414
62806415=for Pod::Functions get host record given name
62816416
62826417=item getnetbyname NAME
62836418
62846419=for Pod::Functions get networks record given name
62856420
62866421=item getprotobyname NAME
62876422
62886423=for Pod::Functions get protocol record given name
62896424
62906425=item getpwuid UID
62916426
62926427=for Pod::Functions get passwd record given user ID
62936428
62946429=item getgrgid GID
62956430
62966431=for Pod::Functions get group record given group user ID
62976432
62986433=item getservbyname NAME,PROTO
62996434
63006435=for Pod::Functions get services record given its name
63016436
63026437=item gethostbyaddr ADDR,ADDRTYPE
63036438
63046439=for Pod::Functions get host record given its address
63056440
63066441=item getnetbyaddr ADDR,ADDRTYPE
63076442
63086443=for Pod::Functions get network record given its address
63096444
63106445=item getprotobynumber NUMBER
63116446
63126447=for Pod::Functions get protocol record numeric protocol
63136448
63146449=item getservbyport PORT,PROTO
63156450
63166451=for Pod::Functions get services record given numeric port
63176452
63186453=item getpwent
63196454
63206455=for Pod::Functions get next passwd record
63216456
63226457=item getgrent
63236458
63246459=for Pod::Functions get next group record
63256460
63266461=item gethostent
63276462
63286463=for Pod::Functions get next hosts record
63296464
63306465=item getnetent
63316466
63326467=for Pod::Functions get next networks record
63336468
63346469=item getprotoent
63356470
63366471=for Pod::Functions get next protocols record
63376472
63386473=item getservent
63396474
63406475=for Pod::Functions get next services record
63416476
63426477=item setpwent
63436478
63446479=for Pod::Functions prepare passwd file for use
63456480
63466481=item setgrent
63476482
63486483=for Pod::Functions prepare group file for use
63496484
63506485=item sethostent STAYOPEN
63516486
63526487=for Pod::Functions prepare hosts file for use
63536488
63546489=item setnetent STAYOPEN
63556490
63566491=for Pod::Functions prepare networks file for use
63576492
63586493=item setprotoent STAYOPEN
63596494
63606495=for Pod::Functions prepare protocols file for use
63616496
63626497=item setservent STAYOPEN
63636498
63646499=for Pod::Functions prepare services file for use
63656500
63666501=item endpwent
63676502
63686503=for Pod::Functions be done using passwd file
63696504
63706505=item endgrent
63716506
63726507=for Pod::Functions be done using group file
63736508
63746509=item endhostent
63756510
63766511=for Pod::Functions be done using hosts file
63776512
63786513=item endnetent
63796514
63806515=for Pod::Functions be done using networks file
63816516
63826517=item endprotoent
63836518
63846519=for Pod::Functions be done using protocols file
63856520
63866521=item endservent
63876522
63886523=for Pod::Functions be done using services file
63896524
63906525=begin original
63916526
63926527These routines are the same as their counterparts in the
63936528system C library. In list context, the return values from the
63946529various get routines are as follows:
63956530
63966531=end original
63976532
63986533これらのルーチンは、システムの C ライブラリの同名の関数と同じです。
63996534リストコンテキストでは、さまざまな
64006535get ルーチンからの返り値は、次のようになります:
64016536
64026537 # 0 1 2 3 4
64036538 my ( $name, $passwd, $gid, $members ) = getgr*
64046539 my ( $name, $aliases, $addrtype, $net ) = getnet*
64056540 my ( $name, $aliases, $port, $proto ) = getserv*
64066541 my ( $name, $aliases, $proto ) = getproto*
64076542 my ( $name, $aliases, $addrtype, $length, @addrs ) = gethost*
64086543 my ( $name, $passwd, $uid, $gid, $quota,
64096544 $comment, $gcos, $dir, $shell, $expire ) = getpw*
64106545 # 5 6 7 8 9
64116546
64126547=begin original
64136548
64146549(If the entry doesn't exist, the return value is a single meaningless true
64156550value.)
64166551
64176552=end original
64186553
64196554(エントリが存在しなければ、返り値は単一の意味のない真の値です。)
64206555
64216556=begin original
64226557
64236558The exact meaning of the $gcos field varies but it usually contains
64246559the real name of the user (as opposed to the login name) and other
64256560information pertaining to the user. Beware, however, that in many
64266561system users are able to change this information and therefore it
64276562cannot be trusted and therefore the $gcos is tainted (see
64286563L<perlsec>). The $passwd and $shell, user's encrypted password and
64296564login shell, are also tainted, for the same reason.
64306565
64316566=end original
64326567
64336568$gcos フィールドの正確な意味はさまざまですが、通常は(ログイン名ではなく)
64346569ユーザーの実際の名前とユーザーに付随する情報を含みます。
64356570但し、多くのシステムではユーザーがこの情報を変更できるので、この情報は
64366571信頼できず、従って $gcos は汚染されます(L<perlsec> を参照してください)。
64376572ユーザーの暗号化されたパスワードとログインシェルである $passwd と
64386573$shell も、同様の理由で汚染されます。
64396574
64406575=begin original
64416576
64426577In scalar context, you get the name, unless the function was a
64436578lookup by name, in which case you get the other thing, whatever it is.
64446579(If the entry doesn't exist you get the undefined value.) For example:
64456580
64466581=end original
64476582
64486583スカラコンテキストでは、*nam、*byname といった NAME で検索するもの以外は、
64496584name を返し、NAME で検索するものは、何か別のものを返します。
64506585(エントリが存在しなければ、未定義値が返ります。)
64516586例えば:
64526587
64536588 my $uid = getpwnam($name);
64546589 my $name = getpwuid($num);
64556590 my $name = getpwent();
64566591 my $gid = getgrnam($name);
64576592 my $name = getgrgid($num);
64586593 my $name = getgrent();
64596594 # etc.
64606595
64616596=begin original
64626597
64636598In I<getpw*()> the fields $quota, $comment, and $expire are special
64646599in that they are unsupported on many systems. If the
64656600$quota is unsupported, it is an empty scalar. If it is supported, it
64666601usually encodes the disk quota. If the $comment field is unsupported,
64676602it is an empty scalar. If it is supported it usually encodes some
64686603administrative comment about the user. In some systems the $quota
64696604field may be $change or $age, fields that have to do with password
64706605aging. In some systems the $comment field may be $class. The $expire
64716606field, if present, encodes the expiration period of the account or the
64726607password. For the availability and the exact meaning of these fields
64736608in your system, please consult L<getpwnam(3)> and your system's
64746609F<pwd.h> file. You can also find out from within Perl what your
64756610$quota and $comment fields mean and whether you have the $expire field
64766611by using the L<C<Config>|Config> module and the values C<d_pwquota>, C<d_pwage>,
64776612C<d_pwchange>, C<d_pwcomment>, and C<d_pwexpire>. Shadow password
64786613files are supported only if your vendor has implemented them in the
64796614intuitive fashion that calling the regular C library routines gets the
64806615shadow versions if you're running under privilege or if there exists
64816616the L<shadow(3)> functions as found in System V (this includes Solaris
64826617and Linux). Those systems that implement a proprietary shadow password
64836618facility are unlikely to be supported.
64846619
64856620=end original
64866621
64876622I<getpw*()> では、$quota, $comment, $expire フィールドは、
64886623多くのシステムでは対応していないので特別な処理がされます。
64896624$quota が非対応の場合、空のスカラになります。
64906625対応している場合、通常はディスククォータの値が入ります。
64916626$comment フィールドが非対応の場合、空のスカラになります。
64926627対応している場合、通常はユーザーに関する管理上のコメントが入ります。
64936628$quota フィールドはパスワードの寿命を示す $change や $age である
64946629システムもあります。
64956630$comment フィールドは $class であるシステムもあります。
64966631$expire フィールドがある場合は、アカウントやパスワードが時間切れになる
64976632期間が入ります。
64986633動作させるシステムでのこれらのフィールドの有効性と正確な意味については、
64996634L<getpwnam(3)> のドキュメントと F<pwd.h> ファイルを参照してください。
65006635$quota と $comment フィールドが何を意味しているかと、$expire フィールドが
65016636あるかどうかは、L<C<Config>|Config> モジュールを使って、C<d_pwquota>,
65026637C<d_pwage>, C<d_pwchange>, C<d_pwcomment>, C<d_pwexpire> の値を
65036638調べることによって Perl 自身で調べることも出来ます。
65046639シャドウパスワードは、通常の C ライブラリルーチンを権限がある状態で
65056640呼び出すことでシャドウ版が取得できるか、System V にあるような
65066641(Solaris と Linux を含みます) L<shadow(3)> 関数があるといった、
65076642直感的な方法で実装されている場合にのみ対応されます。
65086643独占的なシャドウパスワード機能を実装しているシステムでは、
65096644それに対応されることはないでしょう。
65106645
65116646=begin original
65126647
65136648The $members value returned by I<getgr*()> is a space-separated list of
65146649the login names of the members of the group.
65156650
65166651=end original
65176652
65186653I<getgr*()> によって返る値 $members は、グループのメンバの
65196654ログイン名をスペースで区切ったものです。
65206655
65216656=begin original
65226657
65236658For the I<gethost*()> functions, if the C<h_errno> variable is supported in
65246659C, it will be returned to you via L<C<$?>|perlvar/$?> if the function
65256660call fails. The
65266661C<@addrs> value returned by a successful call is a list of raw
65276662addresses returned by the corresponding library call. In the
65286663Internet domain, each address is four bytes long; you can unpack it
65296664by saying something like:
65306665
65316666=end original
65326667
65336668I<gethost*()> 関数では、C で C<h_errno> 変数がサポートされていれば、
65346669関数呼出が失敗したときに、L<C<$?>|perlvar/$?> を通して、その値が返されます。
65356670成功時に返される C<@addrs> 値は、対応するシステムコールが返す、
65366671生のアドレスのリストです。
65376672インターネットドメインでは、個々のアドレスは、4 バイト長です;
65386673以下のようにして unpack することができます:
65396674
65406675 my ($w,$x,$y,$z) = unpack('W4',$addr[0]);
65416676
65426677=begin original
65436678
65446679The Socket library makes this slightly easier:
65456680
65466681=end original
65476682
65486683Socket ライブラリを使うともう少し簡単になります。
65496684
65506685 use Socket;
65516686 my $iaddr = inet_aton("127.1"); # or whatever address
65526687 my $name = gethostbyaddr($iaddr, AF_INET);
65536688
65546689 # or going the other way
65556690 my $straddr = inet_ntoa($iaddr);
65566691
65576692=begin original
65586693
65596694In the opposite way, to resolve a hostname to the IP address
65606695you can write this:
65616696
65626697=end original
65636698
65646699逆方向に、ホスト名から IP アドレスを解決するには以下のように書けます:
65656700
65666701 use Socket;
65676702 my $packed_ip = gethostbyname("www.perl.org");
65686703 my $ip_address;
65696704 if (defined $packed_ip) {
65706705 $ip_address = inet_ntoa($packed_ip);
65716706 }
65726707
65736708=begin original
65746709
65756710Make sure L<C<gethostbyname>|/gethostbyname NAME> is called in SCALAR
65766711context and that its return value is checked for definedness.
65776712
65786713=end original
65796714
65806715L<C<gethostbyname>|/gethostbyname NAME> はスカラコンテキストで
65816716呼び出すようにして、返り値が定義されているかを必ずチェックしてください。
65826717
65836718=begin original
65846719
65856720The L<C<getprotobynumber>|/getprotobynumber NUMBER> function, even
65866721though it only takes one argument, has the precedence of a list
65876722operator, so beware:
65886723
65896724=end original
65906725
65916726L<C<getprotobynumber>|/getprotobynumber NUMBER> 関数は、一つの引数しか
65926727取らないにも関わらず、リスト演算子の優先順位を持ちます; 従って
65936728注意してください:
65946729
65956730 getprotobynumber $number eq 'icmp' # WRONG
65966731 getprotobynumber($number eq 'icmp') # actually means this
65976732 getprotobynumber($number) eq 'icmp' # better this way
65986733
65996734=begin original
66006735
66016736If you get tired of remembering which element of the return list
66026737contains which return value, by-name interfaces are provided in standard
66036738modules: L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
66046739L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
66056740L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
66066741L<C<Time::localtime>|Time::localtime>, and
66076742L<C<User::grent>|User::grent>. These override the normal built-ins,
66086743supplying versions that return objects with the appropriate names for
66096744each field. For example:
66106745
66116746=end original
66126747
66136748返り値のリストの何番目がどの要素かを覚えるのに疲れたなら、
66146749名前ベースのインターフェースが標準モジュールで提供されています:
66156750L<C<File::stat>|File::stat>, L<C<Net::hostent>|Net::hostent>,
66166751L<C<Net::netent>|Net::netent>, L<C<Net::protoent>|Net::protoent>,
66176752L<C<Net::servent>|Net::servent>, L<C<Time::gmtime>|Time::gmtime>,
66186753L<C<Time::localtime>|Time::localtime>,
66196754L<C<User::grent>|User::grent> です。
66206755これらは通常の組み込みを上書きし、
66216756それぞれのフィールドに適切な名前をつけたオブジェクトを返します。
66226757例えば:
66236758
66246759 use File::stat;
66256760 use User::pwent;
66266761 my $is_his = (stat($filename)->uid == pwent($whoever)->uid);
66276762
66286763=begin original
66296764
66306765Even though it looks as though they're the same method calls (uid),
66316766they aren't, because a C<File::stat> object is different from
66326767a C<User::pwent> object.
66336768
66346769=end original
66356770
66366771同じメソッド(uid)を呼び出しているように見えますが、違います;
66376772なぜなら C<File::stat> オブジェクトは C<User::pwent> オブジェクトとは
66386773異なるからです。
66396774
66406775=begin original
66416776
6777Many of these functions are not safe in a multi-threaded environment
6778where more than one thread can be using them. In particular, functions
6779like C<getpwent()> iterate per-process and not per-thread, so if two
6780threads are simultaneously iterating, neither will get all the records.
6781
6782=end original
6783
6784これらの関数の多くは、複数のスレッドがこれらを使うような
6785マルチスレッド環境では安全ではありません。
6786特に、
6787C<getpwent()> のような関数はスレッド単位ではなくプロセス単位で
6788反復するので、二つのスレッドが同時に反復すると、
6789どちらも全てのレコードを得られません。
6790
6791=begin original
6792
6793Some systems have thread-safe versions of some of the functions, such as
6794C<getpwnam_r()> instead of C<getpwnam()>. There, Perl automatically and
6795invisibly substitutes the thread-safe version, without notice. This
6796means that code that safely runs on some systems can fail on others that
6797lack the thread-safe versions.
6798
6799=end original
6800
6801一部のシステムは、
6802C<getpwnam()> の代わりの C<getpwnam_r()> のように、一部の関数について
6803スレッドセーフ版を持っています。
6804その場合、Perl は自動的かつ目に見えないように、通知なしで
6805スレッドセーフ版に置き換えます。
6806つまり、一部のシステムで安全に実行できるコードが
6807スレッドセーフ版のないその他のシステムでは失敗することがあるということです。
6808
6809=begin original
6810
66426811Portability issues: L<perlport/getpwnam> to L<perlport/endservent>.
66436812
66446813=end original
66456814
66466815移植性の問題: L<perlport/getpwnam> から L<perlport/endservent>。
66476816
66486817=item getsockname SOCKET
66496818X<getsockname>
66506819
66516820=for Pod::Functions retrieve the sockaddr for a given socket
66526821
66536822=begin original
66546823
66556824Returns the packed sockaddr address of this end of the SOCKET connection,
66566825in case you don't know the address because you have several different
66576826IPs that the connection might have come in on.
66586827
66596828=end original
66606829
66616830SOCKET 接続のこちら側の pack された sockaddr アドレスを返します;
66626831複数の異なる IP から接続されるためにアドレスがわからない場合に使います。
66636832
66646833 use Socket;
66656834 my $mysockaddr = getsockname($sock);
66666835 my ($port, $myaddr) = sockaddr_in($mysockaddr);
66676836 printf "Connect to %s [%s]\n",
66686837 scalar gethostbyaddr($myaddr, AF_INET),
66696838 inet_ntoa($myaddr);
66706839
66716840=item getsockopt SOCKET,LEVEL,OPTNAME
66726841X<getsockopt>
66736842
66746843=for Pod::Functions get socket options on a given socket
66756844
66766845=begin original
66776846
66786847Queries the option named OPTNAME associated with SOCKET at a given LEVEL.
66796848Options may exist at multiple protocol levels depending on the socket
66806849type, but at least the uppermost socket level SOL_SOCKET (defined in the
66816850L<C<Socket>|Socket> module) will exist. To query options at another
66826851level the protocol number of the appropriate protocol controlling the
66836852option should be supplied. For example, to indicate that an option is
66846853to be interpreted by the TCP protocol, LEVEL should be set to the
66856854protocol number of TCP, which you can get using
66866855L<C<getprotobyname>|/getprotobyname NAME>.
66876856
66886857=end original
66896858
66906859与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを
66916860問い合わせます。
66926861オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも
66936862ありますが、少なくとも最上位ソケットレベル SOL_SOCKET
66946863(L<C<Socket>|Socket> モジュールで定義されています)は存在します。
66956864その他のレベルのオプションを問い合わせるには、そのオプションを制御する
66966865適切なプロトコルのプロトコル番号を指定します。
66976866例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、
66986867LEVEL は L<C<getprotobyname>|/getprotobyname NAME> で得られる TCP の
66996868プロトコル番号を設定します。
67006869
67016870=begin original
67026871
67036872The function returns a packed string representing the requested socket
67046873option, or L<C<undef>|/undef EXPR> on error, with the reason for the
67056874error placed in L<C<$!>|perlvar/$!>. Just what is in the packed string
67066875depends on LEVEL and OPTNAME; consult L<getsockopt(2)> for details. A
67076876common case is that the option is an integer, in which case the result
67086877is a packed integer, which you can decode using
67096878L<C<unpack>|/unpack TEMPLATE,EXPR> with the C<i> (or C<I>) format.
67106879
67116880=end original
67126881
67136882この関数は、要求されたソケットオプションの pack された文字列表現か、
67146883あるいはエラーの場合は L<C<undef>|/undef EXPR> を返し、エラーの理由は
67156884L<C<$!>|perlvar/$!> にあります。
67166885pack された文字列の中身は LEVEL と OPTNAME に依存します;
67176886詳細については L<getsockopt(2)> を確認してください。
67186887一般的な場合はオプションが整数の場合で、この場合結果は
67196888L<C<unpack>|/unpack TEMPLATE,EXPR> の C<i>
67206889(あるいは C<I>)フォーマットでデコードできる pack された整数です。
67216890
67226891=begin original
67236892
67246893Here's an example to test whether Nagle's algorithm is enabled on a socket:
67256894
67266895=end original
67276896
67286897あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です:
67296898
67306899 use Socket qw(:all);
67316900
67326901 defined(my $tcp = getprotobyname("tcp"))
67336902 or die "Could not determine the protocol number for tcp";
67346903 # my $tcp = IPPROTO_TCP; # Alternative
67356904 my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
67366905 or die "getsockopt TCP_NODELAY: $!";
67376906 my $nodelay = unpack("I", $packed);
67386907 print "Nagle's algorithm is turned ",
67396908 $nodelay ? "off\n" : "on\n";
67406909
67416910=begin original
67426911
67436912Portability issues: L<perlport/getsockopt>.
67446913
67456914=end original
67466915
67476916移植性の問題: L<perlport/getsockopt>。
67486917
67496918=item glob EXPR
67506919X<glob> X<wildcard> X<filename, expansion> X<expand>
67516920
67526921=item glob
67536922
67546923=for Pod::Functions expand filenames using wildcards
67556924
67566925=begin original
67576926
67586927In list context, returns a (possibly empty) list of filename expansions on
67596928the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
67606929scalar context, glob iterates through such filename expansions, returning
67616930undef when the list is exhausted. This is the internal function
67626931implementing the C<< <*.c> >> operator, but you can use it directly. If
67636932EXPR is omitted, L<C<$_>|perlvar/$_> is used. The C<< <*.c> >> operator
67646933is discussed in more detail in L<perlop/"I/O Operators">.
67656934
67666935=end original
67676936
67686937リストコンテキストでは、
67696938EXPR の値を、標準 Unix シェル F</bin/csh> が行なうように
67706939ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。
67716940スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、
67726941リストがなくなったら undef を返します。
67736942これは、C<< <*.c> >> 演算子を実装する内部関数ですが、
67746943直接使用することもできます。
67756944EXPR が省略されると、L<C<$_>|perlvar/$_> が使われます。
67766945C<< <*.c> >>演算子については
67776946L<perlop/"I/O Operators"> でより詳細に議論しています。
67786947
67796948=begin original
67806949
67816950Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and
67826951treats
67836952each segment as separate pattern. As such, C<glob("*.c *.h")>
67846953matches all files with a F<.c> or F<.h> extension. The expression
67856954C<glob(".* *")> matches all files in the current working directory.
67866955If you want to glob filenames that might contain whitespace, you'll
67876956have to use extra quotes around the spacey filename to protect it.
67886957For example, to glob filenames that have an C<e> followed by a space
67896958followed by an C<f>, use one of:
67906959
67916960=end original
67926961
67936962L<C<glob>|/glob EXPR> は引数を空白で分割して、それぞれを分割された
67946963パターンとして扱います。
67956964従って、C<glob("*.c *.h")> は F<.c> または F<.h> 拡張子を持つ全てのファイルに
67966965マッチングします。
67976966式 C<glob(".* *")> はカレントワーキングディレクトリの全てのファイルに
67986967マッチングします。
67996968空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために
68006969空白入りファイル名の周りに追加のクォートを使う必要があります。
68016970例えば、C<e> の後に空白、その後に C<f> というファイル名をグロブするには
68026971以下の一つを使います:
68036972
68046973 my @spacies = <"*e f*">;
68056974 my @spacies = glob '"*e f*"';
68066975 my @spacies = glob q("*e f*");
68076976
68086977=begin original
68096978
68106979If you had to get a variable through, you could do this:
68116980
68126981=end original
68136982
68146983変数を通す必要があった場合、以下のようにできました:
68156984
68166985 my @spacies = glob "'*${var}e f*'";
68176986 my @spacies = glob qq("*${var}e f*");
68186987
68196988=begin original
68206989
68216990If non-empty braces are the only wildcard characters used in the
68226991L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many
68236992strings are returned. For example, this produces nine strings, one for
68246993each pairing of fruits and colors:
68256994
68266995=end original
68276996
68286997空でない中かっこが L<C<glob>|/glob EXPR> で使われている唯一の
68296998ワイルドカード文字列の場合、ファイル名とはマッチングせず、
68306999可能性のある文字列が返されます。
68317000例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに
68327001なります:
68337002
68347003 my @many = glob "{apple,tomato,cherry}={green,yellow,red}";
68357004
68367005=begin original
68377006
68387007This operator is implemented using the standard C<File::Glob> extension.
68397008See L<File::Glob> for details, including
68407009L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace
68417010as a pattern separator.
68427011
68437012=end original
68447013
68457014v5.6.0 から、この演算子は標準の C<File::Glob> 拡張を使って
68467015実装されています。
68477016空白をパターンのセパレータとして扱わない
68487017L<C<bsd_glob>|File::Glob/C<bsd_glob>> を含めた
68497018詳細は L<File::Glob> を参照してください。
68507019
68517020=begin original
68527021
7022If a C<glob> expression is used as the condition of a C<while> or C<for>
7023loop, then it will be implicitly assigned to C<$_>. If either a C<glob>
7024expression or an explicit assignment of a C<glob> expression to a scalar
7025is used as a C<while>/C<for> condition, then the condition actually
7026tests for definedness of the expression's value, not for its regular
7027truth value.
7028
7029=end original
7030
7031C<glob> 式が C<while> や C<for> ループの条件として使われた場合、
7032これは暗黙に C<$_> に代入されます。
7033C<glob> 式または C<glob> 式からスカラへの明示的な代入が
7034C<while>/C<for> の条件部として使われた場合、
7035条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
7036テストします。
7037
7038=begin original
7039
68537040Portability issues: L<perlport/glob>.
68547041
68557042=end original
68567043
68577044移植性の問題: L<perlport/glob>。
68587045
68597046=item gmtime EXPR
68607047X<gmtime> X<UTC> X<Greenwich>
68617048
68627049=item gmtime
68637050
68647051=for Pod::Functions convert UNIX time into record or string using Greenwich time
68657052
68667053=begin original
68677054
68687055Works just like L<C<localtime>|/localtime EXPR> but the returned values
68697056are localized for the standard Greenwich time zone.
68707057
68717058=end original
68727059
68737060L<C<localtime>|/localtime EXPR> と同様に働きますが、返り値はグリニッジ標準時に
68747061ローカライズされています。
68757062
68767063=begin original
68777064
68787065Note: When called in list context, $isdst, the last value
68797066returned by gmtime, is always C<0>. There is no
68807067Daylight Saving Time in GMT.
68817068
68827069=end original
68837070
68847071注意: リストコンテキストで呼び出した時、gmtime が返す末尾の値である
68857072$isdst は常に C<0> です。
68867073GMT には夏時間はありません。
68877074
68887075=begin original
68897076
68907077Portability issues: L<perlport/gmtime>.
68917078
68927079=end original
68937080
68947081移植性の問題: L<perlport/gmtime>。
68957082
68967083=item goto LABEL
68977084X<goto> X<jump> X<jmp>
68987085
68997086=item goto EXPR
69007087
69017088=item goto &NAME
69027089
69037090=for Pod::Functions create spaghetti code
69047091
69057092=begin original
69067093
69077094The C<goto LABEL> form finds the statement labeled with LABEL and
69087095resumes execution there. It can't be used to get out of a block or
69097096subroutine given to L<C<sort>|/sort SUBNAME LIST>. It can be used to go
69107097almost anywhere else within the dynamic scope, including out of
69117098subroutines, but it's usually better to use some other construct such as
69127099L<C<last>|/last LABEL> or L<C<die>|/die LIST>. The author of Perl has
69137100never felt the need to use this form of L<C<goto>|/goto LABEL> (in Perl,
69147101that is; C is another matter). (The difference is that C does not offer
69157102named loops combined with loop control. Perl does, and this replaces
69167103most structured uses of L<C<goto>|/goto LABEL> in other languages.)
69177104
69187105=end original
69197106
69207107C<goto LABEL> の形式は、LABEL というラベルの付いた文を
69217108探して、そこへ実行を移すものです。
69227109L<C<sort>|/sort SUBNAME LIST> で与えられたブロックやサブルーチンから外へ
69237110出ることはできません。
69247111これ以外は、サブルーチンの外を含む、動的スコープ内の
69257112ほとんどすべての場所へ行くために使用できますが、普通は、
69267113L<C<last>|/last LABEL> や L<C<die>|/die LIST> といった別の構造を使った方が
69277114良いでしょう。
69287115Perl の作者はこの形式の L<C<goto>|/goto LABEL> を使う必要を感じたことは、
692971161 度もありません (Perl では; C は別のお話です)。
69307117(違いは、C にはループ制御と結びついた名前つきのループがないことです。
69317118Perl にはあり、これが他の言語でのほとんどの構造的な L<C<goto>|/goto LABEL> の
69327119使用法を置き換えます。)
69337120
69347121=begin original
69357122
69367123The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or
69377124a label name. If it evaluates to a code reference, it will be handled
69387125like C<goto &NAME>, below. This is especially useful for implementing
69397126tail recursion via C<goto __SUB__>.
69407127
69417128=end original
69427129
69437130C<goto EXPR> の形式は、C<EXPR> をコードリファレンスまたはラベル名として
69447131評価することを想定します。
69457132コードリファレンスとして評価する場合、後述する C<goto &NAME> のように
69467133扱います。
69477134これは特に、C<goto __SUB__> による末尾再帰の実装に有用です。
69487135
69497136=begin original
69507137
69517138If the expression evaluates to a label name, its scope will be resolved
69527139dynamically. This allows for computed L<C<goto>|/goto LABEL>s per
69537140FORTRAN, but isn't necessarily recommended if you're optimizing for
69547141maintainability:
69557142
69567143=end original
69577144
69587145式がラベル名に評価される場合、このスコープは動的に解決されます。
69597146これにより FORTRAN のような算術 L<C<goto>|/goto LABEL> が可能になりますが、
69607147保守性を重視するならお勧めしません。
69617148
69627149 goto ("FOO", "BAR", "GLARCH")[$i];
69637150
69647151=begin original
69657152
69667153As shown in this example, C<goto EXPR> is exempt from the "looks like a
69677154function" rule. A pair of parentheses following it does not (necessarily)
69687155delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>.
69697156Also, unlike most named operators, this has the same precedence as
69707157assignment.
69717158
69727159=end original
69737160
69747161この例で示したように、C<goto EXPR> は「関数のように見える」ルールから
69757162除外されます。
69767163これに引き続くかっこの組は引数の区切りとは(必ずしも)なりません。
69777164C<goto("NE")."XT"> は C<goto NEXT> と等価です。
69787165また、ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
69797166
69807167=begin original
69817168
69827169Use of C<goto LABEL> or C<goto EXPR> to jump into a construct is
69837170deprecated and will issue a warning. Even then, it may not be used to
69847171go into any construct that requires initialization, such as a
6985subroutine or a C<foreach> loop. It also can't be used to go into a
7172subroutine, a C<foreach> loop, or a C<given>
7173block. In general, it may not be used to jump into the parameter
7174of a binary or list operator, but it may be used to jump into the
7175I<first> parameter of a binary operator. (The C<=>
7176assignment operator's "first" operand is its right-hand
7177operand.) It also can't be used to go into a
69867178construct that is optimized away.
69877179
69887180=end original
69897181
69907182構造の中に飛び込むために C<goto LABEL> や C<goto EXPR> を使うことは
69917183非推奨で、警告が発生します。
6992それでも、サブルーチンや C<foreach> ループのような、初期化が必要な
7184それでも、サブルーチンや C<foreach> ループや C<given> ブロックのような、
7185初期化が必要な
69937186構造の中に入るために使うことは出来ません。
7187一般的に、2 項演算子やリスト演算子の引数に飛び込むことはできませんが、
71882 項演算子の I<最初の> 引数に飛び込むために使われていました。
7189(C<=> 代入演算子の「最初の」オペランドはその右オペランドです。)
69947190また、最適化してなくなってしまった構造の中へ入るために使うことも出来ません。
69957191
69967192=begin original
69977193
69987194The C<goto &NAME> form is quite different from the other forms of
69997195L<C<goto>|/goto LABEL>. In fact, it isn't a goto in the normal sense at
70007196all, and doesn't have the stigma associated with other gotos. Instead,
70017197it exits the current subroutine (losing any changes set by
70027198L<C<local>|/local EXPR>) and immediately calls in its place the named
70037199subroutine using the current value of L<C<@_>|perlvar/@_>. This is used
70047200by C<AUTOLOAD> subroutines that wish to load another subroutine and then
70057201pretend that the other subroutine had been called in the first place
70067202(except that any modifications to L<C<@_>|perlvar/@_> in the current
70077203subroutine are propagated to the other subroutine.) After the
70087204L<C<goto>|/goto LABEL>, not even L<C<caller>|/caller EXPR> will be able
70097205to tell that this routine was called first.
70107206
70117207=end original
70127208
70137209C<goto &NAME> の形式は、その他の L<C<goto>|/goto LABEL> の形式とはかなり
70147210異なったものです。
70157211実際、これは普通の感覚でいうところのどこかへ行くものでは全くなく、
70167212他の goto が持つ不名誉を持っていません。
70177213現在のサブルーチンを終了し (L<C<local>|/local EXPR> による変更は失われます)、
70187214直ちに現在の L<C<@_>|perlvar/@_> の値を使って指定された名前のサブルーチンを
70197215呼び出します。
70207216これは、C<AUTOLOAD> サブルーチンが別のサブルーチンをロードして、
70217217その別のサブルーチンが最初に呼ばれたようにするために使われます
70227218(ただし、現在のサブルーチンで L<C<@_>|perlvar/@_> を修正した場合には、
70237219その別のサブルーチンに伝えられます)。
70247220L<C<goto>|/goto LABEL> のあとは、L<C<caller>|/caller EXPR> でさえも、現在の
70257221サブルーチンが最初に呼び出されたと言うことができません。
70267222
70277223=begin original
70287224
70297225NAME needn't be the name of a subroutine; it can be a scalar variable
70307226containing a code reference or a block that evaluates to a code
70317227reference.
70327228
70337229=end original
70347230
70357231NAME はサブルーチンの名前である必要はありません; コードリファレンスを
70367232含むスカラ値や、コードリファレンスと評価されるブロックでも構いません。
70377233
70387234=item grep BLOCK LIST
70397235X<grep>
70407236
70417237=item grep EXPR,LIST
70427238
70437239=for Pod::Functions locate elements in a list test true against a given criterion
70447240
70457241=begin original
70467242
70477243This is similar in spirit to, but not the same as, L<grep(1)> and its
70487244relatives. In particular, it is not limited to using regular expressions.
70497245
70507246=end original
70517247
70527248これは L<grep(1)> とその親類と同じようなものですが、同じではありません。
70537249特に、正規表現の使用に制限されません。
70547250
70557251=begin original
70567252
70577253Evaluates the BLOCK or EXPR for each element of LIST (locally setting
70587254L<C<$_>|perlvar/$_> to each element) and returns the list value
70597255consisting of those
70607256elements for which the expression evaluated to true. In scalar
70617257context, returns the number of times the expression was true.
70627258
70637259=end original
70647260
70657261LIST の個々の要素に対して、BLOCK か EXPR を評価し
70667262(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
70677263その要素のうち、評価した式が真となったものからなるリスト値が返されます。
70687264スカラコンテキストでは、式が真となった回数を返します。
70697265
70707266 my @foo = grep(!/^#/, @bar); # weed out comments
70717267
70727268=begin original
70737269
70747270or equivalently,
70757271
70767272=end original
70777273
70787274あるいは等価な例として:
70797275
70807276 my @foo = grep {!/^#/} @bar; # weed out comments
70817277
70827278=begin original
70837279
70847280Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
70857281be used to
70867282modify the elements of the LIST. While this is useful and supported,
70877283it can cause bizarre results if the elements of LIST are not variables.
70887284Similarly, grep returns aliases into the original list, much as a for
70897285loop's index variable aliases the list elements. That is, modifying an
70907286element of a list returned by grep (for example, in a C<foreach>,
70917287L<C<map>|/map BLOCK LIST> or another L<C<grep>|/grep BLOCK LIST>)
70927288actually modifies the element in the original list.
70937289This is usually something to be avoided when writing clear code.
70947290
70957291=end original
70967292
70977293L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
70987294変更するために使うことができます。
70997295これは、便利でサポートされていますが、
71007296LIST の要素が変数でないと、おかしな結果になります。
71017297同様に、grep は元のリストへのエイリアスを返します; for ループの
71027298インデックス変数がリスト要素のエイリアスであるのと同様です。
71037299つまり、grep で返されたリストの要素を
71047300(C<foreach>, L<C<map>|/map BLOCK LIST>, または他の
71057301L<C<grep>|/grep BLOCK LIST> で)修正すると元のリストの要素が変更されます。
71067302これはきれいなコードを書くときには普通は回避されます。
71077303
71087304=begin original
71097305
71107306See also L<C<map>|/map BLOCK LIST> for a list composed of the results of
71117307the BLOCK or EXPR.
71127308
71137309=end original
71147310
71157311BLOCK や EXPR の結果をリストの形にしたい場合は L<C<map>|/map BLOCK LIST> を
71167312参照してください。
71177313
71187314=item hex EXPR
71197315X<hex> X<hexadecimal>
71207316
71217317=item hex
71227318
71237319=for Pod::Functions convert a hexadecimal string to a number
71247320
71257321=begin original
71267322
71277323Interprets EXPR as a hex string and returns the corresponding numeric value.
71287324If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
71297325
71307326=end original
71317327
71327328EXPR を 16 進数の文字列と解釈して、対応する数値を返します。
71337329EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
71347330
71357331 print hex '0xAf'; # prints '175'
71367332 print hex 'aF'; # same
71377333 $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/
71387334
71397335=begin original
71407336
71417337A hex string consists of hex digits and an optional C<0x> or C<x> prefix.
71427338Each hex digit may be preceded by a single underscore, which will be ignored.
71437339Any other character triggers a warning and causes the rest of the string
71447340to be ignored (even leading whitespace, unlike L<C<oct>|/oct EXPR>).
71457341Only integers can be represented, and integer overflow triggers a warning.
71467342
71477343=end original
71487344
7149734516 進文字列は 16 進数と、オプションの C<0x> または C<x> 接頭辞からなります。
71507346それぞれの 16 進数は一つの下線を前に置くことができ、これは無視されます。
71517347その他の文字は警告を引き起こし、(例え先頭の空白でも、L<C<oct>|/oct EXPR> と
71527348異なり)文字列の残りの部分は無視されます。
71537349整数のみを表現でき、整数オーバーフローは警告を引き起こします。
71547350
71557351=begin original
71567352
71577353To convert strings that might start with any of C<0>, C<0x>, or C<0b>,
71587354see L<C<oct>|/oct EXPR>. To present something as hex, look into
71597355L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
71607356L<C<sprintf>|/sprintf FORMAT, LIST>, and
71617357L<C<unpack>|/unpack TEMPLATE,EXPR>.
71627358
71637359=end original
71647360
71657361C<0>, C<0x>, C<0b> のいずれかで始まるかもしれない文字列を変換するには、
71667362L<C<oct>|/oct EXPR> を参照してください。
71677363何かを 16 進で表現したい場合は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
71687364L<C<sprintf>|/sprintf FORMAT, LIST>, L<C<unpack>|/unpack TEMPLATE,EXPR> を
71697365参照してください。
71707366
71717367=item import LIST
71727368X<import>
71737369
71747370=for Pod::Functions patch a module's namespace into your own
71757371
71767372=begin original
71777373
71787374There is no builtin L<C<import>|/import LIST> function. It is just an
71797375ordinary method (subroutine) defined (or inherited) by modules that wish
71807376to export names to another module. The
71817377L<C<use>|/use Module VERSION LIST> function calls the
71827378L<C<import>|/import LIST> method for the package used. See also
71837379L<C<use>|/use Module VERSION LIST>, L<perlmod>, and L<Exporter>.
71847380
71857381=end original
71867382
71877383組み込みの L<C<import>|/import LIST> 関数というものはありません。
71887384これは単に、別のモジュールに名前をエクスポートしたいモジュールが
71897385定義した(または継承した)、通常のメソッド(サブルーチン)です。
71907386L<C<use>|/use Module VERSION LIST> 関数はパッケージを使う時に
71917387L<C<import>|/import LIST> メソッドを呼び出します。
71927388L<C<use>|/use Module VERSION LIST>, L<perlmod>, L<Exporter> も
71937389参照してください。
71947390
71957391=item index STR,SUBSTR,POSITION
71967392X<index> X<indexOf> X<InStr>
71977393
71987394=item index STR,SUBSTR
71997395
72007396=for Pod::Functions find a substring within a string
72017397
72027398=begin original
72037399
72047400The index function searches for one string within another, but without
72057401the wildcard-like behavior of a full regular-expression pattern match.
72067402It returns the position of the first occurrence of SUBSTR in STR at
72077403or after POSITION. If POSITION is omitted, starts searching from the
72087404beginning of the string. POSITION before the beginning of the string
72097405or after its end is treated as if it were the beginning or the end,
72107406respectively. POSITION and the return value are based at zero.
72117407If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION>
72127408returns -1.
72137409
72147410=end original
72157411
72167412index 関数は ある文字列をもうひとつの文字列から検索しますが、
72177413完全正規表現パターンマッチのワイルドカード的な振る舞いはしません。
72187414STR の中の POSITION の位置以降で、最初に SUBSTR が見つかった位置を返します。
72197415POSITION が省略された場合には、STR の最初から探し始めます。
72207416POSITION が文字列の先頭より前、あるいは末尾より後ろを指定した場合は、
72217417それぞれ先頭と末尾を指定されたものとして扱われます。
72227418POSITION と返り値のベースは、0 です。
72237419SUBSTR が見つからなかった場合には、L<C<index>|/index STR,SUBSTR,POSITION> は
72247420-1 が返されます。
72257421
72267422=item int EXPR
72277423X<int> X<integer> X<truncate> X<trunc> X<floor>
72287424
72297425=item int
72307426
72317427=for Pod::Functions get the integer portion of a number
72327428
72337429=begin original
72347430
72357431Returns the integer portion of EXPR. If EXPR is omitted, uses
72367432L<C<$_>|perlvar/$_>.
72377433You should not use this function for rounding: one because it truncates
72387434towards C<0>, and two because machine representations of floating-point
72397435numbers can sometimes produce counterintuitive results. For example,
72407436C<int(-6.725/0.025)> produces -268 rather than the correct -269; that's
72417437because it's really more like -268.99999999999994315658 instead. Usually,
72427438the L<C<sprintf>|/sprintf FORMAT, LIST>,
72437439L<C<printf>|/printf FILEHANDLE FORMAT, LIST>, or the
72447440L<C<POSIX::floor>|POSIX/C<floor>> and L<C<POSIX::ceil>|POSIX/C<ceil>>
72457441functions will serve you better than will L<C<int>|/int EXPR>.
72467442
72477443=end original
72487444
72497445EXPR の整数部を返します。
72507446EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
72517447この関数を丸めのために使うべきではありません: 第一の理由として C<0> の
72527448方向への切捨てを行うから、第二の理由として浮動小数点数の機械表現は時々直感に
72537449反した結果を生み出すからです。
72547450たとえば、C<int(-6.725/0.025)> は正しい結果である -269 ではなく -268 を
72557451返します: これは実際には -268.99999999999994315658 というような値に
72567452なっているからです。
72577453通常、L<C<sprintf>|/sprintf FORMAT, LIST>,
72587454L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
72597455L<C<POSIX::floor>|POSIX/C<floor>>, L<C<POSIX::ceil>|POSIX/C<ceil>> の方が
72607456L<C<int>|/int EXPR> より便利です。
72617457
72627458=item ioctl FILEHANDLE,FUNCTION,SCALAR
72637459X<ioctl>
72647460
72657461=for Pod::Functions system-dependent device control system call
72667462
72677463=begin original
72687464
72697465Implements the L<ioctl(2)> function. You'll probably first have to say
72707466
72717467=end original
72727468
72737469L<ioctl(2)> 関数を実装します。
72747470正しい関数の定義を得るために、おそらく最初に
72757471
72767472 require "sys/ioctl.ph"; # probably in
72777473 # $Config{archlib}/sys/ioctl.ph
72787474
72797475=begin original
72807476
72817477to get the correct function definitions. If F<sys/ioctl.ph> doesn't
72827478exist or doesn't have the correct definitions you'll have to roll your
72837479own, based on your C header files such as F<< <sys/ioctl.h> >>.
72847480(There is a Perl script called B<h2ph> that comes with the Perl kit that
72857481may help you in this, but it's nontrivial.) SCALAR will be read and/or
72867482written depending on the FUNCTION; a C pointer to the string value of SCALAR
72877483will be passed as the third argument of the actual
72887484L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> call. (If SCALAR
72897485has no string value but does have a numeric value, that value will be
72907486passed rather than a pointer to the string value. To guarantee this to be
72917487true, add a C<0> to the scalar before using it.) The
72927488L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
72937489functions may be needed to manipulate the values of structures used by
72947490L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>.
72957491
72967492=end original
72977493
72987494としなくてはならないでしょう。
72997495F<sys/ioctl.ph> がないか、間違った定義をしている場合には、
73007496F<< <sys/ioctl.h> >>のような C のヘッダファイルをもとに、
73017497自分で作らなければなりません。
73027498(Perl の配布キットに入っている B<h2ph> という Perl スクリプトが
73037499これを手助けしてくれるでしょうが、これは自明ではありません。)
73047500FOUNCTION に応じて SCALAR が読み書きされます;
73057501SCALAR の文字列値へのポインタが、実際の
73067502L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> コールの
730775033 番目の引数として渡されます。
73087504(SCALAR が文字列値を持っておらず、数値を持っている場合には、
73097505文字列値へのポインタの代わりに、その値が渡されます。
73107506このことを保証するためには、使用する前に SCALAR にC<0> を足してください。)
73117507L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> で使われる構造体の値を
73127508操作するには、L<C<pack>|/pack TEMPLATE,LIST> 関数と
73137509L<C<unpack>|/unpack TEMPLATE,EXPR> 関数が必要となるでしょう。
73147510
73157511=begin original
73167512
73177513The return value of L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> (and
73187514L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) is as follows:
73197515
73207516=end original
73217517
73227518L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>
73237519(と L<C<fcntl>|/fcntl FILEHANDLE,FUNCTION,SCALAR>) の返り値は、
73247520以下のようになります:
73257521
73267522=begin original
73277523
73287524 if OS returns: then Perl returns:
73297525 -1 undefined value
73307526 0 string "0 but true"
73317527 anything else that number
73327528
73337529=end original
73347530
73357531 OS が返した値: Perl が返す値:
73367532 -1 未定義値
73377533 0 「0 だが真」の文字列
73387534 その他 その値そのもの
73397535
73407536=begin original
73417537
73427538Thus Perl returns true on success and false on failure, yet you can
73437539still easily determine the actual value returned by the operating
73447540system:
73457541
73467542=end original
73477543
73487544つまり Perl は、成功時に「真」、失敗時に「偽」を返す
73497545ことになり、OS が実際に返した値も、以下のように簡単に知ることができます。
73507546
73517547 my $retval = ioctl(...) || -1;
73527548 printf "System returned %d\n", $retval;
73537549
73547550=begin original
73557551
73567552The special string C<"0 but true"> is exempt from
73577553L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
73587554L<warnings> on improper numeric conversions.
73597555
73607556=end original
73617557
73627558特別な文字列 C<"0 だが真"> は、不適切な数値変換に関する
73637559L<C<Argument "..." isn't numeric>|perldiag/Argument "%s" isn't numeric%s>
73647560L<warnings> 警告を回避します。
73657561
73667562=begin original
73677563
73687564Portability issues: L<perlport/ioctl>.
73697565
73707566=end original
73717567
73727568移植性の問題: L<perlport/ioctl>。
73737569
73747570=item join EXPR,LIST
73757571X<join>
73767572
73777573=for Pod::Functions join a list into a string using a separator
73787574
73797575=begin original
73807576
73817577Joins the separate strings of LIST into a single string with fields
73827578separated by the value of EXPR, and returns that new string. Example:
73837579
73847580=end original
73857581
73867582LIST の個別の文字列を、EXPR の値で区切って
738775831 つの文字列につなげ、その文字列を返します。
73887584例:
73897585
73907586 my $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
73917587
73927588=begin original
73937589
73947590Beware that unlike L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
73957591L<C<join>|/join EXPR,LIST> doesn't take a pattern as its first argument.
73967592Compare L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>.
73977593
73987594=end original
73997595
74007596L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と違って、
74017597L<C<join>|/join EXPR,LIST> は最初の引数にパターンは取れないことに
74027598注意してください。
74037599L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> と比較してください。
74047600
74057601=item keys HASH
74067602X<keys> X<key>
74077603
74087604=item keys ARRAY
74097605
74107606=for Pod::Functions retrieve list of indices from a hash
74117607
74127608=begin original
74137609
74147610Called in list context, returns a list consisting of all the keys of the
74157611named hash, or in Perl 5.12 or later only, the indices of an array. Perl
74167612releases prior to 5.12 will produce a syntax error if you try to use an
74177613array argument. In scalar context, returns the number of keys or indices.
74187614
74197615=end original
74207616
74217617リストコンテキストで呼び出されると、指定したハッシュのすべてのキー、あるいは
74227618Perl 5.12 以降でのみ、配列のインデックスからなるリストを返します。
742376195.12 より前の Perl は配列引数を使おうとすると文法エラーを出力します。
74247620スカラコンテキストでは、キーやインデックスの数を返します。
74257621
74267622=begin original
74277623
74287624Hash entries are returned in an apparently random order. The actual random
74297625order is specific to a given hash; the exact same series of operations
74307626on two hashes may result in a different order for each hash. Any insertion
74317627into the hash may change the order, as will any deletion, with the exception
74327628that the most recent key returned by L<C<each>|/each HASH> or
74337629L<C<keys>|/keys HASH> may be deleted without changing the order. So
74347630long as a given hash is unmodified you may rely on
74357631L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and L<C<each>|/each
74367632HASH> to repeatedly return the same order
74377633as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
74387634details on why hash order is randomized. Aside from the guarantees
74397635provided here the exact details of Perl's hash algorithm and the hash
74407636traversal order are subject to change in any release of Perl. Tied hashes
74417637may behave differently to Perl's hashes with respect to changes in order on
74427638insertion and deletion of items.
74437639
74447640=end original
74457641
74467642ハッシュ要素は見かけ上、ランダムな順序で返されます。
74477643実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
74487644操作を行っても、ハッシュによって異なった順序になります。
74497645ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
74507646L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
74517647最近のキーは順序を変えることなく削除できます。
74527648ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
74537649L<C<each>|/each HASH> が繰り返し同じ順序で
74547650返すことに依存してもかまいません。
74557651なぜハッシュの順序がランダム化されているかの詳細については
74567652L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
74577653ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
74587654正確な詳細は Perl のリリースによって変更される可能性があります。
74597655tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
74607656異なった振る舞いをします。
74617657
74627658=begin original
74637659
74647660As a side effect, calling L<C<keys>|/keys HASH> resets the internal
7465iterator of the HASH or ARRAY (see L<C<each>|/each HASH>). In
7661iterator of the HASH or ARRAY (see L<C<each>|/each HASH>) before
7662yielding the keys. In
74667663particular, calling L<C<keys>|/keys HASH> in void context resets the
74677664iterator with no other overhead.
74687665
74697666=end original
74707667
7471副作用として、L<C<keys>|/keys HASH> の呼び出しは HASH や ARRAY の反復子を
7668副作用として、L<C<keys>|/keys HASH> の呼び出しは
7669キーを取り出す前に HASH や ARRAY の反復子を
74727670初期化します (L<C<each>|/each HASH> を参照してください)。
74737671特に、無効コンテキストで L<C<keys>|/keys HASH> を呼び出すと
74747672オーバーヘッドなしで反復子を初期化します。
74757673
74767674=begin original
74777675
74787676Here is yet another way to print your environment:
74797677
74807678=end original
74817679
74827680環境変数を表示する別の例です:
74837681
74847682 my @keys = keys %ENV;
74857683 my @values = values %ENV;
74867684 while (@keys) {
74877685 print pop(@keys), '=', pop(@values), "\n";
74887686 }
74897687
74907688=begin original
74917689
74927690or how about sorted by key:
74937691
74947692=end original
74957693
74967694key でソートしてもいいでしょう:
74977695
74987696 foreach my $key (sort(keys %ENV)) {
74997697 print $key, '=', $ENV{$key}, "\n";
75007698 }
75017699
75027700=begin original
75037701
75047702The returned values are copies of the original keys in the hash, so
75057703modifying them will not affect the original hash. Compare
75067704L<C<values>|/values HASH>.
75077705
75087706=end original
75097707
75107708返される値はハッシュにある元のキーのコピーなので、
75117709これを変更しても元のハッシュには影響を与えません。
75127710L<C<values>|/values HASH> と比較してください。
75137711
75147712=begin original
75157713
75167714To sort a hash by value, you'll need to use a
75177715L<C<sort>|/sort SUBNAME LIST> function. Here's a descending numeric
75187716sort of a hash by its values:
75197717
75207718=end original
75217719
75227720ハッシュを値でソートするためには、L<C<sort>|/sort SUBNAME LIST> 関数を使う
75237721必要があります。
75247722以下ではハッシュの値を数値の降順でソートしています:
75257723
75267724 foreach my $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
75277725 printf "%4d %s\n", $hash{$key}, $key;
75287726 }
75297727
75307728=begin original
75317729
75327730Used as an lvalue, L<C<keys>|/keys HASH> allows you to increase the
75337731number of hash buckets
75347732allocated for the given hash. This can gain you a measure of efficiency if
75357733you know the hash is going to get big. (This is similar to pre-extending
75367734an array by assigning a larger number to $#array.) If you say
75377735
75387736=end original
75397737
75407738左辺値として使うことで、L<C<keys>|/keys HASH> を使うことで与えられたハッシュに
75417739割り当てられたハッシュ表の大きさを増やすことができます。
75427740これによって、ハッシュが大きくなっていくなっていくときの
75437741効率の測定ができます。
75447742(これは大きい値を $#array に代入することで配列を予め拡張することに
75457743似ています。)
75467744以下のようにすると:
75477745
75487746 keys %hash = 200;
75497747
75507748=begin original
75517749
75527750then C<%hash> will have at least 200 buckets allocated for it--256 of them,
75537751in fact, since it rounds up to the next power of two. These
75547752buckets will be retained even if you do C<%hash = ()>, use C<undef
75557753%hash> if you want to free the storage while C<%hash> is still in scope.
75567754You can't shrink the number of buckets allocated for the hash using
75577755L<C<keys>|/keys HASH> in this way (but you needn't worry about doing
75587756this by accident, as trying has no effect). C<keys @array> in an lvalue
75597757context is a syntax error.
75607758
75617759=end original
75627760
75637761C<%hash> は少なくとも 200 の大きさの表が割り当てられます --
75647762実際には 2 のべき乗に切り上げられるので、256 が割り当てられます。
75657763この表はたとえ C<%hash = ()> としても残るので、
75667764もし C<%hash> がスコープにいるうちにこの領域を開放したい場合は
75677765C<undef %hash> を使います。
75687766この方法で L<C<keys>|/keys HASH> を使うことで、表の大きさを小さくすることは
75697767できません
75707768(間違えてそのようなことをしても何も起きないので気にすることはありません)。
75717769左辺値コンテキストでの C<keys @array> は文法エラーとなります。
75727770
75737771=begin original
75747772
75757773Starting with Perl 5.14, an experimental feature allowed
75767774L<C<keys>|/keys HASH> to take a scalar expression. This experiment has
75777775been deemed unsuccessful, and was removed as of Perl 5.24.
75787776
75797777=end original
75807778
75817779Perl 5.14 から、L<C<keys>|/keys HASH> がスカラ式を取ることが出来るという
75827780実験的機能がありました。
75837781この実験は失敗と見なされ、Perl 5.24 で削除されました。
75847782
75857783=begin original
75867784
75877785To avoid confusing would-be users of your code who are running earlier
75887786versions of Perl with mysterious syntax errors, put this sort of thing at
75897787the top of your file to signal that your code will work I<only> on Perls of
75907788a recent vintage:
75917789
75927790=end original
75937791
75947792あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
75957793文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
75967794I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
75977795書いてください:
75987796
75997797 use 5.012; # so keys/values/each work on arrays
76007798
76017799=begin original
76027800
76037801See also L<C<each>|/each HASH>, L<C<values>|/values HASH>, and
76047802L<C<sort>|/sort SUBNAME LIST>.
76057803
76067804=end original
76077805
76087806L<C<each>|/each HASH>, L<C<values>|/values HASH>,
76097807L<C<sort>|/sort SUBNAME LIST> も参照してください。
76107808
76117809=item kill SIGNAL, LIST
76127810
76137811=item kill SIGNAL
76147812X<kill> X<signal>
76157813
76167814=for Pod::Functions send a signal to a process or process group
76177815
76187816=begin original
76197817
76207818Sends a signal to a list of processes. Returns the number of arguments
76217819that were successfully used to signal (which is not necessarily the same
76227820as the number of processes actually killed, e.g. where a process group is
76237821killed).
76247822
76257823=end original
76267824
76277825プロセスのリストにシグナルを送ります。
76287826シグナル送信に使われた引数の数を返します
76297827(例えばプロセスグループが kill された場合のように、実際に kill された
76307828プロセスの数と同じとは限りません)。
76317829
76327830 my $cnt = kill 'HUP', $child1, $child2;
76337831 kill 'KILL', @goners;
76347832
76357833=begin original
76367834
76377835SIGNAL may be either a signal name (a string) or a signal number. A signal
76387836name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the
76397837same signal. The string form of SIGNAL is recommended for portability because
76407838the same signal may have different numbers in different operating systems.
76417839
76427840=end original
76437841
76447842SIGNAL はシグナル名(文字列)かシグナル番号のどちらかです。
76457843シグナル名は C<SIG> 接頭辞で始まることがあるので、C<FOO> と C<SIGFOO> は同じ
76467844シグナルを意味します。
76477845移植性から文字列形式の SIGNAL が推奨されます; 同じシグナルが異なった
76487846オペレーティングシステムでは異なった番号になることがあるからです。
76497847
76507848=begin original
76517849
76527850A list of signal names supported by the current platform can be found in
76537851C<$Config{sig_name}>, which is provided by the L<C<Config>|Config>
76547852module. See L<Config> for more details.
76557853
76567854=end original
76577855
76587856現在のプラットフォームが対応しているシグナル名の一覧は、L<C<Config>|Config>
76597857モジュールによって提供される C<$Config{sig_name}> にあります。
76607858さらなる詳細については L<Config> を参照してください。
76617859
76627860=begin original
76637861
76647862A negative signal name is the same as a negative signal number, killing process
76657863groups instead of processes. For example, C<kill '-KILL', $pgrp> and
76667864C<kill -9, $pgrp> will send C<SIGKILL> to
76677865the entire process group specified. That
76687866means you usually want to use positive not negative signals.
76697867
76707868=end original
76717869
76727870負のシグナル名は負のシグナル番号と同じで、
76737871プロセスではなくプロセスグループに対して kill を行ないます。
76747872たとえば、C<kill '-KILL', $pgrp> と C<kill -9, $pgrp> は指定された
76757873プロセスグループ全体に C<SIGKILL> を送ります。
76767874すなわち、通常は、負のシグナルは用いず、正のシグナルを使うことになります。
76777875
76787876=begin original
76797877
76807878If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>),
76817879no signal is sent to the process, but L<C<kill>|/kill SIGNAL, LIST>
76827880checks whether it's I<possible> to send a signal to it
76837881(that means, to be brief, that the process is owned by the same user, or we are
76847882the super-user). This is useful to check that a child process is still
76857883alive (even if only as a zombie) and hasn't changed its UID. See
76867884L<perlport> for notes on the portability of this construct.
76877885
76887886=end original
76897887
76907888SIGNAL が数値 0 か文字列 C<ZERO> (または C<SIGZERO> の場合、プロセスに
76917889シグナルは送られませんが、L<C<kill>|/kill SIGNAL, LIST> は、
76927890シグナルを送ることが I<可能> かどうかを調べます (これは、簡単に言うと、
76937891プロセスが同じユーザーに所有されているか、自分がスーパーユーザーであることを
76947892意味します)。
76957893これは子プロセスが(ゾンビとしてだけでも)まだ生きていて、 UID が
76967894変わっていないことを調べる時に有用です。
76977895この構成の移植性に関する注意については L<perlport> を参照してください。
76987896
76997897=begin original
77007898
77017899The behavior of kill when a I<PROCESS> number is zero or negative depends on
77027900the operating system. For example, on POSIX-conforming systems, zero will
77037901signal the current process group, -1 will signal all processes, and any
77047902other negative PROCESS number will act as a negative signal number and
77057903kill the entire process group specified.
77067904
77077905=end original
77087906
77097907I<PROCESS> 番号が 0 あるいは負数の場合の kill の振る舞いは
77107908オペレーティングシステムに依存します。
77117909例えば、POSIX 準拠のシステムでは、0 は現在のプロセスグループにシグナルを送り、
77127910-1 は全てのプロセスにシグナルを送り、それ以外の負数の PROCESS 番号は
77137911負数のシグナル番号として動作し、指定されたプロセスグループ全体を kill します。
77147912
77157913=begin original
77167914
77177915If both the SIGNAL and the PROCESS are negative, the results are undefined.
77187916A warning may be produced in a future version.
77197917
77207918=end original
77217919
77227920SIGNAL と PROCESS の両方が負数の場合、結果は未定義です。
77237921将来のバージョンでは警告が出るかも知れません。
77247922
77257923=begin original
77267924
77277925See L<perlipc/"Signals"> for more details.
77287926
77297927=end original
77307928
77317929詳細は L<perlipc/"Signals"> を参照してください。
77327930
77337931=begin original
77347932
77357933On some platforms such as Windows where the L<fork(2)> system call is not
77367934available, Perl can be built to emulate L<C<fork>|/fork> at the
77377935interpreter level.
77387936This emulation has limitations related to kill that have to be considered,
77397937for code running on Windows and in code intended to be portable.
77407938
77417939=end original
77427940
77437941Windows のような L<fork(2)> が利用不能なシステムでは、Perl は
77447942L<C<fork>|/fork> をインタプリタレベルでエミュレートします。
77457943エミュレーションは kill に関連して、コードが Windows で実行されて
77467944しかしコードが移植性があると考えられるように制限があります。
77477945
77487946=begin original
77497947
77507948See L<perlfork> for more details.
77517949
77527950=end original
77537951
77547952さらなる詳細については L<perlfork> を参照してください。
77557953
77567954=begin original
77577955
77587956If there is no I<LIST> of processes, no signal is sent, and the return
77597957value is 0. This form is sometimes used, however, because it causes
77607958tainting checks to be run. But see
77617959L<perlsec/Laundering and Detecting Tainted Data>.
77627960
77637961=end original
77647962
77657963処理する I<LIST> がない場合、シグナルは送られず、返り値は 0 です。
77667964しかし、この形式は時々使われます; 実行するために汚染チェックを
77677965引き起こすからです。
77687966しかし L<perlsec/Laundering and Detecting Tainted Data> を参照してください。
77697967
77707968=begin original
77717969
77727970Portability issues: L<perlport/kill>.
77737971
77747972=end original
77757973
77767974移植性の問題: L<perlport/kill>。
77777975
77787976=item last LABEL
77797977X<last> X<break>
77807978
77817979=item last EXPR
77827980
77837981=item last
77847982
77857983=for Pod::Functions exit a block prematurely
77867984
77877985=begin original
77887986
77897987The L<C<last>|/last LABEL> command is like the C<break> statement in C
77907988(as used in
77917989loops); it immediately exits the loop in question. If the LABEL is
77927990omitted, the command refers to the innermost enclosing
77937991loop. The C<last EXPR> form, available starting in Perl
779479925.18.0, allows a label name to be computed at run time,
77957993and is otherwise identical to C<last LABEL>. The
77967994L<C<continue>|/continue BLOCK> block, if any, is not executed:
77977995
77987996=end original
77997997
78007998L<C<last>|/last LABEL> コマンドは、(ループ内で使った) C の C<break> 文と
78017999同じようなもので、LABEL で指定されるループを即座に抜けます。
78028000LABEL が省略されると、コマンドは一番内側のループを参照します。
78038001Perl 5.18.0 から利用可能な C<last EXPR> 形式では、実行時に計算される
78048002ラベル名を使えます; それ以外は C<last LABEL> と同一です。
78058003L<C<continue>|/continue BLOCK> ブロックがあっても実行されません:
78068004
78078005 LINE: while (<STDIN>) {
78088006 last LINE if /^$/; # exit when done with header
78098007 #...
78108008 }
78118009
78128010=begin original
78138011
7814L<C<last>|/last LABEL> cannot be used to exit a block that returns a
8012L<C<last>|/last LABEL> cannot return a value from a block that typically
7815value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used
8013returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
7816to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
8014its flow control behavior, which precludes any return value. It should not be
8015used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
78178016operation.
78188017
78198018=end original
78208019
78218020L<C<last>|/last LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
7822値を返すブロックを終了するのには使えませんし、
8021典型的には値を返すブロックから値返せません
8022これは、返り値を不可能にするフロー制御の振る舞いを実行します。
78238023L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
78248024使うべきではありません。
78258025
78268026=begin original
78278027
78288028Note that a block by itself is semantically identical to a loop
78298029that executes once. Thus L<C<last>|/last LABEL> can be used to effect
78308030an early exit out of such a block.
78318031
78328032=end original
78338033
78348034ブロック自身は一回だけ実行されるループと文法的に同一であることに
78358035注意してください。
78368036従って、L<C<last>|/last LABEL> でそのようなブロックを途中で
78378037抜け出すことができます。
78388038
78398039=begin original
78408040
78418041See also L<C<continue>|/continue BLOCK> for an illustration of how
78428042L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
78438043L<C<redo>|/redo LABEL> work.
78448044
78458045=end original
78468046
78478047L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
78488048どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
78498049
78508050=begin original
78518051
78528052Unlike most named operators, this has the same precedence as assignment.
78538053It is also exempt from the looks-like-a-function rule, so
78548054C<last ("foo")."bar"> will cause "bar" to be part of the argument to
78558055L<C<last>|/last LABEL>.
78568056
78578057=end original
78588058
78598059ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
78608060また、関数のように見えるものの規則からも免れるので、C<last ("foo")."bar"> と
78618061すると "bar" は L<C<last>|/last LABEL> への引数の一部となります。
78628062
78638063=item lc EXPR
78648064X<lc> X<lowercase>
78658065
78668066=item lc
78678067
78688068=for Pod::Functions return lower-case version of a string
78698069
78708070=begin original
78718071
78728072Returns a lowercased version of EXPR. This is the internal function
78738073implementing the C<\L> escape in double-quoted strings.
78748074
78758075=end original
78768076
78778077EXPR を小文字に変換したものを返します。
78788078これは、ダブルクォート文字列における、
78798079C<\L> エスケープを実装する内部関数です。
78808080
78818081=begin original
78828082
78838083If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
78848084
78858085=end original
78868086
78878087EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
78888088
78898089=begin original
78908090
78918091What gets returned depends on several factors:
78928092
78938093=end original
78948094
78958095返り値として得られるものは色々な要素に依存します:
78968096
78978097=over
78988098
78998099=item If C<use bytes> is in effect:
79008100
79018101(C<use bytes> が有効の場合)
79028102
79038103=begin original
79048104
79058105The results follow ASCII rules. Only the characters C<A-Z> change,
79068106to C<a-z> respectively.
79078107
79088108=end original
79098109
79108110結果は ASCII の規則に従います。
79118111C<A-Z> のみが変換され、それぞれ C<a-z> になります。
79128112
79138113=item Otherwise, if C<use locale> for C<LC_CTYPE> is in effect:
79148114
79158115(それ以外の場合で、C<LC_CTYPE> に対して C<use locale> が有効の場合)
79168116
79178117=begin original
79188118
79198119Respects current C<LC_CTYPE> locale for code points < 256; and uses Unicode
79208120rules for the remaining code points (this last can only happen if
79218121the UTF8 flag is also set). See L<perllocale>.
79228122
79238123=end original
79248124
79258125符号位置 < 256 に対しては現在の C<LC_CTYPE> ロケールに従います; そして
79268126残りの符号位置に付いては Unicode の規則を使います (これは UTF8 フラグも
79278127設定されている場合にのみ起こります)。
79288128L<perllocale> を参照してください。
79298129
79308130=begin original
79318131
79328132Starting in v5.20, Perl uses full Unicode rules if the locale is
79338133UTF-8. Otherwise, there is a deficiency in this scheme, which is that
79348134case changes that cross the 255/256
79358135boundary are not well-defined. For example, the lower case of LATIN CAPITAL
79368136LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII
79378137platforms). But under C<use locale> (prior to v5.20 or not a UTF-8
79388138locale), the lower case of U+1E9E is
79398139itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the
79408140current locale, and Perl has no way of knowing if that character even
79418141exists in the locale, much less what code point it is. Perl returns
79428142a result that is above 255 (almost always the input character unchanged),
79438143for all instances (and there aren't many) where the 255/256 boundary
79448144would otherwise be crossed; and starting in v5.22, it raises a
79458145L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".> warning.
79468146
79478147=end original
79488148
79498149v5.20 から、ロケールが UTF-8 の場合は Perl は完全な Unicode の規則を使います。
79508150さもなければ、この手法には、255/266 の境界をまたぐ大文字小文字の変換は
79518151未定義であるという欠点があります。
79528152例えば、Unicode での LATIN CAPITAL LETTER SHARP S (U+1E9E) の小文字は
79538153(ASCII プラットフォームでは) U+00DF です。
79548154しかし C<use locale> が有効(v5.20 より前か、UTF-8 ロケール以外)なら、U+1E9E の
79558155小文字は自分自身です; なぜなら 0xDF は現在のロケールでは
79568156LATIN SMALL LETTER SHARP S ではなく、Perl は例えこのロケールに文字が
79578157存在するかどうかを知る方法がなく、ましてどの符号位置かを知る方法が
79588158ないからです。
79598159Perl は 255/256 境界をまたぐ全ての(多くはありません)実体については
79608160(ほとんど常に入力文字を変更せずに)256 以上の値を返します;
79618161そして v5.22 から
79628162L<locale|perldiag/Can't do %s("%s") on non-UTF-8 locale; resolved to "%s".>
79638163警告を出力します。
79648164
79658165=item Otherwise, If EXPR has the UTF8 flag set:
79668166
79678167(その他の場合で、EXPR に UTF8 フラグがセットされている場合)
79688168
79698169=begin original
79708170
79718171Unicode rules are used for the case change.
79728172
79738173=end original
79748174
79758175大文字小文字変換には Unicode の規則が使われます。
79768176
79778177=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect:
79788178
79798179(それ以外の場合で、C<use feature 'unicode_strings'> か C<use locale ':not_characters'> が有効の場合)
79808180
79818181=begin original
79828182
79838183Unicode rules are used for the case change.
79848184
79858185=end original
79868186
79878187大文字小文字変換には Unicode の規則が使われます。
79888188
79898189=item Otherwise:
79908190
79918191(それ以外の場合)
79928192
79938193=begin original
79948194
79958195ASCII rules are used for the case change. The lowercase of any character
79968196outside the ASCII range is the character itself.
79978197
79988198=end original
79998199
80008200大文字小文字変換には ASCII の規則が使われます。
80018201ASCII の範囲外の文字の「小文字」はその文字自身です。
80028202
80038203=back
80048204
80058205=item lcfirst EXPR
80068206X<lcfirst> X<lowercase>
80078207
80088208=item lcfirst
80098209
80108210=for Pod::Functions return a string with just the next letter in lower case
80118211
80128212=begin original
80138213
80148214Returns the value of EXPR with the first character lowercased. This
80158215is the internal function implementing the C<\l> escape in
80168216double-quoted strings.
80178217
80188218=end original
80198219
80208220最初の文字だけを小文字にした、EXPR を返します。
80218221これは、ダブルクォート文字列における、C<\l> エスケープを
80228222実装する内部関数です。
80238223
80248224=begin original
80258225
80268226If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
80278227
80288228=end original
80298229
80308230EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
80318231
80328232=begin original
80338233
80348234This function behaves the same way under various pragmas, such as in a locale,
80358235as L<C<lc>|/lc EXPR> does.
80368236
80378237=end original
80388238
80398239この関数は、ロケールのようなさまざまなプラグマの影響下では、
80408240L<C<lc>|/lc EXPR> と同様に振る舞います。
80418241
80428242=item length EXPR
80438243X<length> X<size>
80448244
80458245=item length
80468246
80478247=for Pod::Functions return the number of characters in a string
80488248
80498249=begin original
80508250
80518251Returns the length in I<characters> of the value of EXPR. If EXPR is
80528252omitted, returns the length of L<C<$_>|perlvar/$_>. If EXPR is
80538253undefined, returns L<C<undef>|/undef EXPR>.
80548254
80558255=end original
80568256
80578257EXPR の値の I<文字> の長さを返します。
80588258EXPR が省略されたときには、L<C<$_>|perlvar/$_> の長さを返します。
80598259EXPR が未定義値の場合、L<C<undef>|/undef EXPR> を返します。
80608260
80618261=begin original
80628262
80638263This function cannot be used on an entire array or hash to find out how
80648264many elements these have. For that, use C<scalar @array> and C<scalar keys
80658265%hash>, respectively.
80668266
80678267=end original
80688268
80698269この関数は配列やハッシュ全体に対してどれだけの要素を含んでいるかを
80708270調べるためには使えません。
80718271そのような用途には、それぞれ C<scalar @array> と C<scalar keys %hash> を
80728272利用してください。
80738273
80748274=begin original
80758275
80768276Like all Perl character operations, L<C<length>|/length EXPR> normally
80778277deals in logical
80788278characters, not physical bytes. For how many bytes a string encoded as
80798279UTF-8 would take up, use C<length(Encode::encode('UTF-8', EXPR))>
80808280(you'll have to C<use Encode> first). See L<Encode> and L<perlunicode>.
80818281
80828282=end original
80838283
80848284全ての Perl の文字操作と同様、L<C<length>|/length EXPR> は通常物理的な
80858285バイトではなく論理文字を扱います。
80868286UTF-8 でエンコードされた文字列が何バイトかを知るには、
80878287C<length(Encode::encode('UTF-8', EXPR))> を使ってください (先に
80888288C<use Encode> する必要があります)。
80898289L<Encode> と L<perlunicode> を参照してください。
80908290
80918291=item __LINE__
80928292X<__LINE__>
80938293
80948294=for Pod::Functions the current source line number
80958295
80968296=begin original
80978297
80988298A special token that compiles to the current line number.
8299It can be altered by the mechanism described at
8300L<perlsyn/"Plain Old Comments (Not!)">.
80998301
81008302=end original
81018303
81028304現在の行番号にコンパイルされる特殊トークン。
8305L<perlsyn/"Plain Old Comments (Not!)"> で記述されている機構を使って
8306置き換えられます。
81038307
81048308=item link OLDFILE,NEWFILE
81058309X<link>
81068310
81078311=for Pod::Functions create a hard link in the filesystem
81088312
81098313=begin original
81108314
81118315Creates a new filename linked to the old filename. Returns true for
81128316success, false otherwise.
81138317
81148318=end original
81158319
81168320OLDFILE にリンクされた、新しいファイル NEWFILE を作ります。
81178321成功時には真を、さもなければ偽を返します。
81188322
81198323=begin original
81208324
81218325Portability issues: L<perlport/link>.
81228326
81238327=end original
81248328
81258329移植性の問題: L<perlport/link>。
81268330
81278331=item listen SOCKET,QUEUESIZE
81288332X<listen>
81298333
81308334=for Pod::Functions register your socket as a server
81318335
81328336=begin original
81338337
81348338Does the same thing that the L<listen(2)> system call does. Returns true if
81358339it succeeded, false otherwise. See the example in
81368340L<perlipc/"Sockets: Client/Server Communication">.
81378341
81388342=end original
81398343
81408344L<listen(2)> システムコールと同じことをします。
81418345成功時には真を、さもなければ偽を返します。
81428346L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
81438347
81448348=item local EXPR
81458349X<local>
81468350
81478351=for Pod::Functions create a temporary value for a global variable (dynamic scoping)
81488352
81498353=begin original
81508354
81518355You really probably want to be using L<C<my>|/my VARLIST> instead,
81528356because L<C<local>|/local EXPR> isn't what most people think of as
81538357"local". See L<perlsub/"Private Variables via my()"> for details.
81548358
81558359=end original
81568360
81578361あなたはが本当に望んでいるのは L<C<my>|/my VARLIST> の方でしょう;
81588362L<C<local>|/local EXPR> はほとんどの人々が「ローカル」と考えるものと
81598363違うからです。
81608364詳細は L<perlsub/"Private Variables via my()"> を参照してください。
81618365
81628366=begin original
81638367
81648368A local modifies the listed variables to be local to the enclosing
81658369block, file, or eval. If more than one value is listed, the list must
81668370be placed in parentheses. See L<perlsub/"Temporary Values via local()">
81678371for details, including issues with tied arrays and hashes.
81688372
81698373=end original
81708374
81718375"local" はリストアップされた変数を、囲っているブロック、
81728376ファイル、eval の中で、ローカルなものにします。
81738377複数の値を指定する場合は、リストはかっこでくくらなければなりません。
81748378tie した配列とハッシュに関する事項を含む詳細については
81758379L<perlsub/"Temporary Values via local()"> を参照してください。
81768380
81778381=begin original
81788382
81798383The C<delete local EXPR> construct can also be used to localize the deletion
81808384of array/hash elements to the current block.
81818385See L<perlsub/"Localized deletion of elements of composite types">.
81828386
81838387=end original
81848388
81858389C<delete local EXPR> 構文は、配列/ハッシュの要素の削除を現在の
81868390ブロックにローカル化するためにも使われていました。
81878391L<perlsub/"Localized deletion of elements of composite types"> を
81888392参照してください。
81898393
81908394=item localtime EXPR
81918395X<localtime> X<ctime>
81928396
81938397=item localtime
81948398
81958399=for Pod::Functions convert UNIX time into record or string using local time
81968400
81978401=begin original
81988402
81998403Converts a time as returned by the time function to a 9-element list
82008404with the time analyzed for the local time zone. Typically used as
82018405follows:
82028406
82038407=end original
82048408
82058409time 関数が返す時刻を、ローカルなタイムゾーンで測った時刻として、
820684109 要素の配列に変換します。
82078411普通は、以下のようにして使います:
82088412
82098413 # 0 1 2 3 4 5 6 7 8
82108414 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
82118415 localtime(time);
82128416
82138417=begin original
82148418
82158419All list elements are numeric and come straight out of the C `struct
82168420tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours
82178421of the specified time.
82188422
82198423=end original
82208424
82218425すべてのリスト要素は数値で、C の `struct tm' 構造体から
82228426直接持ってきます。
82238427C<$sec>, C<$min>, C<$hour> は指定された時刻の秒、分、時です。
82248428
82258429=begin original
82268430
82278431C<$mday> is the day of the month and C<$mon> the month in
82288432the range C<0..11>, with 0 indicating January and 11 indicating December.
82298433This makes it easy to get a month name from a list:
82308434
82318435=end original
82328436
82338437C<$mday> は月の何日目か、C<$mon> は月の値です; 月の値は C<0..11> で、0 が
823484381 月、11 が 12 月です。
82358439これにより、リストから月の名前を得るのが簡単になります:
82368440
82378441 my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
82388442 print "$abbr[$mon] $mday";
82398443 # $mon=9, $mday=18 gives "Oct 18"
82408444
82418445=begin original
82428446
82438447C<$year> contains the number of years since 1900. To get a 4-digit
82448448year write:
82458449
82468450=end original
82478451
82488452C<$year> は 1900 年からの年数を持ちます。
824984534 桁の年を得るには以下のようにします:
82508454
82518455 $year += 1900;
82528456
82538457=begin original
82548458
82558459To get the last two digits of the year (e.g., "01" in 2001) do:
82568460
82578461=end original
82588462
82598463西暦の下 2 桁(2001 年では "01")がほしい場合は以下のようにします:
82608464
82618465 $year = sprintf("%02d", $year % 100);
82628466
82638467=begin original
82648468
82658469C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating
82668470Wednesday. C<$yday> is the day of the year, in the range C<0..364>
82678471(or C<0..365> in leap years.)
82688472
82698473=end original
82708474
82718475C<$wday> は曜日で、0 が日曜日、3 が水曜日です。
82728476C<$yday> はその年の何日目かで、C<0..364> の値を取ります
82738477(うるう年は C<0..365> です。)
82748478
82758479=begin original
82768480
82778481C<$isdst> is true if the specified time occurs during Daylight Saving
82788482Time, false otherwise.
82798483
82808484=end original
82818485
82828486C<$isdst> は指定された時刻が夏時間の場合は真、そうでなければ偽です。
82838487
82848488=begin original
82858489
82868490If EXPR is omitted, L<C<localtime>|/localtime EXPR> uses the current
82878491time (as returned by L<C<time>|/time>).
82888492
82898493=end original
82908494
82918495EXPR が省略されると、L<C<localtime>|/localtime EXPR> は
82928496(L<C<time>|/time> によって返される) 現在時刻を使います。
82938497
82948498=begin original
82958499
82968500In scalar context, L<C<localtime>|/localtime EXPR> returns the
82978501L<ctime(3)> value:
82988502
82998503=end original
83008504
83018505スカラコンテキストでは、L<C<localtime>|/localtime EXPR> は L<ctime(3)> の値を
83028506返します:
83038507
83048508 my $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
83058509
83068510=begin original
83078511
83088512The format of this scalar value is B<not> locale-dependent but built
83098513into Perl. For GMT instead of local time use the
83108514L<C<gmtime>|/gmtime EXPR> builtin. See also the
83118515L<C<Time::Local>|Time::Local> module (for converting seconds, minutes,
83128516hours, and such back to the integer value returned by L<C<time>|/time>),
83138517and the L<POSIX> module's L<C<strftime>|POSIX/C<strftime>> and
83148518L<C<mktime>|POSIX/C<mktime>> functions.
83158519
83168520=end original
83178521
83188522このスカラ値の形式はロケール依存 B<ではなく>、Perl の組み込みの値です。
83198523ローカル時刻ではなく GMT がほしい場合は L<C<gmtime>|/gmtime EXPR> 組み込み
83208524関数を使ってください。
83218525また、(秒、分、時などの形から、L<C<time>|/time> が返す値である
832285261970 年 1 月 1 日の真夜中からの秒数に変換する)
83238527L<C<Time::Local>|Time::Local> モジュール及び L<POSIX> モジュールで提供される
83248528L<C<strftime>|POSIX/C<strftime>> と L<C<mktime>|POSIX/C<mktime>> 関数も
83258529参照してください。
83268530
83278531=begin original
83288532
83298533To get somewhat similar but locale-dependent date strings, set up your
83308534locale environment variables appropriately (please see L<perllocale>) and
83318535try for example:
83328536
83338537=end original
83348538
83358539似たような、しかしロケール依存の日付文字列がほしい場合は、
83368540ロケール環境変数を適切に設定して(L<perllocale> を参照してください)、
83378541以下の例を試してください:
83388542
83398543 use POSIX qw(strftime);
83408544 my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
83418545 # or for GMT formatted appropriately for your locale:
83428546 my $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
83438547
83448548=begin original
83458549
83468550Note that C<%a> and C<%b>, the short forms of the day of the week
83478551and the month of the year, may not necessarily be three characters wide.
83488552
83498553=end original
83508554
83518555曜日と月の短い表現である C<%a> と C<%b> は、3 文字とは限らないことに
83528556注意してください。
83538557
83548558=begin original
83558559
83568560The L<Time::gmtime> and L<Time::localtime> modules provide a convenient,
83578561by-name access mechanism to the L<C<gmtime>|/gmtime EXPR> and
83588562L<C<localtime>|/localtime EXPR> functions, respectively.
83598563
83608564=end original
83618565
83628566L<Time::gmtime> モジュールと L<Time::localtime> モジュールは、それぞれ
83638567L<C<gmtime>|/gmtime EXPR> 関数と L<C<localtime>|/localtime EXPR> 関数に、
83648568名前でアクセスする機構を提供する便利なモジュールです。
83658569
83668570=begin original
83678571
83688572For a comprehensive date and time representation look at the
83698573L<DateTime> module on CPAN.
83708574
83718575=end original
83728576
83738577包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
83748578参照してください。
83758579
83768580=begin original
83778581
83788582Portability issues: L<perlport/localtime>.
83798583
83808584=end original
83818585
83828586移植性の問題: L<perlport/localtime>。
83838587
83848588=item lock THING
83858589X<lock>
83868590
83878591=for Pod::Functions +5.005 get a thread lock on a variable, subroutine, or method
83888592
83898593=begin original
83908594
83918595This function places an advisory lock on a shared variable or referenced
83928596object contained in I<THING> until the lock goes out of scope.
83938597
83948598=end original
83958599
83968600この関数は I<THING> が含む共有変数またはリファレンスされたオブジェクトに、
83978601スコープから出るまでアドバイサリロックを掛けます.
83988602
83998603=begin original
84008604
84018605The value returned is the scalar itself, if the argument is a scalar, or a
84028606reference, if the argument is a hash, array or subroutine.
84038607
84048608=end original
84058609
84068610返される値は、引数がスカラならそのスカラ自身、引数がハッシュ、配列、
84078611サブルーチンならリファレンスです。
84088612
84098613=begin original
84108614
84118615L<C<lock>|/lock THING> is a "weak keyword"; this means that if you've
84128616defined a function
84138617by this name (before any calls to it), that function will be called
84148618instead. If you are not under C<use threads::shared> this does nothing.
84158619See L<threads::shared>.
84168620
84178621=end original
84188622
84198623L<C<lock>|/lock THING> は「弱いキーワード」です; もしユーザーが(呼び出し前に)
84208624この名前で関数を定義すると、定義された関数の方が呼び出されます。
84218625C<use threads::shared> の影響下でない場合は、これは何もしません。
84228626L<threads::shared> を参照してください。
84238627
84248628=item log EXPR
84258629X<log> X<logarithm> X<e> X<ln> X<base>
84268630
84278631=item log
84288632
84298633=for Pod::Functions retrieve the natural logarithm for a number
84308634
84318635=begin original
84328636
84338637Returns the natural logarithm (base I<e>) of EXPR. If EXPR is omitted,
84348638returns the log of L<C<$_>|perlvar/$_>. To get the
84358639log of another base, use basic algebra:
84368640The base-N log of a number is equal to the natural log of that number
84378641divided by the natural log of N. For example:
84388642
84398643=end original
84408644
84418645EXPR の (I<e> を底とする) 自然対数を返します。
84428646EXPR が省略されると、L<C<$_>|perlvar/$_> の対数を返します。
84438647底の異なる対数を求めるためには、基礎代数を利用してください:
84448648ある数の N を底とする対数は、その数の自然対数を N の自然対数で割ったものです。
84458649例えば:
84468650
84478651 sub log10 {
84488652 my $n = shift;
84498653 return log($n)/log(10);
84508654 }
84518655
84528656=begin original
84538657
84548658See also L<C<exp>|/exp EXPR> for the inverse operation.
84558659
84568660=end original
84578661
84588662逆操作については L<C<exp>|/exp EXPR> を参照してください。
84598663
84608664=item lstat FILEHANDLE
84618665X<lstat>
84628666
84638667=item lstat EXPR
84648668
84658669=item lstat DIRHANDLE
84668670
84678671=item lstat
84688672
84698673=for Pod::Functions stat a symbolic link
84708674
84718675=begin original
84728676
84738677Does the same thing as the L<C<stat>|/stat FILEHANDLE> function
84748678(including setting the special C<_> filehandle) but stats a symbolic
84758679link instead of the file the symbolic link points to. If symbolic links
84768680are unimplemented on your system, a normal L<C<stat>|/stat FILEHANDLE>
84778681is done. For much more detailed information, please see the
84788682documentation for L<C<stat>|/stat FILEHANDLE>.
84798683
84808684=end original
84818685
84828686(特別なファイルハンドルである C<_> の設定を含めて)
84838687L<C<stat>|/stat FILEHANDLE> 関数と同じことをしますが、シンボリックリンクが
84848688指しているファイルではなく、シンボリックリンク自体の stat をとります。
84858689シンボリックリンクがシステムに実装されていないと、通常の
84868690L<C<stat>|/stat FILEHANDLE> が行なわれます。
84878691さらにより詳細な情報については、L<C<stat>|/stat FILEHANDLE> の文書を
84888692参照してください。
84898693
84908694=begin original
84918695
84928696If EXPR is omitted, stats L<C<$_>|perlvar/$_>.
84938697
84948698=end original
84958699
84968700EXPR が省略されると、L<C<$_>|perlvar/$_> の stat をとります。
84978701
84988702=begin original
84998703
85008704Portability issues: L<perlport/lstat>.
85018705
85028706=end original
85038707
85048708移植性の問題: L<perlport/lstat>。
85058709
85068710=item m//
85078711
85088712=for Pod::Functions match a string with a regular expression pattern
85098713
85108714=begin original
85118715
85128716The match operator. See L<perlop/"Regexp Quote-Like Operators">.
85138717
85148718=end original
85158719
85168720マッチ演算子です。
85178721L<perlop/"Regexp Quote-Like Operators"> を参照してください。
85188722
85198723=item map BLOCK LIST
85208724X<map>
85218725
85228726=item map EXPR,LIST
85238727
85248728=for Pod::Functions apply a change to a list to get back a new list with the changes
85258729
85268730=begin original
85278731
85288732Evaluates the BLOCK or EXPR for each element of LIST (locally setting
8529L<C<$_>|perlvar/$_> to each element) and returns the list value composed
8733L<C<$_>|perlvar/$_> to each element) and composes a list of the results of
8530of the
8734each such evaluation. Each element of LIST may produce zero, one, or more
8531results of each such evaluation. In scalar context, returns the
8735elements in the generated list, so the number of elements in the generated
8532total number of elements so generated. Evaluates BLOCK or EXPR in
8736list may differ from that in LIST. In scalar context, returns the total
8533list context, so each element of LIST may produce zero, one, or
8737number of elements so generated. In list context, returns the generated list.
8534more elements in the returned value.
85358738
85368739=end original
85378740
85388741LIST の個々の要素に対して、BLOCK か EXPR を評価し
85398742(L<C<$_>|perlvar/$_> は、ローカルに個々の要素が設定されます) 、
8540それぞれの評価結果からなるリスト値が返されます。
8743それぞれの評価結果からなるリストを作ります。
8744LIST の個々の要素によって作られる、生成されたリストの要素数は、
87450 個の場合もあれば、複数の場合もあるので、
8746生成されたリストの要素数は LIST の要素数と異なるかも知れません。
85418747スカラコンテキストでは、生成された要素の数を返します。
8542BLOCK や EXPR をリストコンテキストで評価しますので、LIST の
8748リストコンテキストでは、生成されたリストを返します
8543個々の要素によって作られる、返り値であるリストの要素数は、
85440 個の場合もあれば、複数の場合もあります。
85458749
85468750 my @chars = map(chr, @numbers);
85478751
85488752=begin original
85498753
85508754translates a list of numbers to the corresponding characters.
85518755
85528756=end original
85538757
85548758は、数のリストを対応する文字に変換します。
85558759
85568760 my @squares = map { $_ * $_ } @numbers;
85578761
85588762=begin original
85598763
85608764translates a list of numbers to their squared values.
85618765
85628766=end original
85638767
85648768これは数値のリストを、その 2 乗に変換します。
85658769
85668770 my @squares = map { $_ > 5 ? ($_ * $_) : () } @numbers;
85678771
85688772=begin original
85698773
85708774shows that number of returned elements can differ from the number of
85718775input elements. To omit an element, return an empty list ().
85728776This could also be achieved by writing
85738777
85748778=end original
85758779
85768780のように、返された要素の数が入力要素の数と異なる場合もあります。
85778781要素を省略するには、空リスト () を返します。
85788782これは以下のように書くことでも達成できて
85798783
85808784 my @squares = map { $_ * $_ } grep { $_ > 5 } @numbers;
85818785
85828786=begin original
85838787
85848788which makes the intention more clear.
85858789
85868790=end original
85878791
85888792この方が目的がよりはっきりします。
85898793
85908794=begin original
85918795
85928796Map always returns a list, which can be
85938797assigned to a hash such that the elements
85948798become key/value pairs. See L<perldata> for more details.
85958799
85968800=end original
85978801
85988802map は常にリストを返し、要素がキー/値の組になるようなハッシュに
85998803代入できます。
86008804さらなる詳細については L<perldata> を参照してください。
86018805
86028806 my %hash = map { get_a_key_for($_) => $_ } @array;
86038807
86048808=begin original
86058809
86068810is just a funny way to write
86078811
86088812=end original
86098813
86108814は以下のものをちょっと変わった書き方で書いたものです。
86118815
86128816 my %hash;
86138817 foreach (@array) {
86148818 $hash{get_a_key_for($_)} = $_;
86158819 }
86168820
86178821=begin original
86188822
86198823Note that L<C<$_>|perlvar/$_> is an alias to the list value, so it can
86208824be used to modify the elements of the LIST. While this is useful and
86218825supported, it can cause bizarre results if the elements of LIST are not
86228826variables. Using a regular C<foreach> loop for this purpose would be
86238827clearer in most cases. See also L<C<grep>|/grep BLOCK LIST> for a
86248828list composed of those items of the original list for which the BLOCK
86258829or EXPR evaluates to true.
86268830
86278831=end original
86288832
86298833L<C<$_>|perlvar/$_> は、LIST の値へのエイリアスですので、LIST の要素を
86308834変更するために使うことができます。
86318835これは、便利でサポートされていますが、
86328836LIST の要素が変数でないと、おかしな結果になります。
86338837この目的には通常の C<foreach> ループを使うことで、ほとんどの場合は
86348838より明確になります。
86358839BLOCK や EXPR が真になる元のリストの要素からなるリストについては、
86368840L<C<grep>|/grep BLOCK LIST> も参照してください。
86378841
86388842=begin original
86398843
86408844C<{> starts both hash references and blocks, so C<map { ...> could be either
86418845the start of map BLOCK LIST or map EXPR, LIST. Because Perl doesn't look
86428846ahead for the closing C<}> it has to take a guess at which it's dealing with
86438847based on what it finds just after the
86448848C<{>. Usually it gets it right, but if it
86458849doesn't it won't realize something is wrong until it gets to the C<}> and
86468850encounters the missing (or unexpected) comma. The syntax error will be
86478851reported close to the C<}>, but you'll need to change something near the C<{>
86488852such as using a unary C<+> or semicolon to give Perl some help:
86498853
86508854=end original
86518855
86528856C<{> はハッシュリファレンスとブロックの両方の開始文字なので、
86538857C<map { ...> は map BLOCK LIST の場合と map EXPR, LIST の場合があります。
86548858Perl は終了文字の C<}> を先読みしないので、C<{> の直後の文字を見て
86558859どちらとして扱うかを推測します。
86568860通常この推測は正しいですが、もし間違った場合は、C<}> まで読み込んで
86578861カンマが足りない(または多い)ことがわかるまで、何かがおかしいことに
86588862気付きません。
86598863C<}> の近くで文法エラーが出ますが、Perl を助けるために単項の C<+> や
86608864セミコロンを使うというように、C<{> の近くの何かを変更する必要があります。
86618865
86628866 my %hash = map { "\L$_" => 1 } @array # perl guesses EXPR. wrong
86638867 my %hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK. right
86648868 my %hash = map {; "\L$_" => 1 } @array # this also works
86658869 my %hash = map { ("\L$_" => 1) } @array # as does this
86668870 my %hash = map { lc($_) => 1 } @array # and this.
86678871 my %hash = map +( lc($_) => 1 ), @array # this is EXPR and works!
86688872
86698873 my %hash = map ( lc($_), 1 ), @array # evaluates to (1, @array)
86708874
86718875=begin original
86728876
86738877or to force an anon hash constructor use C<+{>:
86748878
86758879=end original
86768880
86778881または C<+{> を使って無名ハッシュコンストラクタを強制します:
86788882
86798883 my @hashes = map +{ lc($_) => 1 }, @array # EXPR, so needs
86808884 # comma at end
86818885
86828886=begin original
86838887
86848888to get a list of anonymous hashes each with only one entry apiece.
86858889
86868890=end original
86878891
86888892こうするとそれぞれ 1 要素だけの無名ハッシュのリストを得られます。
86898893
8690=item mkdir FILENAME,MASK
8894=item mkdir FILENAME,MODE
86918895X<mkdir> X<md> X<directory, create>
86928896
86938897=item mkdir FILENAME
86948898
86958899=item mkdir
86968900
86978901=for Pod::Functions create a directory
86988902
86998903=begin original
87008904
87018905Creates the directory specified by FILENAME, with permissions
8702specified by MASK (as modified by L<C<umask>|/umask EXPR>). If it
8906specified by MODE (as modified by L<C<umask>|/umask EXPR>). If it
87038907succeeds it returns true; otherwise it returns false and sets
87048908L<C<$!>|perlvar/$!> (errno).
8705MASK defaults to 0777 if omitted, and FILENAME defaults
8909MODE defaults to 0777 if omitted, and FILENAME defaults
87068910to L<C<$_>|perlvar/$_> if omitted.
87078911
87088912=end original
87098913
8710FILENAME で指定したディレクトリを、MASK で指定した許可モード(を
8914FILENAME で指定したディレクトリを、MODE で指定した許可モード(を
87118915L<C<umask>|/umask EXPR> で修正したもの) で作成します。
87128916成功時には真を返します; さもなければ偽を返して
87138917L<C<$!>|perlvar/$!> (errno) を設定します。
8714MASK を省略すると、0777 とみなし、
8918MODE を省略すると、0777 とみなし、
87158919FILENAME を省略すると、L<C<$_>|perlvar/$_> を使います。
87168920
87178921=begin original
87188922
8719In general, it is better to create directories with a permissive MASK
8923In general, it is better to create directories with a permissive MODE
87208924and let the user modify that with their L<C<umask>|/umask EXPR> than it
87218925is to supply
8722a restrictive MASK and give the user no way to be more permissive.
8926a restrictive MODE and give the user no way to be more permissive.
87238927The exceptions to this rule are when the file or directory should be
87248928kept private (mail files, for instance). The documentation for
8725L<C<umask>|/umask EXPR> discusses the choice of MASK in more detail.
8929L<C<umask>|/umask EXPR> discusses the choice of MODE in more detail.
87268930
87278931=end original
87288932
8729一般的に、制限された MASK を使ってユーザーがより寛容にする方法を
8933一般的に、制限された MODE を使ってユーザーがより寛容にする方法を
8730与えないより、寛容な MASK でディレクトリを作り、ユーザーが自身の
8934与えないより、寛容な MODE でディレクトリを作り、ユーザーが自身の
87318935L<C<umask>|/umask EXPR> で修正するようにした方がよいです。
87328936例外は、(例えばメールファイルのような)プライベートに保つべきファイルや
87338937ディレクトリを書く場合です。
8734L<C<umask>|/umask EXPR> の文書で、MASK の選択に関して詳細に議論しています。
8938L<C<umask>|/umask EXPR> の文書で、MODE の選択に関して詳細に議論しています。
87358939
87368940=begin original
87378941
87388942Note that according to the POSIX 1003.1-1996 the FILENAME may have any
87398943number of trailing slashes. Some operating and filesystems do not get
87408944this right, so Perl automatically removes all trailing slashes to keep
87418945everyone happy.
87428946
87438947=end original
87448948
87458949POSIX 1003.1-1996 によれば、FILENAME には末尾に任意の数のスラッシュを
87468950つけることができます。
87478951このようには動かない OS やファイルシステムもあるので、Perl はみんなが
87488952幸せになれるように、自動的に末尾のスラッシュを削除します。
87498953
87508954=begin original
87518955
87528956To recursively create a directory structure, look at
87538957the L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> function
87548958of the L<File::Path> module.
87558959
87568960=end original
87578961
87588962ディレクトリ構造を再帰的に作成するには、L<File::Path> モジュールの
87598963L<C<make_path>|File::Path/make_path( $dir1, $dir2, .... )> 関数を
87608964参照してください。
87618965
87628966=item msgctl ID,CMD,ARG
87638967X<msgctl>
87648968
87658969=for Pod::Functions SysV IPC message control operations
87668970
87678971=begin original
87688972
87698973Calls the System V IPC function L<msgctl(2)>. You'll probably have to say
87708974
87718975=end original
87728976
87738977System V IPC 関数 L<msgctl(2)> を呼び出します。
87748978正しい定数定義を得るために、まず
87758979
87768980 use IPC::SysV;
87778981
87788982=begin original
87798983
87808984first to get the correct constant definitions. If CMD is C<IPC_STAT>,
87818985then ARG must be a variable that will hold the returned C<msqid_ds>
87828986structure. Returns like L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
87838987the undefined value for error, C<"0 but true"> for zero, or the actual
87848988return value otherwise. See also L<perlipc/"SysV IPC"> and the
87858989documentation for L<C<IPC::SysV>|IPC::SysV> and
87868990L<C<IPC::Semaphore>|IPC::Semaphore>.
87878991
87888992=end original
87898993
87908994と書くことが必要でしょう。
87918995CMD が C<IPC_STAT> であれば、ARG は返される C<msqid_ds> 構造体を
87928996納める変数でなければなりません。
87938997L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
87948998未定義値、ゼロのときは C<"0 but true">、それ以外なら、その値そのものを
87958999返します。
87969000L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
87979001L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
87989002
87999003=begin original
88009004
88019005Portability issues: L<perlport/msgctl>.
88029006
88039007=end original
88049008
88059009移植性の問題: L<perlport/msgctl>。
88069010
88079011=item msgget KEY,FLAGS
88089012X<msgget>
88099013
88109014=for Pod::Functions get SysV IPC message queue
88119015
88129016=begin original
88139017
88149018Calls the System V IPC function L<msgget(2)>. Returns the message queue
88159019id, or L<C<undef>|/undef EXPR> on error. See also L<perlipc/"SysV IPC">
88169020and the documentation for L<C<IPC::SysV>|IPC::SysV> and
88179021L<C<IPC::Msg>|IPC::Msg>.
88189022
88199023=end original
88209024
88219025System V IPC 関数 L<msgget(2)> を呼び出します。
88229026メッセージキューの ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
88239027L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
88249028L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
88259029
88269030=begin original
88279031
88289032Portability issues: L<perlport/msgget>.
88299033
88309034=end original
88319035
88329036移植性の問題: L<perlport/msgget>。
88339037
88349038=item msgrcv ID,VAR,SIZE,TYPE,FLAGS
88359039X<msgrcv>
88369040
88379041=for Pod::Functions receive a SysV IPC message from a message queue
88389042
88399043=begin original
88409044
88419045Calls the System V IPC function msgrcv to receive a message from
88429046message queue ID into variable VAR with a maximum message size of
88439047SIZE. Note that when a message is received, the message type as a
88449048native long integer will be the first thing in VAR, followed by the
88459049actual message. This packing may be opened with C<unpack("l! a*")>.
88469050Taints the variable. Returns true if successful, false
88479051on error. See also L<perlipc/"SysV IPC"> and the documentation for
88489052L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
88499053
88509054=end original
88519055
88529056System V IPC 関数 msgrcv を呼び出し、メッセージキュー ID から、
88539057変数 VAR に最大メッセージ長 SIZE のメッセージを受信します。
88549058メッセージが受信された時、ネイティブな long 整数のメッセージタイプが
88559059VAR の先頭となり、実際のメッセージが続きます。
88569060このパッキングは C<unpack("l! a*")> で展開できます。
88579061変数は汚染されます。
88589062成功時には真を、エラー時には偽を返します。
88599063L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
88609064L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
88619065
88629066=begin original
88639067
88649068Portability issues: L<perlport/msgrcv>.
88659069
88669070=end original
88679071
88689072移植性の問題: L<perlport/msgrcv>。
88699073
88709074=item msgsnd ID,MSG,FLAGS
88719075X<msgsnd>
88729076
88739077=for Pod::Functions send a SysV IPC message to a message queue
88749078
88759079=begin original
88769080
88779081Calls the System V IPC function msgsnd to send the message MSG to the
88789082message queue ID. MSG must begin with the native long integer message
88799083type, be followed by the length of the actual message, and then finally
88809084the message itself. This kind of packing can be achieved with
88819085C<pack("l! a*", $type, $message)>. Returns true if successful,
88829086false on error. See also L<perlipc/"SysV IPC"> and the documentation
88839087for L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Msg>|IPC::Msg>.
88849088
88859089=end original
88869090
88879091System V IPC 関数 msgsnd を呼び出し、メッセージキュー ID に
88889092メッセージ MSG を送信します。
88899093MSG の先頭は、ネイティブな long 整数のメッセージタイプでなければならず、
88909094メッセージの長さ、メッセージ本体と続きます。
88919095これは、C<pack("l! a*", $type, $message)> として生成できます。
88929096成功時には真を、エラー時には偽を返します。
88939097L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV>,
88949098L<C<IPC::Msg>|IPC::Msg> の文書も参照してください。
88959099
88969100=begin original
88979101
88989102Portability issues: L<perlport/msgsnd>.
88999103
89009104=end original
89019105
89029106移植性の問題: L<perlport/msgsnd>。
89039107
89049108=item my VARLIST
89059109X<my>
89069110
89079111=item my TYPE VARLIST
89089112
89099113=item my VARLIST : ATTRS
89109114
89119115=item my TYPE VARLIST : ATTRS
89129116
89139117=for Pod::Functions declare and assign a local variable (lexical scoping)
89149118
89159119=begin original
89169120
89179121A L<C<my>|/my VARLIST> declares the listed variables to be local
89189122(lexically) to the enclosing block, file, or L<C<eval>|/eval EXPR>. If
89199123more than one variable is listed, the list must be placed in
89209124parentheses.
89219125
89229126=end original
89239127
89249128L<C<my>|/my VARLIST> はリストアップされた変数を、囲っているブロック、ファイル、
89259129L<C<eval>|/eval EXPR> の中でローカルな (レキシカルな) ものにします。
89269130複数の変数を指定する場合は、リストはかっこでくくらなければなりません。
89279131
89289132=begin original
89299133
89309134The exact semantics and interface of TYPE and ATTRS are still
89319135evolving. TYPE may be a bareword, a constant declared
89329136with L<C<use constant>|constant>, or L<C<__PACKAGE__>|/__PACKAGE__>. It
89339137is
89349138currently bound to the use of the L<fields> pragma,
89359139and attributes are handled using the L<attributes> pragma, or starting
89369140from Perl 5.8.0 also via the L<Attribute::Handlers> module. See
89379141L<perlsub/"Private Variables via my()"> for details.
89389142
89399143=end original
89409144
89419145TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
89429146TYPE は、裸の単語、L<C<use constant>|constant> で宣言された定数、
89439147L<C<__PACKAGE__>|/__PACKAGE__> のいずれかです。
89449148現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
89459149属性は L<attributes> プラグマか、Perl 5.8.0 からは
89469150L<Attribute::Handlers> モジュールと結び付けられています。
89479151詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
89489152
89499153=begin original
89509154
89519155Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
89529156as a dummy placeholder, for example to skip assignment of initial
89539157values:
89549158
89559159=end original
89569160
89579161かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
89589162飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
89599163
89609164 my ( undef, $min, $hour ) = localtime;
89619165
89629166=item next LABEL
89639167X<next> X<continue>
89649168
89659169=item next EXPR
89669170
89679171=item next
89689172
89699173=for Pod::Functions iterate a block prematurely
89709174
89719175=begin original
89729176
89739177The L<C<next>|/next LABEL> command is like the C<continue> statement in
89749178C; it starts the next iteration of the loop:
89759179
89769180=end original
89779181
89789182L<C<next>|/next LABEL> コマンドは、C での C<continue> 文のようなもので、
89799183ループの次の繰り返しを開始します:
89809184
89819185 LINE: while (<STDIN>) {
89829186 next LINE if /^#/; # discard comments
89839187 #...
89849188 }
89859189
89869190=begin original
89879191
89889192Note that if there were a L<C<continue>|/continue BLOCK> block on the
89899193above, it would get
89909194executed even on discarded lines. If LABEL is omitted, the command
89919195refers to the innermost enclosing loop. The C<next EXPR> form, available
89929196as of Perl 5.18.0, allows a label name to be computed at run time, being
89939197otherwise identical to C<next LABEL>.
89949198
89959199=end original
89969200
89979201L<C<continue>|/continue BLOCK> ブロックが存在すれば、たとえ捨てられる行に
89989202あっても、それが実行されます。
89999203LABEL が省略されると、コマンドは一番内側のループを参照します。
90009204Perl 5.18.0 から利用可能な C<next EXPR> 形式では、実行時に計算される
90019205ラベル名が使えます; それ以外は C<next LABEL> と同一です。
90029206
90039207=begin original
90049208
9005L<C<next>|/next LABEL> cannot be used to exit a block which returns a
9209L<C<next>|/next LABEL> cannot return a value from a block that typically
9006value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used
9210returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
9007to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
9211its flow control behavior, which precludes any return value. It should not be
9212used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
90089213operation.
90099214
90109215=end original
90119216
9012L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
9217L<C<next>|/next LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
9013ブロックから抜けるのには使えません; また、L<C<grep>|/grep BLOCK LIST> や
9218典型的には値を返すブロックから値を返せません
9014L<C<map>|/map BLOCK LIST> 操作から抜けるのに使うべきでりません
9219これ、返値を不可能にするフロー制御の振る舞いを実行し
9220L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
9221使うべきではありません。
90159222
90169223=begin original
90179224
90189225Note that a block by itself is semantically identical to a loop
90199226that executes once. Thus L<C<next>|/next LABEL> will exit such a block
90209227early.
90219228
90229229=end original
90239230
90249231ブロック自身は一回だけ実行されるループと文法的に同一であることに
90259232注意してください。
90269233従って、L<C<next>|/next LABEL> はそのようなブロックから早く抜けるのに使えます。
90279234
90289235=begin original
90299236
90309237See also L<C<continue>|/continue BLOCK> for an illustration of how
90319238L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
90329239L<C<redo>|/redo LABEL> work.
90339240
90349241=end original
90359242
90369243L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
90379244どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
90389245
90399246=begin original
90409247
90419248Unlike most named operators, this has the same precedence as assignment.
90429249It is also exempt from the looks-like-a-function rule, so
90439250C<next ("foo")."bar"> will cause "bar" to be part of the argument to
90449251L<C<next>|/next LABEL>.
90459252
90469253=end original
90479254
90489255ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
90499256また、関数のように見えるものの規則からも免れるので、C<next ("foo")."bar"> と
90509257すると "bar" は L<C<next>|/next LABEL> への引数の一部となります。
90519258
90529259=item no MODULE VERSION LIST
90539260X<no declarations>
90549261X<unimporting>
90559262
90569263=item no MODULE VERSION
90579264
90589265=item no MODULE LIST
90599266
90609267=item no MODULE
90619268
90629269=item no VERSION
90639270
90649271=for Pod::Functions unimport some module symbols or semantics at compile time
90659272
90669273=begin original
90679274
90689275See the L<C<use>|/use Module VERSION LIST> function, of which
90699276L<C<no>|/no MODULE VERSION LIST> is the opposite.
90709277
90719278=end original
90729279
90739280L<C<use>|/use Module VERSION LIST> 関数を参照してください;
90749281L<C<no>|/no MODULE VERSION LIST> は、その逆を行なうものです。
90759282
90769283=item oct EXPR
90779284X<oct> X<octal> X<hex> X<hexadecimal> X<binary> X<bin>
90789285
90799286=item oct
90809287
90819288=for Pod::Functions convert a string to an octal number
90829289
90839290=begin original
90849291
90859292Interprets EXPR as an octal string and returns the corresponding
90869293value. (If EXPR happens to start off with C<0x>, interprets it as a
90879294hex string. If EXPR starts off with C<0b>, it is interpreted as a
90889295binary string. Leading whitespace is ignored in all three cases.)
90899296The following will handle decimal, binary, octal, and hex in standard
90909297Perl notation:
90919298
90929299=end original
90939300
90949301EXPR を 8 進数文字列と解釈して、対応する値を返します。
90959302(EXPR が C<0x> で始まるときには、16 進数文字列と解釈します。
90969303EXPR が C<0b>で始まるときは、2 進数文字列と解釈します。
90979304どの場合でも、先頭の空白は無視されます。)
90989305以下の例は、標準的な Perl の記法での
9099930610 進数、2 進数、8 進数、16 進数を扱います:
91009307
91019308 $val = oct($val) if $val =~ /^0/;
91029309
91039310=begin original
91049311
91059312If EXPR is omitted, uses L<C<$_>|perlvar/$_>. To go the other way
91069313(produce a number in octal), use L<C<sprintf>|/sprintf FORMAT, LIST> or
91079314L<C<printf>|/printf FILEHANDLE FORMAT, LIST>:
91089315
91099316=end original
91109317
91119318EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
91129319(8 進数を扱う)その他の方法をとしては L<C<sprintf>|/sprintf FORMAT, LIST> や
91139320L<C<printf>|/printf FILEHANDLE FORMAT, LIST> があります:
91149321
91159322 my $dec_perms = (stat("filename"))[2] & 07777;
91169323 my $oct_perm_str = sprintf "%o", $perms;
91179324
91189325=begin original
91199326
91209327The L<C<oct>|/oct EXPR> function is commonly used when a string such as
91219328C<644> needs
91229329to be converted into a file mode, for example. Although Perl
91239330automatically converts strings into numbers as needed, this automatic
91249331conversion assumes base 10.
91259332
91269333=end original
91279334
91289335L<C<oct>|/oct EXPR> 関数は例えば、 C<644> といった文字列をファイルモードに
91299336変換する時によく使います。
91309337Perl は必要に応じて自動的に文字列を数値に変換しますが、
91319338この自動変換は十進数を仮定します。
91329339
91339340=begin original
91349341
91359342Leading white space is ignored without warning, as too are any trailing
91369343non-digits, such as a decimal point (L<C<oct>|/oct EXPR> only handles
91379344non-negative integers, not negative integers or floating point).
91389345
91399346=end original
91409347
91419348先頭の空白や、末尾の(小数点のような)非数字は警告なしに無視されます
91429349(L<C<oct>|/oct EXPR> は非負整数のみを扱えます; 負の整数や小数は扱えません)。
91439350
9144=item open FILEHANDLE,EXPR
9145X<open> X<pipe> X<file, open> X<fopen>
91469351
91479352=item open FILEHANDLE,MODE,EXPR
9353X<open> X<pipe> X<file, open> X<fopen>
91489354
91499355=item open FILEHANDLE,MODE,EXPR,LIST
91509356
91519357=item open FILEHANDLE,MODE,REFERENCE
91529358
9359=item open FILEHANDLE,EXPR
9360
91539361=item open FILEHANDLE
91549362
91559363=for Pod::Functions open a file, pipe, or descriptor
91569364
91579365=begin original
91589366
9159Opens the file whose filename is given by EXPR, and associates it with
9367Associates an internal FILEHANDLE with the external file specified by
9160FILEHANDLE.
9368EXPR. That filehandle will subsequently allow you to perform
9369I/O operations on that file, such as reading from it or writing to it.
91619370
91629371=end original
91639372
9164EXPR で与えられたファイル名ファイルを開き、FILEHANDLE と結び付けます。
9373内部 FILEHANDLE を、EXPR で指定された外部ファイルに関連付けます。
9374このファイルハンドルはその後、読んだり書いたりといったそのファイルへの
9375I/O 操作をできるようにします。
91659376
91669377=begin original
91679378
9168Simple examples to open a file for reading:
9379Instead of a filename, you may specify an external command
9380(plus an optional argument list) or a scalar reference, in order to open
9381filehandles on commands or in-memory scalars, respectively.
91699382
91709383=end original
91719384
9172読み込みためにファイルを開くための簡単な例は以下のもので:
9385ファイル名代わり、コマンドやメモリ内スカラへのファイルハンドル
9386開くために、外部コマンド (とオプションの引数リスト) やスカラリファレンスを
9387指定できます。
91739388
9389=begin original
9390
9391A thorough reference to C<open> follows. For a gentler introduction to
9392the basics of C<open>, see also the L<perlopentut> manual page.
9393
9394=end original
9395
9396C<open> の完全なリファレンスは後述します。
9397C<open> の基本に関するより親切な導入に関しては、
9398L<perlopentut> man ページも参照してください。
9399
9400=over
9401
9402=item Working with files
9403
9404=begin original
9405
9406Most often, C<open> gets invoked with three arguments: the required
9407FILEHANDLE (usually an empty scalar variable), followed by MODE (usually
9408a literal describing the I/O mode the filehandle will use), and then the
9409filename that the new filehandle will refer to.
9410
9411=end original
9412
9413ほとんどの場合、C<open> は 3 引数で起動されます:
9414必須の FILEHANDLE (通常は空のスカラ変数), 引き続いて MODE (通常は
9415ファイルハンドルを使う I/O モードを記述するリテラル)、
9416それから新しいファイルハンドルが参照するファイル名です。
9417
9418=over
9419
9420=item Simple examples
9421
9422(単純な例)
9423
9424=begin original
9425
9426Reading from a file:
9427
9428=end original
9429
9430ファイルからの読み込み:
9431
91749432 open(my $fh, "<", "input.txt")
9175 or die "Can't open < input.txt: $!";
9433 or die "Can't open < input.txt: $!";
91769434
9435 # Process every line in input.txt
9436 while (my $line = <$fh>) {
9437 #
9438 # ... do something interesting with $line here ...
9439 #
9440 }
9441
91779442=begin original
91789443
9179and for writing:
9444or writing to one:
91809445
91819446=end original
91829447
9183書き込み用は以下のものです:
9448そして書き込み:
91849449
91859450 open(my $fh, ">", "output.txt")
9186 or die "Can't open > output.txt: $!";
9451 or die "Can't open > output.txt: $!";
91879452
9453 print $fh "This line gets printed into output.txt.\n";
9454
91889455=begin original
91899456
9190(The following is a comprehensive reference to
9457For a summary of common filehandle operations such as these, see
9191L<C<open>|/open FILEHANDLE,EXPR>: for a gentler introduction you may
9458L<perlintro/Files and I/O>.
9192consider L<perlopentut>.)
91939459
91949460=end original
91959461
9196(以下は総合的な L<C<open>|/open FILEHANDLE,EXPR> のリファスです:
9462このような基本的なファイルハドル操作の要約については、
9197より親切な説明については L<perlopentut> を参照してください。)
9463L<perlintro/Files and I/O> を参照してください。
91989464
9465=item About filehandles
9466
9467(ファイルハンドルについて)
9468
91999469=begin original
92009470
9201If FILEHANDLE is an undefined scalar variable (or array or hash element), a
9471The first argument to C<open>, labeled FILEHANDLE in this reference, is
9202new filehandle is autovivified, meaning that the variable is assigned a
9472usually a scalar variable. (Exceptions exist, described in "Other
9203reference to a newly allocated anonymous filehandle. Otherwise if
9473considerations", below.) If the call to C<open> succeeds, then the
9204FILEHANDLE is an expression, its value is the real filehandle. (This is
9474expression provided as FILEHANDLE will get assigned an open
9205considered a symbolic reference, so C<use strict "refs"> should I<not> be
9475I<filehandle>. That filehandle provides an internal reference to the
9206in effect.)
9476specified external file, conveniently stored in a Perl variable, and
9477ready for I/O operations such as reading and writing.
92079478
92089479=end original
92099480
9210FILEHANDLE が未定義のスカ変数(または配列かハッシュの要素)の場合
9481このリファレンスでは FILEHANDLE というベルが付いている
9211新しいファイルハンドルが自動有効化され、そ数は新しく割り当てられた
9482C<open> 最初の引数は、通常はスカラ変数です。
9212無名ファイルハンドルへのリファレンス代入されます。
9483(例外あります; 後述する "Other considerations" で記述されます。)
9213さもなければ、もし FILEHANDLE が式なら、そ値を求めてい実際の
9484C<open>呼び出しが成功すと、
9214ファイルハンドルの名前として使います。
9485FILEHANDLE として提供された式には、
9215(これはシンボリックリファスとして扱わるので、
9486開いた I<ファイルハドル> が代入さます。
9216C<use strict "refs"> 影響 I<受けません>。)
9487ファイルハンドルは指定された外部ファイルへの内部参照提供し、
9488好都合なように Perl 変数に保管し、読み書きのような I/O 操作の準備をします。
92179489
9490=item About modes
9491
9492(モードについて)
9493
92189494=begin original
92199495
9220If three (or more) arguments are specified, the open mode (including
9496When calling C<open> with three or more arguments, the second argument
9221optional encoding) in the second argument are distinct from the filename in
9497-- labeled MODE here -- defines the I<open mode>. MODE is usually a
9222the third. If MODE is C<< < >> or nothing, the file is opened for input.
9498literal string comprising special characters that define the intended
9499I/O role of the filehandle being created: whether it's read-only, or
9500read-and-write, and so on.
9501
9502=end original
9503
95043 引数以上で C<open> を呼び出すとき、
95052 番目の引数 -- ここでは MODE -- は I<開くモード> を定義します。
9506MODE は普通、作られるファイルハンドルが意図している I/O の役割 (読み込み専用、
9507読み書き、など)を定義する特別な文字で構成されるリテラルな文字列です。
9508
9509=begin original
9510
9511If MODE is C<< < >>, the file is opened for input (read-only).
92239512If MODE is C<< > >>, the file is opened for output, with existing files
92249513first being truncated ("clobbered") and nonexisting files newly created.
92259514If MODE is C<<< >> >>>, the file is opened for appending, again being
92269515created if necessary.
92279516
92289517=end original
92299518
92303 (またはそれ以上)の引数指定された場合、2 番目の引数の(オプションの
9519MODE C<< < >> の場合、ファイルは入力用(読み込み専用)に開かれます。
9231エンコーディングを含む)開く時のモードは、3 番目のファイル名と分離されます。
9232MODE が C<< < >> か空の場合、ファイルは入力用に開かれます。
92339520MODE が C<< > >> の場合、ファイルは出力用に開かれ、既にファイルが
92349521ある場合は切り詰められ(上書きされ)、ない場合は新しく作られます。
92359522MODE が C<<< >> >>> の場合、ファイルは追加用に開かれ、やはり必要なら
92369523作成されます。
92379524
92389525=begin original
92399526
92409527You can put a C<+> in front of the C<< > >> or C<< < >> to
92419528indicate that you want both read and write access to the file; thus
92429529C<< +< >> is almost always preferred for read/write updates--the
92439530C<< +> >> mode would clobber the file first. You can't usually use
92449531either read-write mode for updating textfiles, since they have
9245variable-length records. See the B<-i> switch in L<perlrun> for a
9532variable-length records. See the B<-i> switch in
9246better approach. The file is created with permissions of C<0666>
9533L<perlrun|perlrun/-i[extension]> for a better approach. The file is
9247modified by the process's L<C<umask>|/umask EXPR> value.
9534created with permissions of C<0666> modified by the process's
9535L<C<umask>|/umask EXPR> value.
92489536
92499537=end original
92509538
92519539ファイルに読み込みアクセスと書き込みアクセスの両方をしたいことを示すために、
92529540C<< > >> や C<< < >> の前に C<+> を付けることができます:
92539541従って、ほとんど常に C<< +< >> が読み書き更新のために使われます --
92549542C<< +> >> モードはまずファイルを上書きします。
92559543普通はこれらの読み書きモードをテキストファイルの更新のためには使えません;
92569544なぜなら可変長のレコードで構成されているからです。
9257よりよい手法については L<perlrun> の B<-i> オプションを参照してください。
9545よりよい手法については L<perlrun|perlrun/-i[extension]>
9546B<-i> オプションを参照してください。
92589547ファイルは C<0666> をプロセスの L<C<umask>|/umask EXPR> 値で修正した
92599548パーミッションで作成されます。
92609549
92619550=begin original
92629551
92639552These various prefixes correspond to the L<fopen(3)> modes of C<r>,
92649553C<r+>, C<w>, C<w+>, C<a>, and C<a+>.
92659554
92669555=end original
92679556
92689557これらの様々な前置詞は L<fopen(3)> の C<r>, C<r+>,
92699558C<w>, C<w+>, C<a>, C<a+> のモードに対応します。
92709559
92719560=begin original
92729561
9273In the one- and two-argument forms of the call, the mode and filename
9562More examples of different modes in action:
9274should be concatenated (in that order), preferably separated by white
9275space. You can--but shouldn't--omit the mode in these forms when that mode
9276is C<< < >>. It is safe to use the two-argument form of
9277L<C<open>|/open FILEHANDLE,EXPR> if the filename argument is a known literal.
92789563
92799564=end original
92809565
92811 引数 と 2 引数の形式ではモードとファイル名は(この順番で)
9566実用的な異なったモードに関する更なる例:
9282結合されます(空白によって分割されているかもしれません)。
9283この形式で、モードが C<< '<' >> の場合はモードを省略できます (が、
9284するべきではありません)。
9285ファイル引数が既知のリテラルの場合、2 引数形式の
9286L<C<open>|/open FILEHANDLE,EXPR> は安全です。
92879567
9288=begin original
9568 # Open a file for concatenation
9569 open(my $log, ">>", "/usr/spool/news/twitlog")
9570 or warn "Couldn't open log file; discarding input";
92899571
9290For three or more arguments if MODE is C<|->, the filename is
9572 # Open a file for reading and writing
9291interpreted as a command to which output is to be piped, and if MODE
9573 open(my $dbase, "+<", "dbase.mine")
9292is C<-|>, the filename is interpreted as a command that pipes
9574 or die "Can't open 'dbase.mine' for update: $!";
9293output to us. In the two-argument (and one-argument) form, one should
9294replace dash (C<->) with the command.
9295See L<perlipc/"Using open() for IPC"> for more examples of this.
9296(You are not allowed to L<C<open>|/open FILEHANDLE,EXPR> to a command
9297that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and
9298L<perlipc/"Bidirectional Communication with Another Process"> for
9299alternatives.)
93009575
9301=end original
9576=item Checking the return value
93029577
93033 引数以上の形式で
9578(返り値をチェックする)
9304MODE が C<|-> の場合、ファイル名は出力がパイプされるコマンドとして
9305解釈され、MODE が C<-|> の場合、ファイル名は出力がこちらに
9306パイプされるコマンドとして解釈されます。
93072 引数(と 1 引数) の形式ではハイフン(C<->)をコマンドの代わりに使えます。
9308これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
9309参照してください。
9310(L<C<open>|/open FILEHANDLE,EXPR> を入出力 I<両用> にパイプすることは
9311出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>,
9312L<perlipc/"Bidirectional Communication with Another Process"> を
9313参照してください。)
93149579
93159580=begin original
93169581
9317In the form of pipe opens taking three or more arguments, if LIST is specified
9582Open returns nonzero on success, the undefined value otherwise. If the
9318(extra arguments after the command name) then LIST becomes arguments
9583C<open> involved a pipe, the return value happens to be the pid of the
9319to the command invoked if the platform supports it. The meaning of
9584subprocess.
9320L<C<open>|/open FILEHANDLE,EXPR> with more than three arguments for
9321non-pipe modes is not yet defined, but experimental "layers" may give
9322extra LIST arguments meaning.
93239585
93249586=end original
93259587
9326パイプでの三つ以上の引数の形式では、LIST (コマンド名の後の追加の引数) が
9588open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。
9327指定されると、プラットフォームが対応していれば、LIST 起動される
9589パイプに関 C<open> のきには返り値
9328コマンドへ引数となります。
9590サブプロセス pid となります。
9329パイプモードではない L<C<open>|/open FILEHANDLE,EXPR> での三つ以上の引数の
9330意味はまだ未定義ですが、実験的な「層」は追加の LIST 引数の意味を与えます。
93319591
93329592=begin original
93339593
9334In the two-argument (and one-argument) form, opening C<< <- >>
9594When opening a file, it's seldom a good idea to continue if the request
9335or C<-> opens STDIN and opening C<< >- >> opens STDOUT.
9595failed, so C<open> is frequently used with L<C<die>|/die LIST>. Even if
9596you want your code to do something other than C<die> on a failed open,
9597you should still always check the return value from opening a file.
93369598
93379599=end original
93389600
93392 引数(と 1 引数)で C<< <- >> か C<-> open すと STDIN が
9601ファイル開く時、開くのに失敗した時に通常の処理を続けのは普通は悪い
9340オープンされ、C<< >- >> を open すると STDOUT がオープンされます。
9602考えなので、C<open> はしばしば
9603L<C<die>|/die LIST> と結び付けられて使われます。
9604開くときに失敗したときに L<C<die>|/die LIST> 意外の何かを
9605したい場合でも、ファイルを開いた時の返り値を常にチェックするべきです。
93419606
9607=back
9608
9609=item Specifying I/O layers in MODE
9610
9611(MODE で I/O 層を指定する)
9612
93429613=begin original
93439614
9344You may (and usually should) use the three-argument form of open to specify
9615You can use the three-argument form of open to specify
9345I/O layers (sometimes referred to as "disciplines") to apply to the handle
9616I/O layers (sometimes referred to as "disciplines") to apply to the new
9346that affect how the input and output are processed (see L<open> and
9617filehandle. These affect how the input and output are processed (see
9618L<open> and
93479619L<PerlIO> for more details). For example:
93489620
93499621=end original
93509622
9351open の 3 引数形式では、どのよう入出力が処理されるかに影響を与え
9623新しいファイルハンドル適用す
9352I/O 層(「ディシプリン」とも呼ばれます)を指定できま
9624I/O 層(「ディシプリン」とも呼ばれます)を指定するために
9353(そして普通はそうるべきです)
9625open の 3 引数形式を使えま
9626これらはどのように入出力が処理されるかに影響を与えます
93549627(詳細については L<open> と L<PerlIO> を参照してください)。
93559628例えば:
93569629
9357 open(my $fh, "<:encoding(UTF-8)", $filename)
9630 open(my $fh, "<:encoding(UTF-8)", $filename)
9358 || die "Can't open UTF-8 encoded $filename: $!";
9631 || die "Can't open UTF-8 encoded $filename: $!";
93599632
93609633=begin original
93619634
9362opens the UTF8-encoded file containing Unicode characters;
9635This opens the UTF8-encoded file containing Unicode characters;
93639636see L<perluniintro>. Note that if layers are specified in the
9364three-argument form, then default layers stored in ${^OPEN} (see L<perlvar>;
9637three-argument form, then default layers stored in
9365usually set by the L<open> pragma or the switch C<-CioD>) are ignored.
9638L<C<${^OPEN}>|perlvar/${^OPEN}>
9639(usually set by the L<open> pragma or the switch C<-CioD>) are ignored.
93669640Those layers will also be ignored if you specify a colon with no name
93679641following it. In that case the default layer for the operating system
93689642(:raw on Unix, :crlf on Windows) is used.
93699643
93709644=end original
93719645
9372は、Unicode 文字を含む UTF8 エンコードされたファイルを開きます;
9646これは、Unicode 文字を含む UTF8 エンコードされたファイルを開きます;
93739647L<perluniintro> を参照してください。
93743 引数形式で層を指定すると、${^OPEN} (L<perlvar> を参照してください;
96483 引数形式で層を指定すると、L<C<${^OPEN}>|perlvar/${^OPEN}>
9375通常は L<open> プラグマか C<-CioD> オプションでセットされます) に保存された
9649(通常は L<open> プラグマか C<-CioD> オプションでセットされます) に
9376デフォルト層は無視されることに注意してください。
9650保存されたデフォルト層は無視されることに注意してください。
93779651これらの層は、名前なしでコロンを指定した場合にも無視されます。
93789652この場合 OS のデフォルトの層 (Unix では :raw、Windows では :crlf) が
93799653使われます。
93809654
93819655=begin original
93829656
9383Open returns nonzero on success, the undefined value otherwise. If
9384the L<C<open>|/open FILEHANDLE,EXPR> involved a pipe, the return value
9385happens to be the pid of the subprocess.
9386
9387=end original
9388
9389open は、成功時にはゼロ以外を返し、失敗時には未定義値を返します。
9390パイプに関る L<C<open>|/open FILEHANDLE,EXPR> のときには、返り値は
9391サブプロセスの pid となります。
9392
9393=begin original
9394
93959657On some systems (in general, DOS- and Windows-based systems)
93969658L<C<binmode>|/binmode FILEHANDLE, LAYER> is necessary when you're not
93979659working with a text file. For the sake of portability it is a good idea
93989660always to use it when appropriate, and never to use it when it isn't
93999661appropriate. Also, people can set their I/O to be by default
94009662UTF8-encoded Unicode, not bytes.
94019663
94029664=end original
94039665
94049666テキストファイルでないものを扱う場合に
94059667L<C<binmode>|/binmode FILEHANDLE, LAYER> が必要な
94069668システムもあります(一般的には DOS と Windows ベースのシステムです)。
94079669移植性のために、適切なときには常にこれを使い、適切でないときには
94089670決して使わないというのは良い考えです。
94099671また、デフォルトとして I/O を bytes ではなく UTF-8 エンコードされた
94109672Unicode にセットすることも出来ます。
94119673
9674=item Using C<undef> for temporary files
9675
9676(一時ファイルとして C<undef> を使う)
9677
94129678=begin original
94139679
9414When opening a file, it's seldom a good idea to continue
9680As a special case the three-argument form with a read/write mode and the third
9415if the request failed, so L<C<open>|/open FILEHANDLE,EXPR> is frequently
9681argument being L<C<undef>|/undef EXPR>:
9416used with L<C<die>|/die LIST>. Even if L<C<die>|/die LIST> won't do
9417what you want (say, in a CGI script,
9418where you want to format a suitable error message (but there are
9419modules that can help with that problem)) always check
9420the return value from opening a file.
94219682
94229683=end original
94239684
9424ファイルを開く時開くに失敗した時に通常処理を続けるのは普通は悪い
9685特別な場合として3 引数形で読み書きモードで 3 番目引数が
9425考えなので、L<C<open>|/open FILEHANDLE,EXPR> はしばしば
9686L<C<undef>|/undef EXPR> の場合:
9426L<C<die>|/die LIST> と結び付けられて使われます。
9427望むものが L<C<die>|/die LIST> でない場合(例えば、CGI スクリプトのように
9428きれいにフォーマットされたエラーメッセージを作りたい場合
9429(但しこの問題を助けるモジュールがあります))でも、
9430ファイルを開いた時の返り値を常にチェックするべきです。
94319687
9688 open(my $tmp, "+>", undef) or die ...
9689
94329690=begin original
94339691
9434The filehandle will be closed when its reference count reaches zero.
9692opens a filehandle to a newly created empty anonymous temporary file.
9435If it is a lexically scoped variable declared with L<C<my>|/my VARLIST>,
9693(This happens under any mode, which makes C<< +> >> the only useful and
9436that usually
9694sensible mode to use.) You will need to
9437means the end of the enclosing scope. However, this automatic close
9695L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading.
9438does not check for errors, so it is better to explicitly close
9439filehandles, especially those used for writing:
94409696
94419697=end original
94429698
9443ファイルハンドルは、参照カウントが 0 になったとに閉じられます。
9699新しく作成した空の無名一時ファイルとしてファイルハンドルを開きます。
9444これが L<C<my>|/my VARLIST> で宣言されたレキシカルスコープを持つ変数場合、
9700(これはどのモードでも起こりますC<< +> >>みが有用で意味があります)
9445普通は囲まれたスコープの終わり意味します。
9701読み込み行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が
9446しかし、この自動閉じはエラーをチェックしないの、特に書き込み用の場合は、
9702必要す。
9447明示的にファイルハンドルを閉じる方がよいです。
94489703
9449 close($handle)
9704=item Opening a filehandle into an in-memory scalar
9450 || warn "close failed: $!";
94519705
9706(ファイルハンドルをメモリ内スカラに開く)
9707
94529708=begin original
94539709
9454An older style is to use a bareword as the filehandle, as
9710You can open filehandles directly to Perl scalars instead of a file or
9711other resource external to the program. To do so, provide a reference to
9712that scalar as the third argument to C<open>, like so:
94559713
94569714=end original
94579715
9458より古いスタイルは、次のように、ファイルハンドルとし単語を使います
9716ファイルやその他のプログラムから見ての外部リソースではなく、
9717Perl スカラに対して直接ファイルハンドルを開くことができます。
9718そうするためには、次のように、C<open> の 3 番目の引数としてその
9719スカラへのリファレンスを提供します:
94599720
9460 open(FH, "<", "input.txt")
9721 open(my $memory, ">", \$var)
9461 or die "Can't open < input.txt: $!";
9722 or die "Can't open memory file: $!";
9723 print $memory "foo!\n"; # output will appear in $var
94629724
94639725=begin original
94649726
9465Then you can use C<FH> as the filehandle, in C<< close FH >> and C<<
9727To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
9466<FH> >> and so on. Note that it's a global variable, so this form is
9467not recommended in new code.
94689728
94699729=end original
94709730
9471それから C<FH> を、C<< close FH >> や C<< <FH> >> などように、
9731C<STDOUT> や C<STDERR> を「オンメモリ」ファイルとして
9472ファイルハンドルとして使えます
9732再び開きたい場合は、先にそれを閉じます:
9473これはグローバル変数なので、新しいコードでは非推奨であることに
9474注意してください。
94759733
9734 close STDOUT;
9735 open(STDOUT, ">", \$variable)
9736 or die "Can't open STDOUT: $!";
9737
94769738=begin original
94779739
9478As a shortcut a one-argument call takes the filename from the global
9740The scalars for in-memory files are treated as octet strings: unless
9479scalar variable of the same name as the filehandle:
9741the file is being opened with truncation the scalar may not contain
9742any code points over 0xFF.
94809743
94819744=end original
94829745
9483短縮版として、1 引数呼び出しでは、ファイル名を、ファイルハンドルと同じ名前
9746オンメモリファイルのためのスカラはオクテット文字列として扱われます:
9484グローバなスカラ変数かます:
9747ファイが切り詰めれて開かれない限
9748スカラは 0xFF を超える符号位置を含みません。
94859749
9486 $ARTICLE = 100;
9750=begin original
9487 open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
94889751
9752Opening in-memory files I<can> fail for a variety of reasons. As with
9753any other C<open>, check the return value for success.
9754
9755=end original
9756
9757オンメモリファイルを開くのは様々な理由で失敗する I<ことがあります>。
9758その他の C<open> と同様、成功したかを返り値でチェックしてください。
9759
94899760=begin original
94909761
9491Here C<$ARTICLE> must be a global (package) scalar variable - not one
9762I<Technical note>: This feature works only when Perl is built with
9492declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>.
9763PerlIO -- the default, except with older (pre-5.16) Perl installations
9764that were configured to not include it (e.g. via C<Configure
9765-Uuseperlio>). You can see whether your Perl was built with PerlIO by
9766running C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO;
9767otherwise you don't.
94939768
94949769=end original
94959770
9496ここで C<$ARTICLE> はグローバ(パッケージ)スカラ変数でなけばなりません -
9771I<技術ノート>: この機能 Perl が PerlIO を使ってビドさている
9497L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言された
9772場合にのみ動作します; これは (C<Configure -Uuseperlio> によって)
9498変数はあません。
9773これを含まないように設定されていた古い (5.16 より前の) Perl ない限
9774デフォルトです。
9775Perl が PerlIO つきでビルドされているかどうかを確認するには、
9776C<perl -V:useperlio> を見ます。
9777これが C<'define'> なら PerlIO を使っています;
9778そうでなければ使っていません。
94999779
95009780=begin original
95019781
9502As a special case the three-argument form with a read/write mode and the third
9782See L<perliol> for detailed info on PerlIO.
9503argument being L<C<undef>|/undef EXPR>:
95049783
95059784=end original
95069785
9507特別な場合として、3 引数の形で読み書きモードで 3 番目の引数が
9786PerlIO に関する詳い情報につい L<perliol> を参照してください。
9508L<C<undef>|/undef EXPR> の場合:
95099787
9510 open(my $tmp, "+>", undef) or die ...
9788=item Opening a filehandle into a command
95119789
9790(ファイルハンドルをコマンドに開く)
9791
95129792=begin original
95139793
9514opens a filehandle to a newly created empty anonymous temporary file.
9794If MODE is C<|->, then the filename is
9515(This happens under any mode, which makes C<< +> >> the only useful and
9795interpreted as a command to which output is to be piped, and if MODE
9516sensible mode to use.) You will need to
9796is C<-|>, the filename is interpreted as a command that pipes
9517L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to do the reading.
9797output to us. In the two-argument (and one-argument) form, one should
9798replace dash (C<->) with the command.
9799See L<perlipc/"Using open() for IPC"> for more examples of this.
9800(You are not allowed to L<C<open>|/open FILEHANDLE,MODE,EXPR> to a command
9801that pipes both in I<and> out, but see L<IPC::Open2>, L<IPC::Open3>, and
9802L<perlipc/"Bidirectional Communication with Another Process"> for
9803alternatives.)
95189804
95199805=end original
95209806
9521新しく作成した空無名一時ファイルとしてファルハンドルを開きます。
9807MODE が C<|-> 場合、ファイル名は出力がパプされるコマンドとして
9522(こはどのモードでも起こりますが、C<< +> >> 有用で意味があります)
9808解釈され、MODE が C<-|> の場合、ファイル名は出力こちらに
9523読み込みを行うためには L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> が
9809パイプされるコマンドとして解釈されます。
9524必要です。
98102 引数(と 1 引数) の形式はハイフン(C<->)をコマンドの代わりに使えます。
9811これに関するさらなる例については L<perlipc/"Using open() for IPC"> を
9812参照してください。
9813(L<C<open>|/open FILEHANDLE,MODE,EXPR> を入出力 I<両用> にパイプすることは
9814出来ませんが、代替案としては L<IPC::Open2>, L<IPC::Open3>,
9815L<perlipc/"Bidirectional Communication with Another Process"> を
9816参照してください。)
95259817
9818 open(my $article_fh, "-|", "caesar <$article") # decrypt
9819 # article
9820 or die "Can't start caesar: $!";
9821
9822 open(my $article_fh, "caesar <$article |") # ditto
9823 or die "Can't start caesar: $!";
9824
9825 open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id
9826 or die "Can't start sort: $!";
9827
95269828=begin original
95279829
9528Perl is built using PerlIO by default. Unless you've
9830In the form of pipe opens taking three or more arguments, if LIST is specified
9529changed this (such as building Perl with C<Configure -Uuseperlio>), you can
9831(extra arguments after the command name) then LIST becomes arguments
9530open filehandles directly to Perl scalars via:
9832to the command invoked if the platform supports it. The meaning of
9833L<C<open>|/open FILEHANDLE,MODE,EXPR> with more than three arguments for
9834non-pipe modes is not yet defined, but experimental "layers" may give
9835extra LIST arguments meaning.
95319836
95329837=end original
95339838
9534Perl はデフォルト PerlIO を使ってビルされています。
9839パイプの三つ以上の引数の形式では、LIST (コマン名の後の追加の引数) が
9535(C<Configure -Uuseperlio> して Perl をビルドすなどして)こ
9840指定されと、プラットフォームが対応してば、LIST は起動される
9536変更していない限り、以下のようにして、Perl スカラを直接ファイルハンドルで
9841コマンドへの引数となります。
9537開くことがきます:
9842パイプモードはない L<C<open>|/open FILEHANDLE,MODE,EXPR> での
9843三つ以上の引数の意味はまだ未定義ですが、実験的な「層」は
9844追加の LIST 引数の意味を与えます。
95389845
9539 open(my $fh, ">", \$variable) || ..
9846=begin original
95409847
9848If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|>
9849with the one- or two-argument forms of
9850L<C<open>|/open FILEHANDLE,MODE,EXPR>), an implicit L<C<fork>|/fork> is done,
9851so L<C<open>|/open FILEHANDLE,MODE,EXPR> returns twice: in the parent process
9852it returns the pid
9853of the child process, and in the child process it returns (a defined) C<0>.
9854Use C<defined($pid)> or C<//> to determine whether the open was successful.
9855
9856=end original
9857
98581 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR>) で
9859(C<-|> や C<|-> というふうに) C<-> というコマンドにパイプを開くと、
9860暗黙の L<C<fork>|/fork> が行なわれるので、
9861L<C<open>|/open FILEHANDLE,MODE,EXPR> は 2 回返ります;
9862親プロセスには子プロセスの pid が返され、子プロセスには (定義された) C<0> が
9863返されます。
9864open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を
9865使います。
9866
95419867=begin original
95429868
9543To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
9869For example, use either
95449870
95459871=end original
95469872
9547C<STDOUT> や C<STDERR> を「オンメモリ」ファイルとして
9873例えば、以下二つ
9548再び開きたい場合は、先にそれを閉じます:
95499874
9550 close STDOUT;
9875 my $child_pid = open(my $from_kid, "-|")
9551 open(STDOUT, ">", \$variable)
9876 // die "Can't fork: $!";
9552 or die "Can't open STDOUT: $!";
95539877
95549878=begin original
95559879
9556See L<perliol> for detailed info on PerlIO.
9880or
95579881
95589882=end original
95599883
9560PerlIO に関する詳しい情報について L<perliol> を参照してください。
9884また
95619885
9886 my $child_pid = open(my $to_kid, "|-")
9887 // die "Can't fork: $!";
9888
95629889=begin original
95639890
9564General examples:
9891followed by
95659892
95669893=end original
95679894
9568一般的な例:
9895を使って、後で以下のようにします。
95699896
9570 open(my $log, ">>", "/usr/spool/news/twitlog");
9897 if ($child_pid) {
9571 # if the open fails, output is discarded
9898 # am the parent:
9899 # either write $to_kid or else read $from_kid
9900 ...
9901 waitpid $child_pid, 0;
9902 } else {
9903 # am the child; use STDIN/STDOUT normally
9904 ...
9905 exit;
9906 }
95729907
9573 open(my $dbase, "+<", "dbase.mine") # open for update
9908=begin original
9574 or die "Can't open 'dbase.mine' for update: $!";
95759909
9576 open(my $dbase, "+<dbase.mine") # ditto
9910The filehandle behaves normally for the parent, but I/O to that
9577 or die "Can't open 'dbase.mine' for update: $!";
9911filehandle is piped from/to the STDOUT/STDIN of the child process.
9912In the child process, the filehandle isn't opened--I/O happens from/to
9913the new STDOUT/STDIN. Typically this is used like the normal
9914piped open when you want to exercise more control over just how the
9915pipe command gets executed, such as when running setuid and
9916you don't want to have to scan shell commands for metacharacters.
95789917
9579 open(my $article_fh, "-|", "caesar <$article") # decrypt
9918=end original
9580 # article
9581 or die "Can't start caesar: $!";
95829919
9583 open(my $article_fh, "caesar <$article |") # ditto
9920親プロセスでは、このファイルハンドルは通常通りに動作しますが、行なわれる
9584 or die "Can't start caesar: $!";
9921入出力は、子プロセスの STDIN/STDOUT にパイプされます。
9922子プロセス側では、そのファイルハンドルは開かれず、入出力は新しい STDOUT か
9923STDIN に対して行なわれます。
9924これは、setuid で実行して、シェルコマンドのメタ文字を
9925検索させたくないような場合に、パイプコマンドの起動の仕方を
9926制御したいとき、普通のパイプの open と同じように使います。
95859927
9586 open(my $out_fh, "|-", "sort >Tmp$$") # $$ is our process id
9928=begin original
9587 or die "Can't start sort: $!";
95889929
9589 # in-memory files
9930The following blocks are more or less equivalent:
9590 open(my $memory, ">", \$var)
9591 or die "Can't open memory file: $!";
9592 print $memory "foo!\n"; # output will appear in $var
95939931
9932=end original
9933
9934以下の組み合わせは、だいたい同じものです:
9935
9936 open(my $fh, "|tr '[a-z]' '[A-Z]'");
9937 open(my $fh, "|-", "tr '[a-z]' '[A-Z]'");
9938 open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]';
9939 open(my $fh, "|-", "tr", '[a-z]', '[A-Z]');
9940
9941 open(my $fh, "cat -n '$file'|");
9942 open(my $fh, "-|", "cat -n '$file'");
9943 open(my $fh, "-|") || exec "cat", "-n", $file;
9944 open(my $fh, "-|", "cat", "-n", $file);
9945
95949946=begin original
95959947
9948The last two examples in each block show the pipe as "list form", which
9949is not yet supported on all platforms. (If your platform has a real
9950L<C<fork>|/fork>, such as Linux and macOS, you can use the list form; it
9951also works on Windows with Perl 5.22 or later.) You would want to use
9952the list form of the pipe so you can pass literal arguments to the
9953command without risk of the shell interpreting any shell metacharacters
9954in them. However, this also bars you from opening pipes to commands that
9955intentionally contain shell metacharacters, such as:
9956
9957=end original
9958
9959それぞれのブロックの末尾二つの例ではパイプを「リスト形式」にしていますが、
9960これはまだ全てのプラットフォームで対応しているわけではなりません。
9961(もし実行しているプラットフォームで本当の
9962L<C<fork>|/fork> があれば(Linux や
9963MacOS X なら)リスト形式が使えます; Perl 5.22 以降では Windows でも
9964動作します。)
9965パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、
9966シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。
9967しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして
9968開くことを妨げます:
9969
9970 open(my $fh, "|cat -n | expand -4 | lpr")
9971 || die "Can't open pipeline to lpr: $!";
9972
9973=begin original
9974
9975See L<perlipc/"Safe Pipe Opens"> for more examples of this.
9976
9977=end original
9978
9979これに関する更なる例については L<perlipc/"Safe Pipe Opens"> を
9980参照してください。
9981
9982=item Duping filehandles
9983
9984(ハンドルの複製)
9985
9986=begin original
9987
95969988You may also, in the Bourne shell tradition, specify an EXPR beginning
95979989with C<< >& >>, in which case the rest of the string is interpreted
95989990as the name of a filehandle (or file descriptor, if numeric) to be
95999991duped (as in L<dup(2)>) and opened. You may use C<&> after C<< > >>,
96009992C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>, and C<< +< >>.
96019993The mode you specify should match the mode of the original filehandle.
96029994(Duping a filehandle does not take into account any existing contents
96039995of IO buffers.) If you use the three-argument
96049996form, then you can pass either a
96059997number, the name of a filehandle, or the normal "reference to a glob".
96069998
96079999=end original
960810000
960910001Bourne シェルの慣例にしたがって、EXPR の先頭に C<< >& >>
961010002を付けると、EXPR の残りの文字列をファイルハンドル名
961110003(数字であれば、ファイル記述子) と解釈して、それを (L<dup(2)> によって)
961210004複製してオープンします。
961310005C<&> は、C<< > >>, C<<< >> >>>, C<< < >>, C<< +> >>, C<<< +>> >>>,
961410006C<< +< >>というモード指定に付けることができます。
961510007指定するモード指定は、もとのファイルハンドルのモードと
961610008合っていないといけません。
961710009(ファイルハンドルの複製は既に存在する IO バッファの内容に含めません。)
9618100103 引数形式を使う場合は、数値を渡すか、ファイルハンドルの名前を渡すか、
961910011通常の「グロブへのリファレンス」を渡します。
962010012
962110013=begin original
962210014
962310015Here is a script that saves, redirects, and restores C<STDOUT> and
962410016C<STDERR> using various methods:
962510017
962610018=end original
962710019
962810020C<STDOUT> と C<STDERR> 保存し、リダイレクトし、元に戻すスクリプトを示します:
962910021
963010022 #!/usr/bin/perl
9631 open(my $oldout, ">&STDOUT") or die "Can't dup STDOUT: $!";
10023 open(my $oldout, ">&STDOUT")
9632 open(OLDERR, ">&", \*STDERR) or die "Can't dup STDERR: $!";
10024 or die "Can't dup STDOUT: $!";
10025 open(OLDERR, ">&", \*STDERR)
10026 or die "Can't dup STDERR: $!";
963310027
9634 open(STDOUT, '>', "foo.out") or die "Can't redirect STDOUT: $!";
10028 open(STDOUT, '>', "foo.out")
9635 open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!";
10029 or die "Can't redirect STDOUT: $!";
10030 open(STDERR, ">&STDOUT")
10031 or die "Can't dup STDOUT: $!";
963610032
963710033 select STDERR; $| = 1; # make unbuffered
963810034 select STDOUT; $| = 1; # make unbuffered
963910035
964010036 print STDOUT "stdout 1\n"; # this works for
964110037 print STDERR "stderr 1\n"; # subprocesses too
964210038
9643 open(STDOUT, ">&", $oldout) or die "Can't dup \$oldout: $!";
10039 open(STDOUT, ">&", $oldout)
9644 open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!";
10040 or die "Can't dup \$oldout: $!";
10041 open(STDERR, ">&OLDERR")
10042 or die "Can't dup OLDERR: $!";
964510043
964610044 print STDOUT "stdout 2\n";
964710045 print STDERR "stderr 2\n";
964810046
964910047=begin original
965010048
965110049If you specify C<< '<&=X' >>, where C<X> is a file descriptor number
965210050or a filehandle, then Perl will do an equivalent of C's L<fdopen(3)> of
965310051that file descriptor (and not call L<dup(2)>); this is more
965410052parsimonious of file descriptors. For example:
965510053
965610054=end original
965710055
965810056C<X> をファイル記述子の番号かファイルハンドルとして、
965910057C<< '<&=X' >> と指定すると、Perl はそのファイル記述子に対する
966010058C の L<fdopen(3)> と同じことを行ないます(そして L<dup(2)> は呼び出しません);
966110059これはファイル記述子をより節約します。
966210060例えば:
966310061
966410062 # open for input, reusing the fileno of $fd
966510063 open(my $fh, "<&=", $fd)
966610064
966710065=begin original
966810066
966910067or
967010068
967110069=end original
967210070
967310071または
967410072
967510073 open(my $fh, "<&=$fd")
967610074
967710075=begin original
967810076
967910077or
968010078
968110079=end original
968210080
968310081または
968410082
968510083 # open for append, using the fileno of $oldfh
968610084 open(my $fh, ">>&=", $oldfh)
968710085
968810086=begin original
968910087
969010088Being parsimonious on filehandles is also useful (besides being
969110089parsimonious) for example when something is dependent on file
969210090descriptors, like for example locking using
969310091L<C<flock>|/flock FILEHANDLE,OPERATION>. If you do just
969410092C<< open(my $A, ">>&", $B) >>, the filehandle C<$A> will not have the
969510093same file descriptor as C<$B>, and therefore C<flock($A)> will not
969610094C<flock($B)> nor vice versa. But with C<< open(my $A, ">>&=", $B) >>,
969710095the filehandles will share the same underlying system file descriptor.
969810096
969910097=end original
970010098
970110099ファイルハンドルを倹約することは、(倹約できること以外に)何かが
970210100ファイル記述子に依存している場合、例えば
970310101L<C<flock>|/flock FILEHANDLE,OPERATION> を使った
970410102ファイルロックといった場合に有用です。
970510103C<< open(my $A, ">>&", $B) >> とすると、ファイルハンドル C<$A> は C<$B> と同じ
970610104ファイル記述子にはならないので、C<flock($A)> と C<flock($B)> は別々になります。
970710105しかし C<< open(my $A, ">>&=", $B) >> ではファイルハンドルは基礎となるシステムの
970810106同じファイル記述子を共有します。
970910107
971010108=begin original
971110109
971210110Note that under Perls older than 5.8.0, Perl uses the standard C library's'
971310111L<fdopen(3)> to implement the C<=> functionality. On many Unix systems,
971410112L<fdopen(3)> fails when file descriptors exceed a certain value, typically 255.
971510113For Perls 5.8.0 and later, PerlIO is (most often) the default.
971610114
971710115=end original
971810116
9719101175.8.0 より前の Perl の場合、C<=> 機能の実装は
972010118標準 C ライブラリの L<fdopen(3)> を使っています。
972110119多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値
972210120(典型的には 255)を超えた場合に失敗することが知られています。
9723101215.8.0 以降の Perl では、(ほとんどの場合) PerlIO がデフォルトです。
972410122
10123=item Legacy usage
10124
10125(古い使い方)
10126
972510127=begin original
972610128
9727You can see whether your Perl was built with PerlIO by running
10129This section describes ways to call C<open> outside of best practices;
9728C<perl -V:useperlio>. If it says C<'define'>, you have PerlIO;
10130you may encounter these uses in older code. Perl does not consider their
9729otherwise you don't.
10131use deprecated, exactly, but neither is it recommended in new code, for
10132the sake of clarity and readability.
973010133
973110134=end original
973210135
9733Perl が PerlIOきでビルドされてるかどうかを確認するには、
10136この節では、ベストプラクティスではない C<open> の呼び出し方につい
9734C<perl -V:useperlio> を見ます。
10137記述します; より古いコードでこれらが使われているのに遭遇するかもしれません
9735これが C<'define'> なら PerlIO使っています;
10138厳密には、Perl はこれらの仕様廃止予定にはしていませんが、
9736そうでなければ使っていません。
10139明瞭性と可読性のために、新しコードには薦めません。
973710140
10141=over
10142
10143=item Specifying mode and filename as a single argument
10144
10145(モードとファイル名を一つの引数で指定する)
10146
973810147=begin original
973910148
9740If you open a pipe on the command C<-> (that is, specify either C<|-> or C<-|>
10149In the one- and two-argument forms of the call, the mode and filename
9741with the one- or two-argument forms of
10150should be concatenated (in that order), preferably separated by white
9742L<C<open>|/open FILEHANDLE,EXPR>), an implicit L<C<fork>|/fork> is done,
10151space. You can--but shouldn't--omit the mode in these forms when that mode
9743so L<C<open>|/open FILEHANDLE,EXPR> returns twice: in the parent process
10152is C<< < >>. It is safe to use the two-argument form of
9744it returns the pid
10153L<C<open>|/open FILEHANDLE,MODE,EXPR> if the filename argument is a known literal.
9745of the child process, and in the child process it returns (a defined) C<0>.
9746Use C<defined($pid)> or C<//> to determine whether the open was successful.
974710154
974810155=end original
974910156
97501 引数 または 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR>)
101571 引数 2 引数の形式ではモードとファイル名は(こ順番)
9751(C<-|> や C<|-> というふう) C<-> とうコマンドにパイプを開くと、
10158結合されます(空白よって分割されてるかもしれません)。
9752暗黙L<C<fork>|/fork> が行なわれるので、
10159形式で、モードが C<< '<' >> の場合はモードを省略きます (が
9753L<C<open>|/open FILEHANDLE,EXPR> 2 回返ります;
10160するべきでりません)。
9754親プロセスには子プロセスの pid 返され子プロセスには (定義された) C<0> が
10161ファイル引数既知のリテラルの場合2 引数形式の
9755返されます。
10162L<C<open>|/open FILEHANDLE,MODE,EXPR> は安全です。
9756open が成功したかどうかを調べるには、C<defined($pid)> または C<//> を
9757使います。
975810163
10164 open(my $dbase, "+<dbase.mine") # ditto
10165 or die "Can't open 'dbase.mine' for update: $!";
10166
975910167=begin original
976010168
9761For example, use either
10169In the two-argument (and one-argument) form, opening C<< <- >>
10170or C<-> opens STDIN and opening C<< >- >> opens STDOUT.
976210171
976310172=end original
976410173
9765例えば、以下の二つ
101742 引数(と 1 引数)で C<< <- >> か C<-> を open すると STDIN が
10175オープンされ、C<< >- >> を open すると STDOUT がオープンされます。
976610176
9767 my $child_pid = open(my $from_kid, "-|") // die "Can't fork: $!";
9768
976910177=begin original
977010178
9771or
10179New code should favor the three-argument form of C<open> over this older
10180form. Declaring the mode and the filename as two distinct arguments
10181avoids any confusion between the two.
977210182
977310183=end original
977410184
9775また
10185新しいコードで、このより古い形式ではなく、3 引数形式の C<open> を
10186使うべきです。
10187モードとファイル名を異なった二つの引数として指定することで、
10188二つの間の混乱を避けられます。
977610189
9777 my $child_pid = open(my $to_kid, "|-") // die "Can't fork: $!";
10190=item Calling C<open> with one argument via global variables
977810191
10192(グローバル変数を使って C<open> を 1 引数で呼び出す)
10193
977910194=begin original
978010195
9781followed by
10196As a shortcut, a one-argument call takes the filename from the global
10197scalar variable of the same name as the filehandle:
978210198
978310199=end original
978410200
9785を使って、以下ようにします。
10201短縮版として、1 引数呼び出しは、ファイル名を、ファイルハンドルと同じ名前
10202グローバルなスカラ変数から取ります:
978610203
9787 if ($child_pid) {
10204 $ARTICLE = 100;
9788 # am the parent:
10205 open(ARTICLE)
9789 # either write $to_kid or else read $from_kid
10206 or die "Can't find article $ARTICLE: $!\n";
9790 ...
9791 waitpid $child_pid, 0;
9792 } else {
9793 # am the child; use STDIN/STDOUT normally
9794 ...
9795 exit;
9796 }
979710207
979810208=begin original
979910209
9800The filehandle behaves normally for the parent, but I/O to that
10210Here C<$ARTICLE> must be a global (package) scalar variable - not one
9801filehandle is piped from/to the STDOUT/STDIN of the child process.
10211declared with L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>.
9802In the child process, the filehandle isn't opened--I/O happens from/to
9803the new STDOUT/STDIN. Typically this is used like the normal
9804piped open when you want to exercise more control over just how the
9805pipe command gets executed, such as when running setuid and
9806you don't want to have to scan shell commands for metacharacters.
980710212
980810213=end original
980910214
9810親プロセスでは、このファイハンドルは通常通りに動作しますが、行
10215ここ C<$ARTICLE> グローバ(パッケージ)スカラ変数でばなりません -
9811入出力は、子プロセスの STDIN/STDOUT にパイプされます。
10216L<C<my>|/my VARLIST> や L<C<state>|/state VARLIST> で宣言され
9812子プロセス側では、そのファイルハンドルは開かれず、入出力は新しい STDOUT か
10217変数ではありません。
9813STDIN に対して行なわれます。
9814これは、setuid で実行して、シェルコマンドのメタ文字を
9815検索させたくないような場合に、パイプコマンドの起動の仕方を
9816制御したいとき、普通のパイプの open と同じように使います。
981710218
10219=item Assigning a filehandle to a bareword
10220
10221(ファイルハンドルを裸の単語に代入する)
10222
981810223=begin original
981910224
9820The following blocks are more or less equivalent:
10225An older style is to use a bareword as the filehandle, as
982110226
982210227=end original
982310228
9824以下の組み合わせは、だいたい同じも:
10229より古いスタイルは、ように、ファイルハンドルとして裸の単語を使いま
982510230
9826 open(my $fh, "|tr '[a-z]' '[A-Z]'");
10231 open(FH, "<", "input.txt")
9827 open(my $fh, "|-", "tr '[a-z]' '[A-Z]'");
10232 or die "Can't open < input.txt: $!";
9828 open(my $fh, "|-") || exec 'tr', '[a-z]', '[A-Z]';
9829 open(my $fh, "|-", "tr", '[a-z]', '[A-Z]');
983010233
9831 open(my $fh, "cat -n '$file'|");
9832 open(my $fh, "-|", "cat -n '$file'");
9833 open(my $fh, "-|") || exec "cat", "-n", $file;
9834 open(my $fh, "-|", "cat", "-n", $file);
9835
983610234=begin original
983710235
9838The last two examples in each block show the pipe as "list form", which is
10236Then you can use C<FH> as the filehandle, in C<< close FH >> and C<<
9839not yet supported on all platforms. A good rule of thumb is that if
10237<FH> >> and so on. Note that it's a global variable, so this form is
9840your platform has a real L<C<fork>|/fork> (in other words, if your platform is
10238not recommended when dealing with filehandles other than Perl's built-in ones (e.g. STDOUT and STDIN).
9841Unix, including Linux and MacOS X), you can use the list form. You would
9842want to use the list form of the pipe so you can pass literal arguments
9843to the command without risk of the shell interpreting any shell metacharacters
9844in them. However, this also bars you from opening pipes to commands
9845that intentionally contain shell metacharacters, such as:
984610239
984710240=end original
984810241
9849それぞれのブロックの末尾二つの例ではパイプ「リスト形式」していますが
10242それから C<FH> 、C<< close FH >> や C<< <FH> >> などのように、
9850これはまだ全てのプラットォームで対応しているわけではなりせん
10243ァイルハンドルとして使え
9851よい経験則として、もし実行しているプラットフォ本当
10244これグロバル変数なの、Perl 組み込みのもの (例えば STDOUT と STDIN)
9852L<C<fork>|/fork> がれば(言い換えると、プラットフォームが Linux や
10245以外では非推奨であるに注意してください。
9853MacOS X を含む Unix なら)リスト形式が使えます。
9854パイプのリスト形式を使うことで、コマンドへのリテラルな引数を、
9855シェルのメタ文字をシェルが解釈するリスクなしに渡すことができます。
9856しかし、これは以下のように意図的にシェルメタ文字を含むコマンドをパイプとして
9857開くことを妨げます:
985810246
9859 open(my $fh, "|cat -n | expand -4 | lpr")
10247=back
9860 || die "Can't open pipeline to lpr: $!";
986110248
10249=item Other considerations
10250
10251(その他の考慮点)
10252
10253=over
10254
10255=item Automatic filehandle closure
10256
10257(自動的にファイルハンドルを閉じる)
10258
986210259=begin original
986310260
9864See L<perlipc/"Safe Pipe Opens"> for more examples of this.
10261The filehandle will be closed when its reference count reaches zero. If
10262it is a lexically scoped variable declared with L<C<my>|/my VARLIST>,
10263that usually means the end of the enclosing scope. However, this
10264automatic close does not check for errors, so it is better to explicitly
10265close filehandles, especially those used for writing:
986510266
986610267=end original
986710268
9868これに関する更なる例についてL<perlipc/"Safe Pipe Opens"> を
10269ファイルハンドル、参照カウントが 0 になったときに閉じられます。
9869参照してくだい。
10270これが L<C<my>|/my VARLIST> で宣言れたレキシカルスコープを持つ変数の場合、
10271普通は囲まれたスコープの終わりを意味します。
10272しかし、この自動閉じはエラーをチェックしないので、特に書き込み用の場合は、
10273明示的にファイルハンドルを閉じる方がよいです。
987010274
10275 close($handle)
10276 || warn "close failed: $!";
10277
10278=item Automatic pipe flushing
10279
10280(パイプの自動フラッシュ)
10281
987110282=begin original
987210283
987310284Perl will attempt to flush all files opened for
987410285output before any operation that may do a fork, but this may not be
987510286supported on some platforms (see L<perlport>). To be safe, you may need
987610287to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
987710288or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
987810289on any open handles.
987910290
988010291=end original
988110292
988210293v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
988310294fork を行う前にフラッシュしようとしますが、これに対応していない
988410295プラットフォームもあります(L<perlport> を参照してください)。
988510296安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
988610297C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
988710298L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
988810299呼び出す必要があるかもしれません。
988910300
989010301=begin original
989110302
989210303On systems that support a close-on-exec flag on files, the flag will
989310304be set for the newly opened file descriptor as determined by the value
989410305of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
989510306
989610307=end original
989710308
989810309ファイルに対する close-on-exec フラグをサポートしているシステムでは、
989910310フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
990010311ファイル記述子に対してセットされます。
990110312L<perlvar/$^F> を参照してください。
990210313
990310314=begin original
990410315
990510316Closing any piped filehandle causes the parent process to wait for the
990610317child to finish, then returns the status value in L<C<$?>|perlvar/$?> and
990710318L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
990810319
990910320=end original
991010321
991110322パイプのファイルハンドルを close することで、親プロセスは、子プロセスの終了を
991210323待ち、それから L<C<$?>|perlvar/$?> と
991310324L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> にステータス値を
991410325返します。
991510326
10327=item Direct versus by-reference assignment of filehandles
10328
10329(ファイルハンドルの直接代入とリファレンスによる代入)
10330
991610331=begin original
991710332
10333If FILEHANDLE -- the first argument in a call to C<open> -- is an
10334undefined scalar variable (or array or hash element), a new filehandle
10335is autovivified, meaning that the variable is assigned a reference to a
10336newly allocated anonymous filehandle. Otherwise if FILEHANDLE is an
10337expression, its value is the real filehandle. (This is considered a
10338symbolic reference, so C<use strict "refs"> should I<not> be in effect.)
10339
10340=end original
10341
10342FILEHANDLE (C<open> を呼び出すときの最初の引数) が未定義のスカラ変数
10343(または配列かハッシュの要素)の場合、
10344新しいファイルハンドルが自動有効化され、その変数は新しく割り当てられた
10345無名ファイルハンドルへのリファレンスが代入されます。
10346さもなければ、もし FILEHANDLE が式なら、その値を求めている実際の
10347ファイルハンドルの名前として使います。
10348(これはシンボリックリファレンスとして扱われるので、
10349C<use strict "refs"> の影響を I<受けません>。)
10350
10351=item Whitespace and special characters in the filename argument
10352
10353(ファイル名引数の空白と特殊文字)
10354
10355=begin original
10356
991810357The filename passed to the one- and two-argument forms of
9919L<C<open>|/open FILEHANDLE,EXPR> will
10358L<C<open>|/open FILEHANDLE,MODE,EXPR> will
992010359have leading and trailing whitespace deleted and normal
992110360redirection characters honored. This property, known as "magic open",
992210361can often be used to good effect. A user could specify a filename of
992310362F<"rsh cat file |">, or you could change certain filenames as needed:
992410363
992510364=end original
992610365
99271 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,EXPR> に渡された
103661 引数 と 2 引数の形の L<C<open>|/open FILEHANDLE,MODE,EXPR> に渡された
992810367ファイル名は、はじめと終わりの空白が取り除かれ、通常のリダイレクト文字列を
992910368受け付けます。
993010369この機能は "magic open" として知られていますが、普通いい効果をもたらします。
993110370ユーザーは F<"rsh cat file |"> といったファイル名を指定できますし、
993210371特定のファイル名を必要に応じて変更できます。
993310372
993410373 $filename =~ s/(.*\.gz)\s*$/gzip -dc < $1|/;
9935 open(my $fh, $filename) or die "Can't open $filename: $!";
10374 open(my $fh, $filename)
10375 or die "Can't open $filename: $!";
993610376
993710377=begin original
993810378
993910379Use the three-argument form to open a file with arbitrary weird characters in it,
994010380
994110381=end original
994210382
994310383妙な文字が含まれているようなファイル名をオープンするには、
9944103843 引数の形を使います。
994510385
994610386 open(my $fh, "<", $file)
9947 || die "Can't open $file: $!";
10387 || die "Can't open $file: $!";
994810388
994910389=begin original
995010390
995110391otherwise it's necessary to protect any leading and trailing whitespace:
995210392
995310393=end original
995410394
995510395あるいは、次のようにして、最初と最後の空白を保護します:
995610396
995710397 $file =~ s#^(\s)#./$1#;
995810398 open(my $fh, "< $file\0")
9959 || die "Can't open $file: $!";
10399 || die "Can't open $file: $!";
996010400
996110401=begin original
996210402
996310403(this may not work on some bizarre filesystems). One should
996410404conscientiously choose between the I<magic> and I<three-argument> form
9965of L<C<open>|/open FILEHANDLE,EXPR>:
10405of L<C<open>|/open FILEHANDLE,MODE,EXPR>:
996610406
996710407=end original
996810408
996910409(これは奇妙なファイルシステムでは動作しないかもしれません)。
9970L<C<open>|/open FILEHANDLE,EXPR> の I<magic> と I<3 引数> 形式を誠実に
10410L<C<open>|/open FILEHANDLE,MODE,EXPR> の I<magic> と I<3 引数> 形式を誠実に
997110411選択するべきです。
997210412
997310413 open(my $in, $ARGV[0]) || die "Can't open $ARGV[0]: $!";
997410414
997510415=begin original
997610416
997710417will allow the user to specify an argument of the form C<"rsh cat file |">,
997810418but will not work on a filename that happens to have a trailing space, while
997910419
998010420=end original
998110421
998210422とするとユーザーは C<"rsh cat file |"> という形の引数を指定できますが、
998310423末尾にスペースがついてしまったファイル名では動作しません; 一方:
998410424
998510425 open(my $in, "<", $ARGV[0])
9986 || die "Can't open $ARGV[0]: $!";
10426 || die "Can't open $ARGV[0]: $!";
998710427
998810428=begin original
998910429
999010430will have exactly the opposite restrictions. (However, some shells
999110431support the syntax C<< perl your_program.pl <( rsh cat file ) >>, which
999210432produces a filename that can be opened normally.)
999310433
999410434=end original
999510435
999610436はまったく逆の制限があります。
999710437(しかし、一部のシェルは C<< perl your_program.pl <( rsh cat file ) >> という
999810438文法に対応していて、普通に開くことが出来るファイル名を出力します。)
999910439
10440=item Invoking C-style C<open>
10441
10442(C 形式の C<open> の起動)
10443
1000010444=begin original
1000110445
1000210446If you want a "real" C L<open(2)>, then you should use the
1000310447L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> function, which involves
1000410448no such magic (but uses different filemodes than Perl
10005L<C<open>|/open FILEHANDLE,EXPR>, which corresponds to C L<fopen(3)>).
10449L<C<open>|/open FILEHANDLE,MODE,EXPR>, which corresponds to C L<fopen(3)>).
1000610450This is another way to protect your filenames from interpretation. For
1000710451example:
1000810452
1000910453=end original
1001010454
1001110455もし「本当の」C 言語の L<open(2)> が必要なら、このような副作用のない
1001210456L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> 関数を使うべきです
1001310457(ただし、C の L<fopen(3)> に対応する Perl の
10014L<C<open>|/open FILEHANDLE,EXPR> とは違うファイルモードを持ちます)。
10458L<C<open>|/open FILEHANDLE,MODE,EXPR> とは違うファイルモードを持ちます)。
1001510459これはファイル名を解釈から守るもう一つの方法です。
1001610460例えば:
1001710461
1001810462 use IO::Handle;
1001910463 sysopen(my $fh, $path, O_RDWR|O_CREAT|O_EXCL)
1002010464 or die "Can't open $path: $!";
1002110465 $fh->autoflush(1);
1002210466 print $fh "stuff $$\n";
1002310467 seek($fh, 0, 0);
1002410468 print "File contains: ", readline($fh);
1002510469
1002610470=begin original
1002710471
1002810472See L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> for some details about
1002910473mixing reading and writing.
1003010474
1003110475=end original
1003210476
1003310477読み書きを混ぜる場合の詳細については
1003410478L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> を参照してください。
1003510479
10480=item Portability issues
10481
10482(移植性の問題)
10483
1003610484=begin original
1003710485
10038Portability issues: L<perlport/open>.
10486See L<perlport/open>.
1003910487
1004010488=end original
1004110489
10042移植性の問題: L<perlport/open>。
10490L<perlport/open> を参照してください
1004310491
10492=back
10493
10494=back
10495
1004410496=item opendir DIRHANDLE,EXPR
1004510497X<opendir>
1004610498
1004710499=for Pod::Functions open a directory
1004810500
1004910501=begin original
1005010502
1005110503Opens a directory named EXPR for processing by
1005210504L<C<readdir>|/readdir DIRHANDLE>, L<C<telldir>|/telldir DIRHANDLE>,
1005310505L<C<seekdir>|/seekdir DIRHANDLE,POS>,
1005410506L<C<rewinddir>|/rewinddir DIRHANDLE>, and
1005510507L<C<closedir>|/closedir DIRHANDLE>. Returns true if successful.
1005610508DIRHANDLE may be an expression whose value can be used as an indirect
1005710509dirhandle, usually the real dirhandle name. If DIRHANDLE is an undefined
1005810510scalar variable (or array or hash element), the variable is assigned a
1005910511reference to a new anonymous dirhandle; that is, it's autovivified.
10060DIRHANDLEs have their own namespace separate from FILEHANDLEs.
10512Dirhandles are the same objects as filehandles; an I/O object can only
10513be open as one of these handle types at once.
1006110514
1006210515=end original
1006310516
1006410517L<C<readdir>|/readdir DIRHANDLE>、L<C<telldir>|/telldir DIRHANDLE>、
1006510518L<C<seekdir>|/seekdir DIRHANDLE,POS>、L<C<rewinddir>|/rewinddir DIRHANDLE>、
1006610519L<C<closedir>|/closedir DIRHANDLE> で処理するために、EXPR で指定された名前の
1006710520ディレクトリをオープンします。
1006810521成功時には真を返します。
1006910522DIRHANDLE は間接ディレクトリハンドルとして使える値(普通は実際のディレクトリ
1007010523ハンドルの名前)となる式でも構いません。
1007110524DIRHANDLE が未定義のスカラ値(または配列かハッシュの要素)の場合、その変数は
1007210525新しい無名ディレクトリハンドルへのリファレンスが代入されます; つまり、
1007310526自動有効化されます。
10074DIRHANDLE 、FILEHANDLE は別に名前空間を持っていま
10527ディレクトリハンドルファイルハンドル同じオブジェクトで;
10528一つの I/O オブジェクトは同時にこれらのハンドル型のどちらかとしてのみ
10529開くことができます。
1007510530
1007610531=begin original
1007710532
1007810533See the example at L<C<readdir>|/readdir DIRHANDLE>.
1007910534
1008010535=end original
1008110536
1008210537L<C<readdir>|/readdir DIRHANDLE> の例を参照してください。
1008310538
1008410539=item ord EXPR
1008510540X<ord> X<encoding>
1008610541
1008710542=item ord
1008810543
1008910544=for Pod::Functions find a character's numeric representation
1009010545
1009110546=begin original
1009210547
1009310548Returns the numeric value of the first character of EXPR.
1009410549If EXPR is an empty string, returns 0. If EXPR is omitted, uses
1009510550L<C<$_>|perlvar/$_>.
1009610551(Note I<character>, not byte.)
1009710552
1009810553=end original
1009910554
1010010555EXPR の最初の文字の数値としての値を返します。
1010110556EXPR が空文字列の場合は、0 を返します。
1010210557EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1010310558(バイトではなく I<文字> であることに注意してください。)
1010410559
1010510560=begin original
1010610561
1010710562For the reverse, see L<C<chr>|/chr NUMBER>.
1010810563See L<perlunicode> for more about Unicode.
1010910564
1011010565=end original
1011110566
1011210567逆のことをするには L<C<chr>|/chr NUMBER> を参照してください。
1011310568Unicode については L<perlunicode> を参照してください。
1011410569
1011510570=item our VARLIST
1011610571X<our> X<global>
1011710572
1011810573=item our TYPE VARLIST
1011910574
1012010575=item our VARLIST : ATTRS
1012110576
1012210577=item our TYPE VARLIST : ATTRS
1012310578
1012410579=for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping)
1012510580
1012610581=begin original
1012710582
1012810583L<C<our>|/our VARLIST> makes a lexical alias to a package (i.e. global)
1012910584variable of the same name in the current package for use within the
1013010585current lexical scope.
1013110586
1013210587=end original
1013310588
1013410589L<C<our>|/our VARLIST> は単純名を、現在のレキシカルスコープ内で使うために、
1013510590現在のパッケージの同じ名前のパッケージ(つまりグローバルな)変数への
1013610591レキシカルな別名を作ります。
1013710592
1013810593=begin original
1013910594
1014010595L<C<our>|/our VARLIST> has the same scoping rules as
1014110596L<C<my>|/my VARLIST> or L<C<state>|/state VARLIST>, meaning that it is
1014210597only valid within a lexical scope. Unlike L<C<my>|/my VARLIST> and
1014310598L<C<state>|/state VARLIST>, which both declare new (lexical) variables,
1014410599L<C<our>|/our VARLIST> only creates an alias to an existing variable: a
1014510600package variable of the same name.
1014610601
1014710602=end original
1014810603
1014910604L<C<our>|/our VARLIST> は L<C<my>|/my VARLIST> や
1015010605L<C<state>|/state VARLIST> と同じスコープルールを持ちます; つまり
1015110606レキシカルスコープの中でだけ有効です。
1015210607新しい(レキシカル)変数を宣言する L<C<my>|/my VARLIST> や
1015310608L<C<state>|/state VARLIST> と異なり、L<C<our>|/our VARLIST> は既に
1015410609存在する変数への別名を作るだけです: 同じ名前のパッケージ変数です。
1015510610
1015610611=begin original
1015710612
1015810613This means that when C<use strict 'vars'> is in effect, L<C<our>|/our
1015910614VARLIST> lets you use a package variable without qualifying it with the
1016010615package name, but only within the lexical scope of the
1016110616L<C<our>|/our VARLIST> declaration. This applies immediately--even
1016210617within the same statement.
1016310618
1016410619=end original
1016510620
1016610621つまり、C<use strict 'vars'> が有効の場合は、L<C<our>|/our VARLIST> を
1016710622使うことで、
1016810623パッケージ変数をパッケージ名で修飾することなく使うことができますが、
1016910624L<C<our>|/our VARLIST> 宣言のレキシカルスコープ内だけということです。
1017010625これは(たとえ同じ文の中でも)直ちに適用されます。
1017110626
1017210627 package Foo;
1017310628 use strict;
1017410629
1017510630 $Foo::foo = 23;
1017610631
1017710632 {
1017810633 our $foo; # alias to $Foo::foo
1017910634 print $foo; # prints 23
1018010635 }
1018110636
1018210637 print $Foo::foo; # prints 23
1018310638
1018410639 print $foo; # ERROR: requires explicit package name
1018510640
1018610641=begin original
1018710642
1018810643This works even if the package variable has not been used before, as
1018910644package variables spring into existence when first used.
1019010645
1019110646=end original
1019210647
1019310648これはパッケージ変数がまだ使われていなくても動作します; パッケージ変数は、
1019410649最初に使われた時にひょっこり現れるからです。
1019510650
1019610651 package Foo;
1019710652 use strict;
1019810653
1019910654 our $foo = 23; # just like $Foo::foo = 23
1020010655
1020110656 print $Foo::foo; # prints 23
1020210657
1020310658=begin original
1020410659
1020510660Because the variable becomes legal immediately under C<use strict 'vars'>, so
1020610661long as there is no variable with that name is already in scope, you can then
1020710662reference the package variable again even within the same statement.
1020810663
1020910664=end original
1021010665
1021110666変数は C<use strict 'vars'> の基で直ちに正当になるので、
1021210667スコープ内に同じ名前の変数がない限り、
1021310668たとえ同じ文の中でもパッケージ変数を再び参照できます。
1021410669
1021510670 package Foo;
1021610671 use strict;
1021710672
1021810673 my $foo = $foo; # error, undeclared $foo on right-hand side
1021910674 our $foo = $foo; # no errors
1022010675
1022110676=begin original
1022210677
1022310678If more than one variable is listed, the list must be placed
1022410679in parentheses.
1022510680
1022610681=end original
1022710682
1022810683複数の変数を指定する場合は、リストはかっこでくくらなければなりません。
1022910684
1023010685 our($bar, $baz);
1023110686
1023210687=begin original
1023310688
1023410689An L<C<our>|/our VARLIST> declaration declares an alias for a package
1023510690variable that will be visible
1023610691across its entire lexical scope, even across package boundaries. The
1023710692package in which the variable is entered is determined at the point
1023810693of the declaration, not at the point of use. This means the following
1023910694behavior holds:
1024010695
1024110696=end original
1024210697
1024310698L<C<our>|/our VARLIST> 宣言はレキシカルスコープ全体に対して (たとえ
1024410699パッケージ境界を越えていても)見える、パッケージ変数への別名を宣言します。
1024510700この変数が入るパッケージは宣言した時点で定義され、
1024610701使用した時点ではありません。
1024710702これにより、以下のような振る舞いになります:
1024810703
1024910704 package Foo;
1025010705 our $bar; # declares $Foo::bar for rest of lexical scope
1025110706 $bar = 20;
1025210707
1025310708 package Bar;
1025410709 print $bar; # prints 20, as it refers to $Foo::bar
1025510710
1025610711=begin original
1025710712
1025810713Multiple L<C<our>|/our VARLIST> declarations with the same name in the
1025910714same lexical
1026010715scope are allowed if they are in different packages. If they happen
1026110716to be in the same package, Perl will emit warnings if you have asked
1026210717for them, just like multiple L<C<my>|/my VARLIST> declarations. Unlike
1026310718a second L<C<my>|/my VARLIST> declaration, which will bind the name to a
1026410719fresh variable, a second L<C<our>|/our VARLIST> declaration in the same
1026510720package, in the same scope, is merely redundant.
1026610721
1026710722=end original
1026810723
1026910724同じレキシカルスコープでも、パッケージが異なっていれば、同じ名前で複数の
1027010725L<C<our>|/our VARLIST> 宣言ができます。
1027110726同じパッケージになっていると、警告が出力されるようになっていれば
1027210727複数の L<C<my>|/my VARLIST> 宣言がある場合と同じように警告が出力されます。
1027310728新しい変数を名前に割り当てることになる 2 回目の L<C<my>|/my VARLIST> 宣言と
1027410729違って、同じパッケージの同じスコープで 2 回
1027510730L<C<our>|/our VARLIST> 宣言するのは単に冗長です。
1027610731
1027710732 use warnings;
1027810733 package Foo;
1027910734 our $bar; # declares $Foo::bar for rest of lexical scope
1028010735 $bar = 20;
1028110736
1028210737 package Bar;
1028310738 our $bar = 30; # declares $Bar::bar for rest of lexical scope
1028410739 print $bar; # prints 30
1028510740
1028610741 our $bar; # emits warning but has no other effect
1028710742 print $bar; # still prints 30
1028810743
1028910744=begin original
1029010745
1029110746An L<C<our>|/our VARLIST> declaration may also have a list of attributes
1029210747associated with it.
1029310748
1029410749=end original
1029510750
1029610751L<C<our>|/our VARLIST> 宣言には、それと結び付けられる属性のリストを
1029710752持つこともあります。
1029810753
1029910754=begin original
1030010755
1030110756The exact semantics and interface of TYPE and ATTRS are still
1030210757evolving. TYPE is currently bound to the use of the L<fields> pragma,
1030310758and attributes are handled using the L<attributes> pragma, or, starting
1030410759from Perl 5.8.0, also via the L<Attribute::Handlers> module. See
1030510760L<perlsub/"Private Variables via my()"> for details.
1030610761
1030710762=end original
1030810763
1030910764TYPE と ATTRS の正確な文法とインターフェースは今でも進化しています。
1031010765現在のところ、TYPE は L<fields> プラグマの使用と結び付けられていて、
1031110766属性は L<attributes> プラグマか、Perl 5.8.0 からは
1031210767L<Attribute::Handlers> モジュールと結び付けられています。
1031310768詳しくは L<perlsub/"Private Variables via my()"> を参照してください。
1031410769
1031510770=begin original
1031610771
1031710772Note that with a parenthesised list, L<C<undef>|/undef EXPR> can be used
1031810773as a dummy placeholder, for example to skip assignment of initial
1031910774values:
1032010775
1032110776=end original
1032210777
1032310778かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> は、例えば初期値の代入を
1032410779飛ばすために、ダミーのプレースホルダとして使えることに注意してください:
1032510780
1032610781 our ( undef, $min, $hour ) = localtime;
1032710782
1032810783=begin original
1032910784
1033010785L<C<our>|/our VARLIST> differs from L<C<use vars>|vars>, which allows
1033110786use of an unqualified name I<only> within the affected package, but
1033210787across scopes.
1033310788
1033410789=end original
1033510790
1033610791L<C<our>|/our VARLIST> は L<C<use vars>|vars> と異なります; スコープを
1033710792またぐのではなく、影響するパッケージの内側 I<のみ> で完全修飾されていない
1033810793名前を使えるようにします。
1033910794
1034010795=item pack TEMPLATE,LIST
1034110796X<pack>
1034210797
1034310798=for Pod::Functions convert a list into a binary representation
1034410799
1034510800=begin original
1034610801
1034710802Takes a LIST of values and converts it into a string using the rules
1034810803given by the TEMPLATE. The resulting string is the concatenation of
1034910804the converted values. Typically, each converted value looks
1035010805like its machine-level representation. For example, on 32-bit machines
1035110806an integer may be represented by a sequence of 4 bytes, which will in
1035210807Perl be presented as a string that's 4 characters long.
1035310808
1035410809=end original
1035510810
1035610811LIST の値を TEMPLATE で与えられたルールを用いて文字列に変換します。
1035710812結果の文字列は変換した値を連結したものです。
1035810813典型的には、それぞれの変換された値はマシンレベルの表現のように見えます。
1035910814例えば、32-bit マシンでは、整数は 4 バイトで表現されるので、
1036010815Perl では 4 文字の文字列で表現されます。
1036110816
1036210817=begin original
1036310818
1036410819See L<perlpacktut> for an introduction to this function.
1036510820
1036610821=end original
1036710822
1036810823この関数の説明については L<perlpacktut> を参照してください。
1036910824
1037010825=begin original
1037110826
1037210827The TEMPLATE is a sequence of characters that give the order and type
1037310828of values, as follows:
1037410829
1037510830=end original
1037610831
1037710832TEMPLATE は、以下のような値の型と順番を指定する文字を並べたものです:
1037810833
1037910834=begin original
1038010835
1038110836 a A string with arbitrary binary data, will be null padded.
1038210837 A A text (ASCII) string, will be space padded.
1038310838 Z A null-terminated (ASCIZ) string, will be null padded.
1038410839
1038510840=end original
1038610841
1038710842 a 任意のバイナリデータを含む文字列、ヌル文字で埋める。
1038810843 A テキスト (ASCII) 文字列、スペース文字で埋める。
1038910844 Z ヌル文字終端 (ASCIZ) 文字列、ヌル文字で埋める。
1039010845
1039110846=begin original
1039210847
1039310848 b A bit string (ascending bit order inside each byte,
1039410849 like vec()).
1039510850 B A bit string (descending bit order inside each byte).
1039610851 h A hex string (low nybble first).
1039710852 H A hex string (high nybble first).
1039810853
1039910854=end original
1040010855
1040110856 b ビット列 (バイトごとに昇ビット順、vec() と同じ)。
1040210857 B ビット列 (バイトごとに降ビット順)。
1040310858 h 16 進数文字列 (低位ニブルが先)。
1040410859 H 16 進数文字列 (高位ニブルが先)。
1040510860
1040610861=begin original
1040710862
1040810863 c A signed char (8-bit) value.
1040910864 C An unsigned char (octet) value.
1041010865 W An unsigned char value (can be greater than 255).
1041110866
1041210867=end original
1041310868
1041410869 c signed char (8 ビット) 値。
1041510870 C unsigned char (オクテット) 値。
1041610871 W unsigned char 値 (255 より大きいかもしれません)。
1041710872
1041810873=begin original
1041910874
1042010875 s A signed short (16-bit) value.
1042110876 S An unsigned short value.
1042210877
1042310878=end original
1042410879
1042510880 s signed short (16 ビット) 値。
1042610881 S unsigned short 値。
1042710882
1042810883=begin original
1042910884
1043010885 l A signed long (32-bit) value.
1043110886 L An unsigned long value.
1043210887
1043310888=end original
1043410889
1043510890 l signed long (32 ビット) 値。
1043610891 L unsigned long 値。
1043710892
1043810893=begin original
1043910894
1044010895 q A signed quad (64-bit) value.
1044110896 Q An unsigned quad value.
1044210897 (Quads are available only if your system supports 64-bit
1044310898 integer values _and_ if Perl has been compiled to support
1044410899 those. Raises an exception otherwise.)
1044510900
1044610901=end original
1044710902
1044810903 q 符号付き 64 ビット整数。
1044910904 Q 符号なし 64 ビット整数。
1045010905 (64 ビット整数は、システムが 64 ビット整数に対応していて、かつ Perl が
1045110906 64 ビット整数対応としてコンパイルされている場合にのみ使用可能です。
1045210907 それ以外の場合は例外が発生します。)
1045310908
1045410909=begin original
1045510910
1045610911 i A signed integer value.
10457 I A unsigned integer value.
10912 I An unsigned integer value.
1045810913 (This 'integer' is _at_least_ 32 bits wide. Its exact
1045910914 size depends on what a local C compiler calls 'int'.)
1046010915
1046110916=end original
1046210917
1046310918 i signed int 値。
1046410919 I unsigned int 値。
1046510920 (ここでの 'integer' は 「最低」 32 ビット幅です。正確なサイズは
1046610921 ローカルの C コンパイラの 'int' のサイズに依存します。)
1046710922
1046810923=begin original
1046910924
1047010925 n An unsigned short (16-bit) in "network" (big-endian) order.
1047110926 N An unsigned long (32-bit) in "network" (big-endian) order.
1047210927 v An unsigned short (16-bit) in "VAX" (little-endian) order.
1047310928 V An unsigned long (32-bit) in "VAX" (little-endian) order.
1047410929
1047510930=end original
1047610931
1047710932 n "network" 順序 (ビッグエンディアン) の unsigned short (16 ビット)。
1047810933 N "network" 順序 (ビッグエンディアン) の unsigned long (32 ビット)。
1047910934 v "VAX" 順序 (リトルエンディアン) の unsigned short (16 ビット)。
1048010935 V "VAX" 順序 (リトルエンディアン) の unsigned long (32 ビット)。
1048110936
1048210937=begin original
1048310938
1048410939 j A Perl internal signed integer value (IV).
1048510940 J A Perl internal unsigned integer value (UV).
1048610941
1048710942=end original
1048810943
1048910944 j Perl 内部符号付き整数 (IV)。
1049010945 J Perl 内部符号なし整数 (UV)。
1049110946
1049210947=begin original
1049310948
1049410949 f A single-precision float in native format.
1049510950 d A double-precision float in native format.
1049610951
1049710952=end original
1049810953
1049910954 f 機種依存の単精度浮動小数点数。
1050010955 d 機種依存の倍精度浮動小数点数。
1050110956
1050210957=begin original
1050310958
1050410959 F A Perl internal floating-point value (NV) in native format
1050510960 D A float of long-double precision in native format.
1050610961 (Long doubles are available only if your system supports
1050710962 long double values _and_ if Perl has been compiled to
1050810963 support those. Raises an exception otherwise.
1050910964 Note that there are different long double formats.)
1051010965
1051110966=end original
1051210967
1051310968 F ネイティブフォーマットの Perl 内部浮動小数点数 (NV)
1051410969 D ネイティブフォーマットの長い倍精度浮動小数点数(long double)。
1051510970 (long double は、システムが long double に対応していて、かつ Perl が
1051610971 long double 対応としてコンパイルされている場合にのみ使用可能です。
1051710972 それ以外の場合は例外が発生します。
1051810973 long double 型式の場合は異なることに注意してください)
1051910974
1052010975=begin original
1052110976
1052210977 p A pointer to a null-terminated string.
1052310978 P A pointer to a structure (fixed-length string).
1052410979
1052510980=end original
1052610981
1052710982 p ヌル文字で終端する文字列へのポインタ。
1052810983 P 構造体 (固定長文字列) へのポインタ。
1052910984
1053010985=begin original
1053110986
1053210987 u A uuencoded string.
1053310988 U A Unicode character number. Encodes to a character in char-
1053410989 acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in
1053510990 byte mode.
1053610991
1053710992=end original
1053810993
1053910994 u uuencode 文字列。
1054010995 U Unicode 文字番号。文字モードでは文字に、バイトモードなら UTF-8 に
1054110996 (EBCDIC システムでは UTF-EBCDIC に)エンコードされます。
1054210997
1054310998=begin original
1054410999
1054511000 w A BER compressed integer (not an ASN.1 BER, see perlpacktut
1054611001 for details). Its bytes represent an unsigned integer in
1054711002 base 128, most significant digit first, with as few digits
1054811003 as possible. Bit eight (the high bit) is set on each byte
1054911004 except the last.
1055011005
1055111006=end original
1055211007
1055311008 w A BER 圧縮変数(ASN.1 BER ではありません; 詳細については perlpacktut を
1055411009 参照してください)。このバイト列はできるだけ少ない桁数で表現された
1055511010 128 を基とした符号なし整数で、最上位ビットから順に並びます。
1055611011 最後のバイト以外の各バイトのビット 8 (上位ビット) がセットされます。
1055711012
1055811013=begin original
1055911014
1056011015 x A null byte (a.k.a ASCII NUL, "\000", chr(0))
1056111016 X Back up a byte.
1056211017 @ Null-fill or truncate to absolute position, counted from the
1056311018 start of the innermost ()-group.
1056411019 . Null-fill or truncate to absolute position specified by
1056511020 the value.
1056611021 ( Start of a ()-group.
1056711022
1056811023=end original
1056911024
1057011025 x ヌル文字 (つまり ASCII NUL, "\000", chr(0))
1057111026 X 1 文字後退。
1057211027 @ 一番内側の () の組の開始位置から数えて、絶対位置までヌル文字で
1057311028 埋めるか切り詰める。
1057411029 . 値で指定した絶対位置までヌル文字で埋めるか切り詰める。
1057511030 ( () の組の開始。
1057611031
1057711032=begin original
1057811033
1057911034One or more modifiers below may optionally follow certain letters in the
1058011035TEMPLATE (the second column lists letters for which the modifier is valid):
1058111036
1058211037=end original
1058311038
1058411039以下に示す一つまたは複数の修飾子を、TEMPLATE の文字のいくつかにオプションで
1058511040付けることができます(表の 2 列目は、その修飾子が有効な文字です):
1058611041
1058711042=begin original
1058811043
1058911044 ! sSlLiI Forces native (short, long, int) sizes instead
1059011045 of fixed (16-/32-bit) sizes.
1059111046
1059211047=end original
1059311048
1059411049 ! sSlLiI 固定の(16/32 ビット)サイズではなく、ネイティブな
1059511050 (short, long, int)サイズを強制する。
1059611051
1059711052=begin original
1059811053
1059911054 ! xX Make x and X act as alignment commands.
1060011055
1060111056=end original
1060211057
1060311058 ! xX x と X をアライメントコマンドとして振舞わせる。
1060411059
1060511060=begin original
1060611061
1060711062 ! nNvV Treat integers as signed instead of unsigned.
1060811063
1060911064=end original
1061011065
1061111066 ! nNvV 整数を符号なしではなく符号付きとして扱わせる。
1061211067
1061311068=begin original
1061411069
1061511070 ! @. Specify position as byte offset in the internal
1061611071 representation of the packed string. Efficient
1061711072 but dangerous.
1061811073
1061911074=end original
1062011075
1062111076 ! @. pack された内部表現のバイトオフセットとして位置を指定する。
1062211077 効率的ですが危険です。
1062311078
1062411079=begin original
1062511080
1062611081 > sSiIlLqQ Force big-endian byte-order on the type.
1062711082 jJfFdDpP (The "big end" touches the construct.)
1062811083
1062911084=end original
1063011085
1063111086 > sSiIlLqQ これらの型のバイト順をビッグエンディアンに強制します。
1063211087 jJfFdDpP (「大きい端」が構造に触れています。)
1063311088
1063411089=begin original
1063511090
1063611091 < sSiIlLqQ Force little-endian byte-order on the type.
1063711092 jJfFdDpP (The "little end" touches the construct.)
1063811093
1063911094=end original
1064011095
1064111096 < sSiIlLqQ これらの型のバイト順をリトルエンディアンに強制します。
1064211097 jJfFdDpP (「小さい端」が構造に触れています。)
1064311098
1064411099=begin original
1064511100
1064611101The C<< > >> and C<< < >> modifiers can also be used on C<()> groups
1064711102to force a particular byte-order on all components in that group,
1064811103including all its subgroups.
1064911104
1065011105=end original
1065111106
1065211107C<< > >> と C<< < >> の修飾子は C<()>-グループでも使えます;
1065311108この場合はそのグループと全ての副グループ内の全ての要素を特定のバイト順に
1065411109強制します。
1065511110
1065611111=begin comment
1065711112
1065811113Larry recalls that the hex and bit string formats (H, h, B, b) were added to
1065911114pack for processing data from NASA's Magellan probe. Magellan was in an
1066011115elliptical orbit, using the antenna for the radar mapping when close to
1066111116Venus and for communicating data back to Earth for the rest of the orbit.
1066211117There were two transmission units, but one of these failed, and then the
1066311118other developed a fault whereby it would randomly flip the sense of all the
1066411119bits. It was easy to automatically detect complete records with the correct
1066511120sense, and complete records with all the bits flipped. However, this didn't
1066611121recover the records where the sense flipped midway. A colleague of Larry's
1066711122was able to pretty much eyeball where the records flipped, so they wrote an
1066811123editor named kybble (a pun on the dog food Kibbles 'n Bits) to enable him to
1066911124manually correct the records and recover the data. For this purpose pack
1067011125gained the hex and bit string format specifiers.
1067111126
1067211127git shows that they were added to perl 3.0 in patch #44 (Jan 1991, commit
106731112827e2fb84680b9cc1), but the patch description makes no mention of their
1067411129addition, let alone the story behind them.
1067511130
1067611131=end comment
1067711132
1067811133=begin original
1067911134
1068011135The following rules apply:
1068111136
1068211137=end original
1068311138
1068411139以下の条件が適用されます:
1068511140
1068611141=over
1068711142
1068811143=item *
1068911144
1069011145=begin original
1069111146
1069211147Each letter may optionally be followed by a number indicating the repeat
1069311148count. A numeric repeat count may optionally be enclosed in brackets, as
1069411149in C<pack("C[80]", @arr)>. The repeat count gobbles that many values from
1069511150the LIST when used with all format types other than C<a>, C<A>, C<Z>, C<b>,
1069611151C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, and C<P>, where it means
1069711152something else, described below. Supplying a C<*> for the repeat count
1069811153instead of a number means to use however many items are left, except for:
1069911154
1070011155=end original
1070111156
1070211157これらの文字の後には、繰り返し数を示す数字を付けることができます。
1070311158数値の繰り返し数は C<pack "C[80]", @arr> のように大かっこで
1070411159囲むこともできます。
1070511160C<a>, C<A>, C<Z>, C<b>, C<B>, C<h>, C<H>, C<@>, C<.>, C<x>, C<X>, C<P>
1070611161以外の全ての型では、LIST から繰り返し数の値を取り出して使います。
1070711162繰り返し数に C<*> を指定すると、以下の例外を除いて、
1070811163その時点で残っているすべての要素を意味します。
1070911164
1071011165=over
1071111166
1071211167=item *
1071311168
1071411169=begin original
1071511170
1071611171C<@>, C<x>, and C<X>, where it is equivalent to C<0>.
1071711172
1071811173=end original
1071911174
1072011175C<@>, C<x>, C<X> では C<0> と等価です。
1072111176
1072211177=item *
1072311178
1072411179=begin original
1072511180
1072611181<.>, where it means relative to the start of the string.
1072711182
1072811183=end original
1072911184
1073011185<.> では文字列の先頭からの相対位置を意味します。
1073111186
1073211187=item *
1073311188
1073411189=begin original
1073511190
1073611191C<u>, where it is equivalent to 1 (or 45, which here is equivalent).
1073711192
1073811193=end original
1073911194
1074011195C<u> では 1 (あるいはここでは 45 でも等価です) と等価です。
1074111196
1074211197=back
1074311198
1074411199=begin original
1074511200
1074611201One can replace a numeric repeat count with a template letter enclosed in
1074711202brackets to use the packed byte length of the bracketed template for the
1074811203repeat count.
1074911204
1075011205=end original
1075111206
1075211207このテンプレートでパックされたバイト長を繰り返し数として使うために、
1075311208大かっこで囲まれたテンプレートで数値の繰り返し数を置き換えることが
1075411209できます。
1075511210
1075611211=begin original
1075711212
1075811213For example, the template C<x[L]> skips as many bytes as in a packed long,
1075911214and the template C<"$t X[$t] $t"> unpacks twice whatever $t (when
1076011215variable-expanded) unpacks. If the template in brackets contains alignment
1076111216commands (such as C<x![d]>), its packed length is calculated as if the
1076211217start of the template had the maximal possible alignment.
1076311218
1076411219=end original
1076511220
1076611221例えば、テンプレート C<x[L]> は long でパックされたバイト数分だけスキップし、
1076711222テンプレート C<"$t X[$t] $t"> は $t (変数展開された場合)を
1076811223unpack したものの 2 倍を unpack します。
1076911224(C<x![d]> のように) 大かっこにアライメントコマンドが含まれている場合、
1077011225パックされた長さは、テンプレートの先頭で最大限可能なアライメントを
1077111226持っているものとして計算されます。
1077211227
1077311228=begin original
1077411229
1077511230When used with C<Z>, a C<*> as the repeat count is guaranteed to add a
1077611231trailing null byte, so the resulting string is always one byte longer than
1077711232the byte length of the item itself.
1077811233
1077911234=end original
1078011235
1078111236C<Z> で、繰り返し数として C<*> が使われた場合、末尾にヌルバイトが
1078211237保証されるので、結果の文字列は常にアイテム自身のバイト長よりも 1 バイト
1078311238長くなります。
1078411239
1078511240=begin original
1078611241
1078711242When used with C<@>, the repeat count represents an offset from the start
1078811243of the innermost C<()> group.
1078911244
1079011245=end original
1079111246
1079211247C<@> で使うと、繰り返し数は一番内側の C<()> グループの先頭からのオフセットを
1079311248表現します。
1079411249
1079511250=begin original
1079611251
1079711252When used with C<.>, the repeat count determines the starting position to
1079811253calculate the value offset as follows:
1079911254
1080011255=end original
1080111256
1080211257C<.> で使われると、繰り返し数は以下のようにして、
1080311258値のオフセットを計算するための開始位置を決定するために使われます。
1080411259
1080511260=over
1080611261
1080711262=item *
1080811263
1080911264=begin original
1081011265
1081111266If the repeat count is C<0>, it's relative to the current position.
1081211267
1081311268=end original
1081411269
1081511270繰り返し数が C<0> なら、現在位置からの相対位置となります。
1081611271
1081711272=item *
1081811273
1081911274=begin original
1082011275
1082111276If the repeat count is C<*>, the offset is relative to the start of the
1082211277packed string.
1082311278
1082411279=end original
1082511280
1082611281繰り返し数が C<*> なら、オフセットは pack された文字列の先頭からの
1082711282相対位置です。
1082811283
1082911284=item *
1083011285
1083111286=begin original
1083211287
1083311288And if it's an integer I<n>, the offset is relative to the start of the
1083411289I<n>th innermost C<( )> group, or to the start of the string if I<n> is
1083511290bigger then the group level.
1083611291
1083711292=end original
1083811293
1083911294そして整数 I<n> なら、オフセットは一番内側から I<n> 番目の C<( )> グループの
1084011295先頭、あるいは I<n> がグループレベルより大きい場合は文字列の先頭からの
1084111296相対位置です。
1084211297
1084311298=back
1084411299
1084511300=begin original
1084611301
1084711302The repeat count for C<u> is interpreted as the maximal number of bytes
1084811303to encode per line of output, with 0, 1 and 2 replaced by 45. The repeat
1084911304count should not be more than 65.
1085011305
1085111306=end original
1085211307
1085311308C<u> での繰り返し回数は、出力行毎に最大何バイトまでをエンコードするかを
1085411309示します; 0, 1, 2 は 45 として扱われます。
1085511310繰り返し数は 65 を超えてはなりません。
1085611311
1085711312=item *
1085811313
1085911314=begin original
1086011315
1086111316The C<a>, C<A>, and C<Z> types gobble just one value, but pack it as a
1086211317string of length count, padding with nulls or spaces as needed. When
1086311318unpacking, C<A> strips trailing whitespace and nulls, C<Z> strips everything
1086411319after the first null, and C<a> returns data with no stripping at all.
1086511320
1086611321=end original
1086711322
1086811323C<a>, C<A>, C<Z> という型を使うと、値を一つだけ取り出して使いますが、
1086911324繰り返し数で示す長さの文字列となるように、必要に応じてヌル文字か
1087011325スペース文字を付け足します。
1087111326unpack するとき、C<A> は後続の空白やヌル文字を取り除きます; C<Z> は最初の
1087211327ヌル文字以降の全てを取り除きます; C<a> はデータを取り除くことなく
1087311328そのまま返します。
1087411329
1087511330=begin original
1087611331
1087711332If the value to pack is too long, the result is truncated. If it's too
1087811333long and an explicit count is provided, C<Z> packs only C<$count-1> bytes,
1087911334followed by a null byte. Thus C<Z> always packs a trailing null, except
1088011335when the count is 0.
1088111336
1088211337=end original
1088311338
1088411339pack する値が長すぎる場合、結果は切り詰められます。
1088511340長すぎてかつ明示的に個数が指定されている場合、
1088611341C<Z> は C<$count-1> バイトまで pack し、その後にヌルバイトがつきます。
1088711342従って、C<Z> は、繰り返し数が 0 の場合を除いて、常に末尾にヌルバイトが
1088811343つきます。
1088911344
1089011345=item *
1089111346
1089211347=begin original
1089311348
1089411349Likewise, the C<b> and C<B> formats pack a string that's that many bits long.
1089511350Each such format generates 1 bit of the result. These are typically followed
1089611351by a repeat count like C<B8> or C<B64>.
1089711352
1089811353=end original
1089911354
1090011355同様に、C<b> や C<B> は、繰り返し数で示すビット長のビット列に pack します。
1090111356これらの各文字は結果の 1 ビットを生成します。
1090211357これらは典型的には C<B8> や C<B64> のような繰り返しカウントが引き続きます。
1090311358
1090411359=begin original
1090511360
1090611361Each result bit is based on the least-significant bit of the corresponding
1090711362input character, i.e., on C<ord($char)%2>. In particular, characters C<"0">
1090811363and C<"1"> generate bits 0 and 1, as do characters C<"\000"> and C<"\001">.
1090911364
1091011365=end original
1091111366
1091211367結果ビットのそれぞれは対応する入力文字の最下位ビットを基にします
1091311368(つまり C<ord($char)%2>)。
1091411369特に、文字 C<"0"> と C<"1"> は文字 C<"\000"> と C<"\001"> と同様に、
1091511370ビット 0 と 1 を生成します。
1091611371
1091711372=begin original
1091811373
1091911374Starting from the beginning of the input string, each 8-tuple
1092011375of characters is converted to 1 character of output. With format C<b>,
1092111376the first character of the 8-tuple determines the least-significant bit of a
1092211377character; with format C<B>, it determines the most-significant bit of
1092311378a character.
1092411379
1092511380=end original
1092611381
1092711382pack() の入力文字列の先頭から始めて、8 タプル毎に 1 文字の出力に変換されます。
1092811383C<b> フォーマットでは 8 タプルの最初の文字が出力の最下位ビットとなります;
1092911384C<B> フォーマットでは出力の最上位ビットとなります。
1093011385
1093111386=begin original
1093211387
1093311388If the length of the input string is not evenly divisible by 8, the
1093411389remainder is packed as if the input string were padded by null characters
1093511390at the end. Similarly during unpacking, "extra" bits are ignored.
1093611391
1093711392=end original
1093811393
1093911394もし入力文字列の長さが 8 で割り切れない場合、余りの部分は入力文字列の
1094011395最後にヌル文字がパッディングされているものとしてパックされます。
1094111396同様に、unpack 中は「余分な」ビットは無視されます。
1094211397
1094311398=begin original
1094411399
1094511400If the input string is longer than needed, remaining characters are ignored.
1094611401
1094711402=end original
1094811403
1094911404入力文字列が必要な分よりも長い場合、余分な文字は無視されます。
1095011405
1095111406=begin original
1095211407
1095311408A C<*> for the repeat count uses all characters of the input field.
1095411409On unpacking, bits are converted to a string of C<0>s and C<1>s.
1095511410
1095611411=end original
1095711412
1095811413繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
1095911414unpack 時にはビット列は C<0> と C<1> の文字列に変換されます。
1096011415
1096111416=item *
1096211417
1096311418=begin original
1096411419
1096511420The C<h> and C<H> formats pack a string that many nybbles (4-bit groups,
1096611421representable as hexadecimal digits, C<"0".."9"> C<"a".."f">) long.
1096711422
1096811423=end original
1096911424
1097011425C<h> や C<H> は、多ニブル長(16 進文字である C<"0".."9"> C<"a".."f"> で
1097111426表現可能な 4 ビットグループ)のニブル列に pack します。
1097211427
1097311428=begin original
1097411429
1097511430For each such format, L<C<pack>|/pack TEMPLATE,LIST> generates 4 bits of result.
1097611431With non-alphabetical characters, the result is based on the 4 least-significant
1097711432bits of the input character, i.e., on C<ord($char)%16>. In particular,
1097811433characters C<"0"> and C<"1"> generate nybbles 0 and 1, as do bytes
1097911434C<"\000"> and C<"\001">. For characters C<"a".."f"> and C<"A".."F">, the result
1098011435is compatible with the usual hexadecimal digits, so that C<"a"> and
1098111436C<"A"> both generate the nybble C<0xA==10>. Use only these specific hex
1098211437characters with this format.
1098311438
1098411439=end original
1098511440
1098611441このようなフォーマット文字のそれぞれについて、L<C<pack>|/pack TEMPLATE,LIST> は
1098711442結果の 4 ビットを生成します。
1098811443英字でない文字の場合、結果は入力文字の下位 4 ビットを
1098911444基にします(つまり C<ord($char)%16>)。
1099011445特に、文字 C<"0"> と C<"1"> はバイト C<"\000"> と C<"\001"> と同様に
1099111446ニブル 0 と 1 を生成します。
1099211447文字 C<"a".."f"> と C<"A".."F"> の場合は結果は通常の 16 進数と同じ結果に
1099311448なるので、C<"a"> と C<"A"> はどちらも ニブル C<0xa==10> を生成します。
1099411449これらの 16 進文字はこの特定のフォーマットでだけ使ってください。
1099511450
1099611451=begin original
1099711452
1099811453Starting from the beginning of the template to
1099911454L<C<pack>|/pack TEMPLATE,LIST>, each pair
1100011455of characters is converted to 1 character of output. With format C<h>, the
1100111456first character of the pair determines the least-significant nybble of the
1100211457output character; with format C<H>, it determines the most-significant
1100311458nybble.
1100411459
1100511460=end original
1100611461
1100711462L<C<pack>|/pack TEMPLATE,LIST> のテンプレートの先頭から始めて、2 文字毎に
11008114631 文字の出力に変換されます。
1100911464C<h> フォーマットでは 1 文字目が出力の最下位ニブルとなり、
1101011465C<H> フォーマットでは出力の最上位ニブルとなります。
1101111466
1101211467=begin original
1101311468
1101411469If the length of the input string is not even, it behaves as if padded by
1101511470a null character at the end. Similarly, "extra" nybbles are ignored during
1101611471unpacking.
1101711472
1101811473=end original
1101911474
1102011475入力文字列の長さが偶数でない場合、最後にヌル文字でパッディングされて
1102111476いるかのように振る舞います。
1102211477同様に、unpack 中は「余分な」ニブルは無視されます。
1102311478
1102411479=begin original
1102511480
1102611481If the input string is longer than needed, extra characters are ignored.
1102711482
1102811483=end original
1102911484
1103011485入力文字列が必要な分より長い場合、余分な部分は無視されます。
1103111486
1103211487=begin original
1103311488
1103411489A C<*> for the repeat count uses all characters of the input field. For
1103511490L<C<unpack>|/unpack TEMPLATE,EXPR>, nybbles are converted to a string of
1103611491hexadecimal digits.
1103711492
1103811493=end original
1103911494
1104011495繰り返し数として C<*> が指定されると、入力フィールドの全ての文字が使われます。
1104111496L<C<unpack>|/unpack TEMPLATE,EXPR> 時にはニブルは 16 進数の文字列に
1104211497変換されます。
1104311498
1104411499=item *
1104511500
1104611501=begin original
1104711502
1104811503The C<p> format packs a pointer to a null-terminated string. You are
1104911504responsible for ensuring that the string is not a temporary value, as that
1105011505could potentially get deallocated before you got around to using the packed
1105111506result. The C<P> format packs a pointer to a structure of the size indicated
1105211507by the length. A null pointer is created if the corresponding value for
1105311508C<p> or C<P> is L<C<undef>|/undef EXPR>; similarly with
1105411509L<C<unpack>|/unpack TEMPLATE,EXPR>, where a null pointer unpacks into
1105511510L<C<undef>|/undef EXPR>.
1105611511
1105711512=end original
1105811513
1105911514C<p> は、ヌル文字終端文字列へのポインタを pack します。
1106011515文字列が一時的な値でない(つまり pack された結果を使う前に文字列が
1106111516解放されない) ことに責任を持つ必要があります。
1106211517C<P> は、指定した長さの構造体へのポインタを pack します。
1106311518C<p> または C<P> に対応する値が L<C<undef>|/undef EXPR> だった場合、
1106411519ヌルポインタが作成されます; ヌルポインタが L<C<undef>|/undef EXPR> に
1106511520unpack される L<C<unpack>|/unpack TEMPLATE,EXPR> と同様です。
1106611521
1106711522=begin original
1106811523
1106911524If your system has a strange pointer size--meaning a pointer is neither as
1107011525big as an int nor as big as a long--it may not be possible to pack or
1107111526unpack pointers in big- or little-endian byte order. Attempting to do
1107211527so raises an exception.
1107311528
1107411529=end original
1107511530
1107611531システムのポインタが変わったサイズの場合--つまり、int の大きさでも
1107711532long の大きさでもない場合--ポインタをビッグエンディアンやリトルエンディアンの
1107811533バイト順で pack や unpack することはできません。
1107911534そうしようとすると例外が発生します。
1108011535
1108111536=item *
1108211537
1108311538=begin original
1108411539
1108511540The C</> template character allows packing and unpacking of a sequence of
1108611541items where the packed structure contains a packed item count followed by
1108711542the packed items themselves. This is useful when the structure you're
1108811543unpacking has encoded the sizes or repeat counts for some of its fields
1108911544within the structure itself as separate fields.
1109011545
1109111546=end original
1109211547
1109311548C</> テンプレート文字は、アイテムの数の後にアイテムそのものが入っている形の
1109411549アイテム列を pack 及び unpack します。
1109511550これは、unpack したい構造体が、サイズや繰り返し数が構造体自身の中に
1109611551独立したフィールドとしてエンコードされている場合に有効です。
1109711552
1109811553=begin original
1109911554
1110011555For L<C<pack>|/pack TEMPLATE,LIST>, you write
1110111556I<length-item>C</>I<sequence-item>, and the
1110211557I<length-item> describes how the length value is packed. Formats likely
1110311558to be of most use are integer-packing ones like C<n> for Java strings,
1110411559C<w> for ASN.1 or SNMP, and C<N> for Sun XDR.
1110511560
1110611561=end original
1110711562
1110811563L<C<pack>|/pack TEMPLATE,LIST> では I<length-item>C</>I<string-item> の
1110911564形になり、
1111011565I<length-item> は長さの値がどのように pack されているかを指定します。
1111111566もっともよく使われるのは Java 文字列 のための C<n>、ASN.1 や SNMP のための
1111211567C<w>、Sun XDR のための C<N> といった整数型です。
1111311568
1111411569=begin original
1111511570
1111611571For L<C<pack>|/pack TEMPLATE,LIST>, I<sequence-item> may have a repeat
1111711572count, in which case
1111811573the minimum of that and the number of available items is used as the argument
1111911574for I<length-item>. If it has no repeat count or uses a '*', the number
1112011575of available items is used.
1112111576
1112211577=end original
1112311578
1112411579L<C<pack>|/pack TEMPLATE,LIST> では、I<sequence-item> は繰り返し数を
1112511580持つことがあり、その場合はその最小値と利用可能なアイテムの数は
1112611581I<length-item> のための引数として使われます。
1112711582繰り返し数がなかったり、'*' を使うと、利用可能なアイテムの数が使われます。
1112811583
1112911584=begin original
1113011585
1113111586For L<C<unpack>|/unpack TEMPLATE,EXPR>, an internal stack of integer
1113211587arguments unpacked so far is
1113311588used. You write C</>I<sequence-item> and the repeat count is obtained by
1113411589popping off the last element from the stack. The I<sequence-item> must not
1113511590have a repeat count.
1113611591
1113711592=end original
1113811593
1113911594L<C<unpack>|/unpack TEMPLATE,EXPR> では、今まで unpack した数値引数の
1114011595内部スタックが使われます。
1114111596C</>I<sequence-item> と書いて、繰り返し数はスタックから最後の要素を
1114211597取り出すことで得ます。
1114311598I<sequence-item> は繰り返し数を持っていてはいけません。
1114411599
1114511600=begin original
1114611601
1114711602If I<sequence-item> refers to a string type (C<"A">, C<"a">, or C<"Z">),
1114811603the I<length-item> is the string length, not the number of strings. With
1114911604an explicit repeat count for pack, the packed string is adjusted to that
1115011605length. For example:
1115111606
1115211607=end original
1115311608
1115411609I<sequence-item> が文字列型 (C<"A">, C<"a">, C<"Z">) を参照している場合、
1115511610I<length-item> は文字列の数ではなく、文字列の長さです。
1115611611pack で明示的な繰り返し数があると、pack された文字列は与えられた
1115711612長さに調整されます。
1115811613例えば:
1115911614
1116011615 This code: gives this result:
1116111616
1116211617 unpack("W/a", "\004Gurusamy") ("Guru")
1116311618 unpack("a3/A A*", "007 Bond J ") (" Bond", "J")
1116411619 unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".")
1116511620
1116611621 pack("n/a* w/a","hello,","world") "\000\006hello,\005world"
1116711622 pack("a/W2", ord("a") .. ord("z")) "2ab"
1116811623
1116911624=begin original
1117011625
1117111626The I<length-item> is not returned explicitly from
1117211627L<C<unpack>|/unpack TEMPLATE,EXPR>.
1117311628
1117411629=end original
1117511630
1117611631I<length-item> は L<C<unpack>|/unpack TEMPLATE,EXPR> から明示的には
1117711632返されません。
1117811633
1117911634=begin original
1118011635
1118111636Supplying a count to the I<length-item> format letter is only useful with
1118211637C<A>, C<a>, or C<Z>. Packing with a I<length-item> of C<a> or C<Z> may
1118311638introduce C<"\000"> characters, which Perl does not regard as legal in
1118411639numeric strings.
1118511640
1118611641=end original
1118711642
1118811643I<length-item> 文字に繰り返し数をつけるのは、
1118911644文字が C<A>, C<a>, C<Z> でない限りは有用ではありません。
1119011645C<a> や C<Z> を I<length-item> として pack すると C<"\000"> 文字が
1119111646出力されることがあり、Perl はこれを有効な数値文字列として認識しません。
1119211647
1119311648=item *
1119411649
1119511650=begin original
1119611651
1119711652The integer types C<s>, C<S>, C<l>, and C<L> may be
1119811653followed by a C<!> modifier to specify native shorts or
1119911654longs. As shown in the example above, a bare C<l> means
1120011655exactly 32 bits, although the native C<long> as seen by the local C compiler
1120111656may be larger. This is mainly an issue on 64-bit platforms. You can
1120211657see whether using C<!> makes any difference this way:
1120311658
1120411659=end original
1120511660
1120611661C<s>, C<S>, C<l>, C<L> の整数タイプに引き続いて C<!> 修飾子を
1120711662つけることで、ネイティブの short や long を指定できます。
1120811663上述のように、C<l> は正確に 32 ビットですが、ネイティブな
1120911664(ローカルな C コンパイラによる)C<long> はもっと大きいかもしれません。
1121011665これは主に 64 ビットプラットフォームで意味があります。
1121111666C<!> を使うことによって違いがあるかどうかは以下のようにして調べられます:
1121211667
1121311668 printf "format s is %d, s! is %d\n",
1121411669 length pack("s"), length pack("s!");
1121511670
1121611671 printf "format l is %d, l! is %d\n",
1121711672 length pack("l"), length pack("l!");
1121811673
1121911674=begin original
1122011675
1122111676C<i!> and C<I!> are also allowed, but only for completeness' sake:
1122211677they are identical to C<i> and C<I>.
1122311678
1122411679=end original
1122511680
1122611681C<i!> と C<I!> も動作しますが、単に完全性のためだけです;
1122711682これは C<i> 及び C<I> と同じです。
1122811683
1122911684=begin original
1123011685
1123111686The actual sizes (in bytes) of native shorts, ints, longs, and long
1123211687longs on the platform where Perl was built are also available from
1123311688the command line:
1123411689
1123511690=end original
1123611691
1123711692Perl がビルドされたプラットフォームでの short, int, long, long long の
1123811693実際の(バイト数での)サイズはコマンドラインから:
1123911694
1124011695 $ perl -V:{short,int,long{,long}}size
1124111696 shortsize='2';
1124211697 intsize='4';
1124311698 longsize='4';
1124411699 longlongsize='8';
1124511700
1124611701=begin original
1124711702
1124811703or programmatically via the L<C<Config>|Config> module:
1124911704
1125011705=end original
1125111706
1125211707あるいは L<C<Config>|Config> モジュールからプログラムで:
1125311708
1125411709 use Config;
1125511710 print $Config{shortsize}, "\n";
1125611711 print $Config{intsize}, "\n";
1125711712 print $Config{longsize}, "\n";
1125811713 print $Config{longlongsize}, "\n";
1125911714
1126011715=begin original
1126111716
1126211717C<$Config{longlongsize}> is undefined on systems without
1126311718long long support.
1126411719
1126511720=end original
1126611721
1126711722システムが long long に対応していない場合は C<$Config{longlongsize}> は
1126811723未定義値になります。
1126911724
1127011725=item *
1127111726
1127211727=begin original
1127311728
1127411729The integer formats C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, and C<J> are
1127511730inherently non-portable between processors and operating systems because
1127611731they obey native byteorder and endianness. For example, a 4-byte integer
11277117320x12345678 (305419896 decimal) would be ordered natively (arranged in and
1127811733handled by the CPU registers) into bytes as
1127911734
1128011735=end original
1128111736
1128211737整数フォーマット C<s>, C<S>, C<i>, C<I>, C<l>, C<L>, C<j>, C<J> は
1128311738ネイティブなバイト順序とエンディアンに従っているため、
1128411739本質的にプロセッサ間や OS 間で移植性がありません。
1128511740例えば 4 バイトの整数 0x12345678 (10 進数では 305419896) は
1128611741内部では(CPU レジスタによって変換され扱われる形では)
1128711742以下のようなバイト列に並べられます:
1128811743
1128911744 0x12 0x34 0x56 0x78 # big-endian
1129011745 0x78 0x56 0x34 0x12 # little-endian
1129111746
1129211747=begin original
1129311748
1129411749Basically, Intel and VAX CPUs are little-endian, while everybody else,
1129511750including Motorola m68k/88k, PPC, Sparc, HP PA, Power, and Cray, are
1129611751big-endian. Alpha and MIPS can be either: Digital/Compaq uses (well, used)
1129711752them in little-endian mode, but SGI/Cray uses them in big-endian mode.
1129811753
1129911754=end original
1130011755
1130111756基本的に、Intel と VAX の CPU はリトルエンディアンです; 一方、
1130211757Motorola m68k/88k, PPC, Sparc, HP PA, Power, Cray などを含むその他の全ては
1130311758ビッグエンディアンです。
1130411759Alpha と MIPS は両方ともあります: Digital/Compaq はリトルエンディアンモードで
1130511760使っています (えーと、いました) が、SGI/Cray はビッグエンディアンモードで
1130611761使っています。
1130711762
1130811763=begin original
1130911764
1131011765The names I<big-endian> and I<little-endian> are comic references to the
1131111766egg-eating habits of the little-endian Lilliputians and the big-endian
1131211767Blefuscudians from the classic Jonathan Swift satire, I<Gulliver's Travels>.
1131311768This entered computer lingo via the paper "On Holy Wars and a Plea for
1131411769Peace" by Danny Cohen, USC/ISI IEN 137, April 1, 1980.
1131511770
1131611771=end original
1131711772
1131811773I<ビッグエンディアン> と I<リトルエンディアン> の名前は、
1131911774ジョナサン=スウィフトによる風刺小説の古典 I<ガリバー旅行記> での、卵を
1132011775小さい方からむくリリパット国と大きい方からむくブレフスキュ国から
1132111776取られています。
1132211777"On Holy Wars and a Plea for Peace" by Danny Cohen, USC/ISI IEN 137,
1132311778April 1, 1980 の文書からコンピュータ用語として取り入れられました。
1132411779
1132511780=begin original
1132611781
1132711782Some systems may have even weirder byte orders such as
1132811783
1132911784=end original
1133011785
1133111786以下のような、さらに変わったバイト順序を持つシステムもあるかもしれません:
1133211787
1133311788 0x56 0x78 0x12 0x34
1133411789 0x34 0x12 0x78 0x56
1133511790
1133611791=begin original
1133711792
1133811793These are called mid-endian, middle-endian, mixed-endian, or just weird.
1133911794
1134011795=end original
1134111796
1134211797これらは mid-endian, middle-endian, mixed-endian あるいは単におかしなものと
1134311798呼ばれます。
1134411799
1134511800=begin original
1134611801
1134711802You can determine your system endianness with this incantation:
1134811803
1134911804=end original
1135011805
1135111806システムの設定は以下のようにして調べられます:
1135211807
1135311808 printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
1135411809
1135511810=begin original
1135611811
1135711812The byteorder on the platform where Perl was built is also available
1135811813via L<Config>:
1135911814
1136011815=end original
1136111816
1136211817Perl がビルドされたプラットフォームでのバイト順序は
1136311818L<Config> 経由か:
1136411819
1136511820 use Config;
1136611821 print "$Config{byteorder}\n";
1136711822
1136811823=begin original
1136911824
1137011825or from the command line:
1137111826
1137211827=end original
1137311828
1137411829あるいはコマンドラインで:
1137511830
1137611831 $ perl -V:byteorder
1137711832
1137811833=begin original
1137911834
1138011835Byteorders C<"1234"> and C<"12345678"> are little-endian; C<"4321">
1138111836and C<"87654321"> are big-endian. Systems with multiarchitecture binaries
1138211837will have C<"ffff">, signifying that static information doesn't work,
1138311838one must use runtime probing.
1138411839
1138511840=end original
1138611841
1138711842C<"1234"> と C<"12345678"> はリトルエンディアンです;
1138811843C<"4321"> と C<"87654321"> はビッグエンディアンです。
1138911844マルチアーキテクチャバイナリを持つシステムは
1139011845C<"ffff"> となります; これは静的な情報は動作せず、実行時調査を使う必要が
1139111846あることを示します。
1139211847
1139311848=begin original
1139411849
1139511850For portably packed integers, either use the formats C<n>, C<N>, C<v>,
1139611851and C<V> or else use the C<< > >> and C<< < >> modifiers described
1139711852immediately below. See also L<perlport>.
1139811853
1139911854=end original
1140011855
1140111856移植性のあるパック化された整数がほしい場合は、
1140211857C<n>, C<N>, C<v>, C<V> フォーマットを使うか、
1140311858直後で説明する C<< > >> と C<< < >> の修飾子が使えます。
1140411859L<perlport> も参照してください。
1140511860
1140611861=item *
1140711862
1140811863=begin original
1140911864
1141011865Also floating point numbers have endianness. Usually (but not always)
1141111866this agrees with the integer endianness. Even though most platforms
1141211867these days use the IEEE 754 binary format, there are differences,
1141311868especially if the long doubles are involved. You can see the
1141411869C<Config> variables C<doublekind> and C<longdblkind> (also C<doublesize>,
1141511870C<longdblsize>): the "kind" values are enums, unlike C<byteorder>.
1141611871
1141711872=end original
1141811873
1141911874また、浮動小数点数にもエンディアンがあります。
1142011875通常は(但し常にではありません)これは整数のエンディアンと同じです。
1142111876最近のほとんどのプラットフォームが IEEE 754 バイナリ形式を使っているにも
1142211877関わらず、(特に long double 関連で) 相違点があります。
1142311878C<Config> 変数 C<doublekind> と C<longdblkind> (および C<doublesize>,
1142411879C<longdblsize>) を参照できます: "kind" 値は C<byteorder> と異なり、
1142511880順序値です。
1142611881
1142711882=begin original
1142811883
1142911884Portability-wise the best option is probably to keep to the IEEE 754
114301188564-bit doubles, and of agreed-upon endianness. Another possibility
1143111886is the C<"%a">) format of L<C<printf>|/printf FILEHANDLE FORMAT, LIST>.
1143211887
1143311888=end original
1143411889
1143511890移植性を考慮した最良の選択肢はおそらく、IEEE 754 64-bit double と同意した
1143611891エンディアンを維持することです。
1143711892もう一つの可能性は L<C<printf>|/printf FILEHANDLE FORMAT, LIST> の
1143811893C<"%a"> 型式です。
1143911894
1144011895=item *
1144111896
1144211897=begin original
1144311898
1144411899Starting with Perl 5.10.0, integer and floating-point formats, along with
1144511900the C<p> and C<P> formats and C<()> groups, may all be followed by the
1144611901C<< > >> or C<< < >> endianness modifiers to respectively enforce big-
1144711902or little-endian byte-order. These modifiers are especially useful
1144811903given how C<n>, C<N>, C<v>, and C<V> don't cover signed integers,
114491190464-bit integers, or floating-point values.
1145011905
1145111906=end original
1145211907
1145311908Perl 5.10.0 から、C<p> と C<P> フォーマットや C<()> グループと同様、
1145411909全ての整数と浮動小数点数のフォーマットは、C<< > >> や C<< < >> の
1145511910エンディアン修飾子をつけることで、それぞれ
1145611911ビッグエンディアンとリトルエンディアンに強制させることができます。
1145711912C<n>, C<N>, C<v>, C<V> は符号付き整数、64 ビット整数、浮動小数点数に
1145811913対応していないので、これは特に有用です。
1145911914
1146011915=begin original
1146111916
1146211917Here are some concerns to keep in mind when using an endianness modifier:
1146311918
1146411919=end original
1146511920
1146611921エンディアン修飾子を使うときに心に留めておくべきことを記します:
1146711922
1146811923=over
1146911924
1147011925=item *
1147111926
1147211927=begin original
1147311928
1147411929Exchanging signed integers between different platforms works only
1147511930when all platforms store them in the same format. Most platforms store
1147611931signed integers in two's-complement notation, so usually this is not an issue.
1147711932
1147811933=end original
1147911934
1148011935異なったプラットフォームで符号付き整数を交換することは、全ての
1148111936プラットフォームで同じフォーマットで保存されている場合にのみうまくいきます。
1148211937ほとんどのプラットフォームでは符号付き整数は 2 の補数記法で保存するので、
1148311938普通はこれは問題になりません。
1148411939
1148511940=item *
1148611941
1148711942=begin original
1148811943
1148911944The C<< > >> or C<< < >> modifiers can only be used on floating-point
1149011945formats on big- or little-endian machines. Otherwise, attempting to
1149111946use them raises an exception.
1149211947
1149311948=end original
1149411949
1149511950C<< > >> や C<< < >> の修飾子はビッグエンディアンやリトルエンディアンの
1149611951マシンでの浮動小数点フォーマットでのみ使えます。
1149711952それ以外では、そのようなことをすると例外が発生します。
1149811953
1149911954=item *
1150011955
1150111956=begin original
1150211957
1150311958Forcing big- or little-endian byte-order on floating-point values for
1150411959data exchange can work only if all platforms use the same
1150511960binary representation such as IEEE floating-point. Even if all
1150611961platforms are using IEEE, there may still be subtle differences. Being able
1150711962to use C<< > >> or C<< < >> on floating-point values can be useful,
1150811963but also dangerous if you don't know exactly what you're doing.
1150911964It is not a general way to portably store floating-point values.
1151011965
1151111966=end original
1151211967
1151311968データ交換のために浮動小数点数のバイト順をビッグエンディアンかリトル
1151411969エンディアンに強制することは、全てのプラットフォームが
1151511970IEEE 浮動小数点フォーマットのような同じバイナリ表現の場合にのみ
1151611971うまくいきます。
1151711972たとえ全てのプラットフォームが IEEE を使っていても、そこには微妙な違いが
1151811973あるかもしれません。
1151911974浮動小数点数に C<< > >> や C<< < >> が使えることは便利な場合がありますが、
1152011975もし自分が何をしているかを正確に理解していなければ、危険です。
1152111976移植性のある浮動小数点数の保存のための一般的な方法はありません。
1152211977
1152311978=item *
1152411979
1152511980=begin original
1152611981
1152711982When using C<< > >> or C<< < >> on a C<()> group, this affects
1152811983all types inside the group that accept byte-order modifiers,
1152911984including all subgroups. It is silently ignored for all other
1153011985types. You are not allowed to override the byte-order within a group
1153111986that already has a byte-order modifier suffix.
1153211987
1153311988=end original
1153411989
1153511990C<()> グループで C<< > >> や C<< < >> を使うと、これは、副グループを
1153611991含む全ての型のうち、バイト順修飾子を受け入れる全てのものに影響与えます。
1153711992その他の型については沈黙のうちに無視されます。
1153811993既にバイト順接尾辞を持っているグループ内のバイト順を上書きすることは
1153911994できません。
1154011995
1154111996=back
1154211997
1154311998=item *
1154411999
1154512000=begin original
1154612001
1154712002Real numbers (floats and doubles) are in native machine format only.
1154812003Due to the multiplicity of floating-point formats and the lack of a
1154912004standard "network" representation for them, no facility for interchange has been
1155012005made. This means that packed floating-point data written on one machine
1155112006may not be readable on another, even if both use IEEE floating-point
1155212007arithmetic (because the endianness of the memory representation is not part
1155312008of the IEEE spec). See also L<perlport>.
1155412009
1155512010=end original
1155612011
1155712012実数 (float と double) は、機種依存のフォーマットしかありません。
1155812013いろんな浮動小数点数のフォーマットが在り、標準的な "network" 表現といったものが
1155912014ないため、データ交換のための機能は用意してありません。
1156012015つまり、あるマシンで pack した浮動小数点数は、別のマシンでは
1156112016読めないかもしれないということです; たとえ双方で IEEE フォーマットの
1156212017浮動小数点数演算を行なっていてもです (IEEE の仕様では、メモリ表現上の
1156312018バイト順序までは、規定されていないからです)。
1156412019L<perlport> も参照してください。
1156512020
1156612021=begin original
1156712022
1156812023If you know I<exactly> what you're doing, you can use the C<< > >> or C<< < >>
1156912024modifiers to force big- or little-endian byte-order on floating-point values.
1157012025
1157112026=end original
1157212027
1157312028もし何をしようとしているのかを I<正確に> 理解しているなら、浮動小数点数の
1157412029バイト順をビッグエンディアンやリトルエンディアンに強制するために、
1157512030C<< > >> と C<< < >> の修飾子が使えます。
1157612031
1157712032=begin original
1157812033
1157912034Because Perl uses doubles (or long doubles, if configured) internally for
1158012035all numeric calculation, converting from double into float and thence
1158112036to double again loses precision, so C<unpack("f", pack("f", $foo)>)
1158212037will not in general equal $foo.
1158312038
1158412039=end original
1158512040
1158612041Perl では、すべての数値演算のために、内部的に double (または設定によっては
1158712042long double) を使用しているので、double から float へ変換し、それから再び
1158812043double に戻すと精度が落ちることになり、C<unpack("f", pack("f", $foo)>) は、
1158912044一般には $foo と同じではありません。
1159012045
1159112046=item *
1159212047
1159312048=begin original
1159412049
1159512050Pack and unpack can operate in two modes: character mode (C<C0> mode) where
1159612051the packed string is processed per character, and UTF-8 byte mode (C<U0> mode)
1159712052where the packed string is processed in its UTF-8-encoded Unicode form on
1159812053a byte-by-byte basis. Character mode is the default
1159912054unless the format string starts with C<U>. You
1160012055can always switch mode mid-format with an explicit
1160112056C<C0> or C<U0> in the format. This mode remains in effect until the next
1160212057mode change, or until the end of the C<()> group it (directly) applies to.
1160312058
1160412059=end original
1160512060
1160612061pack と unpack は二つのモードで操作します: pack された文字列を文字単位で
1160712062処理する文字モード (C<C0> モード) と、pack された文字列を、バイト毎に、
1160812063その UTF-8 エンコードされた形式で処理するUTF-8 モード (C<U0> モード) です。
1160912064文字モードはフォーマット文字列が C<U> で始まっていない限りはデフォルトです。
1161012065モードはフォーマット中に明示的に C<C0> または C<U0> と書くことでいつでも
1161112066切り替えられます。
1161212067モードは次のモードに切り替えられるか、(直接)適用された C<()> グループが
1161312068終了するまで有効です。
1161412069
1161512070=begin original
1161612071
1161712072Using C<C0> to get Unicode characters while using C<U0> to get I<non>-Unicode
1161812073bytes is not necessarily obvious. Probably only the first of these
1161912074is what you want:
1162012075
1162112076=end original
1162212077
1162312078Unicode 文字を取得するのに C<C0> を使い、I<非> Unicode バイトを取得するのに
1162412079C<U0> を使うというのは必ずしも明白ではありません。
1162512080おそらく、これらのうち最初のものだけが望みのものでしょう:
1162612081
1162712082 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1162812083 perl -CS -ne 'printf "%v04X\n", $_ for unpack("C0A*", $_)'
1162912084 03B1.03C9
1163012085 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1163112086 perl -CS -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
1163212087 CE.B1.CF.89
1163312088 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1163412089 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("C0A*", $_)'
1163512090 CE.B1.CF.89
1163612091 $ perl -CS -E 'say "\x{3B1}\x{3C9}"' |
1163712092 perl -C0 -ne 'printf "%v02X\n", $_ for unpack("U0A*", $_)'
1163812093 C3.8E.C2.B1.C3.8F.C2.89
1163912094
1164012095=begin original
1164112096
1164212097Those examples also illustrate that you should not try to use
1164312098L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> as a
1164412099substitute for the L<Encode> module.
1164512100
1164612101=end original
1164712102
1164812103これらの例は、L<C<pack>|/pack TEMPLATE,LIST>/
1164912104L<C<unpack>|/unpack TEMPLATE,EXPR> を L<Encode> モジュールの代わりとして
1165012105使おうとするべきではないということも示しています。
1165112106
1165212107=item *
1165312108
1165412109=begin original
1165512110
1165612111You must yourself do any alignment or padding by inserting, for example,
1165712112enough C<"x">es while packing. There is no way for
1165812113L<C<pack>|/pack TEMPLATE,LIST> and L<C<unpack>|/unpack TEMPLATE,EXPR>
1165912114to know where characters are going to or coming from, so they
1166012115handle their output and input as flat sequences of characters.
1166112116
1166212117=end original
1166312118
1166412119pack するときに、例えば十分な数の C<"x"> を挿入することによって
1166512120アライメントやパッディングを行うのは全て自分でしなければなりません。
1166612121L<C<pack>|/pack TEMPLATE,LIST> や L<C<unpack>|/unpack TEMPLATE,EXPR> は、
1166712122文字列がどこへ行くかやどこから来たかを
1166812123知る方法はないので、出力と入力をフラットな文字列として扱います。
1166912124
1167012125=item *
1167112126
1167212127=begin original
1167312128
1167412129A C<()> group is a sub-TEMPLATE enclosed in parentheses. A group may
1167512130take a repeat count either as postfix, or for
1167612131L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</>
1167712132template character. Within each repetition of a group, positioning with
1167812133C<@> starts over at 0. Therefore, the result of
1167912134
1168012135=end original
1168112136
1168212137C<()> のグループはかっこで囲われた副テンプレートです。
1168312138グループは繰り返し数を取ることができます; 接尾辞によるか、
1168412139L<C<unpack>|/unpack TEMPLATE,EXPR> の場合は C</> テンプレート文字によります。
1168512140グループの繰り返し毎に、C<@> の位置は 0 になります。
1168612141従って、以下の結果は:
1168712142
1168812143 pack("@1A((@2A)@3A)", qw[X Y Z])
1168912144
1169012145=begin original
1169112146
1169212147is the string C<"\0X\0\0YZ">.
1169312148
1169412149=end original
1169512150
1169612151文字列 C<"\0X\0\0YZ"> です。
1169712152
1169812153=item *
1169912154
1170012155=begin original
1170112156
1170212157C<x> and C<X> accept the C<!> modifier to act as alignment commands: they
1170312158jump forward or back to the closest position aligned at a multiple of C<count>
1170412159characters. For example, to L<C<pack>|/pack TEMPLATE,LIST> or
1170512160L<C<unpack>|/unpack TEMPLATE,EXPR> a C structure like
1170612161
1170712162=end original
1170812163
1170912164C<x> と C<X> にはアライメントコマンドとして C<!> 修飾子を付けることができます:
1171012165これは C<count> 文字の倍数のアライメントとなる、もっとも近い位置に移動します。
1171112166例えば、以下のような C 構造体を L<C<pack>|/pack TEMPLATE,LIST> または
1171212167L<C<unpack>|/unpack TEMPLATE,EXPR> するには
1171312168
1171412169 struct {
1171512170 char c; /* one signed, 8-bit character */
1171612171 double d;
1171712172 char cc[2];
1171812173 }
1171912174
1172012175=begin original
1172112176
1172212177one may need to use the template C<c x![d] d c[2]>. This assumes that
1172312178doubles must be aligned to the size of double.
1172412179
1172512180=end original
1172612181
1172712182C<W x![d] d W[2]> というテンプレートを使う必要があるかもしれません。
1172812183これは double が double のサイズでアライメントされていることを
1172912184仮定しています。
1173012185
1173112186=begin original
1173212187
1173312188For alignment commands, a C<count> of 0 is equivalent to a C<count> of 1;
1173412189both are no-ops.
1173512190
1173612191=end original
1173712192
1173812193アライメントコマンドに対しては、C<count> に 0 を指定するのは
1173912194C<count> に 1 を指定するのと等価です; どちらも何もしません。
1174012195
1174112196=item *
1174212197
1174312198=begin original
1174412199
1174512200C<n>, C<N>, C<v> and C<V> accept the C<!> modifier to
1174612201represent signed 16-/32-bit integers in big-/little-endian order.
1174712202This is portable only when all platforms sharing packed data use the
1174812203same binary representation for signed integers; for example, when all
1174912204platforms use two's-complement representation.
1175012205
1175112206=end original
1175212207
1175312208C<n>, C<N>, C<v>, C<V> はビッグ/リトルエンディアンの順序で符号付き 16 または
117541220932 ビット整数で表現するための C<!> 修飾子を受け入れます。
1175512210これは pack されたデータを共有する全てのプラットフォームが
1175612211符号付き整数について同じバイナリ表現を使う場合にのみ移植性があります;
1175712212例えば、全てのプラットフォームで 2 の補数表現を使う場合です。
1175812213
1175912214=item *
1176012215
1176112216=begin original
1176212217
1176312218Comments can be embedded in a TEMPLATE using C<#> through the end of line.
1176412219White space can separate pack codes from each other, but modifiers and
1176512220repeat counts must follow immediately. Breaking complex templates into
1176612221individual line-by-line components, suitably annotated, can do as much to
1176712222improve legibility and maintainability of pack/unpack formats as C</x> can
1176812223for complicated pattern matches.
1176912224
1177012225=end original
1177112226
1177212227TEMPLATE の中の C<#> から行末まではコメントです。
1177312228空白は pack コードをそれぞれ分けるために使えますが、修飾子と
1177412229繰り返し数は直後に置かなければなりません。
1177512230複雑なテンプレートを個々の行単位の要素に分解して適切に注釈をつけると、
1177612231複雑なパターンマッチングに対する C</x> と同じぐらい、pack/unpack
1177712232フォーマットの読みやすさと保守性が向上します。
1177812233
1177912234=item *
1178012235
1178112236=begin original
1178212237
1178312238If TEMPLATE requires more arguments than L<C<pack>|/pack TEMPLATE,LIST>
1178412239is given, L<C<pack>|/pack TEMPLATE,LIST>
1178512240assumes additional C<""> arguments. If TEMPLATE requires fewer arguments
1178612241than given, extra arguments are ignored.
1178712242
1178812243=end original
1178912244
1179012245TEMPLATE が要求する引数の数が L<C<pack>|/pack TEMPLATE,LIST> が実際に
1179112246与えている数より多い場合、
1179212247L<C<pack>|/pack TEMPLATE,LIST> は追加の C<""> 引数があるものと仮定します。
1179312248TEMPLATE が要求する引数の数の方が少ない場合、余分の引数は無視されます。
1179412249
1179512250=item *
1179612251
1179712252=begin original
1179812253
1179912254Attempting to pack the special floating point values C<Inf> and C<NaN>
1180012255(infinity, also in negative, and not-a-number) into packed integer values
1180112256(like C<"L">) is a fatal error. The reason for this is that there simply
1180212257isn't any sensible mapping for these special values into integers.
1180312258
1180412259=end original
1180512260
1180612261特殊浮動小数点値 C<Inf> と C<NaN>
1180712262((負を含む)無限と非数) を (C<"L"> のような) 整数値に pack しようとすると
1180812263致命的エラーとなります。
1180912264この理由は、単に特殊値を整数に割り当てられないからです。
1181012265
1181112266=back
1181212267
1181312268=begin original
1181412269
1181512270Examples:
1181612271
1181712272=end original
1181812273
1181912274例:
1182012275
1182112276 $foo = pack("WWWW",65,66,67,68);
1182212277 # foo eq "ABCD"
1182312278 $foo = pack("W4",65,66,67,68);
1182412279 # same thing
1182512280 $foo = pack("W4",0x24b6,0x24b7,0x24b8,0x24b9);
1182612281 # same thing with Unicode circled letters.
1182712282 $foo = pack("U4",0x24b6,0x24b7,0x24b8,0x24b9);
1182812283 # same thing with Unicode circled letters. You don't get the
1182912284 # UTF-8 bytes because the U at the start of the format caused
1183012285 # a switch to U0-mode, so the UTF-8 bytes get joined into
1183112286 # characters
1183212287 $foo = pack("C0U4",0x24b6,0x24b7,0x24b8,0x24b9);
1183312288 # foo eq "\xe2\x92\xb6\xe2\x92\xb7\xe2\x92\xb8\xe2\x92\xb9"
1183412289 # This is the UTF-8 encoding of the string in the
1183512290 # previous example
1183612291
1183712292 $foo = pack("ccxxcc",65,66,67,68);
1183812293 # foo eq "AB\0\0CD"
1183912294
1184012295 # NOTE: The examples above featuring "W" and "c" are true
1184112296 # only on ASCII and ASCII-derived systems such as ISO Latin 1
1184212297 # and UTF-8. On EBCDIC systems, the first example would be
1184312298 # $foo = pack("WWWW",193,194,195,196);
1184412299
1184512300 $foo = pack("s2",1,2);
1184612301 # "\001\000\002\000" on little-endian
1184712302 # "\000\001\000\002" on big-endian
1184812303
1184912304 $foo = pack("a4","abcd","x","y","z");
1185012305 # "abcd"
1185112306
1185212307 $foo = pack("aaaa","abcd","x","y","z");
1185312308 # "axyz"
1185412309
1185512310 $foo = pack("a14","abcdefg");
1185612311 # "abcdefg\0\0\0\0\0\0\0"
1185712312
1185812313 $foo = pack("i9pl", gmtime);
1185912314 # a real struct tm (on my system anyway)
1186012315
1186112316 $utmp_template = "Z8 Z8 Z16 L";
1186212317 $utmp = pack($utmp_template, @utmp1);
1186312318 # a struct utmp (BSDish)
1186412319
1186512320 @utmp2 = unpack($utmp_template, $utmp);
1186612321 # "@utmp1" eq "@utmp2"
1186712322
1186812323 sub bintodec {
1186912324 unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
1187012325 }
1187112326
1187212327 $foo = pack('sx2l', 12, 34);
1187312328 # short 12, two zero bytes padding, long 34
1187412329 $bar = pack('s@4l', 12, 34);
1187512330 # short 12, zero fill to position 4, long 34
1187612331 # $foo eq $bar
1187712332 $baz = pack('s.l', 12, 4, 34);
1187812333 # short 12, zero fill to position 4, long 34
1187912334
1188012335 $foo = pack('nN', 42, 4711);
1188112336 # pack big-endian 16- and 32-bit unsigned integers
1188212337 $foo = pack('S>L>', 42, 4711);
1188312338 # exactly the same
1188412339 $foo = pack('s<l<', -42, 4711);
1188512340 # pack little-endian 16- and 32-bit signed integers
1188612341 $foo = pack('(sl)<', -42, 4711);
1188712342 # exactly the same
1188812343
1188912344=begin original
1189012345
1189112346The same template may generally also be used in
1189212347L<C<unpack>|/unpack TEMPLATE,EXPR>.
1189312348
1189412349=end original
1189512350
1189612351一般的には、同じテンプレートが L<C<unpack>|/unpack TEMPLATE,EXPR> でも
1189712352使用できます。
1189812353
1189912354=item package NAMESPACE
1190012355
1190112356=item package NAMESPACE VERSION
1190212357X<package> X<module> X<namespace> X<version>
1190312358
1190412359=item package NAMESPACE BLOCK
1190512360
1190612361=item package NAMESPACE VERSION BLOCK
1190712362X<package> X<module> X<namespace> X<version>
1190812363
1190912364=for Pod::Functions declare a separate global namespace
1191012365
1191112366=begin original
1191212367
1191312368Declares the BLOCK or the rest of the compilation unit as being in the
1191412369given namespace. The scope of the package declaration is either the
1191512370supplied code BLOCK or, in the absence of a BLOCK, from the declaration
1191612371itself through the end of current scope (the enclosing block, file, or
1191712372L<C<eval>|/eval EXPR>). That is, the forms without a BLOCK are
1191812373operative through the end of the current scope, just like the
1191912374L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>, and
1192012375L<C<our>|/our VARLIST> operators. All unqualified dynamic identifiers
1192112376in this scope will be in the given namespace, except where overridden by
1192212377another L<C<package>|/package NAMESPACE> declaration or
1192312378when they're one of the special identifiers that qualify into C<main::>,
1192412379like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables.
1192512380
1192612381=end original
1192712382
1192812383BLOCK や残りのコンパイル単位を与えられた名前空間として宣言します。
1192912384パッケージ宣言のスコープは BLOCK か、BLOCK がないばあいは宣言自身から
1193012385現在のスコープの末尾 (閉じたブロック、ファイル、L<C<eval>|/eval EXPR>) です。
1193112386つまり、BLOCK なしの形式は、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
1193212387L<C<our>|/our VARLIST> 演算子と同様に現在のスコープの末尾にまで作用します。
1193312388このスコープ内の、全ての完全修飾されていない動的識別子は、他の
1193412389L<C<package>|/package NAMESPACE> 宣言によって上書きされるか、
1193512390C<STDOUT>, C<ARGV>, C<ENV> や句読点変数のように C<main::> に
1193612391割り当てられる特殊変数でない限り、指定された
1193712392名前空間になります。
1193812393
1193912394=begin original
1194012395
1194112396A package statement affects dynamic variables only, including those
1194212397you've used L<C<local>|/local EXPR> on, but I<not> lexically-scoped
1194312398variables, which are created with L<C<my>|/my VARLIST>,
1194412399L<C<state>|/state VARLIST>, or L<C<our>|/our VARLIST>. Typically it
1194512400would be the first declaration in a file included by
1194612401L<C<require>|/require VERSION> or L<C<use>|/use Module VERSION LIST>.
1194712402You can switch into a
1194812403package in more than one place, since this only determines which default
1194912404symbol table the compiler uses for the rest of that block. You can refer to
1195012405identifiers in other packages than the current one by prefixing the identifier
1195112406with the package name and a double colon, as in C<$SomePack::var>
1195212407or C<ThatPack::INPUT_HANDLE>. If package name is omitted, the C<main>
1195312408package as assumed. That is, C<$::sail> is equivalent to
1195412409C<$main::sail> (as well as to C<$main'sail>, still seen in ancient
1195512410code, mostly from Perl 4).
1195612411
1195712412=end original
1195812413
1195912414package 文は動的変数にのみ影響します(L<C<local>|/local EXPR> で使ったものも
1196012415含みます)が、L<C<my>|/my VARLIST>, L<C<state>|/state VARLIST>,
1196112416L<C<our>|/our VARLIST> のいずれかで作成された
1196212417レキシカルなスコープの変数には I<影響しません>。
1196312418典型的にはこれは L<C<require>|/require VERSION> や
1196412419L<C<use>|/use Module VERSION LIST> 演算子でインクルードされるファイルの
1196512420最初に宣言されます。
1196612421パッケージを複数の場所で切り替えることができます;
1196712422なぜならこれは単にコンパイラがこのブロックの残りに対してどの
1196812423シンボルテーブルを使うかにのみ影響するからです。
1196912424他のパッケージの識別子は、C<$SomePack::var> や
1197012425C<ThatPack::INPUT_HANDLE> のように、識別子にパッケージ名と
1197112426コロン二つをつけることで参照できます。
1197212427パッケージ名が省略された場合、C<main> パッケージが仮定されます。
1197312428つまり、C<$::sail> は C<$main::sail> と等価です(ほとんどは Perl 4 からの、
1197412429古いコードでは C<$main'sail> もまだ見られます)。
1197512430
1197612431=begin original
1197712432
1197812433If VERSION is provided, L<C<package>|/package NAMESPACE> sets the
1197912434C<$VERSION> variable in the given
1198012435namespace to a L<version> object with the VERSION provided. VERSION must be a
1198112436"strict" style version number as defined by the L<version> module: a positive
1198212437decimal number (integer or decimal-fraction) without exponentiation or else a
1198312438dotted-decimal v-string with a leading 'v' character and at least three
1198412439components. You should set C<$VERSION> only once per package.
1198512440
1198612441=end original
1198712442
1198812443VERSION が指定されると、L<C<package>|/package NAMESPACE> は与えられた
1198912444名前空間の C<$VERSION> 変数に、
1199012445指定された VERSION の L<version> オブジェクトをセットします。
1199112446VERSION は L<version> で定義されている「厳密な」形式のバージョン番号で
1199212447なければなりません: 指数のない正の 10 進数 (整数か 10 進小数) か、
1199312448さもなければ先頭に 'v' の文字が付いて、少なくとも三つの部分から
1199412449構成されるドット付き 10 進v-文字列です。
1199512450C<$VERSION> はパッケージ毎に 1 回だけセットするべきです。
1199612451
1199712452=begin original
1199812453
1199912454See L<perlmod/"Packages"> for more information about packages, modules,
1200012455and classes. See L<perlsub> for other scoping issues.
1200112456
1200212457=end original
1200312458
1200412459パッケージ、モジュール、クラスに関するさらなる情報については
1200512460L<perlmod/"Packages"> を参照してください。
1200612461その他のスコープに関する話題については L<perlsub> を参照してください。
1200712462
1200812463=item __PACKAGE__
1200912464X<__PACKAGE__>
1201012465
1201112466=for Pod::Functions +5.004 the current package
1201212467
1201312468=begin original
1201412469
1201512470A special token that returns the name of the package in which it occurs.
1201612471
1201712472=end original
1201812473
1201912474これが書いてあるパッケージの名前を返す特殊トークン。
1202012475
1202112476=item pipe READHANDLE,WRITEHANDLE
1202212477X<pipe>
1202312478
1202412479=for Pod::Functions open a pair of connected filehandles
1202512480
1202612481=begin original
1202712482
1202812483Opens a pair of connected pipes like the corresponding system call.
1202912484Note that if you set up a loop of piped processes, deadlock can occur
1203012485unless you are very careful. In addition, note that Perl's pipes use
1203112486IO buffering, so you may need to set L<C<$E<verbar>>|perlvar/$E<verbar>>
1203212487to flush your WRITEHANDLE after each command, depending on the
1203312488application.
1203412489
1203512490=end original
1203612491
1203712492対応するシステムコールと同じように、接続されたパイプのペアを開きます。
1203812493パイプでプロセスをループにするときには、よほど気を付けないと、
1203912494デッドロックが起こり得ます。
1204012495さらに、Perl のパイプでは、IO のバッファリングを使ので、
1204112496アプリケーションによっては、コマンドごとに WRITEHANDLE を
1204212497フラッシュするように、L<C<$E<verbar>>|perlvar/$E<verbar>> を設定することが
1204312498必要になるかもしれません。
1204412499
1204512500=begin original
1204612501
1204712502Returns true on success.
1204812503
1204912504=end original
1205012505
1205112506成功時には真を返します。
1205212507
1205312508=begin original
1205412509
1205512510See L<IPC::Open2>, L<IPC::Open3>, and
1205612511L<perlipc/"Bidirectional Communication with Another Process">
1205712512for examples of such things.
1205812513
1205912514=end original
1206012515
1206112516これらに関する例については、L<IPC::Open2>, L<IPC::Open3>,
1206212517L<perlipc/"Bidirectional Communication with Another Process"> を
1206312518参照してください。
1206412519
1206512520=begin original
1206612521
1206712522On systems that support a close-on-exec flag on files, that flag is set
1206812523on all newly opened file descriptors whose
1206912524L<C<fileno>|/fileno FILEHANDLE>s are I<higher> than the current value of
1207012525L<C<$^F>|perlvar/$^F> (by default 2 for C<STDERR>). See L<perlvar/$^F>.
1207112526
1207212527=end original
1207312528
1207412529ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1207512530新しくオープンされたファイル記述子のうち、
1207612531L<C<fileno>|/fileno FILEHANDLE> が現在の L<C<$^F>|perlvar/$^F> の値
1207712532(デフォルトでは C<STDERR> の 2)
1207812533I<よりも大きい> ものに対してフラグがセットされます。
1207912534L<perlvar/$^F> を参照してください。
1208012535
1208112536=item pop ARRAY
1208212537X<pop> X<stack>
1208312538
1208412539=item pop
1208512540
1208612541=for Pod::Functions remove the last element from an array and return it
1208712542
1208812543=begin original
1208912544
1209012545Pops and returns the last value of the array, shortening the array by
1209112546one element.
1209212547
1209312548=end original
1209412549
1209512550配列の最後の値をポップして返し、配列の大きさを 1 だけ小さくします。
1209612551
1209712552=begin original
1209812553
1209912554Returns the undefined value if the array is empty, although this may
1210012555also happen at other times. If ARRAY is omitted, pops the
1210112556L<C<@ARGV>|perlvar/@ARGV> array in the main program, but the
1210212557L<C<@_>|perlvar/@_> array in subroutines, just like
1210312558L<C<shift>|/shift ARRAY>.
1210412559
1210512560=end original
1210612561
1210712562指定された配列に要素がなければ未定義値が返されますが、
1210812563しかしこれは他の場合にも起こり得ます。
1210912564ARRAY が省略されると、L<C<shift>|/shift ARRAY> と同様に、メインプログラムでは
1211012565L<C<@ARGV>|perlvar/@ARGV> が使われますが、
1211112566サブルーチンでは L<C<@_>|perlvar/@_> が使われます。
1211212567
1211312568=begin original
1211412569
1211512570Starting with Perl 5.14, an experimental feature allowed
1211612571L<C<pop>|/pop ARRAY> to take a
1211712572scalar expression. This experiment has been deemed unsuccessful, and was
1211812573removed as of Perl 5.24.
1211912574
1212012575=end original
1212112576
1212212577Perl 5.14 から、L<C<pop>|/pop ARRAY> がスカラ式を取ることが出来るという
1212312578実験的機能がありました。
1212412579この実験は失敗と見なされ、Perl 5.24 で削除されました。
1212512580
1212612581=item pos SCALAR
1212712582X<pos> X<match, position>
1212812583
1212912584=item pos
1213012585
1213112586=for Pod::Functions find or set the offset for the last/next m//g search
1213212587
1213312588=begin original
1213412589
1213512590Returns the offset of where the last C<m//g> search left off for the
1213612591variable in question (L<C<$_>|perlvar/$_> is used when the variable is not
1213712592specified). This offset is in characters unless the
1213812593(no-longer-recommended) L<C<use bytes>|bytes> pragma is in effect, in
1213912594which case the offset is in bytes. Note that 0 is a valid match offset.
1214012595L<C<undef>|/undef EXPR> indicates
1214112596that the search position is reset (usually due to match failure, but
1214212597can also be because no match has yet been run on the scalar).
1214312598
1214412599=end original
1214512600
1214612601対象の変数に対して、前回の C<m//g> が終了した場所の
1214712602オフセットを返します(変数が指定されなかった場合は L<C<$_>|perlvar/$_> が
1214812603使われます)。
1214912604オフセットは、(もはや勧められない) L<C<use bytes>|bytes> プラグマが有効の
1215012605場合(この場合はバイト単位です)を除いて、文字単位です。
12151126060 は有効なマッチオフセットであることに注意してください。
1215212607L<C<undef>|/undef EXPR> は検索位置がリセットされることを意味します (通常は
1215312608マッチ失敗が原因ですが、このスカラ値にまだマッチングが
1215412609行われていないためかもしれません)。
1215512610
1215612611=begin original
1215712612
1215812613L<C<pos>|/pos SCALAR> directly accesses the location used by the regexp
1215912614engine to store the offset, so assigning to L<C<pos>|/pos SCALAR> will
1216012615change that offset, and so will also influence the C<\G> zero-width
1216112616assertion in regular expressions. Both of these effects take place for
1216212617the next match, so you can't affect the position with
1216312618L<C<pos>|/pos SCALAR> during the current match, such as in
1216412619C<(?{pos() = 5})> or C<s//pos() = 5/e>.
1216512620
1216612621=end original
1216712622
1216812623L<C<pos>|/pos SCALAR> は正規表現エンジンがオフセットを保存するために使う場所を
1216912624直接アクセスするので、L<C<pos>|/pos SCALAR> への代入はオフセットを変更し、
1217012625そのような変更は正規表現における C<\G> ゼロ幅アサートにも影響を与えます。
1217112626これらの効果の両方は次のマッチングのために行われるので、
1217212627C<(?{pos() = 5})> や C<s//pos() = 5/e> のように現在のマッチング中の
1217312628L<C<pos>|/pos SCALAR> の位置には影響を与えません。
1217412629
1217512630=begin original
1217612631
1217712632Setting L<C<pos>|/pos SCALAR> also resets the I<matched with
1217812633zero-length> flag, described
1217912634under L<perlre/"Repeated Patterns Matching a Zero-length Substring">.
1218012635
1218112636=end original
1218212637
1218312638L<C<pos>|/pos SCALAR> を設定すると、
1218412639L<perlre/"Repeated Patterns Matching a Zero-length Substring"> に
1218512640記述されている、I<長さ 0 でマッチング> フラグもリセットされます。
1218612641
1218712642=begin original
1218812643
1218912644Because a failed C<m//gc> match doesn't reset the offset, the return
1219012645from L<C<pos>|/pos SCALAR> won't change either in this case. See
1219112646L<perlre> and L<perlop>.
1219212647
1219312648=end original
1219412649
1219512650C<m//gc> マッチに失敗してもオフセットはリセットしないので、
1219612651L<C<pos>|/pos SCALAR> からの返り値はどちらの場合も変更されません。
1219712652L<perlre> と L<perlop> を参照してください。
1219812653
1219912654=item print FILEHANDLE LIST
1220012655X<print>
1220112656
1220212657=item print FILEHANDLE
1220312658
1220412659=item print LIST
1220512660
1220612661=item print
1220712662
1220812663=for Pod::Functions output a list to a filehandle
1220912664
1221012665=begin original
1221112666
1221212667Prints a string or a list of strings. Returns true if successful.
1221312668FILEHANDLE may be a scalar variable containing the name of or a reference
1221412669to the filehandle, thus introducing one level of indirection. (NOTE: If
1221512670FILEHANDLE is a variable and the next token is a term, it may be
1221612671misinterpreted as an operator unless you interpose a C<+> or put
1221712672parentheses around the arguments.) If FILEHANDLE is omitted, prints to the
1221812673last selected (see L<C<select>|/select FILEHANDLE>) output handle. If
1221912674LIST is omitted, prints L<C<$_>|perlvar/$_> to the currently selected
1222012675output handle. To use FILEHANDLE alone to print the content of
1222112676L<C<$_>|perlvar/$_> to it, you must use a bareword filehandle like
1222212677C<FH>, not an indirect one like C<$fh>. To set the default output handle
1222312678to something other than STDOUT, use the select operation.
1222412679
1222512680=end original
1222612681
1222712682文字列か文字列のリストを出力します。
1222812683成功時には真を返します。
1222912684FILEHANDLE は、ファイルハンドル名またはそのリファレンスが
1223012685入っているスカラ変数名でもよいので、一段階の間接指定が行なえます。
1223112686(注: FILEHANDLE に変数を使い、次のトークンが「項」のときには、
1223212687間に C<+> を置くか、引数の前後を括弧で括らなければ、
1223312688誤って解釈されることがあります。)
1223412689FILEHANDLE を省略した場合には、最後に選択された
1223512690(L<C<select>|/select FILEHANDLE> 参照) 出力チャネルに出力します。
1223612691LIST を省略すると、L<C<$_>|perlvar/$_> が現在選択されている出力ハンドルに
1223712692出力されます。
1223812693L<C<$_>|perlvar/$_> の内容を表示するために FILEHANDLE のみを使用するには、
1223912694C<$fh> のような間接ファイルハンドルではなく、C<FH> のような裸の単語の
1224012695ファイルハンドルを使わなければなりません。
1224112696デフォルトの出力チャネルを STDOUT 以外にするには、select 演算子を
1224212697使ってください。
1224312698
1224412699=begin original
1224512700
1224612701The current value of L<C<$,>|perlvar/$,> (if any) is printed between
1224712702each LIST item. The current value of L<C<$\>|perlvar/$\> (if any) is
1224812703printed after the entire LIST has been printed. Because print takes a
1224912704LIST, anything in the LIST is evaluated in list context, including any
1225012705subroutines whose return lists you pass to
1225112706L<C<print>|/print FILEHANDLE LIST>. Be careful not to follow the print
1225212707keyword with a left
1225312708parenthesis unless you want the corresponding right parenthesis to
1225412709terminate the arguments to the print; put parentheses around all arguments
1225512710(or interpose a C<+>, but that doesn't look as good).
1225612711
1225712712=end original
1225812713
1225912714L<C<$,>|perlvar/$,> の値が(もしあれば)各 LIST 要素の間に出力されます。
1226012715LIST 全体が出力された後、(もしあれば) L<C<$\>|perlvar/$\> の現在の値が
1226112716出力されます。
1226212717print の引数は LIST なので、LIST の中のものは、すべてリストコンテキストで
1226312718評価されます; L<C<print>|/print FILEHANDLE LIST> に渡した、リストを返す
1226412719サブルーチンも含みます。
1226512720また、すべての引数を括弧で括るのでなければ、print というキーワードの
1226612721次に開き括弧を書いてはいけません; すべての引数を括弧で括ってください
1226712722(あるいは "print" と引数の間に C<+> を書きますが、これはあまり
1226812723よくありません)。
1226912724
1227012725=begin original
1227112726
1227212727If you're storing handles in an array or hash, or in general whenever
1227312728you're using any expression more complex than a bareword handle or a plain,
1227412729unsubscripted scalar variable to retrieve it, you will have to use a block
1227512730returning the filehandle value instead, in which case the LIST may not be
1227612731omitted:
1227712732
1227812733=end original
1227912734
1228012735もし FILESHANDLE を配列、ハッシュあるいは一般的には裸の単語のハンドルや
1228112736普通のスカラ変数よりも複雑な表現を使っている場合、代わりにその値を返す
1228212737ブロックを使う必要があります; この場合 LIST は省略できません:
1228312738
1228412739 print { $files[$i] } "stuff\n";
1228512740 print { $OK ? *STDOUT : *STDERR } "stuff\n";
1228612741
1228712742=begin original
1228812743
1228912744Printing to a closed pipe or socket will generate a SIGPIPE signal. See
1229012745L<perlipc> for more on signal handling.
1229112746
1229212747=end original
1229312748
1229412749閉じたパイプやソケットに print すると SIGPIPE シグナルが生成されます。
1229512750さらなるシグナル操作については L<perlipc> を参照してください。
1229612751
1229712752=item printf FILEHANDLE FORMAT, LIST
1229812753X<printf>
1229912754
1230012755=item printf FILEHANDLE
1230112756
1230212757=item printf FORMAT, LIST
1230312758
1230412759=item printf
1230512760
1230612761=for Pod::Functions output a formatted list to a filehandle
1230712762
1230812763=begin original
1230912764
1231012765Equivalent to C<print FILEHANDLE sprintf(FORMAT, LIST)>, except that
1231112766L<C<$\>|perlvar/$\> (the output record separator) is not appended. The
1231212767FORMAT and the LIST are actually parsed as a single list. The first
1231312768argument of the list will be interpreted as the
1231412769L<C<printf>|/printf FILEHANDLE FORMAT, LIST> format. This means that
1231512770C<printf(@_)> will use C<$_[0]> as the format. See
1231612771L<sprintf|/sprintf FORMAT, LIST> for an explanation of the format
1231712772argument. If C<use locale> (including C<use locale ':not_characters'>)
1231812773is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
1231912774called, the character used for the decimal separator in formatted
1232012775floating-point numbers is affected by the C<LC_NUMERIC> locale setting.
1232112776See L<perllocale> and L<POSIX>.
1232212777
1232312778=end original
1232412779
1232512780L<C<$\>|perlvar/$\>(出力レコードセパレータ)を追加しないことを除けば、
1232612781C<print FILEHANDLE sprintf(FORMAT, LIST)> と等価です。
1232712782FORMAT と LIST は実際には単一のリストとしてパースされます。
1232812783リストの最初の要素は、L<C<printf>|/printf FILEHANDLE FORMAT, LIST>
1232912784フォーマットと解釈されます。
1233012785これは、C<printf(@_)> はフォーマットとして C<$_[0]> を使うということです。
1233112786フォーマット引数の説明については L<sprintf|/sprintf FORMAT, LIST> を
1233212787参照してください。
1233312788(C<use locale ':not_characters'> を含む) C<use locale> が有効で、
1233412789L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されていれば、
1233512790小数点に使われる文字は C<LC_NUMERIC> ロケール設定の影響を受けます。
1233612791L<perllocale> と L<POSIX> を参照してください。
1233712792
1233812793=begin original
1233912794
1234012795For historical reasons, if you omit the list, L<C<$_>|perlvar/$_> is
1234112796used as the format;
1234212797to use FILEHANDLE without a list, you must use a bareword filehandle like
1234312798C<FH>, not an indirect one like C<$fh>. However, this will rarely do what
1234412799you want; if L<C<$_>|perlvar/$_> contains formatting codes, they will be
1234512800replaced with the empty string and a warning will be emitted if
1234612801L<warnings> are enabled. Just use L<C<print>|/print FILEHANDLE LIST> if
1234712802you want to print the contents of L<C<$_>|perlvar/$_>.
1234812803
1234912804=end original
1235012805
1235112806歴史的な理由により、リストを省略すると、フォーマットとして
1235212807L<C<$_>|perlvar/$_> が使われます;
1235312808リストなしで FILEHANDLE を使用するには、C<$fh> のような
1235412809間接ファイルハンドルではなく、C<FH> のような裸の単語の
1235512810ファイルハンドルを使わなければなりません。
1235612811しかし、これがあなたが求めていることをすることはまれです;
1235712812L<C<$_>|perlvar/$_> がフォーマッティングコードの場合、空文字列に置き換えられ、
1235812813L<warnings> が有効なら警告が出力されます。
1235912814L<C<$_>|perlvar/$_> の内容を表示したい場合は、単に
1236012815L<C<print>|/print FILEHANDLE LIST> を使ってください。
1236112816
1236212817=begin original
1236312818
1236412819Don't fall into the trap of using a
1236512820L<C<printf>|/printf FILEHANDLE FORMAT, LIST> when a simple
1236612821L<C<print>|/print FILEHANDLE LIST> would do. The
1236712822L<C<print>|/print FILEHANDLE LIST> is more efficient and less error
1236812823prone.
1236912824
1237012825=end original
1237112826
1237212827単純な L<C<print>|/print FILEHANDLE LIST> を使うべきところで
1237312828L<C<printf>|/printf FILEHANDLE FORMAT, LIST> を使ってしまう
1237412829罠にかからないようにしてください。
1237512830L<C<print>|/print FILEHANDLE LIST> はより効率的で、間違いが起こりにくいです。
1237612831
1237712832=item prototype FUNCTION
1237812833X<prototype>
1237912834
1238012835=item prototype
1238112836
1238212837=for Pod::Functions +5.002 get the prototype (if any) of a subroutine
1238312838
1238412839=begin original
1238512840
1238612841Returns the prototype of a function as a string (or
1238712842L<C<undef>|/undef EXPR> if the
1238812843function has no prototype). FUNCTION is a reference to, or the name of,
1238912844the function whose prototype you want to retrieve. If FUNCTION is omitted,
1239012845L<C<$_>|perlvar/$_> is used.
1239112846
1239212847=end original
1239312848
1239412849関数のプロトタイプを文字列として返します(関数にプロトタイプがない場合は
1239512850L<C<undef>|/undef EXPR> を返します)。
1239612851FUNCTION はプロトタイプを得たい関数の名前、またはリファレンスです。
1239712852FUNCTION が省略された場合、L<C<$_>|perlvar/$_> が使われます。
1239812853
1239912854=begin original
1240012855
1240112856If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
1240212857name for a Perl builtin. If the builtin's arguments
1240312858cannot be adequately expressed by a prototype
1240412859(such as L<C<system>|/system LIST>), L<C<prototype>|/prototype FUNCTION>
1240512860returns L<C<undef>|/undef EXPR>, because the builtin
1240612861does not really behave like a Perl function. Otherwise, the string
1240712862describing the equivalent prototype is returned.
1240812863
1240912864=end original
1241012865
1241112866FUNCTION が C<CORE::> で始まっている場合、残りは Perl ビルドインの名前として
1241212867扱われます。
1241312868このビルドインの引数が(L<C<system>|/system LIST> のように)プロトタイプとして
1241412869適切に記述できない場合、L<C<prototype>|/prototype FUNCTION> は
1241512870L<C<undef>|/undef EXPR> を返します;
1241612871なぜならビルドインは実際に Perl 関数のように振舞わないからです。
1241712872それ以外では、等価なプロトタイプを表現した文字列が返されます。
1241812873
1241912874=item push ARRAY,LIST
1242012875X<push> X<stack>
1242112876
1242212877=for Pod::Functions append one or more elements to an array
1242312878
1242412879=begin original
1242512880
1242612881Treats ARRAY as a stack by appending the values of LIST to the end of
1242712882ARRAY. The length of ARRAY increases by the length of LIST. Has the same
1242812883effect as
1242912884
1243012885=end original
1243112886
1243212887ARRAY をスタックとして扱い、LIST 内の値を ARRAY の終わりに追加します。
1243312888ARRAY の大きさは、LIST の長さ分だけ大きくなります。
1243412889これは、
1243512890
1243612891 for my $value (LIST) {
1243712892 $ARRAY[++$#ARRAY] = $value;
1243812893 }
1243912894
1244012895=begin original
1244112896
1244212897but is more efficient. Returns the number of elements in the array following
1244312898the completed L<C<push>|/push ARRAY,LIST>.
1244412899
1244512900=end original
1244612901
1244712902とするのと同じ効果がありますが、より効率的です。
1244812903L<C<push>|/push ARRAY,LIST> の処理終了後の配列の要素数を返します。
1244912904
1245012905=begin original
1245112906
1245212907Starting with Perl 5.14, an experimental feature allowed
1245312908L<C<push>|/push ARRAY,LIST> to take a
1245412909scalar expression. This experiment has been deemed unsuccessful, and was
1245512910removed as of Perl 5.24.
1245612911
1245712912=end original
1245812913
1245912914Perl 5.14 から、L<C<push>|/push ARRAY,LIST> がスカラ式を取ることが出来るという
1246012915実験的機能がありました。
1246112916この実験は失敗と見なされ、Perl 5.24 で削除されました。
1246212917
1246312918=item q/STRING/
1246412919
1246512920=for Pod::Functions singly quote a string
1246612921
1246712922=item qq/STRING/
1246812923
1246912924=for Pod::Functions doubly quote a string
1247012925
1247112926=item qw/STRING/
1247212927
1247312928=for Pod::Functions quote a list of words
1247412929
1247512930=item qx/STRING/
1247612931
1247712932=for Pod::Functions backquote quote a string
1247812933
1247912934=begin original
1248012935
1248112936Generalized quotes. See L<perlop/"Quote-Like Operators">.
1248212937
1248312938=end original
1248412939
1248512940汎用のクォートです。
1248612941L<perlop/"Quote-Like Operators"> を参照してください。
1248712942
1248812943=item qr/STRING/
1248912944
1249012945=for Pod::Functions +5.005 compile pattern
1249112946
1249212947=begin original
1249312948
1249412949Regexp-like quote. See L<perlop/"Regexp Quote-Like Operators">.
1249512950
1249612951=end original
1249712952
1249812953正規表現風のクォートです。
1249912954L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1250012955
1250112956=item quotemeta EXPR
1250212957X<quotemeta> X<metacharacter>
1250312958
1250412959=item quotemeta
1250512960
1250612961=for Pod::Functions quote regular expression magic characters
1250712962
1250812963=begin original
1250912964
1251012965Returns the value of EXPR with all the ASCII non-"word"
1251112966characters backslashed. (That is, all ASCII characters not matching
1251212967C</[A-Za-z_0-9]/> will be preceded by a backslash in the
1251312968returned string, regardless of any locale settings.)
1251412969This is the internal function implementing
1251512970the C<\Q> escape in double-quoted strings.
1251612971(See below for the behavior on non-ASCII code points.)
1251712972
1251812973=end original
1251912974
1252012975EXPR の中のすべての ASCII 非英数字キャラクタをバックスラッシュで
1252112976エスケープしたものを返します。
1252212977(つまり、C</[A-Za-z_0-9]/> にマッチしない全ての ASCII 文字の前には
1252312978ロケールに関わらずバックスラッシュが前置されます。)
1252412979これは、ダブルクォート文字列での C<\Q> エスケープを実装するための
1252512980内部関数です。
1252612981(非 ASCII 符号位置での振る舞いについては以下を参照してください。)
1252712982
1252812983=begin original
1252912984
1253012985If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1253112986
1253212987=end original
1253312988
1253412989EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1253512990
1253612991=begin original
1253712992
1253812993quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into
1253912994regular expressions, because by default an interpolated variable will be
1254012995considered a mini-regular expression. For example:
1254112996
1254212997=end original
1254312998
1254412999クォートメタ (と C<\Q> ... C<\E>) は、文字列を正規表現に展開するのに
1254513000便利です; なぜなら、デフォルトでは展開された変数は小さな正規表現として
1254613001扱われるからです。
1254713002例えば:
1254813003
1254913004 my $sentence = 'The quick brown fox jumped over the lazy dog';
1255013005 my $substring = 'quick.*?fox';
1255113006 $sentence =~ s{$substring}{big bad wolf};
1255213007
1255313008=begin original
1255413009
1255513010Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>.
1255613011
1255713012=end original
1255813013
1255913014とすると、C<$sentence> は C<'The big bad wolf jumped over...'> になります。
1256013015
1256113016=begin original
1256213017
1256313018On the other hand:
1256413019
1256513020=end original
1256613021
1256713022一方:
1256813023
1256913024 my $sentence = 'The quick brown fox jumped over the lazy dog';
1257013025 my $substring = 'quick.*?fox';
1257113026 $sentence =~ s{\Q$substring\E}{big bad wolf};
1257213027
1257313028=begin original
1257413029
1257513030Or:
1257613031
1257713032=end original
1257813033
1257913034あるいは:
1258013035
1258113036 my $sentence = 'The quick brown fox jumped over the lazy dog';
1258213037 my $substring = 'quick.*?fox';
1258313038 my $quoted_substring = quotemeta($substring);
1258413039 $sentence =~ s{$quoted_substring}{big bad wolf};
1258513040
1258613041=begin original
1258713042
1258813043Will both leave the sentence as is.
1258913044Normally, when accepting literal string input from the user,
1259013045L<C<quotemeta>|/quotemeta EXPR> or C<\Q> must be used.
1259113046
1259213047=end original
1259313048
1259413049とすると、両方ともそのままです。
1259513050普通は、ユーザーからのリテラルな文字列入力を受け付ける場合は、
1259613051必ず L<C<quotemeta>|/quotemeta EXPR> か C<\Q> を使わなければなりません。
1259713052
1259813053=begin original
1259913054
1260013055In Perl v5.14, all non-ASCII characters are quoted in non-UTF-8-encoded
1260113056strings, but not quoted in UTF-8 strings.
1260213057
1260313058=end original
1260413059
1260513060Perl v5.14 では、全ての非 ASCII 文字は非 UTF-8 エンコードされた
1260613061文字列ではクォートされませんが、UTF-8 文字列ではクォートされます。
1260713062
1260813063=begin original
1260913064
1261013065Starting in Perl v5.16, Perl adopted a Unicode-defined strategy for
1261113066quoting non-ASCII characters; the quoting of ASCII characters is
1261213067unchanged.
1261313068
1261413069=end original
1261513070
1261613071Perl v5.16 から、Perl は非 ASCII 文字をクォートするのに Unicode で
1261713072定義された戦略を採用しました; ASCII 文字のクォートは変わりません。
1261813073
1261913074=begin original
1262013075
1262113076Also unchanged is the quoting of non-UTF-8 strings when outside the
1262213077scope of a
1262313078L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature>,
1262413079which is to quote all
1262513080characters in the upper Latin1 range. This provides complete backwards
1262613081compatibility for old programs which do not use Unicode. (Note that
1262713082C<unicode_strings> is automatically enabled within the scope of a
1262813083S<C<use v5.12>> or greater.)
1262913084
1263013085=end original
1263113086
1263213087また、
1263313088L<C<use feature 'unicode_strings'>|feature/The 'unicode_strings' feature> の
1263413089範囲外で非 UTF-8 文字列をクォートするのも変わりません; 上位の Latin1 の範囲の
1263513090全ての文字をクォートします。
1263613091これは Unicode を使わない古いプログラムに対して完全な後方互換性を提供します。
1263713092(C<unicode_strings> は S<C<use v5.12>> またはそれ以上のスコープでは
1263813093自動的に有効になることに注意してください。)
1263913094
1264013095=begin original
1264113096
1264213097Within the scope of L<C<use locale>|locale>, all non-ASCII Latin1 code
1264313098points
1264413099are quoted whether the string is encoded as UTF-8 or not. As mentioned
1264513100above, locale does not affect the quoting of ASCII-range characters.
1264613101This protects against those locales where characters such as C<"|"> are
1264713102considered to be word characters.
1264813103
1264913104=end original
1265013105
1265113106L<C<use locale>|locale> スコープの内側では、全ての非 ASCII Latin1 符号位置は
1265213107文字列が UTF-8 でエンコードされているかどうかに関わらずクォートされます。
1265313108上述のように、ロケールは ASCII の範囲の文字のクォートに影響を与えません。
1265413109これは C<"|"> のような文字が単語文字として考えられるロケールから守ります。
1265513110
1265613111=begin original
1265713112
1265813113Otherwise, Perl quotes non-ASCII characters using an adaptation from
12659Unicode (see L<http://www.unicode.org/reports/tr31/>).
13114Unicode (see L<https://www.unicode.org/reports/tr31/>).
1266013115The only code points that are quoted are those that have any of the
1266113116Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space,
1266213117Default_Ignorable_Code_Point, or General_Category=Control.
1266313118
1266413119=end original
1266513120
1266613121さもなければ、Perl は Unicode からの本版を使って非 ASCII 文字をクォートします
12667(L<http://www.unicode.org/reports/tr31/> 参照)。
13122(L<https://www.unicode.org/reports/tr31/> 参照)。
1266813123クォートされる符号位置は以下のどれかの Unicode を特性を持つものだけです:
1266913124Pattern_Syntax, Pattern_White_Space, White_Space,
1267013125Default_Ignorable_Code_Point, or General_Category=Control。
1267113126
1267213127=begin original
1267313128
1267413129Of these properties, the two important ones are Pattern_Syntax and
1267513130Pattern_White_Space. They have been set up by Unicode for exactly this
1267613131purpose of deciding which characters in a regular expression pattern
1267713132should be quoted. No character that can be in an identifier has these
1267813133properties.
1267913134
1268013135=end original
1268113136
1268213137これらの特性の中で、重要な二つは Pattern_Syntax と Pattern_White_Space です。
1268313138これらはまさに正規表現中パターン中のどの文字をクォートするべきかを
1268413139決定するという目的のために Unicode によって設定されています。
1268513140識別子になる文字はこれらの特性はありません。
1268613141
1268713142=begin original
1268813143
1268913144Perl promises, that if we ever add regular expression pattern
1269013145metacharacters to the dozen already defined
1269113146(C<\ E<verbar> ( ) [ { ^ $ * + ? .>), that we will only use ones that have the
1269213147Pattern_Syntax property. Perl also promises, that if we ever add
1269313148characters that are considered to be white space in regular expressions
1269413149(currently mostly affected by C</x>), they will all have the
1269513150Pattern_White_Space property.
1269613151
1269713152=end original
1269813153
1269913154Perl は、正規表現メタ文字として既に定義されている
1270013155(C<\ E<verbar> ( ) [ { ^ $ * + ? .>) ものに追加するときは、
1270113156Pattern_Syntax 特性を持つものだけを使うことを約束します。
1270213157Perl はまた、(現在の所ほとんどは C</x> よって影響される)正規表現中で空白と
1270313158考えられる文字に追加するときは、Pattern_White_Space 特性を
1270413159持つものであることを約束します。
1270513160
1270613161=begin original
1270713162
1270813163Unicode promises that the set of code points that have these two
1270913164properties will never change, so something that is not quoted in v5.16
1271013165will never need to be quoted in any future Perl release. (Not all the
1271113166code points that match Pattern_Syntax have actually had characters
1271213167assigned to them; so there is room to grow, but they are quoted
1271313168whether assigned or not. Perl, of course, would never use an
1271413169unassigned code point as an actual metacharacter.)
1271513170
1271613171=end original
1271713172
1271813173Unicode はこれら二つの特性を持つ符号位置の集合が決して変わらないことを
1271913174約束しているので、v5.16 でクォートされないものは将来の Perl リリースでも
1272013175クォートする必要はありません。
1272113176(Pattern_Syntax にマッチングする全ての符号位置が実際に割り当てられている
1272213177文字を持っているわけではありません; したがって拡張する余地がありますが、
1272313178割り当てられているかどうかに関わらずクォートされます。
1272413179Perl はもちろん割り当てられていない符号位置を実際のメタ文字として使うことは
1272513180ありません。)
1272613181
1272713182=begin original
1272813183
1272913184Quoting characters that have the other 3 properties is done to enhance
1273013185the readability of the regular expression and not because they actually
1273113186need to be quoted for regular expression purposes (characters with the
1273213187White_Space property are likely to be indistinguishable on the page or
1273313188screen from those with the Pattern_White_Space property; and the other
1273413189two properties contain non-printing characters).
1273513190
1273613191=end original
1273713192
1273813193その他の 3 特性を持つ文字のクォートは正規表現の可読性を向上させるために
1273913194行われ、実際には正規表現の目的でクォートする必要があるからではありません
1274013195(White_Space 特性を持つ文字は表示上は Pattern_White_Space 特性を持つ文字と
1274113196おそらく区別が付かないでしょう; そして残りの
1274213197二つの特性は非表示文字を含んでいます).
1274313198
1274413199=item rand EXPR
1274513200X<rand> X<random>
1274613201
1274713202=item rand
1274813203
1274913204=for Pod::Functions retrieve the next pseudorandom number
1275013205
1275113206=begin original
1275213207
1275313208Returns a random fractional number greater than or equal to C<0> and less
1275413209than the value of EXPR. (EXPR should be positive.) If EXPR is
1275513210omitted, the value C<1> is used. Currently EXPR with the value C<0> is
1275613211also special-cased as C<1> (this was undocumented before Perl 5.8.0
1275713212and is subject to change in future versions of Perl). Automatically calls
1275813213L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been
1275913214called. See also L<C<srand>|/srand EXPR>.
1276013215
1276113216=end original
1276213217
1276313218C<0> 以上 EXPR の値未満の小数の乱数値を返します。
1276413219(EXPR は正の数である必要があります。)
1276513220EXPR が省略されると、C<1> が使われます。
1276613221現在のところ、EXPR に値 C<0> をセットすると C<1> として特別扱いされます
1276713222(これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では
1276813223変更される可能性があります)。
1276913224L<C<srand>|/srand EXPR> が既に呼ばれている場合以外は、自動的に
1277013225L<C<srand>|/srand EXPR> 関数を呼び出します。
1277113226L<C<srand>|/srand EXPR> も参照してください。
1277213227
1277313228=begin original
1277413229
1277513230Apply L<C<int>|/int EXPR> to the value returned by L<C<rand>|/rand EXPR>
1277613231if you want random integers instead of random fractional numbers. For
1277713232example,
1277813233
1277913234=end original
1278013235
1278113236ランダムな小数ではなく、ランダムな整数がほしい場合は、
1278213237L<C<rand>|/rand EXPR> から返された値に L<C<int>|/int EXPR> を
1278313238適用してください。
1278413239例えば:
1278513240
1278613241 int(rand(10))
1278713242
1278813243=begin original
1278913244
1279013245returns a random integer between C<0> and C<9>, inclusive.
1279113246
1279213247=end original
1279313248
1279413249これは C<0> から C<9> の値をランダムに返します。
1279513250
1279613251=begin original
1279713252
1279813253(Note: If your rand function consistently returns numbers that are too
1279913254large or too small, then your version of Perl was probably compiled
1280013255with the wrong number of RANDBITS.)
1280113256
1280213257=end original
1280313258
1280413259(注: もし、rand 関数が、常に大きい値ばかりや、小さい数ばかりを
1280513260返すようなら、お使いになっている Perl が、
1280613261良くない RANDBITS を使ってコンパイルされている可能性があります。)
1280713262
1280813263=begin original
1280913264
1281013265B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
1281113266on it in security-sensitive situations.> As of this writing, a
1281213267number of third-party CPAN modules offer random number generators
1281313268intended by their authors to be cryptographically secure,
1281413269including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1281513270and L<Math::TrulyRandom>.
1281613271
1281713272=end original
1281813273
1281913274B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
1282013275セキュリティ的に重要な状況でこれに頼るべきではありません。>
1282113276これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
1282213277作者によって暗号学的に安全であることを目的とした乱数生成器を
1282313278提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1282413279L<Math::TrulyRandom> などです。
1282513280
1282613281=item read FILEHANDLE,SCALAR,LENGTH,OFFSET
1282713282X<read> X<file, read>
1282813283
1282913284=item read FILEHANDLE,SCALAR,LENGTH
1283013285
1283113286=for Pod::Functions fixed-length buffered input from a filehandle
1283213287
1283313288=begin original
1283413289
1283513290Attempts to read LENGTH I<characters> of data into variable SCALAR
1283613291from the specified FILEHANDLE. Returns the number of characters
1283713292actually read, C<0> at end of file, or undef if there was an error (in
1283813293the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will be grown
1283913294or shrunk
1284013295so that the last character actually read is the last character of the
1284113296scalar after the read.
1284213297
1284313298=end original
1284413299
1284513300指定した FILEHANDLE から、変数 SCALAR に LENGTH I<文字> のデータを
1284613301読み込みます。
1284713302実際に読み込まれた文字数、ファイル終端の場合は C<0>、エラーの場合は undef の
1284813303いずれかを返します (後者の場合、L<C<$!>|perlvar/$!> もセットされます)。
1284913304SCALAR は伸び縮みするので、読み込み後は、実際に読み込んだ最後の文字がスカラの
1285013305最後の文字になります。
1285113306
1285213307=begin original
1285313308
1285413309An OFFSET may be specified to place the read data at some place in the
1285513310string other than the beginning. A negative OFFSET specifies
1285613311placement at that many characters counting backwards from the end of
1285713312the string. A positive OFFSET greater than the length of SCALAR
1285813313results in the string being padded to the required size with C<"\0">
1285913314bytes before the result of the read is appended.
1286013315
1286113316=end original
1286213317
1286313318OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
1286413319OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1286513320位置を指定します。
1286613321OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
1286713322追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
1286813323
1286913324=begin original
1287013325
1287113326The call is implemented in terms of either Perl's or your system's native
12872L<fread(3)> library function. To get a true L<read(2)> system call, see
13327L<fread(3)> library function, via the L<PerlIO> layers applied to the
13328handle. To get a true L<read(2)> system call, see
1287313329L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>.
1287413330
1287513331=end original
1287613332
12877この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って
13333この関数は、Perl か システムの L<fread(3)> ライブラリ関数を使って
12878実装ています。
13334ハンドルに適用されている L<PerlIO> 層経由で実装されています。
1287913335本当の L<read(2)> システムコールを利用するには、
1288013336L<sysread|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を参照してください。
1288113337
1288213338=begin original
1288313339
1288413340Note the I<characters>: depending on the status of the filehandle,
1288513341either (8-bit) bytes or characters are read. By default, all
1288613342filehandles operate on bytes, but for example if the filehandle has
1288713343been opened with the C<:utf8> I/O layer (see
12888L<C<open>|/open FILEHANDLE,EXPR>, and the L<open>
13344L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open>
1288913345pragma), the I/O will operate on UTF8-encoded Unicode
1289013346characters, not bytes. Similarly for the C<:encoding> layer:
1289113347in that case pretty much any characters can be read.
1289213348
1289313349=end original
1289413350
1289513351I<文字> に関する注意: ファイルハンドルの状態によって、(8 ビットの) バイトか
1289613352文字が読み込まれます。
1289713353デフォルトでは全てのファイルハンドルはバイトを処理しますが、
12898例えばファイルハンドルが C<:utf8> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>,
13354例えばファイルハンドルが C<:utf8> I/O 層
12899L<open> プラグマを参照してください) で開かれた場合、I/O はバイトではなく、
13355(L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください) で
13356開かれた場合、I/O はバイトではなく、
1290013357UTF8 エンコードされた Unicode 文字を操作します。
1290113358C<:encoding> 層も同様です:
1290213359この場合、ほとんど大体全ての文字が読み込めます。
1290313360
1290413361=item readdir DIRHANDLE
1290513362X<readdir>
1290613363
1290713364=for Pod::Functions get a directory from a directory handle
1290813365
1290913366=begin original
1291013367
1291113368Returns the next directory entry for a directory opened by
1291213369L<C<opendir>|/opendir DIRHANDLE,EXPR>.
1291313370If used in list context, returns all the rest of the entries in the
1291413371directory. If there are no more entries, returns the undefined value in
1291513372scalar context and the empty list in list context.
1291613373
1291713374=end original
1291813375
1291913376L<C<opendir>|/opendir DIRHANDLE,EXPR> でオープンしたディレクトリで、次の
1292013377ディレクトリエントリを返します。
1292113378リストコンテキストで用いると、そのディレクトリの残りのエントリを、すべて
1292213379返します。
1292313380エントリが残っていない場合には、スカラコンテキストでは未定義値を、
1292413381リストコンテキストでは空リストを返します。
1292513382
1292613383=begin original
1292713384
1292813385If you're planning to filetest the return values out of a
1292913386L<C<readdir>|/readdir DIRHANDLE>, you'd better prepend the directory in
1293013387question. Otherwise, because we didn't L<C<chdir>|/chdir EXPR> there,
1293113388it would have been testing the wrong file.
1293213389
1293313390=end original
1293413391
1293513392L<C<readdir>|/readdir DIRHANDLE> の返り値をファイルテストに使おうと
1293613393計画しているなら、頭にディレクトリをつける必要があります。
1293713394さもなければ、ここでは L<C<chdir>|/chdir EXPR> はしないので、
1293813395間違ったファイルをテストしてしまうことになるでしょう。
1293913396
1294013397 opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!";
1294113398 my @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
1294213399 closedir $dh;
1294313400
1294413401=begin original
1294513402
1294613403As of Perl 5.12 you can use a bare L<C<readdir>|/readdir DIRHANDLE> in a
1294713404C<while> loop, which will set L<C<$_>|perlvar/$_> on every iteration.
13405If either a C<readdir> expression or an explicit assignment of a
13406C<readdir> expression to a scalar is used as a C<while>/C<for> condition,
13407then the condition actually tests for definedness of the expression's
13408value, not for its regular truth value.
1294813409
1294913410=end original
1295013411
1295113412Perl 5.12 から裸の L<C<readdir>|/readdir DIRHANDLE> を C<while> で
1295213413使うことができ、この場合繰り返し毎に L<C<$_>|perlvar/$_> にセットされます。
13414C<readdir> 式または C<readdir> 式からスカラへの明示的な代入が
13415C<while>/C<for> の条件部として使われた場合、
13416条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
13417テストします。
1295313418
1295413419 opendir(my $dh, $some_dir) || die "Can't open $some_dir: $!";
1295513420 while (readdir $dh) {
1295613421 print "$some_dir/$_\n";
1295713422 }
1295813423 closedir $dh;
1295913424
1296013425=begin original
1296113426
1296213427To avoid confusing would-be users of your code who are running earlier
1296313428versions of Perl with mysterious failures, put this sort of thing at the
1296413429top of your file to signal that your code will work I<only> on Perls of a
1296513430recent vintage:
1296613431
1296713432=end original
1296813433
1296913434あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
1297013435失敗で混乱することを避けるために、コードが最近のバージョンの Perl で
1297113436I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
1297213437書いてください:
1297313438
1297413439 use 5.012; # so readdir assigns to $_ in a lone while test
1297513440
1297613441=item readline EXPR
1297713442
1297813443=item readline
1297913444X<readline> X<gets> X<fgets>
1298013445
1298113446=for Pod::Functions fetch a record from a file
1298213447
1298313448=begin original
1298413449
1298513450Reads from the filehandle whose typeglob is contained in EXPR (or from
1298613451C<*ARGV> if EXPR is not provided). In scalar context, each call reads and
1298713452returns the next line until end-of-file is reached, whereupon the
1298813453subsequent call returns L<C<undef>|/undef EXPR>. In list context, reads
1298913454until end-of-file is reached and returns a list of lines. Note that the
1299013455notion of "line" used here is whatever you may have defined with
1299113456L<C<$E<sol>>|perlvar/$E<sol>> (or C<$INPUT_RECORD_SEPARATOR> in
1299213457L<English>). See L<perlvar/"$/">.
1299313458
1299413459=end original
1299513460
1299613461型グロブが EXPR (EXPR がない場合は C<*ARGV>) に含まれている
1299713462ファイルハンドルから読み込みます。
1299813463スカラコンテキストでは、呼び出し毎に一行読み込んで返します; ファイルの
1299913464最後まで読み込んだら、以後の呼び出しでは L<C<undef>|/undef EXPR> を返します。
1300013465リストコンテキストでは、ファイルの最後まで読み込んで、行のリストを返します。
1300113466ここでの「行」とは、L<C<$E<sol>>|perlvar/$E<sol>> (または
1300213467L<English> モジュールでは C<$INPUT_RECORD_SEPARATOR>) で
1300313468定義されることに注意してください。
1300413469L<perlvar/"$/"> を参照してください。
1300513470
1300613471=begin original
1300713472
1300813473When L<C<$E<sol>>|perlvar/$E<sol>> is set to L<C<undef>|/undef EXPR>,
1300913474when L<C<readline>|/readline EXPR> is in scalar context (i.e., file
1301013475slurp mode), and when an empty file is read, it returns C<''> the first
1301113476time, followed by L<C<undef>|/undef EXPR> subsequently.
1301213477
1301313478=end original
1301413479
1301513480L<C<$E<sol>>|perlvar/$E<sol>> に L<C<undef>|/undef EXPR> を設定した場合は、
1301613481L<C<readline>|/readline EXPR> はスカラコンテキスト (つまりファイル吸い込み
1301713482モード)となり、空のファイルを読み込んだ場合は、最初は C<''> を返し、
1301813483それ以降は L<C<undef>|/undef EXPR> を返します。
1301913484
1302013485=begin original
1302113486
1302213487This is the internal function implementing the C<< <EXPR> >>
1302313488operator, but you can use it directly. The C<< <EXPR> >>
1302413489operator is discussed in more detail in L<perlop/"I/O Operators">.
1302513490
1302613491=end original
1302713492
1302813493これは C<< <EXPR> >> 演算子を実装している内部関数ですが、
1302913494直接使うこともできます。
1303013495C<< <EXPR> >> 演算子についてのさらなる詳細については
1303113496L<perlop/"I/O Operators"> で議論されています。
1303213497
1303313498 my $line = <STDIN>;
1303413499 my $line = readline(STDIN); # same thing
1303513500
1303613501=begin original
1303713502
1303813503If L<C<readline>|/readline EXPR> encounters an operating system error,
1303913504L<C<$!>|perlvar/$!> will be set with the corresponding error message.
1304013505It can be helpful to check L<C<$!>|perlvar/$!> when you are reading from
1304113506filehandles you don't trust, such as a tty or a socket. The following
1304213507example uses the operator form of L<C<readline>|/readline EXPR> and dies
1304313508if the result is not defined.
1304413509
1304513510=end original
1304613511
1304713512L<C<readline>|/readline EXPR> が OS のシステムエラーになると、
1304813513L<C<$!>|perlvar/$!> に対応するエラーメッセージがセットされます。
1304913514tty やソケットといった、信頼できないファイルハンドルから読み込む時には
1305013515L<C<$!>|perlvar/$!> をチェックするのが助けになります。
1305113516以下の例は演算子の形の L<C<readline>|/readline EXPR> を使っており、結果が
1305213517未定義の場合は die します。
1305313518
1305413519 while ( ! eof($fh) ) {
1305513520 defined( $_ = readline $fh ) or die "readline failed: $!";
1305613521 ...
1305713522 }
1305813523
1305913524=begin original
1306013525
1306113526Note that you have can't handle L<C<readline>|/readline EXPR> errors
1306213527that way with the C<ARGV> filehandle. In that case, you have to open
1306313528each element of L<C<@ARGV>|perlvar/@ARGV> yourself since
1306413529L<C<eof>|/eof FILEHANDLE> handles C<ARGV> differently.
1306513530
1306613531=end original
1306713532
1306813533L<C<readline>|/readline EXPR> のエラーは C<ARGV> ファイルハンドルの方法では
1306913534扱えないことに注意してください。
1307013535この場合、L<C<eof>|/eof FILEHANDLE> は C<ARGV> を異なった方法で扱うので、
1307113536L<C<@ARGV>|perlvar/@ARGV> のそれぞれの要素を自分でオープンする必要があります。
1307213537
1307313538 foreach my $arg (@ARGV) {
1307413539 open(my $fh, $arg) or warn "Can't open $arg: $!";
1307513540
1307613541 while ( ! eof($fh) ) {
1307713542 defined( $_ = readline $fh )
1307813543 or die "readline failed for $arg: $!";
1307913544 ...
1308013545 }
1308113546 }
1308213547
13548=begin original
13549
13550Like the C<< <EXPR> >> operator, if a C<readline> expression is
13551used as the condition of a C<while> or C<for> loop, then it will be
13552implicitly assigned to C<$_>. If either a C<readline> expression or
13553an explicit assignment of a C<readline> expression to a scalar is used
13554as a C<while>/C<for> condition, then the condition actually tests for
13555definedness of the expression's value, not for its regular truth value.
13556
13557=end original
13558
13559C<< <EXPR> >> 演算子と同様、
13560C<readline> 式が C<while> や C<for> ループの条件として使われた場合、
13561これは暗黙に C<$_> に代入されます。
13562C<readline> 式または C<readline> 式からスカラへの明示的な代入が
13563C<while>/C<for> の条件部として使われた場合、
13564条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを
13565テストします。
13566
1308313567=item readlink EXPR
1308413568X<readlink>
1308513569
1308613570=item readlink
1308713571
1308813572=for Pod::Functions determine where a symbolic link is pointing
1308913573
1309013574=begin original
1309113575
1309213576Returns the value of a symbolic link, if symbolic links are
1309313577implemented. If not, raises an exception. If there is a system
1309413578error, returns the undefined value and sets L<C<$!>|perlvar/$!> (errno).
1309513579If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1309613580
1309713581=end original
1309813582
1309913583シンボリックリンクが実装されていれば、シンボリックリンクの値を返します。
1310013584実装されていないときには、例外が発生します。
1310113585何らかのシステムエラーが検出されると、未定義値を返し、
1310213586L<C<$!>|perlvar/$!> (errno) を設定します。
1310313587EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1310413588
1310513589=begin original
1310613590
1310713591Portability issues: L<perlport/readlink>.
1310813592
1310913593=end original
1311013594
1311113595移植性の問題: L<perlport/readlink>。
1311213596
1311313597=item readpipe EXPR
1311413598
1311513599=item readpipe
1311613600X<readpipe>
1311713601
1311813602=for Pod::Functions execute a system command and collect standard output
1311913603
1312013604=begin original
1312113605
1312213606EXPR is executed as a system command.
1312313607The collected standard output of the command is returned.
1312413608In scalar context, it comes back as a single (potentially
1312513609multi-line) string. In list context, returns a list of lines
1312613610(however you've defined lines with L<C<$E<sol>>|perlvar/$E<sol>> (or
1312713611C<$INPUT_RECORD_SEPARATOR> in L<English>)).
1312813612This is the internal function implementing the C<qx/EXPR/>
1312913613operator, but you can use it directly. The C<qx/EXPR/>
13130operator is discussed in more detail in L<perlop/"I/O Operators">.
13614operator is discussed in more detail in L<perlop/"C<qx/I<STRING>/>">.
1313113615If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1313213616
1313313617=end original
1313413618
1313513619EXPR がシステムコマンドとして実行されます。
1313613620コマンドの標準出力の内容が返されます。
1313713621スカラコンテキストでは、単一の(内部的に複数行の)文字列を返します。
1313813622リストコンテキストでは、行のリストを返します
1313913623(但し、行は L<C<$E<sol>>|perlvar/$E<sol>> (または L<English> モジュールでは
1314013624C<$INPUT_RECORD_SEPARATOR> で定義されます)。
1314113625これは C<qx/EXPR/> 演算子を実装する内部関数ですが、直接使うことも出来ます。
13142C<qx/EXPR/> 演算子は L<perlop/"I/O Operators"> でより詳細に述べられています。
13626C<qx/EXPR/> 演算子は L<perlop/"C<qx/I<STRING>/>"> でより詳細に
13627述べられています。
1314313628EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1314413629
1314513630=item recv SOCKET,SCALAR,LENGTH,FLAGS
1314613631X<recv>
1314713632
1314813633=for Pod::Functions receive a message over a Socket
1314913634
1315013635=begin original
1315113636
1315213637Receives a message on a socket. Attempts to receive LENGTH characters
1315313638of data into variable SCALAR from the specified SOCKET filehandle.
1315413639SCALAR will be grown or shrunk to the length actually read. Takes the
1315513640same flags as the system call of the same name. Returns the address
1315613641of the sender if SOCKET's protocol supports this; returns an empty
1315713642string otherwise. If there's an error, returns the undefined value.
1315813643This call is actually implemented in terms of the L<recvfrom(2)> system call.
1315913644See L<perlipc/"UDP: Message Passing"> for examples.
1316013645
1316113646=end original
1316213647
1316313648ソケット上のメッセージを受信します。
1316413649指定されたファイルハンドル SOCKET から、変数 SCALAR に
1316513650LENGTH 文字のデータを読み込もうとします。
1316613651SCALAR は、実際に読まれた長さによって、大きくなったり、小さくなったりします。
1316713652同名のシステムコールと同じフラグが指定できます。
1316813653SOCKET のプロトコルが対応していれば、送信側のアドレスを返します。
1316913654エラー発生時には、未定義値を返します。
1317013655実際には、C の L<recvfrom(2)> を呼びます。
1317113656例については L<perlipc/"UDP: Message Passing"> を参照してください。
1317213657
1317313658=begin original
1317413659
13175Note the I<characters>: depending on the status of the socket, either
13660Note that if the socket has been marked as C<:utf8>, C<recv> will
13176(8-bit) bytes or characters are received. By default all sockets
13661throw an exception. The C<:encoding(...)> layer implicitly introduces
13177operate on bytes, but for example if the socket has been changed using
13662the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>.
13178L<C<binmode>|/binmode FILEHANDLE, LAYER> to operate with the
13179C<:encoding(UTF-8)> I/O layer (see the L<open> pragma), the I/O will
13180operate on UTF8-encoded Unicode
13181characters, not bytes. Similarly for the C<:encoding> layer: in that
13182case pretty much any characters can be read.
1318313663
1318413664=end original
1318513665
13186I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
13666ソケットが C<:utf8> としてマークされている場合、
13187文字受信ます
13667C<recv> は例外投げることに注意てください
13188デフォルトで全てのソケットはバイト処理しますが、例えばソケットが
13668C<:encoding(...)> 層暗黙に C<:utf8> 層導入します
13189L<C<binmode>|/binmode FILEHANDLE, LAYER> で C<:encoding(UTF-8)> I/O 層
13669L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。
13190(L<open> プラグマを参照してください) を使うように指定された場合、
13191I/O はバイトではなく、UTF8 エンコードされた Unicode 文字を操作します。
13192C<:encoding> 層も同様です:
13193この場合、ほとんど大体全ての文字が読み込めます。
1319413670
1319513671=item redo LABEL
1319613672X<redo>
1319713673
1319813674=item redo EXPR
1319913675
1320013676=item redo
1320113677
1320213678=for Pod::Functions start this loop iteration over again
1320313679
1320413680=begin original
1320513681
1320613682The L<C<redo>|/redo LABEL> command restarts the loop block without
1320713683evaluating the conditional again. The L<C<continue>|/continue BLOCK>
1320813684block, if any, is not executed. If
1320913685the LABEL is omitted, the command refers to the innermost enclosing
1321013686loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a
1321113687label name to be computed at run time, and is otherwise identical to C<redo
1321213688LABEL>. Programs that want to lie to themselves about what was just input
1321313689normally use this command:
1321413690
1321513691=end original
1321613692
1321713693L<C<redo>|/redo LABEL> コマンドは、条件を再評価しないで、ループブロックの
1321813694始めからもう一度実行を開始します。
1321913695L<C<continue>|/continue BLOCK> ブロックがあっても、実行されません。
1322013696LABEL が省略されると、コマンドは一番内側のループを参照します。
1322113697Perl 5.18.0 から利用可能な C<redo EXPR> 形式では、実行時に計算されるラベル名が
1322213698使えます; それ以外は C<redo LABEL> と同一です。
1322313699このコマンドは通常、自分への入力を欺くために使用します:
1322413700
1322513701 # a simpleminded Pascal comment stripper
1322613702 # (warning: assumes no { or } in strings)
1322713703 LINE: while (<STDIN>) {
1322813704 while (s|({.*}.*){.*}|$1 |) {}
1322913705 s|{.*}| |;
1323013706 if (s|{.*| |) {
1323113707 my $front = $_;
1323213708 while (<STDIN>) {
1323313709 if (/}/) { # end of comment?
1323413710 s|^|$front\{|;
1323513711 redo LINE;
1323613712 }
1323713713 }
1323813714 }
1323913715 print;
1324013716 }
1324113717
1324213718=begin original
1324313719
13244L<C<redo>|/redo LABEL> cannot be used to retry a block that returns a
13720L<C<redo>|/redo LABEL> cannot return a value from a block that typically
13245value such as C<eval {}>, C<sub {}>, or C<do {}>, and should not be used
13721returns a value, such as C<eval {}>, C<sub {}>, or C<do {}>. It will perform
13246to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
13722its flow control behavior, which precludes any return value. It should not be
13723used to exit a L<C<grep>|/grep BLOCK LIST> or L<C<map>|/map BLOCK LIST>
1324713724operation.
1324813725
1324913726=end original
1325013727
13251L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> のように値を返す
13728L<C<redo>|/redo LABEL> は C<eval {}>, C<sub {}>, C<do {}> といった
13252ブロックを繰りすのには使えません; また、L<C<grep>|/grep BLOCK LIST> や
13729典型的には値を返すブロックから値を返ません
13253L<C<map>|/map BLOCK LIST> 操作から抜けるのに使うべきでりません
13730これ、返値を不可能にするフロー制御の振る舞いを実行し
13731L<C<grep>|/grep BLOCK LIST> や L<C<map>|/map BLOCK LIST> 操作を終了するのに
13732使うべきではありません。
1325413733
1325513734=begin original
1325613735
1325713736Note that a block by itself is semantically identical to a loop
1325813737that executes once. Thus L<C<redo>|/redo LABEL> inside such a block
1325913738will effectively turn it into a looping construct.
1326013739
1326113740=end original
1326213741
1326313742ブロック自身は一回だけ実行されるループと文法的に同一であることに
1326413743注意してください。
1326513744従って、ブロックの中で L<C<redo>|/redo LABEL> を使うことで効果的に
1326613745ループ構造に変換します。
1326713746
1326813747=begin original
1326913748
1327013749See also L<C<continue>|/continue BLOCK> for an illustration of how
1327113750L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, and
1327213751L<C<redo>|/redo LABEL> work.
1327313752
1327413753=end original
1327513754
1327613755L<C<last>|/last LABEL>, L<C<next>|/next LABEL>, L<C<redo>|/redo LABEL> が
1327713756どのように働くかについては L<C<continue>|/continue BLOCK> も参照してください。
1327813757
1327913758=begin original
1328013759
1328113760Unlike most named operators, this has the same precedence as assignment.
1328213761It is also exempt from the looks-like-a-function rule, so
1328313762C<redo ("foo")."bar"> will cause "bar" to be part of the argument to
1328413763L<C<redo>|/redo LABEL>.
1328513764
1328613765=end original
1328713766
1328813767ほとんどの名前付き演算子と異なり、これは代入と同じ優先順位を持ちます。
1328913768また、関数のように見えるものの規則からも免れるので、C<redo ("foo")."bar"> と
1329013769すると "bar" は L<C<redo>|/redo LABEL> への引数の一部となります。
1329113770
1329213771=item ref EXPR
1329313772X<ref> X<reference>
1329413773
1329513774=item ref
1329613775
1329713776=for Pod::Functions find out the type of thing being referenced
1329813777
1329913778=begin original
1330013779
13301Returns a non-empty string if EXPR is a reference, the empty
13780Examines the value of EXPR, expecting it to be a reference, and returns
13302string otherwise. If EXPR is not specified, L<C<$_>|perlvar/$_> will be
13781a string giving information about the reference and the type of referent.
13303used. The value returned depends on the type of thing the reference is
13782If EXPR is not specified, L<C<$_>|perlvar/$_> will be used.
13304a reference to.
1330513783
1330613784=end original
1330713785
13308EXPR がリファレンスであれば、空でない文字列を返し、さもなくば、
13786Examines the value of
13309空文字列返します。
13787リファレンスと想定される EXPR の値調べて、
13310EXPR が指定されなければ、L<C<$_>|perlvar/$_> が使われま
13788そのリファレンスとリファレンス先の型に関る情報を表す
13311される値は、リファレンスが参照するものの型に依存します。
13789文字列を返します。
13790EXPR が指定されていない場合、L<C<$_>|perlvar/$_> が使われます。
1331213791
1331313792=begin original
1331413793
13315Builtin types include:
13794If the operand is not a reference, then the empty string will be returned.
13795An empty string will only be returned in this situation. C<ref> is often
13796useful to just test whether a value is a reference, which can be done
13797by comparing the result to the empty string. It is a common mistake
13798to use the result of C<ref> directly as a truth value: this goes wrong
13799because C<0> (which is false) can be returned for a reference.
1331613800
1331713801=end original
1331813802
13319組み込みの型には以下のものあります。
13803オペランドがリファレンスでない場合空文字列返されます。
13804空文字列はこの場合にのみ返されます。
13805結果を空文字列を比較することでできるので、
13806C<ref> は単にある値がリファレンスかどうかを調べるのにしばしば有用です。
13807C<ref> の結果を直接真の値として使うのは良くある誤りです:
13808リファレンスの場合に (偽である) C<0> が返されることがあるので、
13809これは誤りです。
1332013810
13321 SCALAR
13322 ARRAY
13323 HASH
13324 CODE
13325 REF
13326 GLOB
13327 LVALUE
13328 FORMAT
13329 IO
13330 VSTRING
13331 Regexp
13332
1333313811=begin original
1333413812
13335You can think of L<C<ref>|/ref EXPR> as a C<typeof> operator.
13813If the operand is a reference to a blessed object, then the name of
13814the class into which the referent is blessed will be returned. C<ref>
13815doesn't care what the physical type of the referent is; blessing takes
13816precedence over such concerns. Beware that exact comparison of C<ref>
13817results against a class name doesn't perform a class membership test:
13818a class's members also include objects blessed into subclasses, for
13819which C<ref> will return the name of the subclass. Also beware that
13820class names can clash with the built-in type names (described below).
1333613821
1333713822=end original
1333813823
13339L<C<ref>|/ref EXPR> は、C<typeof> 演算子ように考えることができます。
13824オペランドが bless されたオブジェクトへリファレンスの場合、
13825リファレンス先が bless されているクラス名が返されます。
13826C<ref> はリファレンス先の物理的な種類については気にしません;
13827bless されているかがそのような関心より優先されます。
13828C<ref> の結果とクラス名の正確な比較は、クラスの所属のテストを
13829実行しないことに注意してください:
13830C<ref> がサブクラスの名前を返す場合、
13831あるクラスのメンバはサブクラスに bless されているオブジェクトを
13832含んでいます。
13833クラス名は(後述する)組み込みの型名と衝突することにも注意してください。
1334013834
13341 if (ref($r) eq "HASH") {
13342 print "r is a reference to a hash.\n";
13343 }
13344 unless (ref($r)) {
13345 print "r is not a reference at all.\n";
13346 }
13347
1334813835=begin original
1334913836
13350The return value C<LVALUE> indicates a reference to an lvalue that is not
13837If the operand is a reference to an unblessed object, then the return
13351a variable. You get this from taking the reference of function calls like
13838value indicates the type of object. If the unblessed referent is not
13352L<C<pos>|/pos SCALAR> or
13839a scalar, then the return value will be one of the strings C<ARRAY>,
13353L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>. C<VSTRING> is
13840C<HASH>, C<CODE>, C<FORMAT>, or C<IO>, indicating only which kind of
13354returned if the reference points to a
13841object it is. If the unblessed referent is a scalar, then the return
13355L<version string|perldata/"Version Strings">.
13842value will be one of the strings C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>,
13843C<LVALUE>, or C<REGEXP>, depending on the kind of value the scalar
13844currently has. But note that C<qr//> scalars are created already
13845blessed, so C<ref qr/.../> will likely return C<Regexp>. Beware that
13846these built-in type names can also be used as
13847class names, so C<ref> returning one of these names doesn't unambiguously
13848indicate that the referent is of the kind to which the name refers.
1335613849
1335713850=end original
1335813851
13359返り値 C<LVALUE> は、変数ではない左辺値へのリファレンスを示します。
13852オペランドが bless されていないオブジェクトへのリファレンスの場合、
13360これ、L<C<pos>|/pos SCALAR> や
13853返り値オブジェクトの型を示します。
13361L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> のよう関数呼び出しの
13854bless されていいリファレンス先がスカラではない場合、
13362リファレンスから得られま
13855返り値はオブジェクトの種類を示
13363C<VSTRING> は、リファレンスが L<version string|perldata/"Version Strings">
13856C<ARRAY>, C<HASH>, C<CODE>, C<FORMAT>, C<IO> のいずれかの文字列です。
13364指してい場合に返されます。
13857bless されていないリファレンス先がスカラの場合
13858返り値はそのスカラが現在保持している種類に依存して、
13859C<SCALAR>, C<VSTRING>, C<REF>, C<GLOB>, C<LVALUE>, C<REGEXP> の
13860いずれかの文字列です。
13861しかし、C<qr//> は既に bless されて作成されるので、
13862C<ref qr/.../> はおそらく C<Regexp> を返すことに注意してください。
13863これらの組み込み型名はまたクラス名として使われることができるので、
13864C<ref> がこれらの名前の一つを返すことは、
13865明らかにリファレンス先がその名前が示している種類のものであることを
13866示しているわけではないことに注意してください。
1336513867
1336613868=begin original
1336713869
13368The result C<Regexp> indicates that the argument is a regular expression
13870The ambiguity between built-in type names and class names significantly
13369resulting from L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>>.
13871limits the utility of C<ref>. For unambiguous information, use
13872L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> for information about
13873blessing, and L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> for
13874information about physical types. Use L<the C<isa> method|UNIVERSAL/C<<
13875$obj->isa( TYPE ) >>> for class membership tests, though one must be
13876sure of blessedness before attempting a method call.
1337013877
1337113878=end original
1337213879
13373C<Regexp> う結果は、引数が
13880組み込み型とクラス名の間の曖昧さは C<ref> の有用性を大きく制限してます。
13374L<C<qrE<sol>E<sol>>|/qrE<sol>STRINGE<sol>> からの結果であ
13881曖昧でない情報のためには、bless に関す情報については
13375正規表現であること意味します。
13882L<C<Scalar::Util::blessed()>|Scalar::Util/blessed>
13883物理的な型の情報については
13884L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> を使ってください。
13885クラスの所属メンバテストには
13886L<the C<isa> method|UNIVERSAL/C<<
13887$obj->isa( TYPE ) >>> を使ってください;
13888但し、メソッド呼び出しを試みる前に bless されていることを
13889確認しなければなりません。
1337613890
1337713891=begin original
1337813892
13379If the referenced object has been blessed into a package, then that package
13893See also L<perlref> and L<perlobj>.
13380name is returned instead. But don't use that, as it's now considered
13381"bad practice". For one reason, an object could be using a class called
13382C<Regexp> or C<IO>, or even C<HASH>. Also, L<C<ref>|/ref EXPR> doesn't
13383take into account subclasses, like
13384L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> does.
1338513894
1338613895=end original
1338713896
13388参照されるオブジェクトが、何らかのパッケージに bless されたのであれば、
13897L<perlref> と L<perlobj> 参照してください。
13389これらの代わりに、そのパッケージ名が返されます。
13390しかし、これは今では「悪い習慣」と考えられているので、しないでください。
13391理由の一つは、オブジェクトは C<Regexp>, C<IO> や C<HASH> などと呼ばれる
13392クラスを使うかも知れないからです。
13393また、L<C<ref>|/ref EXPR> は
13394L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> のようにサブクラスを
13395考慮したりはしません。
1339613898
13397=begin original
13398
13399Instead, use L<C<blessed>|Scalar::Util/blessed> (in the L<Scalar::Util>
13400module) for boolean checks, L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>>
13401for specific class checks and L<C<reftype>|Scalar::Util/reftype> (also
13402from L<Scalar::Util>) for type checks. (See L<perlobj> for details and
13403a L<C<blessed>|Scalar::Util/blessed>/L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>>
13404example.)
13405
13406=end original
13407
13408代わりに、真偽値チェックには (L<Scalar::Util> モジュールにある)
13409L<C<blessed>|Scalar::Util/blessed> を、特定のクラスのチェックには
13410L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> を、型のチェックには
13411(これも L<Scalar::Util> にある) L<C<reftype>|Scalar::Util/reftype> を
13412使ってください。
13413(詳細と L<C<blessed>|Scalar::Util/blessed>/
13414L<C<isa>|UNIVERSAL/C<< $obj->isa( TYPE ) >>> の例については
13415L<perlobj> を参照してください。)
13416
13417=begin original
13418
13419See also L<perlref>.
13420
13421=end original
13422
13423L<perlref> も参照してください。
13424
1342513899=item rename OLDNAME,NEWNAME
1342613900X<rename> X<move> X<mv> X<ren>
1342713901
1342813902=for Pod::Functions change a filename
1342913903
1343013904=begin original
1343113905
1343213906Changes the name of a file; an existing file NEWNAME will be
1343313907clobbered. Returns true for success, false otherwise.
1343413908
1343513909=end original
1343613910
1343713911ファイルの名前を変更します; NEWNAME というファイルが既に存在した場合、
1343813912上書きされるかもしれません。
1343913913成功時には真を、さもなければ偽を返します。
1344013914
1344113915=begin original
1344213916
1344313917Behavior of this function varies wildly depending on your system
1344413918implementation. For example, it will usually not work across file system
1344513919boundaries, even though the system I<mv> command sometimes compensates
1344613920for this. Other restrictions include whether it works on directories,
1344713921open files, or pre-existing files. Check L<perlport> and either the
1344813922L<rename(2)> manpage or equivalent system documentation for details.
1344913923
1345013924=end original
1345113925
1345213926この関数の振る舞いはシステムの実装に大きく依存して異なります。
1345313927例えば、普通はファイルシステムにまたがってパス名を付け替えることはできません;
1345413928システムの I<mv> がこれを補完している場合でもそうです。
1345513929その他の制限には、ディレクトリ、オープンしているファイル、既に存在している
1345613930ファイルに対して使えるか、といったことを含みます。
1345713931詳しくは、L<perlport> および L<rename(2)> man ページあるいは同様の
1345813932システムドキュメントを参照してください。
1345913933
1346013934=begin original
1346113935
1346213936For a platform independent L<C<move>|File::Copy/move> function look at
1346313937the L<File::Copy> module.
1346413938
1346513939=end original
1346613940
1346713941プラットフォームに依存しない L<C<move>|File::Copy/move> 関数については
1346813942L<File::Copy> モジュールを参照してください。
1346913943
1347013944=begin original
1347113945
1347213946Portability issues: L<perlport/rename>.
1347313947
1347413948=end original
1347513949
1347613950移植性の問題: L<perlport/rename>。
1347713951
1347813952=item require VERSION
1347913953X<require>
1348013954
1348113955=item require EXPR
1348213956
1348313957=item require
1348413958
1348513959=for Pod::Functions load in external functions from a library at runtime
1348613960
1348713961=begin original
1348813962
1348913963Demands a version of Perl specified by VERSION, or demands some semantics
1349013964specified by EXPR or by L<C<$_>|perlvar/$_> if EXPR is not supplied.
1349113965
1349213966=end original
1349313967
1349413968VERSION で指定される Perl のバージョンを要求するか、
1349513969EXPR (省略時には L<C<$_>|perlvar/$_>) によって指定されるいくつかの動作を
1349613970要求します。
1349713971
1349813972=begin original
1349913973
13500VERSION may be either a numeric argument such as 5.006, which will be
13974VERSION may be either a literal such as v5.24.1, which will be
13501compared to L<C<$]>|perlvar/$]>, or a literal of the form v5.6.1, which
13975compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in L<English>),
13502will be compared to L<C<$^V>|perlvar/$^V> (or C<$PERL_VERSION> in
13976or a numeric argument of the form 5.024001, which will be compared to
13503L<English>). An exception is raised if VERSION is greater than the
13977L<C<$]>|perlvar/$]>. An exception is raised if VERSION is greater than
13504version of the current Perl interpreter. Compare with
13978the version of the current Perl interpreter. Compare with
1350513979L<C<use>|/use Module VERSION LIST>, which can do a similar check at
1350613980compile time.
1350713981
1350813982=end original
1350913983
13510VERSION は 5.006 のような数値(L<C<$]>|perlvar/$]> と比較されます)か、
13984VERSION は、v5.24.1 のようなリテラル
13511v5.6.1 の形 (L<C<$^V>|perlvar/$^V> (または L<English> モジュールでは
13985(L<C<$^V>|perlvar/$^V> (または L<English> モジュールでは
13512C<$PERL_VERSION>) と比較されます)で指定します。
13986C<$PERL_VERSION>) と比較されます) か、
139875.024001 の数値形式(L<C<$]>|perlvar/$]> と比較されます)で指定します。
1351313988VERSION が Perl の現在のバージョンより大きいと、例外が発生します。
1351413989L<C<use>|/use Module VERSION LIST> と似ていますが、これはコンパイル時に
1351513990チェックされます。
1351613991
1351713992=begin original
1351813993
13519Specifying VERSION as a literal of the form v5.6.1 should generally be
13994Specifying VERSION as a numeric argument of the form 5.024001 should
13520avoided, because it leads to misleading error messages under earlier
13995generally be avoided as older less readable syntax compared to
13521versions of Perl that do not support this syntax. The equivalent numeric
13996v5.24.1. Before perl 5.8.0 (released in 2002), the more verbose numeric
13522version should be used instead.
13997form was the only supported syntax, which is why you might see it in
13998older code.
1352313999
1352414000=end original
1352514001
13526VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
14002VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです;
13527なぜなら、この文法対応していない Perl の初期のバージョン
14003v5.24.1 比べより古く読みにく文法だからす。
13528誤解せるうなエラーメッセージが出るからす。
14004(2002 年にリリースれた) perl 5.8.0 り前は、より冗長な
13529代わりに等価な数値表現を使うべきす。
14005数値形式が唯一対応している文法した; これが古いコードでこれを
14006見るかも知れない理由です。
1353014007
1353114008=begin original
1353214009
13533 require v5.6.1; # run time version check
14010 require v5.24.1; # run time version check
13534 require 5.6.1; # ditto
14011 require 5.24.1; # ditto
13535 require 5.006_001; # ditto; preferred for backwards
14012 require 5.024_001; # ditto; older syntax compatible
13536 compatibility
14013 with perl 5.6
1353714014
1353814015=end original
1353914016
13540 require v5.6.1; # 実行時バージョンチェック
14017 require v5.24.1; # 実行時バージョンチェック
13541 require 5.6.1; # 同様
14018 require 5.24.1; # 同様
13542 require 5.006_001; # 同様; 後方互換性のためには望まし
14019 require 5.024_001; # 同様; perl 5.6 と互換性のある古文法
1354314020
1354414021=begin original
1354514022
1354614023Otherwise, L<C<require>|/require VERSION> demands that a library file be
1354714024included if it hasn't already been included. The file is included via
1354814025the do-FILE mechanism, which is essentially just a variety of
1354914026L<C<eval>|/eval EXPR> with the
1355014027caveat that lexical variables in the invoking script will be invisible
1355114028to the included code. If it were implemented in pure Perl, it
1355214029would have semantics similar to the following:
1355314030
1355414031=end original
1355514032
1355614033それ以外の場合には、L<C<require>|/require VERSION> は、既に
1355714034読み込まれていないときに読み込むライブラリファイルを要求するものとなります。
1355814035そのファイルは、基本的には L<C<eval>|/eval EXPR> の一種である、
1355914036do-FILE によって読み込まれますが、起動したスクリプトのレキシカル変数は
1356014037読み込まれたコードから見えないという欠点があります。
1356114038ピュア Perl で実装した場合、意味的には、次のようなサブルーチンと
1356214039同じようなものです:
1356314040
1356414041 use Carp 'croak';
1356514042 use version;
1356614043
1356714044 sub require {
1356814045 my ($filename) = @_;
1356914046 if ( my $version = eval { version->parse($filename) } ) {
1357014047 if ( $version > $^V ) {
1357114048 my $vn = $version->normal;
1357214049 croak "Perl $vn required--this is only $^V, stopped";
1357314050 }
1357414051 return 1;
1357514052 }
1357614053
1357714054 if (exists $INC{$filename}) {
1357814055 return 1 if $INC{$filename};
1357914056 croak "Compilation failed in require";
1358014057 }
1358114058
1358214059 foreach $prefix (@INC) {
1358314060 if (ref($prefix)) {
1358414061 #... do other stuff - see text below ....
1358514062 }
1358614063 # (see text below about possible appending of .pmc
1358714064 # suffix to $filename)
1358814065 my $realfilename = "$prefix/$filename";
1358914066 next if ! -e $realfilename || -d _ || -b _;
1359014067 $INC{$filename} = $realfilename;
1359114068 my $result = do($realfilename);
1359214069 # but run in caller's namespace
1359314070
1359414071 if (!defined $result) {
1359514072 $INC{$filename} = undef;
1359614073 croak $@ ? "$@Compilation failed in require"
1359714074 : "Can't locate $filename: $!\n";
1359814075 }
1359914076 if (!$result) {
1360014077 delete $INC{$filename};
1360114078 croak "$filename did not return true value";
1360214079 }
1360314080 $! = 0;
1360414081 return $result;
1360514082 }
1360614083 croak "Can't locate $filename in \@INC ...";
1360714084 }
1360814085
1360914086=begin original
1361014087
1361114088Note that the file will not be included twice under the same specified
1361214089name.
1361314090
1361414091=end original
1361514092
1361614093ファイルは、同じ名前で 2 回読み込まれることはないことに注意してください。
1361714094
1361814095=begin original
1361914096
1362014097The file must return true as the last statement to indicate
1362114098successful execution of any initialization code, so it's customary to
1362214099end such a file with C<1;> unless you're sure it'll return true
1362314100otherwise. But it's better just to put the C<1;>, in case you add more
1362414101statements.
1362514102
1362614103=end original
1362714104
1362814105初期化コードの実行がうまくいったことを示すために、ファイルは真を
1362914106返さなければならないので、真を返すようになっている自信がある場合を除いては、
1363014107ファイルの最後に C<1;> と書くのが習慣です。
1363114108しかし、実行文を追加するような場合に備えて、C<1;> と書いておいた方が良いです。
1363214109
1363314110=begin original
1363414111
1363514112If EXPR is a bareword, L<C<require>|/require VERSION> assumes a F<.pm>
1363614113extension and replaces C<::> with C</> in the filename for you,
1363714114to make it easy to load standard modules. This form of loading of
13638modules does not risk altering your namespace.
14115modules does not risk altering your namespace, however it will autovivify
14116the stash for the required module.
1363914117
1364014118=end original
1364114119
1364214120EXPR が裸の単語であるときには、標準モジュールのロードを簡単にするように、
1364314121L<C<require>|/require VERSION> は拡張子が F<.pm> であり、C<::> を C</> に
1364414122変えたものがファイル名であると仮定します。
13645この形式のモジュールロードは、名前空間を変更してしまう危険はありません
14123この形式のモジュールロードは、名前空間を変更してしまう危険はありませんが、
14124要求されたモジュールのためのスタッシュが自動有効化されます。
1364614125
1364714126=begin original
1364814127
1364914128In other words, if you try this:
1365014129
1365114130=end original
1365214131
1365314132言い換えると、以下のようにすると:
1365414133
1365514134 require Foo::Bar; # a splendid bareword
1365614135
1365714136=begin original
1365814137
1365914138The require function will actually look for the F<Foo/Bar.pm> file in the
13660directories specified in the L<C<@INC>|perlvar/@INC> array.
14139directories specified in the L<C<@INC>|perlvar/@INC> array, and it will
14140autovivify the C<Foo::Bar::> stash at compile time.
1366114141
1366214142=end original
1366314143
1366414144require 関数は L<C<@INC>|perlvar/@INC> 配列で指定されたディレクトリにある
13665F<Foo/Bar.pm> ファイルを探します。
14145F<Foo/Bar.pm> ファイルを探し、コンパイル時に
14146C<Foo::Bar::> のスタッシュを自動有効化します。
1366614147
1366714148=begin original
1366814149
1366914150But if you try this:
1367014151
1367114152=end original
1367214153
1367314154しかし、以下のようにすると:
1367414155
1367514156 my $class = 'Foo::Bar';
1367614157 require $class; # $class is not a bareword
1367714158 #or
1367814159 require "Foo::Bar"; # not a bareword because of the ""
1367914160
1368014161=begin original
1368114162
1368214163The require function will look for the F<Foo::Bar> file in the
1368314164L<C<@INC>|perlvar/@INC> array and
1368414165will complain about not finding F<Foo::Bar> there. In this case you can do:
1368514166
1368614167=end original
1368714168
1368814169require 関数は L<C<@INC>|perlvar/@INC> 配列の F<Foo::Bar> ファイルを探し、
1368914170おそらくそこに F<Foo::Bar> がないと文句をいうことになるでしょう。
13690このような場合には、以下のようにします:
14171このような場合には、以下のように:
1369114172
1369214173 eval "require $class";
1369314174
1369414175=begin original
1369514176
14177or you could do
14178
14179=end original
14180
14181あるいは次のようにも出来ます
14182
14183 require "Foo/Bar.pm";
14184
14185=begin original
14186
14187Neither of these forms will autovivify any stashes at compile time and
14188only have run time effects.
14189
14190=end original
14191
14192これらのどちらもコンパイル時にスタッシュを自動有効化せず、
14193実行時の効果のみを持ちます。
14194
14195=begin original
14196
1369614197Now that you understand how L<C<require>|/require VERSION> looks for
1369714198files with a bareword argument, there is a little extra functionality
1369814199going on behind the scenes. Before L<C<require>|/require VERSION> looks
1369914200for a F<.pm> extension, it will first look for a similar filename with a
1370014201F<.pmc> extension. If this file is found, it will be loaded in place of
13701any file ending in a F<.pm> extension.
14202any file ending in a F<.pm> extension. This applies to both the explicit
14203C<require "Foo/Bar.pm";> form and the C<require Foo::Bar;> form.
1370214204
1370314205=end original
1370414206
1370514207引数が裸の単語の場合、L<C<require>|/require VERSION> がどのようにファイルを
1370614208探すかを理解してください; 水面下でちょっとした追加の機能があります。
1370714209L<C<require>|/require VERSION> が拡張子 F<.pm> のファイルを探す前に、まず
1370814210拡張子 F<.pmc> を持つファイルを探します。
1370914211このファイルが見つかると、このファイルが拡張子 F<.pm> の代わりに
1371014212読み込まれます。
14213これは明示的な C<require "Foo/Bar.pm";> 形式と C<require Foo::Bar;> 形式の
14214両方に適用されます。
1371114215
1371214216=begin original
1371314217
1371414218You can also insert hooks into the import facility by putting Perl code
1371514219directly into the L<C<@INC>|perlvar/@INC> array. There are three forms
1371614220of hooks: subroutine references, array references, and blessed objects.
1371714221
1371814222=end original
1371914223
1372014224L<C<@INC>|perlvar/@INC> 配列に直接 Perl コードを入れることで、インポート機能に
1372114225フックを挿入できます。
13722142263 種類のフックがあります: サブルーチンリファレンス、配列リファレンス、
1372314227bless されたオブジェクトです。
1372414228
1372514229=begin original
1372614230
1372714231Subroutine references are the simplest case. When the inclusion system
1372814232walks through L<C<@INC>|perlvar/@INC> and encounters a subroutine, this
1372914233subroutine gets called with two parameters, the first a reference to
1373014234itself, and the second the name of the file to be included (e.g.,
1373114235F<Foo/Bar.pm>). The subroutine should return either nothing or else a
1373214236list of up to four values in the following order:
1373314237
1373414238=end original
1373514239
1373614240サブルーチンへのリファレンスは一番単純な場合です。
1373714241インクルード機能が L<C<@INC>|perlvar/@INC> を走査してサブルーチンに
1373814242出会った場合、このサブルーチンは二つの引数と共に呼び出されます;
1373914243一つ目は自身へのリファレンス、二つ目はインクルードされるファイル名
1374014244(F<Foo/Bar.pm> など)です。
1374114245サブルーチンは何も返さないか、以下の順で最大四つの値のリストを返します。
1374214246
1374314247=over
1374414248
1374514249=item 1
1374614250
1374714251=begin original
1374814252
1374914253A reference to a scalar, containing any initial source code to prepend to
1375014254the file or generator output.
1375114255
1375214256=end original
1375314257
1375414258ファイルやジェネレータの出力の前に追加される初期化ソースコードを含む
1375514259スカラへのリファレンス。
1375614260
1375714261=item 2
1375814262
1375914263=begin original
1376014264
1376114265A filehandle, from which the file will be read.
1376214266
1376314267=end original
1376414268
1376514269ファイルが読み込まれるファイルハンドル。
1376614270
1376714271=item 3
1376814272
1376914273=begin original
1377014274
1377114275A reference to a subroutine. If there is no filehandle (previous item),
1377214276then this subroutine is expected to generate one line of source code per
1377314277call, writing the line into L<C<$_>|perlvar/$_> and returning 1, then
1377414278finally at end of file returning 0. If there is a filehandle, then the
1377514279subroutine will be called to act as a simple source filter, with the
1377614280line as read in L<C<$_>|perlvar/$_>.
1377714281Again, return 1 for each valid line, and 0 after all lines have been
1377814282returned.
14283For historical reasons the subroutine will receive a meaningless argument
14284(in fact always the numeric value zero) as C<$_[0]>.
1377914285
1378014286=end original
1378114287
1378214288サブルーチンへのリファレンス。
1378314289(一つ前のアイテムである)ファイルハンドルがない場合、サブルーチンは呼び出し毎に
1378414290一行のソースコードを生成し、その行を L<C<$_>|perlvar/$_> に書き込んで 1 を
1378514291返し、それから最終的にファイル終端で 0 を返すものと想定されます。
1378614292ファイルハンドルがある場合、サブルーチンは単純なソースフィルタとして
1378714293振舞うように呼び出され、行は L<C<$_>|perlvar/$_> から読み込まれます。
1378814294再び、有効な行ごとに 1 を返し、全ての行を返した後では 0 を返します。
14295歴史的な理由により、サブルーチンは C<$_[0]> として意味のない引数
14296(実際には常に数値 0) を受け取ります。
1378914297
1379014298=item 4
1379114299
1379214300=begin original
1379314301
13794Optional state for the subroutine. The state is passed in as C<$_[1]>. A
14302Optional state for the subroutine. The state is passed in as C<$_[1]>.
13795reference to the subroutine itself is passed in as C<$_[0]>.
1379614303
1379714304=end original
1379814305
1379914306サブルーチンのための状態(オプション)。
1380014307状態は C<$_[1]> として渡されます。
13801サブルーチンへのリファレンス自身は C<$_[0]> として渡されます。
1380214308
1380314309=back
1380414310
1380514311=begin original
1380614312
1380714313If an empty list, L<C<undef>|/undef EXPR>, or nothing that matches the
1380814314first 3 values above is returned, then L<C<require>|/require VERSION>
1380914315looks at the remaining elements of L<C<@INC>|perlvar/@INC>.
1381014316Note that this filehandle must be a real filehandle (strictly a typeglob
1381114317or reference to a typeglob, whether blessed or unblessed); tied filehandles
1381214318will be ignored and processing will stop there.
1381314319
1381414320=end original
1381514321
1381614322空リスト、L<C<undef>|/undef EXPR>、または上記の最初の三つの値のどれとも
1381714323一致しないものが返されると、L<C<require>|/require VERSION> は
1381814324L<C<@INC>|perlvar/@INC> の残りの要素を見ます。
1381914325このファイルハンドルは実際のファイルハンドル(厳密には型グロブ、型グロブへの
1382014326リファレンス、bless されているかに関わらず)でなければなりません;
1382114327tie されたファイルハンドルは無視され、返り値の処理はそこで停止します。
1382214328
1382314329=begin original
1382414330
1382514331If the hook is an array reference, its first element must be a subroutine
1382614332reference. This subroutine is called as above, but the first parameter is
1382714333the array reference. This lets you indirectly pass arguments to
1382814334the subroutine.
1382914335
1383014336=end original
1383114337
1383214338フックが配列のリファレンスの場合、その最初の要素はサブルーチンへの
1383314339リファレンスでなければなりません。
1383414340このサブルーチンは上述のように呼び出されますが、その最初の引数は
1383514341配列のリファレンスです。
1383614342これによって、間接的にサブルーチンに引数を渡すことが出来ます。
1383714343
1383814344=begin original
1383914345
1384014346In other words, you can write:
1384114347
1384214348=end original
1384314349
1384414350言い換えると、以下のように書いたり:
1384514351
1384614352 push @INC, \&my_sub;
1384714353 sub my_sub {
1384814354 my ($coderef, $filename) = @_; # $coderef is \&my_sub
1384914355 ...
1385014356 }
1385114357
1385214358=begin original
1385314359
1385414360or:
1385514361
1385614362=end original
1385714363
1385814364または以下のように書けます:
1385914365
1386014366 push @INC, [ \&my_sub, $x, $y, ... ];
1386114367 sub my_sub {
1386214368 my ($arrayref, $filename) = @_;
1386314369 # Retrieve $x, $y, ...
1386414370 my (undef, @parameters) = @$arrayref;
1386514371 ...
1386614372 }
1386714373
1386814374=begin original
1386914375
1387014376If the hook is an object, it must provide an C<INC> method that will be
1387114377called as above, the first parameter being the object itself. (Note that
1387214378you must fully qualify the sub's name, as unqualified C<INC> is always forced
1387314379into package C<main>.) Here is a typical code layout:
1387414380
1387514381=end original
1387614382
1387714383フックがオブジェクトの場合、C<INC> メソッドを提供している必要があります;
1387814384それが、最初の引数をオブジェクト自身として上述のように呼び出されます。
1387914385(修飾されていない C<INC> は常にパッケージ C<main> に強制されるため、
1388014386サブルーチン名は完全修飾する必要があることに注意してください。)
1388114387以下は典型的なコードレイアウトです:
1388214388
1388314389 # In Foo.pm
1388414390 package Foo;
1388514391 sub new { ... }
1388614392 sub Foo::INC {
1388714393 my ($self, $filename) = @_;
1388814394 ...
1388914395 }
1389014396
1389114397 # In the main program
1389214398 push @INC, Foo->new(...);
1389314399
1389414400=begin original
1389514401
1389614402These hooks are also permitted to set the L<C<%INC>|perlvar/%INC> entry
1389714403corresponding to the files they have loaded. See L<perlvar/%INC>.
1389814404
1389914405=end original
1390014406
1390114407これらのフックは、読み込まれるファイルに対応する
1390214408L<C<%INC>|perlvar/%INC> エントリをセットすることも許可します。
1390314409L<perlvar/%INC> を参照してください。
1390414410
1390514411=begin original
1390614412
1390714413For a yet-more-powerful import facility, see
1390814414L<C<use>|/use Module VERSION LIST> and L<perlmod>.
1390914415
1391014416=end original
1391114417
1391214418より強力な import 機能については、このドキュメントの
1391314419L<C<use>|/use Module VERSION LIST> の項と、L<perlmod> を参照してください。
1391414420
1391514421=item reset EXPR
1391614422X<reset>
1391714423
1391814424=item reset
1391914425
1392014426=for Pod::Functions clear all variables of a given name
1392114427
1392214428=begin original
1392314429
1392414430Generally used in a L<C<continue>|/continue BLOCK> block at the end of a
1392514431loop to clear variables and reset C<m?pattern?> searches so that they
1392614432work again. The
1392714433expression is interpreted as a list of single characters (hyphens
13928allowed for ranges). All variables and arrays beginning with one of
14434allowed for ranges). All variables (scalars, arrays, and hashes)
14435in the current package beginning with one of
1392914436those letters are reset to their pristine state. If the expression is
1393014437omitted, one-match searches (C<m?pattern?>) are reset to match again.
1393114438Only resets variables or searches in the current package. Always returns
13932144391. Examples:
1393314440
1393414441=end original
1393514442
1393614443通常、ループの最後に、変数をクリアし、C<m?pattern?> 検索を再び動作するように
1393714444リセットするため、L<C<continue>|/continue BLOCK> ブロックで使われます。
1393814445EXPR は、文字を並べたもの (範囲を指定するのに、ハイフンが使えます) と
1393914446解釈されます。
13940名前がその文字のいずれかで始まる変数や配列は、
14447名前がその文字のいずれかで始まる、現在のパッケージの全ての変数
14448(スカラ、配列、ハッシュ)は、
1394114449最初の状態にリセットされます。
1394214450EXPR を省略すると、1 回検索 (C<m?pattern?>) を再びマッチするように
1394314451リセットできます。
1394414452カレントパッケージの変数もしくは検索だけがリセットされます。
1394514453常に 1 を返します。
1394614454例:
1394714455
1394814456 reset 'X'; # reset all X variables
1394914457 reset 'a-z'; # reset lower case variables
1395014458 reset; # just reset m?one-time? searches
1395114459
1395214460=begin original
1395314461
1395414462Resetting C<"A-Z"> is not recommended because you'll wipe out your
1395514463L<C<@ARGV>|perlvar/@ARGV> and L<C<@INC>|perlvar/@INC> arrays and your
1395614464L<C<%ENV>|perlvar/%ENV> hash.
13957Resets only package variables; lexical variables are unaffected, but
13958they clean themselves up on scope exit anyway, so you'll probably want
13959to use them instead. See L<C<my>|/my VARLIST>.
1396014465
1396114466=end original
1396214467
1396314468reset C<"A-Z"> とすると、L<C<@ARGV>|perlvar/@ARGV>,
1396414469L<C<@INC>|perlvar/@INC> 配列や L<C<%ENV>|perlvar/%ENV> ハッシュも
1396514470なくなってしまうので、止めた方が良いでしょう。
14471
14472=begin original
14473
14474Resets only package variables; lexical variables are unaffected, but
14475they clean themselves up on scope exit anyway, so you'll probably want
14476to use them instead. See L<C<my>|/my VARLIST>.
14477
14478=end original
14479
1396614480パッケージ変数だけがリセットされます; レキシカル変数は影響を受けませんが、
1396714481スコープから外れれば自動的に綺麗になるので、これからはこちらを
1396814482使うようにした方がよいでしょう。
1396914483L<C<my>|/my VARLIST> を参照してください。
1397014484
1397114485=item return EXPR
1397214486X<return>
1397314487
1397414488=item return
1397514489
1397614490=for Pod::Functions get out of a function early
1397714491
1397814492=begin original
1397914493
1398014494Returns from a subroutine, L<C<eval>|/eval EXPR>,
1398114495L<C<do FILE>|/do EXPR>, L<C<sort>|/sort SUBNAME LIST> block or regex
13982eval block (but not a L<C<grep>|/grep BLOCK LIST> or
14496eval block (but not a L<C<grep>|/grep BLOCK LIST>,
13983L<C<map>|/map BLOCK LIST> block) with the value
14497L<C<map>|/map BLOCK LIST>, or L<C<do BLOCK>|/do BLOCK> block) with the value
1398414498given in EXPR. Evaluation of EXPR may be in list, scalar, or void
1398514499context, depending on how the return value will be used, and the context
1398614500may vary from one execution to the next (see
1398714501L<C<wantarray>|/wantarray>). If no EXPR
1398814502is given, returns an empty list in list context, the undefined value in
1398914503scalar context, and (of course) nothing at all in void context.
1399014504
1399114505=end original
1399214506
1399314507サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR>,
1399414508L<C<sort>|/sort SUBNAME LIST> ブロックまたは正規表現 eval ブロック
13995(但し L<C<grep>|/grep BLOCK LIST>
14509(但し L<C<grep>|/grep BLOCK LIST>,
13996L<C<map>|/map BLOCK LIST> ブロックではない) から
14510L<C<map>|/map BLOCK LIST>, L<C<do BLOCK>|/do BLOCK> ブロックではない) から
1399714511EXPR で与えられた値をもって、リターンします。
1399814512EXPR の評価は、返り値がどのように使われるかによってリスト、スカラ、
1399914513無効コンテキストになります; またコンテキストは実行毎に変わります
1400014514(L<C<wantarray>|/wantarray> を参照してください)。
1400114515EXPR が指定されなかった場合は、リストコンテキストでは空リストを、
1400214516スカラコンテキストでは未定義値を返します; そして(もちろん)
1400314517無効コンテキストでは何も返しません。
1400414518
1400514519=begin original
1400614520
1400714521(In the absence of an explicit L<C<return>|/return EXPR>, a subroutine,
1400814522L<C<eval>|/eval EXPR>,
1400914523or L<C<do FILE>|/do EXPR> automatically returns the value of the last expression
1401014524evaluated.)
1401114525
1401214526=end original
1401314527
1401414528(サブルーチン, L<C<eval>|/eval EXPR>, L<C<do FILE>|/do EXPR> に明示的に
1401514529L<C<return>|/return EXPR> がなければ、最後に評価された値で、
1401614530自動的にリターンします。)
1401714531
1401814532=begin original
1401914533
1402014534Unlike most named operators, this is also exempt from the
1402114535looks-like-a-function rule, so C<return ("foo")."bar"> will
1402214536cause C<"bar"> to be part of the argument to L<C<return>|/return EXPR>.
1402314537
1402414538=end original
1402514539
1402614540ほとんどの名前付き演算子と異なり、関数のように見えるものの規則からも
1402714541免れるので、C<return ("foo")."bar"> とすると C<"bar"> は
1402814542L<C<return>|/return EXPR> への引数の一部となります。
1402914543
1403014544=item reverse LIST
1403114545X<reverse> X<rev> X<invert>
1403214546
1403314547=for Pod::Functions flip a string or a list
1403414548
1403514549=begin original
1403614550
1403714551In list context, returns a list value consisting of the elements
1403814552of LIST in the opposite order. In scalar context, concatenates the
1403914553elements of LIST and returns a string value with all characters
1404014554in the opposite order.
1404114555
1404214556=end original
1404314557
1404414558リストコンテキストでは、LIST を構成する要素を逆順に並べた
1404514559リスト値を返します。
1404614560スカラコンテキストでは、LIST の要素を連結して、
1404714561全ての文字を逆順にした文字列を返します。
1404814562
1404914563 print join(", ", reverse "world", "Hello"); # Hello, world
1405014564
1405114565 print scalar reverse "dlrow ,", "olleH"; # Hello, world
1405214566
1405314567=begin original
1405414568
1405514569Used without arguments in scalar context, L<C<reverse>|/reverse LIST>
1405614570reverses L<C<$_>|perlvar/$_>.
1405714571
1405814572=end original
1405914573
1406014574スカラコンテキストで引数なしで使うと、L<C<reverse>|/reverse LIST> は
1406114575L<C<$_>|perlvar/$_> を逆順にします。
1406214576
1406314577 $_ = "dlrow ,olleH";
1406414578 print reverse; # No output, list context
1406514579 print scalar reverse; # Hello, world
1406614580
1406714581=begin original
1406814582
1406914583Note that reversing an array to itself (as in C<@a = reverse @a>) will
1407014584preserve non-existent elements whenever possible; i.e., for non-magical
1407114585arrays or for tied arrays with C<EXISTS> and C<DELETE> methods.
1407214586
1407314587=end original
1407414588
1407514589(C<@a = reverse @a> のように) 反転した配列を自分自身に代入すると、
1407614590存在しない要素は可能なら(つまりマジカルでない配列や
1407714591C<EXISTS> と C<DELETE> メソッドがある tie された配列)
1407814592いつでも保存されることに注意してください。
1407914593
1408014594=begin original
1408114595
1408214596This operator is also handy for inverting a hash, although there are some
1408314597caveats. If a value is duplicated in the original hash, only one of those
1408414598can be represented as a key in the inverted hash. Also, this has to
1408514599unwind one hash and build a whole new one, which may take some time
1408614600on a large hash, such as from a DBM file.
1408714601
1408814602=end original
1408914603
1409014604この演算子はハッシュの逆順にするのにも便利ですが、いくつかの弱点があります。
1409114605元のハッシュで値が重複していると、それらのうち一つだけが
1409214606逆順になったハッシュのキーとして表現されます。
1409314607また、これは一つのハッシュをほどいて完全に新しいハッシュを作るので、
1409414608DBM ファイルからのような大きなハッシュでは少し時間がかかります。
1409514609
1409614610 my %by_name = reverse %by_address; # Invert the hash
1409714611
1409814612=item rewinddir DIRHANDLE
1409914613X<rewinddir>
1410014614
1410114615=for Pod::Functions reset directory handle
1410214616
1410314617=begin original
1410414618
1410514619Sets the current position to the beginning of the directory for the
1410614620L<C<readdir>|/readdir DIRHANDLE> routine on DIRHANDLE.
1410714621
1410814622=end original
1410914623
1411014624DIRHANDLE に対する L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
1411114625ディレクトリの最初に設定します。
1411214626
1411314627=begin original
1411414628
1411514629Portability issues: L<perlport/rewinddir>.
1411614630
1411714631=end original
1411814632
1411914633移植性の問題: L<perlport/rewinddir>。
1412014634
1412114635=item rindex STR,SUBSTR,POSITION
1412214636X<rindex>
1412314637
1412414638=item rindex STR,SUBSTR
1412514639
1412614640=for Pod::Functions right-to-left substring search
1412714641
1412814642=begin original
1412914643
1413014644Works just like L<C<index>|/index STR,SUBSTR,POSITION> except that it
1413114645returns the position of the I<last>
1413214646occurrence of SUBSTR in STR. If POSITION is specified, returns the
1413314647last occurrence beginning at or before that position.
1413414648
1413514649=end original
1413614650
1413714651STR 中で I<最後に> 見つかった SUBSTR の位置を返すことを除いて、
1413814652L<C<index>|/index STR,SUBSTR,POSITION> と同じように動作します。
1413914653POSITION を指定すると、その位置から始まるか、その位置より前の、
1414014654最後の位置を返します。
1414114655
1414214656=item rmdir FILENAME
1414314657X<rmdir> X<rd> X<directory, remove>
1414414658
1414514659=item rmdir
1414614660
1414714661=for Pod::Functions remove a directory
1414814662
1414914663=begin original
1415014664
1415114665Deletes the directory specified by FILENAME if that directory is
1415214666empty. If it succeeds it returns true; otherwise it returns false and
1415314667sets L<C<$!>|perlvar/$!> (errno). If FILENAME is omitted, uses
1415414668L<C<$_>|perlvar/$_>.
1415514669
1415614670=end original
1415714671
1415814672FILENAME で指定したディレクトリが空であれば、
1415914673そのディレクトリを削除します。
1416014674成功時には真を返します; さもなければ偽を返して L<C<$!>|perlvar/$!> (errno) を
1416114675設定します。
1416214676FILENAME を省略した場合には、L<C<$_>|perlvar/$_> を使用します。
1416314677
1416414678=begin original
1416514679
1416614680To remove a directory tree recursively (C<rm -rf> on Unix) look at
1416714681the L<C<rmtree>|File::Path/rmtree( $dir )> function of the L<File::Path>
1416814682module.
1416914683
1417014684=end original
1417114685
1417214686ディレクトリツリーを再帰的に削除したい (Unix での C<rm -rf>) 場合、
1417314687L<File::Path> モジュールの L<C<rmtree>|File::Path/rmtree( $dir )> 関数を
1417414688参照してください。
1417514689
1417614690=item s///
1417714691
1417814692=for Pod::Functions replace a pattern with a string
1417914693
1418014694=begin original
1418114695
1418214696The substitution operator. See L<perlop/"Regexp Quote-Like Operators">.
1418314697
1418414698=end original
1418514699
1418614700置換演算子。
1418714701L<perlop/"Regexp Quote-Like Operators"> を参照してください。
1418814702
1418914703=item say FILEHANDLE LIST
1419014704X<say>
1419114705
1419214706=item say FILEHANDLE
1419314707
1419414708=item say LIST
1419514709
1419614710=item say
1419714711
1419814712=for Pod::Functions +say output a list to a filehandle, appending a newline
1419914713
1420014714=begin original
1420114715
1420214716Just like L<C<print>|/print FILEHANDLE LIST>, but implicitly appends a
14203newline. C<say LIST> is simply an abbreviation for
14717newline at the end of the LIST instead of any value L<C<$\>|perlvar/$\>
14204C<{ local $\ = "\n"; print LIST }>. To use FILEHANDLE without a LIST to
14718might have. To use FILEHANDLE without a LIST to
1420514719print the contents of L<C<$_>|perlvar/$_> to it, you must use a bareword
1420614720filehandle like C<FH>, not an indirect one like C<$fh>.
1420714721
1420814722=end original
1420914723
14210L<C<print>|/print FILEHANDLE LIST> と同様ですが、暗黙に改行が追加されます。
14724L<C<print>|/print FILEHANDLE LIST> と同様ですが、
14211C<say LIST> は単に C<{ local $\ = "\n"; print LIST }> 省略形です。
14725L<C<$\>|perlvar/$\> の値の代わりに LIST の末尾に
14726改行が暗黙に追加されます。
1421214727L<C<$_>|perlvar/$_> の内容を表示するために LIST なしで FILEHANDLE を
1421314728使用するには、C<$fh> のような間接ファイルハンドルではなく、C<FH> のような
1421414729裸の単語のファイルハンドルを使わなければなりません。
1421514730
1421614731=begin original
1421714732
1421814733L<C<say>|/say FILEHANDLE LIST> is available only if the
1421914734L<C<"say"> feature|feature/The 'say' feature> is enabled or if it is
1422014735prefixed with C<CORE::>. The
1422114736L<C<"say"> feature|feature/The 'say' feature> is enabled automatically
1422214737with a C<use v5.10> (or higher) declaration in the current scope.
1422314738
1422414739=end original
1422514740
1422614741L<C<say>|/say FILEHANDLE LIST> は
1422714742L<C<"say"> 機能|feature/The 'say' feature> が有効か C<CORE::> が
1422814743前置されたときにのみ利用可能です。
1422914744L<C<"say"> 機能|feature/The 'say' feature> は現在のスコープで
1423014745C<use v5.10> (またはそれ以上) が宣言されると自動的に有効になります。
1423114746
1423214747=item scalar EXPR
1423314748X<scalar> X<context>
1423414749
1423514750=for Pod::Functions force a scalar context
1423614751
1423714752=begin original
1423814753
1423914754Forces EXPR to be interpreted in scalar context and returns the value
1424014755of EXPR.
1424114756
1424214757=end original
1424314758
1424414759EXPR を強制的にスカラコンテキストで解釈されるようにして、
1424514760EXPR の値を返します。
1424614761
1424714762 my @counts = ( scalar @a, scalar @b, scalar @c );
1424814763
1424914764=begin original
1425014765
1425114766There is no equivalent operator to force an expression to
1425214767be interpolated in list context because in practice, this is never
1425314768needed. If you really wanted to do so, however, you could use
1425414769the construction C<@{[ (some expression) ]}>, but usually a simple
1425514770C<(some expression)> suffices.
1425614771
1425714772=end original
1425814773
1425914774式を強制的にリストコンテキストで解釈させるようにする演算子はありません;
1426014775理論的には不要だからです。
1426114776それでも、もしそうしたいのなら、C<@{[ (some expression) ]}> という構造を
1426214777使えます; しかし、普通は単に C<(some expression)> とすれば十分です。
1426314778
1426414779=begin original
1426514780
1426614781Because L<C<scalar>|/scalar EXPR> is a unary operator, if you
1426714782accidentally use a
1426814783parenthesized list for the EXPR, this behaves as a scalar comma expression,
1426914784evaluating all but the last element in void context and returning the final
1427014785element evaluated in scalar context. This is seldom what you want.
1427114786
1427214787=end original
1427314788
1427414789L<C<scalar>|/scalar EXPR> は単項演算子なので、EXPR として括弧でくくった
1427514790リストを使った場合、これはスカラカンマ表現として振舞い、最後以外の全ては
1427614791無効コンテキストとして扱われ、最後の要素をスカラコンテキストとして扱った
1427714792結果が返されます。
1427814793これがあなたの望むものであることはめったにないでしょう。
1427914794
1428014795=begin original
1428114796
1428214797The following single statement:
1428314798
1428414799=end original
1428514800
1428614801以下の一つの文は:
1428714802
1428814803 print uc(scalar(foo(), $bar)), $baz;
1428914804
1429014805=begin original
1429114806
1429214807is the moral equivalent of these two:
1429314808
1429414809=end original
1429514810
1429614811以下の二つの文と等価です。
1429714812
1429814813 foo();
1429914814 print(uc($bar), $baz);
1430014815
1430114816=begin original
1430214817
1430314818See L<perlop> for more details on unary operators and the comma operator,
1430414819and L<perldata> for details on evaluating a hash in scalar contex.
1430514820
1430614821=end original
1430714822
1430814823単項演算子とカンマ演算子に関する詳細については L<perlop> を、
1430914824スカラコンテキストでのハッシュの評価に関する詳細については L<perldata> を
1431014825参照してください。
1431114826
1431214827=item seek FILEHANDLE,POSITION,WHENCE
1431314828X<seek> X<fseek> X<filehandle, position>
1431414829
1431514830=for Pod::Functions reposition file pointer for random-access I/O
1431614831
1431714832=begin original
1431814833
1431914834Sets FILEHANDLE's position, just like the L<fseek(3)> call of C C<stdio>.
1432014835FILEHANDLE may be an expression whose value gives the name of the
1432114836filehandle. The values for WHENCE are C<0> to set the new position
1432214837I<in bytes> to POSITION; C<1> to set it to the current position plus
1432314838POSITION; and C<2> to set it to EOF plus POSITION, typically
1432414839negative. For WHENCE you may use the constants C<SEEK_SET>,
1432514840C<SEEK_CUR>, and C<SEEK_END> (start of the file, current position, end
1432614841of the file) from the L<Fcntl> module. Returns C<1> on success, false
1432714842otherwise.
1432814843
1432914844=end original
1433014845
1433114846C の C<stdio> ライブラリの L<fseek(3)> 関数のように、FILEHANDLE の
1433214847ファイルポインタを任意の位置に設定します。
1433314848FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1433414849WHENCE の値が、C<0> ならば、新しい位置を I<バイト単位で> POSITION の位置へ
1433514850設定します; C<1> ならば、現在位置から POSITION 加えた位置へ
1433614851設定します; C<2> ならば、EOF からPOSITION だけ加えた位置へ、新しい位置を
1433714852設定します。
1433814853この値には、L<Fcntl> モジュールで使われている C<SEEK_SET>、C<SEEK_CUR>、
1433914854C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1434014855使うこともできます。
1434114856成功時には、C<1> を、失敗時にはそれ以外を返します。
1434214857
1434314858=begin original
1434414859
1434514860Note the emphasis on bytes: even if the filehandle has been set to operate
1434614861on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
1434714862L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1434814863L<C<tell>|/tell FILEHANDLE>, and
1434914864L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
1435014865family of functions use byte offsets, not character offsets,
1435114866because seeking to a character offset would be very slow in a UTF-8 file.
1435214867
1435314868=end original
1435414869
1435514870バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
1435614871ファイルハンドルが文字単位で処理するように設定されていたとしても、
1435714872L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1435814873L<C<tell>|/tell FILEHANDLE>,
1435914874L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
1436014875文字オフセットではなくバイトオフセットを使います;
1436114876文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1436214877
1436314878=begin original
1436414879
1436514880If you want to position the file for
1436614881L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> or
1436714882L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, don't use
1436814883L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, because buffering makes its
1436914884effect on the file's read-write position unpredictable and non-portable.
1437014885Use L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> instead.
1437114886
1437214887=end original
1437314888
1437414889L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> や
1437514890L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> のためにファイルの
1437614891位置を指定したい場合は、L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は
1437714892使えません; なぜならバッファリングのためにファイルの読み込み位置は
1437814893動作は予測不能で移植性のないものになってしまいます。
1437914894代わりに L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> を使ってください。
1438014895
1438114896=begin original
1438214897
1438314898Due to the rules and rigors of ANSI C, on some systems you have to do a
1438414899seek whenever you switch between reading and writing. Amongst other
1438514900things, this may have the effect of calling stdio's L<clearerr(3)>.
1438614901A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving the file position:
1438714902
1438814903=end original
1438914904
1439014905ANSI C の規則と困難により、システムによっては読み込みと書き込みを
1439114906切り替える度にシークしなければならない場合があります。
1439214907その他のことの中で、これは stdio の L<clearerr(3)> を呼び出す効果があります。
1439314908WHENCE の C<1> (C<SEEK_CUR>) が、ファイル位置を変えないので有用です:
1439414909
1439514910 seek($fh, 0, 1);
1439614911
1439714912=begin original
1439814913
1439914914This is also useful for applications emulating C<tail -f>. Once you hit
1440014915EOF on your read and then sleep for a while, you (probably) have to stick in a
1440114916dummy L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> to reset things. The
1440214917L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> doesn't change the position,
1440314918but it I<does> clear the end-of-file condition on the handle, so that the
1440414919next C<readline FILE> makes Perl try again to read something. (We hope.)
1440514920
1440614921=end original
1440714922
1440814923これはアプリケーションで C<tail -f> をエミュレートするのにも有用です。
1440914924一度読み込み時に EOF に到達すると、しばらくスリープし、
1441014925(おそらく) ダミーの L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> をすることで
1441114926リセットする必要があります。
1441214927L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE> は現在の位置を変更しませんが、
1441314928ハンドルの EOF 状態をI<クリアします> ので、次の C<readline FILE> で Perl は
1441414929再び何かを読み込もうとします。(そのはずです。)
1441514930
1441614931=begin original
1441714932
1441814933If that doesn't work (some I/O implementations are particularly
1441914934cantankerous), you might need something like this:
1442014935
1442114936=end original
1442214937
1442314938これが動かない場合(特に意地の悪い I/O 実装もあります)、
1442414939以下のようなことをする必要があります:
1442514940
1442614941 for (;;) {
1442714942 for ($curpos = tell($fh); $_ = readline($fh);
1442814943 $curpos = tell($fh)) {
1442914944 # search for some stuff and put it into files
1443014945 }
1443114946 sleep($for_a_while);
1443214947 seek($fh, $curpos, 0);
1443314948 }
1443414949
1443514950=item seekdir DIRHANDLE,POS
1443614951X<seekdir>
1443714952
1443814953=for Pod::Functions reposition directory pointer
1443914954
1444014955=begin original
1444114956
1444214957Sets the current position for the L<C<readdir>|/readdir DIRHANDLE>
1444314958routine on DIRHANDLE. POS must be a value returned by
1444414959L<C<telldir>|/telldir DIRHANDLE>. L<C<seekdir>|/seekdir DIRHANDLE,POS>
1444514960also has the same caveats about possible directory compaction as the
1444614961corresponding system library routine.
1444714962
1444814963=end original
1444914964
1445014965DIRHANDLE での L<C<readdir>|/readdir DIRHANDLE> ルーチンの現在位置を
1445114966設定します。
1445214967POS は、L<C<telldir>|/telldir DIRHANDLE> が返す値でなければなりません。
1445314968L<C<seekdir>|/seekdir DIRHANDLE,POS> は同名のシステムライブラリルーチンと
1445414969同じく、ディレクトリ縮小時の問題が考えられます。
1445514970
1445614971=item select FILEHANDLE
1445714972X<select> X<filehandle, default>
1445814973
1445914974=item select
1446014975
1446114976=for Pod::Functions reset default output or do I/O multiplexing
1446214977
1446314978=begin original
1446414979
1446514980Returns the currently selected filehandle. If FILEHANDLE is supplied,
1446614981sets the new current default filehandle for output. This has two
1446714982effects: first, a L<C<write>|/write FILEHANDLE> or a L<C<print>|/print
1446814983FILEHANDLE LIST> without a filehandle
1446914984default to this FILEHANDLE. Second, references to variables related to
1447014985output will refer to this output channel.
1447114986
1447214987=end original
1447314988
1447414989その時点で、選択されていたファイルハンドルを返します。
1447514990FILEHANDLE を指定した場合には、その値を出力のデフォルトファイルハンドルに
1447614991設定します。
1447714992これには、2 つの効果があります: まず、ファイルハンドルを指定しないで
1447814993L<C<write>|/write FILEHANDLE> や L<C<print>|/print FILEHANDLE LIST> を
1447914994行なった場合のデフォルトが、この FILEHANDLE になります。
1448014995もう一つは、出力関連の変数への参照は、この出力チャネルを
1448114996参照するようになります。
1448214997
1448314998=begin original
1448414999
1448515000For example, to set the top-of-form format for more than one
1448615001output channel, you might do the following:
1448715002
1448815003=end original
1448915004
1449015005例えば、複数の出力チャネルに対して、ページ先頭フォーマットを
1449115006設定するには:
1449215007
1449315008 select(REPORT1);
1449415009 $^ = 'report1_top';
1449515010 select(REPORT2);
1449615011 $^ = 'report2_top';
1449715012
1449815013=begin original
1449915014
1450015015FILEHANDLE may be an expression whose value gives the name of the
1450115016actual filehandle. Thus:
1450215017
1450315018=end original
1450415019
1450515020FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
1450615021つまり、以下のようなものです:
1450715022
1450815023 my $oldfh = select(STDERR); $| = 1; select($oldfh);
1450915024
1451015025=begin original
1451115026
1451215027Some programmers may prefer to think of filehandles as objects with
1451315028methods, preferring to write the last example as:
1451415029
1451515030=end original
1451615031
1451715032ファイルハンドルはメソッドを持ったオブジェクトであると考えることを好む
1451815033プログラマもいるかもしれません; そのような場合のための最後の例は
1451915034以下のようなものです:
1452015035
1452115036 STDERR->autoflush(1);
1452215037
1452315038=begin original
1452415039
1452515040(Prior to Perl version 5.14, you have to C<use IO::Handle;> explicitly
1452615041first.)
1452715042
1452815043=end original
1452915044
1453015045(Perl バージョン 5.14 以前では、まず明示的に C<use IO::Handle;> とする
1453115046必要があります。)
1453215047
1453315048=begin original
1453415049
1453515050Portability issues: L<perlport/select>.
1453615051
1453715052=end original
1453815053
1453915054移植性の問題: L<perlport/select>。
1454015055
1454115056=item select RBITS,WBITS,EBITS,TIMEOUT
1454215057X<select>
1454315058
1454415059=begin original
1454515060
1454615061This calls the L<select(2)> syscall with the bit masks specified, which
1454715062can be constructed using L<C<fileno>|/fileno FILEHANDLE> and
1454815063L<C<vec>|/vec EXPR,OFFSET,BITS>, along these lines:
1454915064
1455015065=end original
1455115066
1455215067これは、L<select(2)> システムコールを、指定したビットマスクで呼び出します;
1455315068ビットマスクは、L<C<fileno>|/fileno FILEHANDLE> と
1455415069L<C<vec>|/vec EXPR,OFFSET,BITS> を使って、以下のようにして作成できます:
1455515070
1455615071 my $rin = my $win = my $ein = '';
1455715072 vec($rin, fileno(STDIN), 1) = 1;
1455815073 vec($win, fileno(STDOUT), 1) = 1;
1455915074 $ein = $rin | $win;
1456015075
1456115076=begin original
1456215077
1456315078If you want to select on many filehandles, you may wish to write a
1456415079subroutine like this:
1456515080
1456615081=end original
1456715082
1456815083複数のファイルハンドルに select を行ないたいのであれば、
1456915084以下のようにします:
1457015085
1457115086 sub fhbits {
1457215087 my @fhlist = @_;
1457315088 my $bits = "";
1457415089 for my $fh (@fhlist) {
1457515090 vec($bits, fileno($fh), 1) = 1;
1457615091 }
1457715092 return $bits;
1457815093 }
1457915094 my $rin = fhbits(\*STDIN, $tty, $mysock);
1458015095
1458115096=begin original
1458215097
1458315098The usual idiom is:
1458415099
1458515100=end original
1458615101
1458715102通常は、
1458815103
1458915104 my ($nfound, $timeleft) =
1459015105 select(my $rout = $rin, my $wout = $win, my $eout = $ein,
1459115106 $timeout);
1459215107
1459315108=begin original
1459415109
1459515110or to block until something becomes ready just do this
1459615111
1459715112=end original
1459815113
1459915114のように使い、いずれかの準備が整うまでブロックするには、
1460015115以下のようにします。
1460115116
1460215117 my $nfound =
1460315118 select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef);
1460415119
1460515120=begin original
1460615121
1460715122Most systems do not bother to return anything useful in C<$timeleft>, so
1460815123calling L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> in scalar context
1460915124just returns C<$nfound>.
1461015125
1461115126=end original
1461215127
1461315128ほとんどのシステムではわざわざ意味のある値を C<$timeleft> に返さないので、
1461415129L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> をスカラコンテキストで
1461515130呼び出すと、単に C<$nfound> を返します。
1461615131
1461715132=begin original
1461815133
1461915134Any of the bit masks can also be L<C<undef>|/undef EXPR>. The timeout,
1462015135if specified, is
1462115136in seconds, which may be fractional. Note: not all implementations are
1462215137capable of returning the C<$timeleft>. If not, they always return
1462315138C<$timeleft> equal to the supplied C<$timeout>.
1462415139
1462515140=end original
1462615141
1462715142どのビットマスクにも L<C<undef>|/undef EXPR> を設定することができます。
1462815143TIMEOUT を指定するときは、秒数で指定し、小数でかまいません。
1462915144注: すべての実装で、C<$timeleft> が返せるものではありません。
1463015145その場合、C<$timeleft> には、常に指定した C<$timeout> と同じ値が返されます。
1463115146
1463215147=begin original
1463315148
1463415149You can effect a sleep of 250 milliseconds this way:
1463515150
1463615151=end original
1463715152
1463815153250 ミリ秒の sleep と同じ効果が、以下のようにして得られます。
1463915154
1464015155 select(undef, undef, undef, 0.25);
1464115156
1464215157=begin original
1464315158
1464415159Note that whether L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> gets
1464515160restarted after signals (say, SIGALRM) is implementation-dependent. See
1464615161also L<perlport> for notes on the portability of
1464715162L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>.
1464815163
1464915164=end original
1465015165
1465115166L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> がシグナル (例えば、SIGALRM) の
1465215167後に再起動するかどうかは実装依存であることに注意してください。
1465315168L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> の移植性に関する
1465415169注意については L<perlport> も参照してください。
1465515170
1465615171=begin original
1465715172
1465815173On error, L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> behaves just
1465915174like L<select(2)>: it returns C<-1> and sets L<C<$!>|perlvar/$!>.
1466015175
1466115176=end original
1466215177
1466315178エラー時は、L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> は
1466415179L<select(2)> のように振舞います:
1466515180C<-1> を返し、L<C<$!>|perlvar/$!> をセットします。
1466615181
1466715182=begin original
1466815183
1466915184On some Unixes, L<select(2)> may report a socket file descriptor as
1467015185"ready for reading" even when no data is available, and thus any
1467115186subsequent L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> would block.
1467215187This can be avoided if you always use C<O_NONBLOCK> on the socket. See
1467315188L<select(2)> and L<fcntl(2)> for further details.
1467415189
1467515190=end original
1467615191
1467715192Unix の中には、実際に利用可能なデータがないために引き続く
1467815193L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> が
1467915194ブロックされる場合でも、L<select(2)> が、ソケットファイル記述子が
1468015195「読み込み準備中」であると報告するものもあります。
1468115196これは、ソケットに対して常に C<O_NONBLOCK> フラグを使うことで回避できます。
1468215197さらなる詳細については L<select(2)> と L<fcntl(2)> を参照してください。
1468315198
1468415199=begin original
1468515200
1468615201The standard L<C<IO::Select>|IO::Select> module provides a
1468715202user-friendlier interface to
1468815203L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, mostly because it does
1468915204all the bit-mask work for you.
1469015205
1469115206=end original
1469215207
1469315208標準の L<C<IO::Select>|IO::Select> モジュールは
1469415209L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> へのよりユーザーフレンドリーな
1469515210インターフェースを提供します; 主な理由はビットマスクの仕事を
1469615211してくれることです。
1469715212
1469815213=begin original
1469915214
1470015215B<WARNING>: One should not attempt to mix buffered I/O (like
1470115216L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> or
1470215217L<C<readline>|/readline EXPR>) with
1470315218L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT>, except as permitted by
1470415219POSIX, and even then only on POSIX systems. You have to use
1470515220L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> instead.
1470615221
1470715222=end original
1470815223
1470915224B<警告>: バッファ付き I/O (L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> や
1471015225L<C<readline>|/readline EXPR>) と
1471115226L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を
1471215227混ぜて使ってはいけません(例外: POSIX で認められている形で使い、
1471315228POSIX システムでだけ動かす場合を除きます)。
1471415229代わりに L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を
1471515230使わなければなりません。
1471615231
1471715232=begin original
1471815233
1471915234Portability issues: L<perlport/select>.
1472015235
1472115236=end original
1472215237
1472315238移植性の問題: L<perlport/select>。
1472415239
1472515240=item semctl ID,SEMNUM,CMD,ARG
1472615241X<semctl>
1472715242
1472815243=for Pod::Functions SysV semaphore control operations
1472915244
1473015245=begin original
1473115246
1473215247Calls the System V IPC function L<semctl(2)>. You'll probably have to say
1473315248
1473415249=end original
1473515250
1473615251System V IPC 関数 L<semctl(2)> を呼び出します。
1473715252正しい定数定義を得るために、まず
1473815253
1473915254 use IPC::SysV;
1474015255
1474115256=begin original
1474215257
1474315258first to get the correct constant definitions. If CMD is IPC_STAT or
1474415259GETALL, then ARG must be a variable that will hold the returned
1474515260semid_ds structure or semaphore value array. Returns like
1474615261L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR>:
1474715262the undefined value for error, "C<0 but true>" for zero, or the actual
1474815263return value otherwise. The ARG must consist of a vector of native
1474915264short integers, which may be created with C<pack("s!",(0)x$nsem)>.
1475015265See also L<perlipc/"SysV IPC"> and the documentation for
1475115266L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1475215267
1475315268=end original
1475415269
1475515270と書くことが必要でしょう。
1475615271CMD が、IPC_STAT か GETALL のときには、ARG は、返される
1475715272semid_ds 構造体か、セマフォ値の配列を納める変数でなければなりません。
1475815273L<C<ioctl>|/ioctl FILEHANDLE,FUNCTION,SCALAR> と同じように、エラー時には
1475915274未定義値、ゼロのときは C<"0 だが真">、それ以外なら、その値そのものを返します。
1476015275ARG はネイティブな short int のベクターから成っていなければなりません; これは
1476115276C<pack("s!",(0)x$nsem)> で作成できます。
1476215277L<perlipc/"SysV IPC"> と、
1476315278L<C<IPC::SysV>|IPC::SysV>, L<C<IPC::Semaphore>|IPC::Semaphore> の文書も
1476415279参照してください。
1476515280
1476615281=begin original
1476715282
1476815283Portability issues: L<perlport/semctl>.
1476915284
1477015285=end original
1477115286
1477215287移植性の問題: L<perlport/semctl>。
1477315288
1477415289=item semget KEY,NSEMS,FLAGS
1477515290X<semget>
1477615291
1477715292=for Pod::Functions get set of SysV semaphores
1477815293
1477915294=begin original
1478015295
1478115296Calls the System V IPC function L<semget(2)>. Returns the semaphore id, or
1478215297the undefined value on error. See also
1478315298L<perlipc/"SysV IPC"> and the documentation for
1478415299L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1478515300
1478615301=end original
1478715302
1478815303System V IPC 関数 L<semget(2)> を呼び出します。
1478915304セマフォ ID か、エラー時には未定義値を返します。
1479015305L<perlipc/"SysV IPC"> と、L<C<IPC::SysV>|IPC::SysV>,
1479115306L<C<IPC::Semaphore>|IPC::Semaphore> 文書も参照してください。
1479215307
1479315308=begin original
1479415309
1479515310Portability issues: L<perlport/semget>.
1479615311
1479715312=end original
1479815313
1479915314移植性の問題: L<perlport/semget>。
1480015315
1480115316=item semop KEY,OPSTRING
1480215317X<semop>
1480315318
1480415319=for Pod::Functions SysV semaphore operations
1480515320
1480615321=begin original
1480715322
1480815323Calls the System V IPC function L<semop(2)> for semaphore operations
1480915324such as signalling and waiting. OPSTRING must be a packed array of
1481015325semop structures. Each semop structure can be generated with
1481115326C<pack("s!3", $semnum, $semop, $semflag)>. The length of OPSTRING
1481215327implies the number of semaphore operations. Returns true if
1481315328successful, false on error. As an example, the
1481415329following code waits on semaphore $semnum of semaphore id $semid:
1481515330
1481615331=end original
1481715332
1481815333シグナルを送信や、待ち合わせなどのセマフォ操作を行なうために、
1481915334System V IPC 関数 L<semop(2)> を呼び出します。
1482015335OPSTRING は、semop 構造体の pack された配列でなければなりません。
1482115336semop 構造体は、それぞれ、C<pack("s!3", $semnum, $semop, $semflag)> のように
1482215337作ることができます。
1482315338セマフォ操作の数は、OPSTRING の長さからわかります。
1482415339成功時には真を、エラー時には偽を返します。
1482515340以下の例は、セマフォ ID $semid のセマフォ $semnum で
1482615341待ち合わせを行ないます。
1482715342
1482815343 my $semop = pack("s!3", $semnum, -1, 0);
1482915344 die "Semaphore trouble: $!\n" unless semop($semid, $semop);
1483015345
1483115346=begin original
1483215347
1483315348To signal the semaphore, replace C<-1> with C<1>. See also
1483415349L<perlipc/"SysV IPC"> and the documentation for
1483515350L<C<IPC::SysV>|IPC::SysV> and L<C<IPC::Semaphore>|IPC::Semaphore>.
1483615351
1483715352=end original
1483815353
1483915354セマフォにシグナルを送るには、C<-1> を C<1> に変更してください。
1484015355L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV>,
1484115356L<C<IPC::Semaphore>|IPC::Semaphore> の文書も参照してください。
1484215357
1484315358=begin original
1484415359
1484515360Portability issues: L<perlport/semop>.
1484615361
1484715362=end original
1484815363
1484915364移植性の問題: L<perlport/semop>。
1485015365
1485115366=item send SOCKET,MSG,FLAGS,TO
1485215367X<send>
1485315368
1485415369=item send SOCKET,MSG,FLAGS
1485515370
1485615371=for Pod::Functions send a message over a socket
1485715372
1485815373=begin original
1485915374
1486015375Sends a message on a socket. Attempts to send the scalar MSG to the SOCKET
1486115376filehandle. Takes the same flags as the system call of the same name. On
1486215377unconnected sockets, you must specify a destination to I<send to>, in which
1486315378case it does a L<sendto(2)> syscall. Returns the number of characters sent,
1486415379or the undefined value on error. The L<sendmsg(2)> syscall is currently
1486515380unimplemented. See L<perlipc/"UDP: Message Passing"> for examples.
1486615381
1486715382=end original
1486815383
1486915384ソケットにメッセージを送ります。
1487015385スカラ MSG を ファイルハンドル SOCKET に送ろうとします。
1487115386同名のシステムコールと同じフラグが指定できます。
1487215387接続していないソケットには、I<send to> に接続先を指定しなければならず、
1487315388この場合、L<sendto(2)> を実行します。
1487415389送信した文字数か、エラー時には、未定義値を返します。
1487515390システムコール L<sendmsg(2)> は現在実装されていません。
1487615391例については L<perlipc/"UDP: Message Passing"> を参照してください。
1487715392
1487815393=begin original
1487915394
14880Note the I<characters>: depending on the status of the socket, either
15395Note that if the socket has been marked as C<:utf8>, C<send> will
14881(8-bit) bytes or characters are sent. By default all sockets operate
15396throw an exception. The C<:encoding(...)> layer implicitly introduces
14882on bytes, but for example if the socket has been changed using
15397the C<:utf8> layer. See L<C<binmode>|/binmode FILEHANDLE, LAYER>.
14883L<C<binmode>|/binmode FILEHANDLE, LAYER> to operate with the
14884C<:encoding(UTF-8)> I/O layer (see L<C<open>|/open FILEHANDLE,EXPR>, or
14885the L<open> pragma), the I/O will operate on UTF-8
14886encoded Unicode characters, not bytes. Similarly for the C<:encoding>
14887layer: in that case pretty much any characters can be sent.
1488815398
1488915399=end original
1489015400
14891I<文字> に関する注意: ソケットの状態によって、(8 ビットの) バイトか
15401ソケットが C<:utf8> とマークされている場合、
14892文字送信ます
15402C<send> は例外投げることに注意てください
14893デフォルトで全てのソケットはバイト処理しますが、
15403C<:encoding(...)> 層暗黙に C<:utf8> 層導入します
14894例えばソケットが L<C<binmode>|/binmode FILEHANDLE, LAYER>
15404L<C<binmode>|/binmode FILEHANDLE, LAYER> を参照してください。
14895C<:encoding(UTF-8)> I/O 層(L<C<open>|/open FILEHANDLE,EXPR>、
14896L<open> プラグマを参照してください) を使うように指定された場合、
14897I/O はバイトではなく、UTF-8 エンコードされた Unicode 文字を操作します。
14898C<:encoding> 層も同様です:
14899この場合、ほとんど大体全ての文字が書き込めます。
1490015405
1490115406=item setpgrp PID,PGRP
1490215407X<setpgrp> X<group>
1490315408
1490415409=for Pod::Functions set the process group of a process
1490515410
1490615411=begin original
1490715412
1490815413Sets the current process group for the specified PID, C<0> for the current
1490915414process. Raises an exception when used on a machine that doesn't
1491015415implement POSIX L<setpgid(2)> or BSD L<setpgrp(2)>. If the arguments
1491115416are omitted, it defaults to C<0,0>. Note that the BSD 4.2 version of
1491215417L<C<setpgrp>|/setpgrp PID,PGRP> does not accept any arguments, so only
1491315418C<setpgrp(0,0)> is portable. See also
1491415419L<C<POSIX::setsid()>|POSIX/C<setsid>>.
1491515420
1491615421=end original
1491715422
1491815423指定した PID (C<0> を指定するとカレントプロセス) に
1491915424対するプロセスグループを設定します。
1492015425POSIX L<setpgrp(2)> または BSD L<setpgrp(2)> が実装されていないマシンでは、
1492115426例外が発生します。
1492215427引数が省略された場合は、C<0,0>が使われます。
1492315428BSD 4.2 版の L<C<setpgrp>|/setpgrp PID,PGRP> は引数を取ることができないので、
1492415429C<setpgrp(0,0)> のみが移植性があることに注意してください。
1492515430L<C<POSIX::setsid()>|POSIX/C<setsid>> も参照してください。
1492615431
1492715432=begin original
1492815433
1492915434Portability issues: L<perlport/setpgrp>.
1493015435
1493115436=end original
1493215437
1493315438移植性の問題: L<perlport/setpgrp>。
1493415439
1493515440=item setpriority WHICH,WHO,PRIORITY
1493615441X<setpriority> X<priority> X<nice> X<renice>
1493715442
1493815443=for Pod::Functions set a process's nice value
1493915444
1494015445=begin original
1494115446
1494215447Sets the current priority for a process, a process group, or a user.
1494315448(See L<setpriority(2)>.) Raises an exception when used on a machine
1494415449that doesn't implement L<setpriority(2)>.
1494515450
1494615451=end original
1494715452
1494815453プロセス、プロセスグループ、ユーザに対する優先順位を設定します。
1494915454(L<setpriority(2)> を参照してください。)
1495015455L<setpriority(2)> が実装されていないマシンでは、例外が発生します。
1495115456
1495215457=begin original
1495315458
15459C<WHICH> can be any of C<PRIO_PROCESS>, C<PRIO_PGRP> or C<PRIO_USER>
15460imported from L<POSIX/RESOURCE CONSTANTS>.
15461
15462=end original
15463
15464C<WHICH> は、L<POSIX/RESOURCE CONSTANTS> からインポートされた
15465C<PRIO_PROCESS>, C<PRIO_PGRP>, C<PRIO_USER> のいずれかです。
15466
15467=begin original
15468
1495415469Portability issues: L<perlport/setpriority>.
1495515470
1495615471=end original
1495715472
1495815473移植性の問題: L<perlport/setpriority>。
1495915474
1496015475=item setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
1496115476X<setsockopt>
1496215477
1496315478=for Pod::Functions set some socket options
1496415479
1496515480=begin original
1496615481
1496715482Sets the socket option requested. Returns L<C<undef>|/undef EXPR> on
1496815483error. Use integer constants provided by the L<C<Socket>|Socket> module
1496915484for
1497015485LEVEL and OPNAME. Values for LEVEL can also be obtained from
1497115486getprotobyname. OPTVAL might either be a packed string or an integer.
1497215487An integer OPTVAL is shorthand for pack("i", OPTVAL).
1497315488
1497415489=end original
1497515490
1497615491要求したソケットオプションを設定します。
1497715492エラー時には、L<C<undef>|/undef EXPR> を返します。
1497815493LEVEL と OPNAME には L<C<Socket>|Socket> モジュールが提供する
1497915494整数定数を使います。
1498015495LEVEL の値は getprotobyname から得ることもできます。
1498115496OPTVAL は pack された文字列か整数です。
1498215497整数の OPTVAL は pack("i", OPTVAL) の省略表現です。
1498315498
1498415499=begin original
1498515500
1498615501An example disabling Nagle's algorithm on a socket:
1498715502
1498815503=end original
1498915504
1499015505ソケットに対する Nagle のアルゴリズムを無効にする例です:
1499115506
1499215507 use Socket qw(IPPROTO_TCP TCP_NODELAY);
1499315508 setsockopt($socket, IPPROTO_TCP, TCP_NODELAY, 1);
1499415509
1499515510=begin original
1499615511
1499715512Portability issues: L<perlport/setsockopt>.
1499815513
1499915514=end original
1500015515
1500115516移植性の問題: L<perlport/setsockopt>。
1500215517
1500315518=item shift ARRAY
1500415519X<shift>
1500515520
1500615521=item shift
1500715522
1500815523=for Pod::Functions remove the first element of an array, and return it
1500915524
1501015525=begin original
1501115526
1501215527Shifts the first value of the array off and returns it, shortening the
1501315528array by 1 and moving everything down. If there are no elements in the
1501415529array, returns the undefined value. If ARRAY is omitted, shifts the
1501515530L<C<@_>|perlvar/@_> array within the lexical scope of subroutines and
1501615531formats, and the L<C<@ARGV>|perlvar/@ARGV> array outside a subroutine
1501715532and also within the lexical scopes
1501815533established by the C<eval STRING>, C<BEGIN {}>, C<INIT {}>, C<CHECK {}>,
1501915534C<UNITCHECK {}>, and C<END {}> constructs.
1502015535
1502115536=end original
1502215537
1502315538配列の最初の値を取り出して、その値を返し、配列を一つ短くして、すべての要素を
1502415539前へずらします。
1502515540配列に要素がなければ、未定義値を返します。
1502615541ARRAY を省略すると、サブルーチンやフォーマットのレキシカルスコープでは
1502715542L<C<@_>|perlvar/@_> を、サブルーチンの外側で、C<eval STRING>, C<BEGIN {}>,
1502815543C<INIT {}>, C<CHECK {}>, C<UNITCHECK {}>, C<END {}> で作成された
1502915544レキシカルスコープでは L<C<@ARGV>|perlvar/@ARGV> が用いられます。
1503015545
1503115546=begin original
1503215547
1503315548Starting with Perl 5.14, an experimental feature allowed
1503415549L<C<shift>|/shift ARRAY> to take a
1503515550scalar expression. This experiment has been deemed unsuccessful, and was
1503615551removed as of Perl 5.24.
1503715552
1503815553=end original
1503915554
1504015555Perl 5.14 から、L<C<shift>|/shift ARRAY> がスカラ式を取ることが出来るという
1504115556実験的機能がありました。
1504215557この実験は失敗と見なされ、Perl 5.24 で削除されました。
1504315558
1504415559=begin original
1504515560
1504615561See also L<C<unshift>|/unshift ARRAY,LIST>, L<C<push>|/push ARRAY,LIST>,
1504715562and L<C<pop>|/pop ARRAY>. L<C<shift>|/shift ARRAY> and
1504815563L<C<unshift>|/unshift ARRAY,LIST> do the same thing to the left end of
1504915564an array that L<C<pop>|/pop ARRAY> and L<C<push>|/push ARRAY,LIST> do to
1505015565the right end.
1505115566
1505215567=end original
1505315568
1505415569L<C<unshift>|/unshift ARRAY,LIST>、L<C<push>|/push ARRAY,LIST>、
1505515570L<C<pop>|/pop ARRAY> も参照してください。
1505615571L<C<shift>|/shift ARRAY> と L<C<unshift>|/unshift ARRAY,LIST> は、
1505715572L<C<pop>|/pop ARRAY> と L<C<push>|/push ARRAY,LIST> が配列の右端で
1505815573行なうことを、左端で行ないます。
1505915574
1506015575=item shmctl ID,CMD,ARG
1506115576X<shmctl>
1506215577
1506315578=for Pod::Functions SysV shared memory operations
1506415579
1506515580=begin original
1506615581
1506715582Calls the System V IPC function shmctl. You'll probably have to say
1506815583
1506915584=end original
1507015585
1507115586System V IPC 関数 shmctl を呼び出します。
1507215587正しい定数定義を得るために、まず
1507315588
1507415589 use IPC::SysV;
1507515590
1507615591=begin original
1507715592
1507815593first to get the correct constant definitions. If CMD is C<IPC_STAT>,
1507915594then ARG must be a variable that will hold the returned C<shmid_ds>
1508015595structure. Returns like ioctl: L<C<undef>|/undef EXPR> for error; "C<0>
1508115596but true" for zero; and the actual return value otherwise.
1508215597See also L<perlipc/"SysV IPC"> and the documentation for
1508315598L<C<IPC::SysV>|IPC::SysV>.
1508415599
1508515600=end original
1508615601
1508715602と書くことが必要でしょう。
1508815603CMD が、C<IPC_STAT> ならば、ARG は、返される C<shmid_ds> 構造体を
1508915604納める変数でなければなりません。
1509015605ioctl と同様です: エラー時には L<C<undef>|/undef EXPR>; ゼロのときは
1509115606"C<0> だが真"; それ以外なら、その値そのものを返します。
1509215607L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。
1509315608
1509415609=begin original
1509515610
1509615611Portability issues: L<perlport/shmctl>.
1509715612
1509815613=end original
1509915614
1510015615移植性の問題: L<perlport/shmctl>。
1510115616
1510215617=item shmget KEY,SIZE,FLAGS
1510315618X<shmget>
1510415619
1510515620=for Pod::Functions get SysV shared memory segment identifier
1510615621
1510715622=begin original
1510815623
1510915624Calls the System V IPC function shmget. Returns the shared memory
1511015625segment id, or L<C<undef>|/undef EXPR> on error.
1511115626See also L<perlipc/"SysV IPC"> and the documentation for
1511215627L<C<IPC::SysV>|IPC::SysV>.
1511315628
1511415629=end original
1511515630
1511615631System V IPC 関数 shmget を呼び出します。
1511715632共有メモリのセグメント ID か、エラー時には L<C<undef>|/undef EXPR> を返します。
1511815633L<perlipc/"SysV IPC"> と L<C<IPC::SysV>|IPC::SysV> の文書も参照してください。
1511915634
1512015635=begin original
1512115636
1512215637Portability issues: L<perlport/shmget>.
1512315638
1512415639=end original
1512515640
1512615641移植性の問題: L<perlport/shmget>。
1512715642
1512815643=item shmread ID,VAR,POS,SIZE
1512915644X<shmread>
1513015645X<shmwrite>
1513115646
1513215647=for Pod::Functions read SysV shared memory
1513315648
1513415649=item shmwrite ID,STRING,POS,SIZE
1513515650
1513615651=for Pod::Functions write SysV shared memory
1513715652
1513815653=begin original
1513915654
1514015655Reads or writes the System V shared memory segment ID starting at
1514115656position POS for size SIZE by attaching to it, copying in/out, and
1514215657detaching from it. When reading, VAR must be a variable that will
1514315658hold the data read. When writing, if STRING is too long, only SIZE
1514415659bytes are used; if STRING is too short, nulls are written to fill out
1514515660SIZE bytes. Return true if successful, false on error.
1514615661L<C<shmread>|/shmread ID,VAR,POS,SIZE> taints the variable. See also
1514715662L<perlipc/"SysV IPC"> and the documentation for
1514815663L<C<IPC::SysV>|IPC::SysV> and the L<C<IPC::Shareable>|IPC::Shareable>
1514915664module from CPAN.
1515015665
1515115666=end original
1515215667
1515315668System V 共有メモリセグメント ID に対し、アタッチして、コピーを行ない、
1515415669デタッチするという形で、位置 POS から、サイズ SIZE だけ、読み込みか書き込みを
1515515670行ないます。
1515615671読み込み時には、VAR は読み込んだデータを納める変数でなければなりません。
1515715672書き込み時には、STRING が長すぎても、SIZE バイトだけが使われます; STRING が
1515815673短すぎる場合には、SIZE バイトを埋めるために、ヌル文字が書き込まれます。
1515915674成功時には真を、エラー時には偽を返します。
1516015675L<C<shmread>|/shmread ID,VAR,POS,SIZE> は変数を汚染します。
1516115676L<perlipc/"SysV IPC"> および、L<C<IPC::SysV>|IPC::SysV> と CPAN の
1516215677L<C<IPC::Shareable>|IPC::Shareable> の文書も参照してください。
1516315678
1516415679=begin original
1516515680
1516615681Portability issues: L<perlport/shmread> and L<perlport/shmwrite>.
1516715682
1516815683=end original
1516915684
1517015685移植性の問題: L<perlport/shmread> と L<perlport/shmwrite>。
1517115686
1517215687=item shutdown SOCKET,HOW
1517315688X<shutdown>
1517415689
1517515690=for Pod::Functions close down just half of a socket connection
1517615691
1517715692=begin original
1517815693
1517915694Shuts down a socket connection in the manner indicated by HOW, which
1518015695has the same interpretation as in the syscall of the same name.
1518115696
1518215697=end original
1518315698
1518415699同名のシステムコールと同じように解釈される HOW によって、
1518515700指定された方法でソケット接続のシャットダウンを行ないます。
1518615701
1518715702 shutdown($socket, 0); # I/we have stopped reading data
1518815703 shutdown($socket, 1); # I/we have stopped writing data
1518915704 shutdown($socket, 2); # I/we have stopped using this socket
1519015705
1519115706=begin original
1519215707
1519315708This is useful with sockets when you want to tell the other
1519415709side you're done writing but not done reading, or vice versa.
1519515710It's also a more insistent form of close because it also
1519615711disables the file descriptor in any forked copies in other
1519715712processes.
1519815713
1519915714=end original
1520015715
1520115716これは、こちらがソケットを書き終わったが読み終わっていない、
1520215717またはその逆を相手側に伝えたいときに便利です。
1520315718これはその他のプロセスでフォークしたファイル記述子のコピーも
1520415719無効にするので、よりしつこい閉じ方です。
1520515720
1520615721=begin original
1520715722
1520815723Returns C<1> for success; on error, returns L<C<undef>|/undef EXPR> if
1520915724the first argument is not a valid filehandle, or returns C<0> and sets
1521015725L<C<$!>|perlvar/$!> for any other failure.
1521115726
1521215727=end original
1521315728
1521415729成功時には C<1> を返します;
1521515730エラーの場合、最初の引数が有効なファイルハンドルでない場合は
1521615731L<C<undef>|/undef EXPR> を返し、その他のエラーの場合は C<0> を返して
1521715732L<C<$!>|perlvar/$!> をセットします。
1521815733
1521915734=item sin EXPR
1522015735X<sin> X<sine> X<asin> X<arcsine>
1522115736
1522215737=item sin
1522315738
1522415739=for Pod::Functions return the sine of a number
1522515740
1522615741=begin original
1522715742
1522815743Returns the sine of EXPR (expressed in radians). If EXPR is omitted,
1522915744returns sine of L<C<$_>|perlvar/$_>.
1523015745
1523115746=end original
1523215747
1523315748(ラジアンで示した) EXPR の正弦を返します。
1523415749EXPR が省略されたときには、L<C<$_>|perlvar/$_> の正弦を返します。
1523515750
1523615751=begin original
1523715752
1523815753For the inverse sine operation, you may use the C<Math::Trig::asin>
1523915754function, or use this relation:
1524015755
1524115756=end original
1524215757
1524315758逆正弦を求めるためには、C<Math::Trig::asin> 関数を使うか、
1524415759以下の関係を使ってください:
1524515760
1524615761 sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
1524715762
1524815763=item sleep EXPR
1524915764X<sleep> X<pause>
1525015765
1525115766=item sleep
1525215767
1525315768=for Pod::Functions block for some number of seconds
1525415769
1525515770=begin original
1525615771
1525715772Causes the script to sleep for (integer) EXPR seconds, or forever if no
1525815773argument is given. Returns the integer number of seconds actually slept.
1525915774
1526015775=end original
1526115776
1526215777スクリプトを(整数の) EXPR で指定した秒数 (省略時には、永久に)
1526315778スリープさせます。
1526415779実際にスリープした秒数を返します。
1526515780
1526615781=begin original
1526715782
1526815783May be interrupted if the process receives a signal such as C<SIGALRM>.
1526915784
1527015785=end original
1527115786
1527215787そのプロセスが C<SIGALRM>のようなシグナルを受信すると、
1527315788割り込みがかかります。
1527415789
1527515790 eval {
1527615791 local $SIG{ALRM} = sub { die "Alarm!\n" };
1527715792 sleep;
1527815793 };
1527915794 die $@ unless $@ eq "Alarm!\n";
1528015795
1528115796=begin original
1528215797
1528315798You probably cannot mix L<C<alarm>|/alarm SECONDS> and
1528415799L<C<sleep>|/sleep EXPR> calls, because L<C<sleep>|/sleep EXPR> is often
1528515800implemented using L<C<alarm>|/alarm SECONDS>.
1528615801
1528715802=end original
1528815803
1528915804L<C<sleep>|/sleep EXPR> は、L<C<alarm>|/alarm SECONDS> を使って
1529015805実装されることが多いので、L<C<alarm>|/alarm SECONDS> と
1529115806L<C<sleep>|/sleep EXPR> は、混ぜて使用することはおそらくできません。
1529215807
1529315808=begin original
1529415809
1529515810On some older systems, it may sleep up to a full second less than what
1529615811you requested, depending on how it counts seconds. Most modern systems
1529715812always sleep the full amount. They may appear to sleep longer than that,
1529815813however, because your process might not be scheduled right away in a
1529915814busy multitasking system.
1530015815
1530115816=end original
1530215817
1530315818古いシステムでは、どのように秒を数えるかによって、要求した秒数に完全に
1530415819満たないうちに、スリープから抜ける場合があります。
1530515820最近のシステムでは、常に完全にスリープします。
1530615821しかし、負荷の高いマルチタスクシステムでは
1530715822正しくスケジューリングされないがために
1530815823より長い時間スリープすることがあります。
1530915824
1531015825=begin original
1531115826
1531215827For delays of finer granularity than one second, the L<Time::HiRes>
1531315828module (from CPAN, and starting from Perl 5.8 part of the standard
1531415829distribution) provides L<C<usleep>|Time::HiRes/usleep ( $useconds )>.
1531515830You may also use Perl's four-argument
1531615831version of L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> leaving the
1531715832first three arguments undefined, or you might be able to use the
1531815833L<C<syscall>|/syscall NUMBER, LIST> interface to access L<setitimer(2)>
1531915834if your system supports it. See L<perlfaq8> for details.
1532015835
1532115836=end original
1532215837
15323158381 秒より精度の高いスリープを行なうには、L<Time::HiRes> モジュール(CPAN から、
1532415839また Perl 5.8 からは標準配布されています) が
1532515840L<C<usleep>|Time::HiRes/usleep ( $useconds )> を提供します。
1532615841Perl の 4 引数版 L<C<select>|/select RBITS,WBITS,EBITS,TIMEOUT> を最初の
15327158423 引数を未定義にして使うか、L<setitimer(2)> をサポートしているシステムでは、
1532815843Perl の L<C<syscall>|/syscall NUMBER, LIST> インタフェースを使って
1532915844アクセスすることもできます。
1533015845詳しくは L<perlfaq8> を参照してください。
1533115846
1533215847=begin original
1533315848
1533415849See also the L<POSIX> module's L<C<pause>|POSIX/C<pause>> function.
1533515850
1533615851=end original
1533715852
1533815853L<POSIX> モジュールの L<C<pause>|POSIX/C<pause>> 関数も参照してください。
1533915854
1534015855=item socket SOCKET,DOMAIN,TYPE,PROTOCOL
1534115856X<socket>
1534215857
1534315858=for Pod::Functions create a socket
1534415859
1534515860=begin original
1534615861
1534715862Opens a socket of the specified kind and attaches it to filehandle
1534815863SOCKET. DOMAIN, TYPE, and PROTOCOL are specified the same as for
1534915864the syscall of the same name. You should C<use Socket> first
1535015865to get the proper definitions imported. See the examples in
1535115866L<perlipc/"Sockets: Client/Server Communication">.
1535215867
1535315868=end original
1535415869
1535515870指定した種類のソケットをオープンし、ファイルハンドル SOCKET にアタッチします。
1535615871DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
1535715872適切な定義を import するために、まず、C<use Socket> とするとよいでしょう。
1535815873L<perlipc/"Sockets: Client/Server Communication"> の例を参照してください。
1535915874
1536015875=begin original
1536115876
1536215877On systems that support a close-on-exec flag on files, the flag will
1536315878be set for the newly opened file descriptor, as determined by the
1536415879value of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1536515880
1536615881=end original
1536715882
1536815883ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1536915884フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
1537015885ファイル記述子に対してセットされます。
1537115886L<perlvar/$^F> を参照してください。
1537215887
1537315888=item socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
1537415889X<socketpair>
1537515890
1537615891=for Pod::Functions create a pair of sockets
1537715892
1537815893=begin original
1537915894
1538015895Creates an unnamed pair of sockets in the specified domain, of the
1538115896specified type. DOMAIN, TYPE, and PROTOCOL are specified the same as
1538215897for the syscall of the same name. If unimplemented, raises an exception.
1538315898Returns true if successful.
1538415899
1538515900=end original
1538615901
1538715902指定した DOMAIN に、指定した TYPE で名前の無いソケットのペアを生成します。
1538815903DOMAIN, TYPE, PROTOCOL は、同名のシステムコールと同じように指定します。
1538915904実装されていない場合には、例外が発生します。
1539015905成功時には真を返します。
1539115906
1539215907=begin original
1539315908
1539415909On systems that support a close-on-exec flag on files, the flag will
1539515910be set for the newly opened file descriptors, as determined by the value
1539615911of L<C<$^F>|perlvar/$^F>. See L<perlvar/$^F>.
1539715912
1539815913=end original
1539915914
1540015915ファイルに対する close-on-exec フラグをサポートしているシステムでは、
1540115916フラグは L<C<$^F>|perlvar/$^F> の値で決定される、新しくオープンされた
1540215917ファイル記述子に対してセットされます。
1540315918L<perlvar/$^F> を参照してください。
1540415919
1540515920=begin original
1540615921
1540715922Some systems define L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> in terms of
1540815923L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL>, in
1540915924which a call to C<pipe($rdr, $wtr)> is essentially:
1541015925
1541115926=end original
1541215927
1541315928L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
1541415929L<C<socketpair>|/socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL> を使って
1541515930定義しているシステムもあります;
1541615931C<pipe($rdr, $wtr)> は本質的には以下のようになります:
1541715932
1541815933 use Socket;
1541915934 socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
1542015935 shutdown($rdr, 1); # no more writing for reader
1542115936 shutdown($wtr, 0); # no more reading for writer
1542215937
1542315938=begin original
1542415939
1542515940See L<perlipc> for an example of socketpair use. Perl 5.8 and later will
1542615941emulate socketpair using IP sockets to localhost if your system implements
1542715942sockets but not socketpair.
1542815943
1542915944=end original
1543015945
1543115946socketpair の使用例については L<perlipc> を参照してください。
1543215947Perl 5.8 以降では、システムがソケットを実装しているが socketpair を
1543315948実装していない場合、localhost に対して IP ソケットを使うことで
1543415949socketpair をエミュレートします。
1543515950
1543615951=begin original
1543715952
1543815953Portability issues: L<perlport/socketpair>.
1543915954
1544015955=end original
1544115956
1544215957移植性の問題: L<perlport/socketpair>。
1544315958
1544415959=item sort SUBNAME LIST
15445X<sort> X<qsort> X<quicksort> X<mergesort>
15960X<sort>
1544615961
1544715962=item sort BLOCK LIST
1544815963
1544915964=item sort LIST
1545015965
1545115966=for Pod::Functions sort a list of values
1545215967
1545315968=begin original
1545415969
1545515970In list context, this sorts the LIST and returns the sorted list value.
1545615971In scalar context, the behaviour of L<C<sort>|/sort SUBNAME LIST> is
1545715972undefined.
1545815973
1545915974=end original
1546015975
1546115976リストコンテキストでは、LIST をソートし、ソートされたリスト値を返します。
1546215977スカラコンテキストでは、L<C<sort>|/sort SUBNAME LIST> の振る舞いは未定義です。
1546315978
1546415979=begin original
1546515980
1546615981If SUBNAME or BLOCK is omitted, L<C<sort>|/sort SUBNAME LIST>s in
1546715982standard string comparison
1546815983order. If SUBNAME is specified, it gives the name of a subroutine
1546915984that returns an integer less than, equal to, or greater than C<0>,
1547015985depending on how the elements of the list are to be ordered. (The
1547115986C<< <=> >> and C<cmp> operators are extremely useful in such routines.)
1547215987SUBNAME may be a scalar variable name (unsubscripted), in which case
1547315988the value provides the name of (or a reference to) the actual
1547415989subroutine to use. In place of a SUBNAME, you can provide a BLOCK as
1547515990an anonymous, in-line sort subroutine.
1547615991
1547715992=end original
1547815993
1547915994SUBNAME や BLOCK を省略すると、L<C<sort>|/sort SUBNAME LIST> は標準の
1548015995文字列比較の順番で行なわれます。
1548115996SUBNAME を指定すると、それは、リストの要素をどのような順番に並べるかに
1548215997応じて、負の整数、C<0>、正の整数を返すサブルーチンの名前であると解釈されます。
1548315998(このようなルーチンには、C<< <=> >> 演算子や C<cmp> 演算子が、
1548415999たいへん便利です。)
1548516000SUBNAME は、スカラ変数名(添字なし)でもよく、その場合には、その値が使用する
1548616001実際のサブルーチンの名前(またはそのリファレンス)と解釈されます。
1548716002SUBNAME の代わりに、無名のインラインソートルーチンとして、BLOCK を
1548816003書くことができます。
1548916004
1549016005=begin original
1549116006
1549216007If the subroutine's prototype is C<($$)>, the elements to be compared are
1549316008passed by reference in L<C<@_>|perlvar/@_>, as for a normal subroutine.
1549416009This is slower than unprototyped subroutines, where the elements to be
1549516010compared are passed into the subroutine as the package global variables
1549616011C<$a> and C<$b> (see example below).
1549716012
1549816013=end original
1549916014
1550016015サブルーチンのプロトタイプが C<($$)>の場合、比較する要素は通常のサブルーチンと
1550116016同じように L<C<@_>|perlvar/@_> の中にリファレンスとして渡されます。
1550216017これはプロトタイプなしのサブルーチンより遅いです; この場合は比較のため
1550316018サブルーチンに渡される二つの要素は、パッケージのグローバル変数 C<$a> と
1550416019C<$b> で渡されます(次の例を参照してください)。
1550516020
1550616021=begin original
1550716022
1550816023If the subroutine is an XSUB, the elements to be compared are pushed on
1550916024to the stack, the way arguments are usually passed to XSUBs. C<$a> and
1551016025C<$b> are not set.
1551116026
1551216027=end original
1551316028
1551416029サブルーチンが XSUB の場合、比較される要素は、普通に引数を XSUB に渡す形で、
1551516030スタックにプッシュされます。
1551616031C<$a> と C<$b> は設定されません。
1551716032
1551816033=begin original
1551916034
1552016035The values to be compared are always passed by reference and should not
1552116036be modified.
1552216037
1552316038=end original
1552416039
1552516040比較される値はリファレンスによって渡されるので、変更するべきではありません。
1552616041
1552716042=begin original
1552816043
1552916044You also cannot exit out of the sort block or subroutine using any of the
1553016045loop control operators described in L<perlsyn> or with
1553116046L<C<goto>|/goto LABEL>.
1553216047
1553316048=end original
1553416049
1553516050また、ソートブロックやサブルーチンから L<perlsyn> で説明されている
1553616051ループ制御子や L<C<goto>|/goto LABEL> を使って抜けてはいけません。
1553716052
1553816053=begin original
1553916054
1554016055When L<C<use locale>|locale> (but not C<use locale ':not_characters'>)
1554116056is in effect, C<sort LIST> sorts LIST according to the
1554216057current collation locale. See L<perllocale>.
1554316058
1554416059=end original
1554516060
1554616061L<C<use locale>|locale> が有効(そして C<use locale ':not_characters'> が
1554716062有効でない)の場合、C<sort LIST> は LIST を現在の比較ロケールに従って
1554816063ソートします。
1554916064L<perllocale> を参照してください。
1555016065
1555116066=begin original
1555216067
1555316068L<C<sort>|/sort SUBNAME LIST> returns aliases into the original list,
1555416069much as a for loop's index variable aliases the list elements. That is,
1555516070modifying an element of a list returned by L<C<sort>|/sort SUBNAME LIST>
1555616071(for example, in a C<foreach>, L<C<map>|/map BLOCK LIST> or
1555716072L<C<grep>|/grep BLOCK LIST>)
1555816073actually modifies the element in the original list. This is usually
1555916074something to be avoided when writing clear code.
1556016075
1556116076=end original
1556216077
1556316078L<C<sort>|/sort SUBNAME LIST> は元のリストへのエイリアスを返します;
1556416079for ループのインデックス変数がリスト要素へのエイリアスと同様です。
1556516080つまり、L<C<sort>|/sort SUBNAME LIST> で返されるリストの要素を(例えば、
1556616081C<foreach> や L<C<map>|/map BLOCK LIST> や
1556716082L<C<grep>|/grep BLOCK LIST> で)変更すると、実際に元のリストの要素が
1556816083変更されます。
1556916084これはきれいなコードを書くときには普通は回避されます。
1557016085
1557116086=begin original
1557216087
15573Perl 5.6 and earlier used a quicksort algorithm to implement sort.
16088Historically Perl has varied in whether sorting is stable by default.
15574That algorithm was not stable and I<could> go quadratic. (A I<stable> sort
16089If stability matters, it can be controlled explicitly by using the
15575preserves the input order of elements that compare equal. Although
16090L<sort> pragma.
15576quicksort's run time is O(NlogN) when averaged over all arrays of
15577length N, the time can be O(N**2), I<quadratic> behavior, for some
15578inputs.) In 5.7, the quicksort implementation was replaced with
15579a stable mergesort algorithm whose worst-case behavior is O(NlogN).
15580But benchmarks indicated that for some inputs, on some platforms,
15581the original quicksort was faster. 5.8 has a L<sort> pragma for
15582limited control of the sort. Its rather blunt control of the
15583underlying algorithm may not persist into future Perls, but the
15584ability to characterize the input or output in implementation
15585independent ways quite probably will.
1558616091
1558716092=end original
1558816093
15589Perl 5.6 以前ではソートの実装にクイックソートアゴリズムを使っていました
16094歴史的にソートがデフォトで安定かどうかは様々です
15590このアルゴリズムは安定しておらず、2 乗の時間掛か I<可能性があります>
16095安定問題にな場合は、L<sort> プラグマを使うことで明示的に制御できます。
15591(I<安定した> ソートは、比較した時に同じ要素の入力順が保存されます。
15592クイックソートの実行時間は、長さ N の全ての配列の平均では O(NlogN) ですが、
15593入力によっては O(N**2) という I<2 乗の> 振る舞いをすることがあります。)
155945.7 では、クイックソートによる実装は、最悪の場合の振る舞いも O(NlogN) である、
15595安定したマージソートアルゴリズムに置き換えられました。
15596しかし、入力とプラットフォームによっては、ベンチマークはクイックソートの方が
15597速くなります。
155985.8 ではソートを限定的に制御できる L<sort> プラグマがあります。
15599この、アルゴリズムの直接的な制御方法は将来の perl では引き継がれないかも
15600しれませんが、実装に依存しない形で入力や出力を性格付ける機能は
15601おそらくあります。
1560216096
1560316097=begin original
1560416098
1560516099Examples:
1560616100
1560716101=end original
1560816102
1560916103例:
1561016104
1561116105 # sort lexically
1561216106 my @articles = sort @files;
1561316107
1561416108 # same thing, but with explicit sort routine
1561516109 my @articles = sort {$a cmp $b} @files;
1561616110
1561716111 # now case-insensitively
1561816112 my @articles = sort {fc($a) cmp fc($b)} @files;
1561916113
1562016114 # same thing in reversed order
1562116115 my @articles = sort {$b cmp $a} @files;
1562216116
1562316117 # sort numerically ascending
1562416118 my @articles = sort {$a <=> $b} @files;
1562516119
1562616120 # sort numerically descending
1562716121 my @articles = sort {$b <=> $a} @files;
1562816122
1562916123 # this sorts the %age hash by value instead of key
1563016124 # using an in-line function
1563116125 my @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
1563216126
1563316127 # sort using explicit subroutine name
1563416128 sub byage {
1563516129 $age{$a} <=> $age{$b}; # presuming numeric
1563616130 }
1563716131 my @sortedclass = sort byage @class;
1563816132
1563916133 sub backwards { $b cmp $a }
1564016134 my @harry = qw(dog cat x Cain Abel);
1564116135 my @george = qw(gone chased yz Punished Axed);
1564216136 print sort @harry;
1564316137 # prints AbelCaincatdogx
1564416138 print sort backwards @harry;
1564516139 # prints xdogcatCainAbel
1564616140 print sort @george, 'to', @harry;
1564716141 # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
1564816142
1564916143 # inefficiently sort by descending numeric compare using
1565016144 # the first integer after the first = sign, or the
1565116145 # whole record case-insensitively otherwise
1565216146
1565316147 my @new = sort {
1565416148 ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
1565516149 ||
1565616150 fc($a) cmp fc($b)
1565716151 } @old;
1565816152
1565916153 # same thing, but much more efficiently;
1566016154 # we'll build auxiliary indices instead
1566116155 # for speed
1566216156 my (@nums, @caps);
1566316157 for (@old) {
1566416158 push @nums, ( /=(\d+)/ ? $1 : undef );
1566516159 push @caps, fc($_);
1566616160 }
1566716161
1566816162 my @new = @old[ sort {
1566916163 $nums[$b] <=> $nums[$a]
1567016164 ||
1567116165 $caps[$a] cmp $caps[$b]
1567216166 } 0..$#old
1567316167 ];
1567416168
1567516169 # same thing, but without any temps
1567616170 my @new = map { $_->[0] }
1567716171 sort { $b->[1] <=> $a->[1]
1567816172 ||
1567916173 $a->[2] cmp $b->[2]
1568016174 } map { [$_, /=(\d+)/, fc($_)] } @old;
1568116175
1568216176 # using a prototype allows you to use any comparison subroutine
1568316177 # as a sort subroutine (including other package's subroutines)
1568416178 package Other;
1568516179 sub backwards ($$) { $_[1] cmp $_[0]; } # $a and $b are
1568616180 # not set here
1568716181 package main;
1568816182 my @new = sort Other::backwards @old;
1568916183
15690 # guarantee stability, regardless of algorithm
16184 # guarantee stability
1569116185 use sort 'stable';
1569216186 my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
1569316187
15694 # force use of mergesort (not portable outside Perl 5.8)
15695 use sort '_mergesort'; # note discouraging _
15696 my @new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
15697
1569816188=begin original
1569916189
1570016190Warning: syntactical care is required when sorting the list returned from
1570116191a function. If you want to sort the list returned by the function call
1570216192C<find_records(@key)>, you can use:
1570316193
1570416194=end original
1570516195
15706警告: 関数からかえされたリストをソートするときには文法上の注意が必要です。
16196警告: 関数からされたリストをソートするときには文法上の注意が必要です。
1570716197関数呼び出し C<find_records(@key)> から返されたリストをソートしたい場合、
1570816198以下のように出来ます:
1570916199
1571016200 my @contact = sort { $a cmp $b } find_records @key;
1571116201 my @contact = sort +find_records(@key);
1571216202 my @contact = sort &find_records(@key);
1571316203 my @contact = sort(find_records(@key));
1571416204
1571516205=begin original
1571616206
1571716207If instead you want to sort the array C<@key> with the comparison routine
1571816208C<find_records()> then you can use:
1571916209
1572016210=end original
1572116211
1572216212一方、配列 C<@key> を比較ルーチン C<find_records()> でソートしたい場合は、
1572316213以下のように出来ます:
1572416214
1572516215 my @contact = sort { find_records() } @key;
1572616216 my @contact = sort find_records(@key);
1572716217 my @contact = sort(find_records @key);
1572816218 my @contact = sort(find_records (@key));
1572916219
1573016220=begin original
1573116221
1573216222C<$a> and C<$b> are set as package globals in the package the sort() is
1573316223called from. That means C<$main::a> and C<$main::b> (or C<$::a> and
1573416224C<$::b>) in the C<main> package, C<$FooPack::a> and C<$FooPack::b> in the
1573516225C<FooPack> package, etc. If the sort block is in scope of a C<my> or
1573616226C<state> declaration of C<$a> and/or C<$b>, you I<must> spell out the full
1573716227name of the variables in the sort block :
1573816228
1573916229=end original
1574016230
1574116231C<$a> と C<$b> は、sort() を呼び出したパッケージのパッケージグローバルとして
1574216232設定されます。
1574316233つまり、C<main> パッケージの C<$main::a> と C<$main::b>
1574416234(あるいは C<$::a> と C<$::b>) 、
1574516235C<FooPack> パッケージの C<$FooPack::a> と C<$FooPack::b>、などです。
1574616236ソートブロックが C<$a> や C<$b> の C<my> または C<state> のスコープ内の場合、
1574716237ソートブロックの変数の完全名を I<指定しなければなりません>:
1574816238
1574916239 package main;
1575016240 my $a = "C"; # DANGER, Will Robinson, DANGER !!!
1575116241
1575216242 print sort { $a cmp $b } qw(A C E G B D F H);
1575316243 # WRONG
1575416244 sub badlexi { $a cmp $b }
1575516245 print sort badlexi qw(A C E G B D F H);
1575616246 # WRONG
1575716247 # the above prints BACFEDGH or some other incorrect ordering
1575816248
1575916249 print sort { $::a cmp $::b } qw(A C E G B D F H);
1576016250 # OK
1576116251 print sort { our $a cmp our $b } qw(A C E G B D F H);
1576216252 # also OK
1576316253 print sort { our ($a, $b); $a cmp $b } qw(A C E G B D F H);
1576416254 # also OK
1576516255 sub lexi { our $a cmp our $b }
1576616256 print sort lexi qw(A C E G B D F H);
1576716257 # also OK
1576816258 # the above print ABCDEFGH
1576916259
1577016260=begin original
1577116261
1577216262With proper care you may mix package and my (or state) C<$a> and/or C<$b>:
1577316263
1577416264=end original
1577516265
1577616266適切に注意すれば、パッケージと my (あるいは state) C<$a> や C<$b> を
1577716267混ぜることができます:
1577816268
1577916269 my $a = {
1578016270 tiny => -2,
1578116271 small => -1,
1578216272 normal => 0,
1578316273 big => 1,
1578416274 huge => 2
1578516275 };
1578616276
1578716277 say sort { $a->{our $a} <=> $a->{our $b} }
1578816278 qw{ huge normal tiny small big};
1578916279
1579016280 # prints tinysmallnormalbighuge
1579116281
1579216282=begin original
1579316283
15794C<$a> and C<$b> are implicitely local to the sort() execution and regain their
16284C<$a> and C<$b> are implicitly local to the sort() execution and regain their
1579516285former values upon completing the sort.
1579616286
1579716287=end original
1579816288
1579916289C<$a> と C<$b> は sort() の実行中は暗黙にローカル化され、ソート終了時に
1580016290元の値に戻ります。
1580116291
1580216292=begin original
1580316293
1580416294Sort subroutines written using C<$a> and C<$b> are bound to their calling
1580516295package. It is possible, but of limited interest, to define them in a
1580616296different package, since the subroutine must still refer to the calling
1580716297package's C<$a> and C<$b> :
1580816298
1580916299=end original
1581016300
1581116301C<$a> と C<$b> を使って書かれたソートサブルーチンはその呼び出しパッケージに
1581216302しなければなりません。
1581316303異なるパッケージに定義することは可能ですが、
1581416304これは可能ですが、限られた関心しかありません;
1581516305サブルーチンは呼び出しパッケージの C<$a> と C<$b> を
1581616306参照しなければならないからです:
1581716307
1581816308 package Foo;
1581916309 sub lexi { $Bar::a cmp $Bar::b }
1582016310 package Bar;
1582116311 ... sort Foo::lexi ...
1582216312
1582316313=begin original
1582416314
1582516315Use the prototyped versions (see above) for a more generic alternative.
1582616316
1582716317=end original
1582816318
1582916319より一般的な代替案としては(前述の)プロトタイプ版を使ってください。
1583016320
1583116321=begin original
1583216322
1583316323The comparison function is required to behave. If it returns
1583416324inconsistent results (sometimes saying C<$x[1]> is less than C<$x[2]> and
1583516325sometimes saying the opposite, for example) the results are not
1583616326well-defined.
1583716327
1583816328=end original
1583916329
1584016330比較関数は一貫した振る舞いをすることが求められます。
1584116331一貫しない結果を返す(例えば、あるときは C<$x[1]> が C<$x[2]> より
1584216332小さいと返し、またあるときは逆を返す)場合、結果は未定義です。
1584316333
1584416334=begin original
1584516335
1584616336Because C<< <=> >> returns L<C<undef>|/undef EXPR> when either operand
1584716337is C<NaN> (not-a-number), be careful when sorting with a
1584816338comparison function like C<< $a <=> $b >> any lists that might contain a
1584916339C<NaN>. The following example takes advantage that C<NaN != NaN> to
1585016340eliminate any C<NaN>s from the input list.
1585116341
1585216342=end original
1585316343
1585416344C<< <=> >> はどちらかのオペランドが C<NaN> (not-a-number) のときに
1585516345L<C<undef>|/undef EXPR> を返すので、C<< $a <=> $b >> といった比較関数で
1585616346ソートする場合はリストに C<NaN> が含まれないように注意してください。
1585716347以下の例は 入力リストから C<NaN> を取り除くために C<NaN != NaN> という性質を
1585816348利用しています。
1585916349
1586016350 my @result = sort { $a <=> $b } grep { $_ == $_ } @input;
1586116351
1586216352=item splice ARRAY,OFFSET,LENGTH,LIST
1586316353X<splice>
1586416354
1586516355=item splice ARRAY,OFFSET,LENGTH
1586616356
1586716357=item splice ARRAY,OFFSET
1586816358
1586916359=item splice ARRAY
1587016360
1587116361=for Pod::Functions add or remove elements anywhere in an array
1587216362
1587316363=begin original
1587416364
1587516365Removes the elements designated by OFFSET and LENGTH from an array, and
1587616366replaces them with the elements of LIST, if any. In list context,
1587716367returns the elements removed from the array. In scalar context,
1587816368returns the last element removed, or L<C<undef>|/undef EXPR> if no
1587916369elements are
1588016370removed. The array grows or shrinks as necessary.
1588116371If OFFSET is negative then it starts that far from the end of the array.
1588216372If LENGTH is omitted, removes everything from OFFSET onward.
1588316373If LENGTH is negative, removes the elements from OFFSET onward
1588416374except for -LENGTH elements at the end of the array.
1588516375If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
1588616376past the end of the array and a LENGTH was provided, Perl issues a warning,
1588716377and splices at the end of the array.
1588816378
1588916379=end original
1589016380
1589116381ARRAY から OFFSET、LENGTH で指定される要素を取り除き、
1589216382LIST があれば、それを代わりに挿入します。
1589316383リストコンテキストでは、配列から取り除かれた要素を返します。
1589416384スカラコンテキストでは、取り除かれた最後の要素を返します; 要素が
1589516385取り除かれなかった場合は L<C<undef>|/undef EXPR> を返します。
1589616386配列は、必要に応じて、大きくなったり、小さくなったりします。
1589716387OFFSET が負の数の場合は、配列の最後からの距離を示します。
1589816388LENGTH が省略されると、OFFSET 以降のすべての要素を取り除きます。
1589916389LENGTH が負の数の場合は、OFFSET から前方へ、配列の最後から -LENGTH 要素を
1590016390除いて取り除きます。
1590116391OFFSET と LENGTH の両方が省略されると、全ての要素を取り除きます。
1590216392OFFSET が配列の最後より後ろで、 LENGTH が指定されていると、Perl は警告を出し、
1590316393配列の最後に対して処理します。
1590416394
1590516395=begin original
1590616396
1590716397The following equivalences hold (assuming C<< $#a >= $i >> )
1590816398
1590916399=end original
1591016400
1591116401以下は、(C<< $#a >= $i >> と仮定すると) それぞれ、等価です。
1591216402
1591316403 push(@a,$x,$y) splice(@a,@a,0,$x,$y)
1591416404 pop(@a) splice(@a,-1)
1591516405 shift(@a) splice(@a,0,1)
1591616406 unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
1591716407 $a[$i] = $y splice(@a,$i,1,$y)
1591816408
1591916409=begin original
1592016410
1592116411L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> can be used, for example,
1592216412to implement n-ary queue processing:
1592316413
1592416414=end original
1592516415
1592616416L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> は、例えば、n-ary キュー処理の
1592716417実装に使えます:
1592816418
1592916419 sub nary_print {
1593016420 my $n = shift;
1593116421 while (my @next_n = splice @_, 0, $n) {
1593216422 say join q{ -- }, @next_n;
1593316423 }
1593416424 }
1593516425
1593616426 nary_print(3, qw(a b c d e f g h));
1593716427 # prints:
1593816428 # a -- b -- c
1593916429 # d -- e -- f
1594016430 # g -- h
1594116431
1594216432=begin original
1594316433
1594416434Starting with Perl 5.14, an experimental feature allowed
1594516435L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> to take a
1594616436scalar expression. This experiment has been deemed unsuccessful, and was
1594716437removed as of Perl 5.24.
1594816438
1594916439=end original
1595016440
1595116441Perl 5.14 から、L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> がスカラ式を
1595216442取ることが出来るという実験的機能がありました。
1595316443この実験は失敗と見なされ、Perl 5.24 で削除されました。
1595416444
1595516445=item split /PATTERN/,EXPR,LIMIT
1595616446X<split>
1595716447
1595816448=item split /PATTERN/,EXPR
1595916449
1596016450=item split /PATTERN/
1596116451
1596216452=item split
1596316453
1596416454=for Pod::Functions split up a string using a regexp delimiter
1596516455
1596616456=begin original
1596716457
1596816458Splits the string EXPR into a list of strings and returns the
1596916459list in list context, or the size of the list in scalar context.
1597016460(Prior to Perl 5.11, it also overwrote C<@_> with the list in
1597116461void and scalar context. If you target old perls, beware.)
1597216462
1597316463=end original
1597416464
1597516465文字列 EXPR を文字列のリストに分割して、リストコンテキストではそのリストを
1597616466返し、スカラコンテキストではリストの大きさを返します。
1597716467(Perl 5.11 以前では、無効コンテキストやスカラコンテキストの場合は
1597816468C<@_> をリストで上書きします。
1597916469もし古い perl を対象にするなら、注意してください。)
1598016470
1598116471=begin original
1598216472
1598316473If only PATTERN is given, EXPR defaults to L<C<$_>|perlvar/$_>.
1598416474
1598516475=end original
1598616476
1598716477PATTERN のみが与えられた場合、EXPR のデフォルトは L<C<$_>|perlvar/$_> です。
1598816478
1598916479=begin original
1599016480
1599116481Anything in EXPR that matches PATTERN is taken to be a separator
1599216482that separates the EXPR into substrings (called "I<fields>") that
1599316483do B<not> include the separator. Note that a separator may be
1599416484longer than one character or even have no characters at all (the
1599516485empty string, which is a zero-width match).
1599616486
1599716487=end original
1599816488
1599916489EXPR の中で PATTERN にマッチングするものは何でも EXPR を("I<fields>" と
1600016490呼ばれる)セパレータを B<含まない> 部分文字列に分割するための
1600116491セパレータとなります。
1600216492セパレータは一文字より長くてもよく、全く文字がなくてもよい(空文字列は
1600316493ゼロ幅マッチングです)ということに注意してください。
1600416494
1600516495=begin original
1600616496
1600716497The PATTERN need not be constant; an expression may be used
1600816498to specify a pattern that varies at runtime.
1600916499
1601016500=end original
1601116501
1601216502PATTERN は定数である必要はありません; 実行時に変更されるパターンを
1601316503指定するために式を使えます。
1601416504
1601516505=begin original
1601616506
1601716507If PATTERN matches the empty string, the EXPR is split at the match
1601816508position (between characters). As an example, the following:
1601916509
1602016510=end original
1602116511
1602216512PATTERN が空文字列にマッチングする場合、EXPR はマッチング位置
1602316513(文字の間)で分割されます。
1602416514例えば、以下のものは:
1602516515
1602616516 print join(':', split(/b/, 'abc')), "\n";
1602716517
1602816518=begin original
1602916519
1603016520uses the C<b> in C<'abc'> as a separator to produce the output C<a:c>.
1603116521However, this:
1603216522
1603316523=end original
1603416524
1603516525C<'abc'> の C<b> をセパレータとして使って出力 C<a:c> を生成します。
1603616526しかし、これは:
1603716527
1603816528 print join(':', split(//, 'abc')), "\n";
1603916529
1604016530=begin original
1604116531
1604216532uses empty string matches as separators to produce the output
1604316533C<a:b:c>; thus, the empty string may be used to split EXPR into a
1604416534list of its component characters.
1604516535
1604616536=end original
1604716537
1604816538空文字列マッチングをセパレータとして使って出力 C<a:b:c> を生成します; 従って、
1604916539空文字列は EXPR を構成する文字のリストに分割するために使われます。
1605016540
1605116541=begin original
1605216542
1605316543As a special case for L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT>,
1605416544the empty pattern given in
1605516545L<match operator|perlop/"m/PATTERN/msixpodualngc"> syntax (C<//>)
1605616546specifically matches the empty string, which is contrary to its usual
1605716547interpretation as the last successful match.
1605816548
1605916549=end original
1606016550
1606116551L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> の特殊な場合として、
1606216552L<マッチング演算子|perlop/"m/PATTERN/msixpodualngc"> 文法で与えられた
1606316553空パターン (C<//>) は特に空文字列にマッチングし、最後に成功した
1606416554マッチングという普通の解釈と異なります。
1606516555
1606616556=begin original
1606716557
1606816558If PATTERN is C</^/>, then it is treated as if it used the
1606916559L<multiline modifier|perlreref/OPERATORS> (C</^/m>), since it
1607016560isn't much use otherwise.
1607116561
1607216562=end original
1607316563
1607416564PATTERN が C</^/> の場合、L<複数行修飾子|perlreref/OPERATORS>
1607516565(C</^/m>) が使われたかのように扱われます; そうでなければほとんど
1607616566使えないからです。
1607716567
1607816568=begin original
1607916569
1608016570C<E<sol>m> and any of the other pattern modifiers valid for C<qr>
1608116571(summarized in L<perlop/qrE<sol>STRINGE<sol>msixpodualn>) may be
1608216572specified explicitly.
1608316573
1608416574=end original
1608516575
1608616576C<qr> で有効な C<E<sol>m> 及びその他のパターン修飾子
1608716577(L<perlop/qrE<sol>STRINGE<sol>msixpodualn> にまとめられています) は
1608816578明示的に定義されます。
1608916579
1609016580=begin original
1609116581
1609216582As another special case,
1609316583L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> emulates the default
1609416584behavior of the
1609516585command line tool B<awk> when the PATTERN is either omitted or a
1609616586string composed of a single space character (such as S<C<' '>> or
1609716587S<C<"\x20">>, but not e.g. S<C</ />>). In this case, any leading
1609816588whitespace in EXPR is removed before splitting occurs, and the PATTERN is
1609916589instead treated as if it were C</\s+/>; in particular, this means that
1610016590I<any> contiguous whitespace (not just a single space character) is used as
1610116591a separator. However, this special treatment can be avoided by specifying
1610216592the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
1610316593only a single space character to be a separator. In earlier Perls this
1610416594special case was restricted to the use of a plain S<C<" ">> as the
1610516595pattern argument to split; in Perl 5.18.0 and later this special case is
1610616596triggered by any expression which evaluates to the simple string S<C<" ">>.
1610716597
1610816598=end original
1610916599
1611016600もう一つの特別な場合として、
1611116601L<C<split>|/split E<sol>PATTERNE<sol>,EXPR,LIMIT> は
1611216602PATTERN が省略されるか単一のスペース文字からなる文字列 (つまり例えば
1611316603S<C</ />> ではなく S<C<' '>> や S<C<"\x20">>) の場合、コマンドラインツール
1611416604B<awk> のデフォルトの振る舞いをエミュレートします。
1611516605この場合、EXPR の先頭の空白は分割を行う前に削除され、PATTERN は
1611616606C</\s+/> であったかのように扱われます; 特に、これは (単に単一の
1611716607スペース文字ではなく) I<あらゆる> 連続した空白がセパレータとして
1611816608使われるということです。
1611916609しかし、この特別の扱いは文字列 S<C<" ">> の代わりにパターン S<C</ />> を
1612016610指定することで回避でき、それによってセパレータとして単一の
1612116611スペース文字のみが使われます。
1612216612以前の Perl ではこの特別な場合は split のパターン引数として単に S<C<" ">> を
1612316613使った場合に制限されていました; Perl 5.18.0 以降では、この特別な場合は
1612416614単純な文字列 S<C<" ">> と評価される任意の式によって引き起こされます。
1612516615
1612616616=begin original
1612716617
16618As 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
16620'unicode_strings' feature >>. In previous versions, and outside the scope of
16621that feature, it exhibits L<perlunicode/The "Unicode Bug">: characters that are
16622whitespace according to Unicode rules but not according to ASCII rules can be
16623treated as part of fields rather than as field separators, depending on the
16624string's internal encoding.
16625
16626=end original
16627
16628Perl 5.28 から、この特別な場合の空白分割は
16629L<< S<C<"use feature 'unicode_strings">>|feature/The
16630'unicode_strings' feature >> のスコープの中では想定通りに動作します。
16631以前のバージョンでは、そしてこの機能のスコープの外側では、
16632これは L<perlunicode/The "Unicode Bug"> を引き起こします:
16633Unicode によれば空白だけれども ASCII の規則ではそうではない文字は、
16634文字列の内部エンコーディングに依存して、
16635フィールドの区切りではなくフィールドの一部として扱われることがあります。
16636
16637=begin original
16638
1612816639If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering
1612916640the previously described I<awk> emulation.
1613016641
1613116642=end original
1613216643
1613316644省略されると、PATTERN のデフォルトは単一のスペース S<C<" ">> になり、
1613416645先に記述した I<awk> エミュレーションを起動します。
1613516646
1613616647=begin original
1613716648
1613816649If LIMIT is specified and positive, it represents the maximum number
1613916650of fields into which the EXPR may be split; in other words, LIMIT is
1614016651one greater than the maximum number of times EXPR may be split. Thus,
1614116652the LIMIT value C<1> means that EXPR may be split a maximum of zero
1614216653times, producing a maximum of one field (namely, the entire value of
1614316654EXPR). For instance:
1614416655
1614516656=end original
1614616657
1614716658LIMIT が指定された正数の場合、EXPR が分割されるフィールドの最大数を
1614816659表現します; 言い換えると、 LIMIT は EXPR が分割される数より一つ大きい数です。
1614916660従って、LIMIT の値 C<1> は EXPR が最大 0 回分割されるということで、
1615016661最大で一つのフィールドを生成します (言い換えると、EXPR 全体の値です)。
1615116662例えば:
1615216663
1615316664 print join(':', split(//, 'abc', 1)), "\n";
1615416665
1615516666=begin original
1615616667
1615716668produces the output C<abc>, and this:
1615816669
1615916670=end original
1616016671
1616116672これは C<abc> を出力し、次のものは:
1616216673
1616316674 print join(':', split(//, 'abc', 2)), "\n";
1616416675
1616516676=begin original
1616616677
1616716678produces the output C<a:bc>, and each of these:
1616816679
1616916680=end original
1617016681
1617116682C<a:bc> を出力し、以下のものそれぞれは:
1617216683
1617316684 print join(':', split(//, 'abc', 3)), "\n";
1617416685 print join(':', split(//, 'abc', 4)), "\n";
1617516686
1617616687=begin original
1617716688
1617816689produces the output C<a:b:c>.
1617916690
1618016691=end original
1618116692
1618216693C<a:b:c> を出力します。
1618316694
1618416695=begin original
1618516696
1618616697If LIMIT is negative, it is treated as if it were instead arbitrarily
1618716698large; as many fields as possible are produced.
1618816699
1618916700=end original
1619016701
1619116702LIMIT が負数なら、非常に大きい数であるかのように扱われます; できるだけ多くの
1619216703フィールドが生成されます。
1619316704
1619416705=begin original
1619516706
1619616707If LIMIT is omitted (or, equivalently, zero), then it is usually
1619716708treated as if it were instead negative but with the exception that
1619816709trailing empty fields are stripped (empty leading fields are always
1619916710preserved); if all fields are empty, then all fields are considered to
1620016711be trailing (and are thus stripped in this case). Thus, the following:
1620116712
1620216713=end original
1620316714
1620416715LIMIT が省略されると(あるいは等価な 0 なら)、普通は負数が指定されたかのように
1620516716動作しますが、末尾の空フィールドは取り除かれるという例外があります
1620616717(先頭の空フィールドは常に保存されます); もし全てのフィールドが空なら、
1620716718全てのフィールドが末尾として扱われます(そしてこの場合取り除かれます)。
1620816719従って、以下のようにすると:
1620916720
1621016721 print join(':', split(/,/, 'a,b,c,,,')), "\n";
1621116722
1621216723=begin original
1621316724
1621416725produces the output C<a:b:c>, but the following:
1621516726
1621616727=end original
1621716728
1621816729出力 C<a:b:c> を生成しますが、以下のようにすると:
1621916730
1622016731 print join(':', split(/,/, 'a,b,c,,,', -1)), "\n";
1622116732
1622216733=begin original
1622316734
1622416735produces the output C<a:b:c:::>.
1622516736
1622616737=end original
1622716738
1622816739出力 C<a:b:c:::> を生成します。
1622916740
1623016741=begin original
1623116742
1623216743In time-critical applications, it is worthwhile to avoid splitting
1623316744into more fields than necessary. Thus, when assigning to a list,
1623416745if LIMIT is omitted (or zero), then LIMIT is treated as though it
1623516746were one larger than the number of variables in the list; for the
1623616747following, LIMIT is implicitly 3:
1623716748
1623816749=end original
1623916750
1624016751時間に厳しいアプリケーションでは、必要でないフィールドの分割を避けるのは
1624116752価値があります。
1624216753従って、リストに代入される場合に、LIMIT が省略される(または 0)と、
1624316754LIMIT は リストにある変数の数より一つ大きい数のように扱われます;
1624416755次の場合、LIMIT は暗黙に 3 になります:
1624516756
1624616757 my ($login, $passwd) = split(/:/);
1624716758
1624816759=begin original
1624916760
1625016761Note that splitting an EXPR that evaluates to the empty string always
1625116762produces zero fields, regardless of the LIMIT specified.
1625216763
1625316764=end original
1625416765
1625516766LIMIT の指定に関わらず、空文字列に評価される EXPR を分割すると常に 0 個の
1625616767フィールドを生成することに注意してください。
1625716768
1625816769=begin original
1625916770
1626016771An empty leading field is produced when there is a positive-width
1626116772match at the beginning of EXPR. For instance:
1626216773
1626316774=end original
1626416775
1626516776EXPR の先頭で正数幅でマッチングしたときには先頭に空のフィールドが
1626616777生成されます。
1626716778例えば:
1626816779
1626916780 print join(':', split(/ /, ' abc')), "\n";
1627016781
1627116782=begin original
1627216783
1627316784produces the output C<:abc>. However, a zero-width match at the
1627416785beginning of EXPR never produces an empty field, so that:
1627516786
1627616787=end original
1627716788
1627816789これは出力 C<:abc> を生成します。
1627916790しかし、EXPR の先頭でのゼロ幅マッチングは決して空フィールドを生成しないので:
1628016791
1628116792 print join(':', split(//, ' abc'));
1628216793
1628316794=begin original
1628416795
1628516796produces the output S<C< :a:b:c>> (rather than S<C<: :a:b:c>>).
1628616797
1628716798=end original
1628816799
1628916800これは(S<C<: :a:b:c>> ではなく)出力 S<C< :a:b:c>> を生成します。
1629016801
1629116802=begin original
1629216803
1629316804An empty trailing field, on the other hand, is produced when there is a
1629416805match at the end of EXPR, regardless of the length of the match
1629516806(of course, unless a non-zero LIMIT is given explicitly, such fields are
1629616807removed, as in the last example). Thus:
1629716808
1629816809=end original
1629916810
1630016811一方、末尾の空のフィールドは、マッチングの長さに関わらず、EXPR の末尾で
1630116812マッチングしたときに生成されます(もちろん非 0 の LIMIT が明示的に
1630216813指定されていない場合です; このようなフィールドは前の例のように
1630316814取り除かれます)。
1630416815従って:
1630516816
1630616817 print join(':', split(//, ' abc', -1)), "\n";
1630716818
1630816819=begin original
1630916820
1631016821produces the output S<C< :a:b:c:>>.
1631116822
1631216823=end original
1631316824
1631416825これは出力 S<C< :a:b:c:>> を生成します。
1631516826
1631616827=begin original
1631716828
1631816829If the PATTERN contains
1631916830L<capturing groups|perlretut/Grouping things and hierarchical matching>,
1632016831then for each separator, an additional field is produced for each substring
1632116832captured by a group (in the order in which the groups are specified,
1632216833as per L<backreferences|perlretut/Backreferences>); if any group does not
1632316834match, then it captures the L<C<undef>|/undef EXPR> value instead of a
1632416835substring. Also,
1632516836note that any such additional field is produced whenever there is a
1632616837separator (that is, whenever a split occurs), and such an additional field
1632716838does B<not> count towards the LIMIT. Consider the following expressions
1632816839evaluated in list context (each returned list is provided in the associated
1632916840comment):
1633016841
1633116842=end original
1633216843
1633316844PATTERN が
1633416845L<捕捉グループ|perlretut/Grouping things and hierarchical matching> を
1633516846含んでいる場合、それぞれのセパレータについて、
1633616847(L<後方参照|perlretut/Backreferences> のようにグループが指定された)
1633716848グループによって捕捉されたそれぞれの部分文字列について追加のフィールドが
1633816849生成されます; どのグループもマッチングしなかった場合、部分文字列の代わりに
1633916850L<C<undef>|/undef EXPR> 値を捕捉します。
1634016851また、このような追加のフィールドはセパレータがあるとき(つまり、分割が
1634116852行われるとき)はいつでも生成され、このような追加のフィールドは
1634216853LIMIT に関してはカウント B<されない> ことに注意してください。
1634316854リストコンテキストで評価される以下のような式を考えます
1634416855(それぞれの返されるリストは関連づけられたコメントで提供されます):
1634516856
1634616857 split(/-|,/, "1-10,20", 3)
1634716858 # ('1', '10', '20')
1634816859
1634916860 split(/(-|,)/, "1-10,20", 3)
1635016861 # ('1', '-', '10', ',', '20')
1635116862
1635216863 split(/-|(,)/, "1-10,20", 3)
1635316864 # ('1', undef, '10', ',', '20')
1635416865
1635516866 split(/(-)|,/, "1-10,20", 3)
1635616867 # ('1', '-', '10', undef, '20')
1635716868
1635816869 split(/(-)|(,)/, "1-10,20", 3)
1635916870 # ('1', '-', undef, '10', undef, ',', '20')
1636016871
1636116872=item sprintf FORMAT, LIST
1636216873X<sprintf>
1636316874
1636416875=for Pod::Functions formatted print into a string
1636516876
1636616877=begin original
1636716878
1636816879Returns a string formatted by the usual
1636916880L<C<printf>|/printf FILEHANDLE FORMAT, LIST> conventions of the C
1637016881library function L<C<sprintf>|/sprintf FORMAT, LIST>. See below for
1637116882more details and see L<sprintf(3)> or L<printf(3)> on your system for an
1637216883explanation of the general principles.
1637316884
1637416885=end original
1637516886
1637616887C ライブラリ関数 L<C<sprintf>|/sprintf FORMAT, LIST> の
1637716888普通の L<C<printf>|/printf FILEHANDLE FORMAT, LIST> 記法の
1637816889整形された文字列を返します。
1637916890一般的な原則の説明については以下の説明と、システムの
1638016891L<sprintf(3)> または L<printf(3)> の説明を参照してください。
1638116892
1638216893=begin original
1638316894
1638416895For example:
1638516896
1638616897=end original
1638716898
1638816899例えば:
1638916900
1639016901 # Format number with up to 8 leading zeroes
1639116902 my $result = sprintf("%08d", $number);
1639216903
1639316904 # Round number to 3 digits after decimal point
1639416905 my $rounded = sprintf("%.3f", $number);
1639516906
1639616907=begin original
1639716908
1639816909Perl does its own L<C<sprintf>|/sprintf FORMAT, LIST> formatting: it
1639916910emulates the C
1640016911function L<sprintf(3)>, but doesn't use it except for floating-point
1640116912numbers, and even then only standard modifiers are allowed.
1640216913Non-standard extensions in your local L<sprintf(3)> are
1640316914therefore unavailable from Perl.
1640416915
1640516916=end original
1640616917
1640716918Perl は L<C<sprintf>|/sprintf FORMAT, LIST> フォーマット処理を自力で行います:
1640816919これは C の L<sprintf(3)> 関数をエミュレートしますが、C の関数は使いません
1640916920(浮動小数点を除きますが、それでも標準の記述子のみが利用できます)。
1641016921従って、ローカルな非標準の L<sprintf(3)> 拡張機能は Perl では使えません。
1641116922
1641216923=begin original
1641316924
1641416925Unlike L<C<printf>|/printf FILEHANDLE FORMAT, LIST>,
1641516926L<C<sprintf>|/sprintf FORMAT, LIST> does not do what you probably mean
1641616927when you pass it an array as your first argument.
1641716928The array is given scalar context,
1641816929and instead of using the 0th element of the array as the format, Perl will
1641916930use the count of elements in the array as the format, which is almost never
1642016931useful.
1642116932
1642216933=end original
1642316934
1642416935L<C<printf>|/printf FILEHANDLE FORMAT, LIST> と違って、
1642516936L<C<sprintf>|/sprintf FORMAT, LIST> の最初の引数に配列を渡しても
1642616937あなたが多分望むとおりには動作しません。
1642716938配列はスカラコンテキストで渡されるので、配列の 0 番目の要素ではなく、
1642816939配列の要素数をフォーマットとして扱います; これはほとんど役に立ちません。
1642916940
1643016941=begin original
1643116942
1643216943Perl's L<C<sprintf>|/sprintf FORMAT, LIST> permits the following
1643316944universally-known conversions:
1643416945
1643516946=end original
1643616947
1643716948Perl の L<C<sprintf>|/sprintf FORMAT, LIST> は以下の一般に知られている変換に
1643816949対応しています:
1643916950
1644016951=begin original
1644116952
1644216953 %% a percent sign
1644316954 %c a character with the given number
1644416955 %s a string
1644516956 %d a signed integer, in decimal
1644616957 %u an unsigned integer, in decimal
1644716958 %o an unsigned integer, in octal
1644816959 %x an unsigned integer, in hexadecimal
1644916960 %e a floating-point number, in scientific notation
1645016961 %f a floating-point number, in fixed decimal notation
1645116962 %g a floating-point number, in %e or %f notation
1645216963
1645316964=end original
1645416965
1645516966 %% パーセントマーク
1645616967 %c 与えられた番号の文字
1645716968 %s 文字列
1645816969 %d 符号付き 10 進数
1645916970 %u 符号なし 10 進数
1646016971 %o 符号なし 8 進数
1646116972 %x 符号なし 16 進数
1646216973 %e 科学的表記の浮動小数点数
1646316974 %f 固定 10 進数表記の浮動小数点数
1646416975 %g %e か %f の表記の浮動小数点数
1646516976
1646616977=begin original
1646716978
1646816979In addition, Perl permits the following widely-supported conversions:
1646916980
1647016981=end original
1647116982
1647216983さらに、Perl では以下のよく使われている変換に対応しています:
1647316984
1647416985=begin original
1647516986
1647616987 %X like %x, but using upper-case letters
1647716988 %E like %e, but using an upper-case "E"
1647816989 %G like %g, but with an upper-case "E" (if applicable)
1647916990 %b an unsigned integer, in binary
1648016991 %B like %b, but using an upper-case "B" with the # flag
1648116992 %p a pointer (outputs the Perl value's address in hexadecimal)
1648216993 %n special: *stores* the number of characters output so far
1648316994 into the next argument in the parameter list
1648416995 %a hexadecimal floating point
1648516996 %A like %a, but using upper-case letters
1648616997
1648716998=end original
1648816999
1648917000 %X %x と同様だが大文字を使う
1649017001 %E %e と同様だが大文字の "E" を使う
1649117002 %G %g と同様だが(適切なら)大文字の "E" を使う
1649217003 %b 符号なし 2 進数
1649317004 %B %b と同様だが、# フラグで大文字の "B" を使う
1649417005 %p ポインタ (Perl の値のアドレスを 16 進数で出力する)
1649517006 %n 特殊: 出力文字数を引数リストの次の変数に「格納」する
1649617007 %a 16 進浮動小数点
1649717008 %A %a と同様だが、大文字を使う
1649817009
1649917010=begin original
1650017011
1650117012Finally, for backward (and we do mean "backward") compatibility, Perl
1650217013permits these unnecessary but widely-supported conversions:
1650317014
1650417015=end original
1650517016
1650617017最後に、過去との互換性(これは「過去」だと考えています)のために、
1650717018Perl は以下の不要ではあるけれども広く使われている変換に対応しています。
1650817019
1650917020=begin original
1651017021
1651117022 %i a synonym for %d
1651217023 %D a synonym for %ld
1651317024 %U a synonym for %lu
1651417025 %O a synonym for %lo
1651517026 %F a synonym for %f
1651617027
1651717028=end original
1651817029
1651917030 %i %d の同義語
1652017031 %D %ld の同義語
1652117032 %U %lu の同義語
1652217033 %O %lo の同義語
1652317034 %F %f の同義語
1652417035
1652517036=begin original
1652617037
1652717038Note that the number of exponent digits in the scientific notation produced
1652817039by C<%e>, C<%E>, C<%g> and C<%G> for numbers with the modulus of the
1652917040exponent less than 100 is system-dependent: it may be three or less
1653017041(zero-padded as necessary). In other words, 1.23 times ten to the
165311704299th may be either "1.23e99" or "1.23e099". Similarly for C<%a> and C<%A>:
1653217043the exponent or the hexadecimal digits may float: especially the
1653317044"long doubles" Perl configuration option may cause surprises.
1653417045
1653517046=end original
1653617047
1653717048C<%e>, C<%E>, C<%g>, C<%G> において、指数部が 100 未満の場合の
1653817049指数部の科学的な表記法はシステム依存であることに注意してください:
16539170503 桁かもしれませんし、それ以下かもしれません(必要に応じて 0 で
1654017051パッディングされます)。
1654117052言い換えると、 1.23 掛ける 10 の 99 乗は "1.23e99" かもしれませんし
1654217053"1.23e099" かもしれません。
1654317054同様に C<%a> と C<%A> の場合:
1654417055指数部と 16 進数が浮動小数点かもしれません:
1654517056特に "long doubles" Perl 設定オプションが驚きを引き起こすかもしれません。
1654617057
1654717058=begin original
1654817059
1654917060Between the C<%> and the format letter, you may specify several
1655017061additional attributes controlling the interpretation of the format.
1655117062In order, these are:
1655217063
1655317064=end original
1655417065
1655517066C<%> とフォーマット文字の間に、フォーマットの解釈を制御するための、
1655617067いくつかの追加の属性を指定できます。
1655717068順番に、以下のものがあります:
1655817069
1655917070=over 4
1656017071
1656117072=item format parameter index
1656217073
1656317074(フォーマットパラメータインデックス)
1656417075
1656517076=begin original
1656617077
1656717078An explicit format parameter index, such as C<2$>. By default sprintf
1656817079will format the next unused argument in the list, but this allows you
1656917080to take the arguments out of order:
1657017081
1657117082=end original
1657217083
1657317084C<2$> のような明示的なフォーマットパラメータインデックス。
1657417085デフォルトでは sprintf はリストの次の使われていない引数を
1657517086フォーマットしますが、これによって異なった順番の引数を使えるようにします:
1657617087
1657717088 printf '%2$d %1$d', 12, 34; # prints "34 12"
1657817089 printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1"
1657917090
1658017091=item flags
1658117092
1658217093(フラグ)
1658317094
1658417095=begin original
1658517096
1658617097one or more of:
1658717098
1658817099=end original
1658917100
1659017101以下のうちの一つまたは複数指定できます:
1659117102
1659217103=begin original
1659317104
1659417105 space prefix non-negative number with a space
1659517106 + prefix non-negative number with a plus sign
1659617107 - left-justify within the field
1659717108 0 use zeros, not spaces, to right-justify
1659817109 # ensure the leading "0" for any octal,
1659917110 prefix non-zero hexadecimal with "0x" or "0X",
1660017111 prefix non-zero binary with "0b" or "0B"
1660117112
1660217113=end original
1660317114
1660417115 space 非負数の前に空白をつける
1660517116 + 非負数の前にプラス記号をつける
1660617117 - フィールド内で左詰めする
1660717118 0 右詰めに空白ではなくゼロを使う
1660817119 # 8 進数では確実に先頭に "0" をつける;
1660917120 非 0 の 16 進数では "0x" か "0X" をつける;
1661017121 非 0 の 2 進数では "0b" か "0B" をつける
1661117122
1661217123=begin original
1661317124
1661417125For example:
1661517126
1661617127=end original
1661717128
1661817129例えば:
1661917130
1662017131 printf '<% d>', 12; # prints "< 12>"
1662117132 printf '<% d>', 0; # prints "< 0>"
1662217133 printf '<% d>', -12; # prints "<-12>"
1662317134 printf '<%+d>', 12; # prints "<+12>"
1662417135 printf '<%+d>', 0; # prints "<+0>"
1662517136 printf '<%+d>', -12; # prints "<-12>"
1662617137 printf '<%6s>', 12; # prints "< 12>"
1662717138 printf '<%-6s>', 12; # prints "<12 >"
1662817139 printf '<%06s>', 12; # prints "<000012>"
1662917140 printf '<%#o>', 12; # prints "<014>"
1663017141 printf '<%#x>', 12; # prints "<0xc>"
1663117142 printf '<%#X>', 12; # prints "<0XC>"
1663217143 printf '<%#b>', 12; # prints "<0b1100>"
1663317144 printf '<%#B>', 12; # prints "<0B1100>"
1663417145
1663517146=begin original
1663617147
1663717148When a space and a plus sign are given as the flags at once,
1663817149the space is ignored.
1663917150
1664017151=end original
1664117152
1664217153空白とプラス記号がフラグとして同時に与えられると、
1664317154空白は無視されます。
1664417155
1664517156 printf '<%+ d>', 12; # prints "<+12>"
1664617157 printf '<% +d>', 12; # prints "<+12>"
1664717158
1664817159=begin original
1664917160
1665017161When the # flag and a precision are given in the %o conversion,
1665117162the precision is incremented if it's necessary for the leading "0".
1665217163
1665317164=end original
1665417165
1665517166%o 変換に # フラグと精度が与えられると、先頭の "0" が必要な場合は
1665617167精度に 1 が加えられます。
1665717168
1665817169 printf '<%#.5o>', 012; # prints "<00012>"
1665917170 printf '<%#.5o>', 012345; # prints "<012345>"
1666017171 printf '<%#.0o>', 0; # prints "<0>"
1666117172
1666217173=item vector flag
1666317174
1666417175(ベクタフラグ)
1666517176
1666617177=begin original
1666717178
1666817179This flag tells Perl to interpret the supplied string as a vector of
1666917180integers, one for each character in the string. Perl applies the format to
1667017181each integer in turn, then joins the resulting strings with a separator (a
1667117182dot C<.> by default). This can be useful for displaying ordinal values of
1667217183characters in arbitrary strings:
1667317184
1667417185=end original
1667517186
1667617187このフラグは Perl に、与えられた文字列を、文字毎に一つの整数のベクタとして
1667717188解釈させます。
1667817189Perl は各数値をフォーマットし、それから結果の文字列をセパレータ
1667917190(デフォルトでは C<.>)で連結します。
1668017191これは任意の文字列の文字を順序付きの値として表示するのに便利です:
1668117192
1668217193 printf "%vd", "AB\x{100}"; # prints "65.66.256"
1668317194 printf "version is v%vd\n", $^V; # Perl's version
1668417195
1668517196=begin original
1668617197
1668717198Put an asterisk C<*> before the C<v> to override the string to
1668817199use to separate the numbers:
1668917200
1669017201=end original
1669117202
1669217203アスタリスク C<*> を C<v> の前に置くと、数値を分けるために使われる文字列を
1669317204上書きします:
1669417205
1669517206 printf "address is %*vX\n", ":", $addr; # IPv6 address
1669617207 printf "bits are %0*v8b\n", " ", $bits; # random bitstring
1669717208
1669817209=begin original
1669917210
1670017211You can also explicitly specify the argument number to use for
1670117212the join string using something like C<*2$v>; for example:
1670217213
1670317214=end original
1670417215
1670517216また、C<*2$v> のように、連結する文字列として使う引数の番号を明示的に
1670617217指定できます; 例えば:
1670717218
1670817219 printf '%*4$vX %*4$vX %*4$vX', # 3 IPv6 addresses
1670917220 @addr[1..3], ":";
1671017221
1671117222=item (minimum) width
1671217223
1671317224((最小)幅)
1671417225
1671517226=begin original
1671617227
1671717228Arguments are usually formatted to be only as wide as required to
1671817229display the given value. You can override the width by putting
1671917230a number here, or get the width from the next argument (with C<*>)
1672017231or from a specified argument (e.g., with C<*2$>):
1672117232
1672217233=end original
1672317234
1672417235引数は、普通は値を表示するのに必要なちょうどの幅でフォーマットされます。
1672517236ここに数値を置くか、(C<*> で)次の引数か(C<*2$> で)明示的に指定した引数で
1672617237幅を上書きできます。
1672717238
1672817239 printf "<%s>", "a"; # prints "<a>"
1672917240 printf "<%6s>", "a"; # prints "< a>"
1673017241 printf "<%*s>", 6, "a"; # prints "< a>"
1673117242 printf '<%*2$s>', "a", 6; # prints "< a>"
1673217243 printf "<%2s>", "long"; # prints "<long>" (does not truncate)
1673317244
1673417245=begin original
1673517246
1673617247If a field width obtained through C<*> is negative, it has the same
1673717248effect as the C<-> flag: left-justification.
1673817249
1673917250=end original
1674017251
1674117252C<*> を通して得られたフィールドの値が負数の場合、C<-> フラグと
1674217253同様の効果 (左詰め) があります。
1674317254
1674417255=item precision, or maximum width
1674517256X<precision>
1674617257
1674717258(精度あるいは最大幅)
1674817259
1674917260=begin original
1675017261
1675117262You can specify a precision (for numeric conversions) or a maximum
1675217263width (for string conversions) by specifying a C<.> followed by a number.
1675317264For floating-point formats except C<g> and C<G>, this specifies
1675417265how many places right of the decimal point to show (the default being 6).
1675517266For example:
1675617267
1675717268=end original
1675817269
1675917270C<.> の後に数値を指定することで、(数値変換の場合)精度や(文字列変換の場合)
1676017271最大幅を指定できます。
1676117272小数点数フォーマットの場合、C<g> と C<G> を除いて、表示する小数点以下の
1676217273桁数を指定します(デフォルトは 6 です)。
1676317274例えば:
1676417275
1676517276 # these examples are subject to system-specific variation
1676617277 printf '<%f>', 1; # prints "<1.000000>"
1676717278 printf '<%.1f>', 1; # prints "<1.0>"
1676817279 printf '<%.0f>', 1; # prints "<1>"
1676917280 printf '<%e>', 10; # prints "<1.000000e+01>"
1677017281 printf '<%.1e>', 10; # prints "<1.0e+01>"
1677117282
1677217283=begin original
1677317284
1677417285For "g" and "G", this specifies the maximum number of significant digits to
1677517286show; for example:
1677617287
1677717288=end original
1677817289
1677917290"g" と "G" の場合、これは最大有効数字を指定します; 例えば:
1678017291
1678117292 # These examples are subject to system-specific variation.
1678217293 printf '<%g>', 1; # prints "<1>"
1678317294 printf '<%.10g>', 1; # prints "<1>"
1678417295 printf '<%g>', 100; # prints "<100>"
1678517296 printf '<%.1g>', 100; # prints "<1e+02>"
1678617297 printf '<%.2g>', 100.01; # prints "<1e+02>"
1678717298 printf '<%.5g>', 100.01; # prints "<100.01>"
1678817299 printf '<%.4g>', 100.01; # prints "<100>"
1678917300 printf '<%.1g>', 0.0111; # prints "<0.01>"
1679017301 printf '<%.2g>', 0.0111; # prints "<0.011>"
1679117302 printf '<%.3g>', 0.0111; # prints "<0.0111>"
1679217303
1679317304=begin original
1679417305
1679517306For integer conversions, specifying a precision implies that the
1679617307output of the number itself should be zero-padded to this width,
1679717308where the 0 flag is ignored:
1679817309
1679917310=end original
1680017311
1680117312整数変換の場合、精度を指定すると、数値自体の出力はこの幅に 0 で
1680217313パッディングするべきであることを暗に示すことになり、0 フラグは
1680317314無視されます:
1680417315
1680517316 printf '<%.6d>', 1; # prints "<000001>"
1680617317 printf '<%+.6d>', 1; # prints "<+000001>"
1680717318 printf '<%-10.6d>', 1; # prints "<000001 >"
1680817319 printf '<%10.6d>', 1; # prints "< 000001>"
1680917320 printf '<%010.6d>', 1; # prints "< 000001>"
1681017321 printf '<%+10.6d>', 1; # prints "< +000001>"
1681117322
1681217323 printf '<%.6x>', 1; # prints "<000001>"
1681317324 printf '<%#.6x>', 1; # prints "<0x000001>"
1681417325 printf '<%-10.6x>', 1; # prints "<000001 >"
1681517326 printf '<%10.6x>', 1; # prints "< 000001>"
1681617327 printf '<%010.6x>', 1; # prints "< 000001>"
1681717328 printf '<%#10.6x>', 1; # prints "< 0x000001>"
1681817329
1681917330=begin original
1682017331
1682117332For string conversions, specifying a precision truncates the string
1682217333to fit the specified width:
1682317334
1682417335=end original
1682517336
1682617337文字列変換の場合、精度を指定すると、指定された幅に収まるように文字列を
1682717338切り詰めます:
1682817339
1682917340 printf '<%.5s>', "truncated"; # prints "<trunc>"
1683017341 printf '<%10.5s>', "truncated"; # prints "< trunc>"
1683117342
1683217343=begin original
1683317344
1683417345You can also get the precision from the next argument using C<.*>, or from a
1683517346specified argument (e.g., with C<.*2$>):
1683617347
1683717348=end original
1683817349
1683917350C<.*> を使って精度を次の引数から取ったり、
1684017351(C<.*2$> のように) 指定した引数から取ったりすることもできます:
1684117352
1684217353 printf '<%.6x>', 1; # prints "<000001>"
1684317354 printf '<%.*x>', 6, 1; # prints "<000001>"
1684417355
1684517356 printf '<%.*2$x>', 1, 6; # prints "<000001>"
1684617357
1684717358 printf '<%6.*2$x>', 1, 4; # prints "< 0001>"
1684817359
1684917360=begin original
1685017361
1685117362If a precision obtained through C<*> is negative, it counts
1685217363as having no precision at all.
1685317364
1685417365=end original
1685517366
1685617367C<*> によって得られた精度が負数の場合、精度が指定されなかった場合と
1685717368同じ効果となります。
1685817369
1685917370 printf '<%.*s>', 7, "string"; # prints "<string>"
1686017371 printf '<%.*s>', 3, "string"; # prints "<str>"
1686117372 printf '<%.*s>', 0, "string"; # prints "<>"
1686217373 printf '<%.*s>', -1, "string"; # prints "<string>"
1686317374
1686417375 printf '<%.*d>', 1, 0; # prints "<0>"
1686517376 printf '<%.*d>', 0, 0; # prints "<>"
1686617377 printf '<%.*d>', -1, 0; # prints "<0>"
1686717378
1686817379=item size
1686917380
1687017381(サイズ)
1687117382
1687217383=begin original
1687317384
1687417385For numeric conversions, you can specify the size to interpret the
1687517386number as using C<l>, C<h>, C<V>, C<q>, C<L>, or C<ll>. For integer
1687617387conversions (C<d u o x X b i D U O>), numbers are usually assumed to be
1687717388whatever the default integer size is on your platform (usually 32 or 64
1687817389bits), but you can override this to use instead one of the standard C types,
1687917390as supported by the compiler used to build Perl:
1688017391
1688117392=end original
1688217393
1688317394数値変換では、C<l>, C<h>, C<V>, C<q>, C<L>, C<ll> を使って解釈する数値の
1688417395大きさを指定できます。
1688517396整数変換 (C<d u o x X b i D U O>) では、数値は通常プラットフォームの
1688617397デフォルトの整数のサイズ (通常は 32 ビットか 64 ビット) を仮定しますが、
1688717398これを Perl がビルドされたコンパイラが対応している標準 C の型の一つで
1688817399上書きできます:
1688917400
1689017401=begin original
1689117402
1689217403 hh interpret integer as C type "char" or "unsigned
1689317404 char" on Perl 5.14 or later
1689417405 h interpret integer as C type "short" or
1689517406 "unsigned short"
1689617407 j interpret integer as C type "intmax_t" on Perl
16897 5.14 or later, and only with a C99 compiler
17408 5.14 or later; and prior to Perl 5.30, only with
16898 (unportable)
17409 a C99 compiler (unportable)
1689917410 l interpret integer as C type "long" or
1690017411 "unsigned long"
1690117412 q, L, or ll interpret integer as C type "long long",
1690217413 "unsigned long long", or "quad" (typically
1690317414 64-bit integers)
1690417415 t interpret integer as C type "ptrdiff_t" on Perl
1690517416 5.14 or later
16906 z interpret integer as C type "size_t" on Perl 5.14
17417 z interpret integer as C types "size_t" or
16907 or later
17418 "ssize_t" on Perl 5.14 or later
1690817419
1690917420=end original
1691017421
1691117422 hh Perl 5.14 以降で整数を C の "char" または "unsigned char"
1691217423 型として解釈する
1691317424 h 整数を C の "char" または "unsigned char" 型として解釈する
16914 j Perl 5.14 以降 C99 コンパイラのみで整数を C の "intmax_t"
17425 j Perl 5.14 以降 Perl 5.30 以前の C99 コンパイラのみで整数を
16915 型として解釈する (移植性なし)
17426 C の "intmax_t" 型として解釈する (移植性なし)
1691617427 l 整数を C の "long" または "unsigned long" と解釈する
1691717428 h 整数を C の "short" または "unsigned short" と解釈する
1691817429 q, L or ll 整数を C の "long long", "unsigned long long",
1691917430 "quads"(典型的には 64 ビット整数) のどれかと解釈する
1692017431 t Perl 5.14 以降で整数を C の "ptrdiff_t" 型として解釈する
16921 z Perl 5.14 以降で整数を C の "size_t" 型として解釈する
17432 z Perl 5.14 以降で整数を C の "size_t" 型または "ssize_t" 型
17433 として解釈する
1692217434
1692317435=begin original
1692417436
1692517437As of 5.14, none of these raises an exception if they are not supported on
1692617438your platform. However, if warnings are enabled, a warning of the
1692717439L<C<printf>|warnings> warning class is issued on an unsupported
1692817440conversion flag. Should you instead prefer an exception, do this:
1692917441
1693017442=end original
1693117443
16932174445.14 から、プラットフォームがこれらに対応していないときでも例外が
1693317445発生しなくなりました。
1693417446しかし、もし警告が有効になっているなら、
1693517447非対応変換フラグに関して L<C<printf>|warnings> 警告クラスの警告が発生します。
1693617448例外の方がお好みなら、以下のようにします:
1693717449
1693817450 use warnings FATAL => "printf";
1693917451
1694017452=begin original
1694117453
1694217454If you would like to know about a version dependency before you
1694317455start running the program, put something like this at its top:
1694417456
1694517457=end original
1694617458
1694717459プログラムの実行開始前にバージョン依存について知りたいなら、先頭に
1694817460以下のようなものを書きます:
1694917461
1695017462 use 5.014; # for hh/j/t/z/ printf modifiers
1695117463
1695217464=begin original
1695317465
1695417466You can find out whether your Perl supports quads via L<Config>:
1695517467
1695617468=end original
1695717469
1695817470Perl が 64 ビット整数に対応しているかどうかは L<Config> を使って
1695917471調べられます:
1696017472
1696117473 use Config;
1696217474 if ($Config{use64bitint} eq "define"
1696317475 || $Config{longsize} >= 8) {
1696417476 print "Nice quads!\n";
1696517477 }
1696617478
1696717479=begin original
1696817480
1696917481For floating-point conversions (C<e f g E F G>), numbers are usually assumed
1697017482to be the default floating-point size on your platform (double or long double),
1697117483but you can force "long double" with C<q>, C<L>, or C<ll> if your
1697217484platform supports them. You can find out whether your Perl supports long
1697317485doubles via L<Config>:
1697417486
1697517487=end original
1697617488
1697717489浮動小数点数変換 (C<e f g E F G>) では、普通はプラットフォームのデフォルトの
1697817490不動小数点数のサイズ (double か long double) を仮定しますが、
1697917491プラットフォームが対応しているなら、C<q>, C<L>, C<ll> に対して
1698017492"long double" を強制できます。
1698117493Perl が long double に対応しているかどうかは L<Config> を使って
1698217494調べられます:
1698317495
1698417496 use Config;
1698517497 print "long doubles\n" if $Config{d_longdbl} eq "define";
1698617498
1698717499=begin original
1698817500
1698917501You can find out whether Perl considers "long double" to be the default
1699017502floating-point size to use on your platform via L<Config>:
1699117503
1699217504=end original
1699317505
1699417506Perl が "long double" をデフォルトの浮動小数点数として扱っているかどうかは
1699517507L<Config> を使って調べられます:
1699617508
1699717509 use Config;
1699817510 if ($Config{uselongdouble} eq "define") {
1699917511 print "long doubles by default\n";
1700017512 }
1700117513
1700217514=begin original
1700317515
1700417516It can also be that long doubles and doubles are the same thing:
1700517517
1700617518=end original
1700717519
1700817520long double と double が同じ場合もあります:
1700917521
1701017522 use Config;
1701117523 ($Config{doublesize} == $Config{longdblsize}) &&
1701217524 print "doubles are long doubles\n";
1701317525
1701417526=begin original
1701517527
1701617528The size specifier C<V> has no effect for Perl code, but is supported for
1701717529compatibility with XS code. It means "use the standard size for a Perl
1701817530integer or floating-point number", which is the default.
1701917531
1702017532=end original
1702117533
1702217534サイズ指定子 C<V> は Perl のコードには何の影響もありませんが、これは
1702317535XS コードとの互換性のために対応しています。
1702417536これは「Perl 整数 (または浮動小数点数) として標準的なサイズを使う」ことを
1702517537意味し、これはデフォルトです。
1702617538
1702717539=item order of arguments
1702817540
1702917541(引数の順序)
1703017542
1703117543=begin original
1703217544
1703317545Normally, L<C<sprintf>|/sprintf FORMAT, LIST> takes the next unused
1703417546argument as the value to
1703517547format for each format specification. If the format specification
1703617548uses C<*> to require additional arguments, these are consumed from
1703717549the argument list in the order they appear in the format
1703817550specification I<before> the value to format. Where an argument is
1703917551specified by an explicit index, this does not affect the normal
1704017552order for the arguments, even when the explicitly specified index
1704117553would have been the next argument.
1704217554
1704317555=end original
1704417556
1704517557通常、L<C<sprintf>|/sprintf FORMAT, LIST> は各フォーマット指定について、
1704617558使われていない次の引数を
1704717559フォーマットする値として使います。
1704817560追加の引数を要求するためにフォーマット指定 C<*> を使うと、
1704917561これらはフォーマットする値の I<前> のフォーマット指定に現れる順番に
1705017562引数リストから消費されます。
1705117563引数の位置が明示的なインデックスを使って指定された場合、
1705217564(明示的に指定したインデックスが次の引数の場合でも)
1705317565これは通常の引数の順番に影響を与えません。
1705417566
1705517567=begin original
1705617568
1705717569So:
1705817570
1705917571=end original
1706017572
1706117573それで:
1706217574
1706317575 printf "<%*.*s>", $a, $b, $c;
1706417576
1706517577=begin original
1706617578
1706717579uses C<$a> for the width, C<$b> for the precision, and C<$c>
1706817580as the value to format; while:
1706917581
1707017582=end original
1707117583
1707217584とすると C<$a> を幅に、C<$b> を精度に、C<$c> をフォーマットの値に
1707317585使います; 一方:
1707417586
1707517587 printf '<%*1$.*s>', $a, $b;
1707617588
1707717589=begin original
1707817590
1707917591would use C<$a> for the width and precision, and C<$b> as the
1708017592value to format.
1708117593
1708217594=end original
1708317595
1708417596とすると C<$a> を幅と精度に、C<$b> をフォーマットの値に使います。
1708517597
1708617598=begin original
1708717599
1708817600Here are some more examples; be aware that when using an explicit
1708917601index, the C<$> may need escaping:
1709017602
1709117603=end original
1709217604
1709317605以下にさらなる例を示します; 明示的にインデックスを使う場合、C<$> は
1709417606エスケープする必要があることに注意してください:
1709517607
1709617608 printf "%2\$d %d\n", 12, 34; # will print "34 12\n"
1709717609 printf "%2\$d %d %d\n", 12, 34; # will print "34 12 34\n"
1709817610 printf "%3\$d %d %d\n", 12, 34, 56; # will print "56 12 34\n"
1709917611 printf "%2\$*3\$d %d\n", 12, 34, 3; # will print " 34 12\n"
1710017612 printf "%*1\$.*f\n", 4, 5, 10; # will print "5.0000\n"
1710117613
1710217614=back
1710317615
1710417616=begin original
1710517617
1710617618If L<C<use locale>|locale> (including C<use locale ':not_characters'>)
1710717619is in effect and L<C<POSIX::setlocale>|POSIX/C<setlocale>> has been
1710817620called,
1710917621the character used for the decimal separator in formatted floating-point
1711017622numbers is affected by the C<LC_NUMERIC> locale. See L<perllocale>
1711117623and L<POSIX>.
1711217624
1711317625=end original
1711417626
1711517627(C<use locale ':not_characters'> を含む)L<C<use locale>|locale> が有効で、
1711617628L<C<POSIX::setlocale>|POSIX/C<setlocale>> が呼び出されている場合、
1711717629フォーマットされた浮動小数点数の小数点として使われる文字は
1711817630C<LC_NUMERIC> ロケールの影響を受けます。
1711917631L<perllocale> と L<POSIX> を参照してください。
1712017632
1712117633=item sqrt EXPR
1712217634X<sqrt> X<root> X<square root>
1712317635
1712417636=item sqrt
1712517637
1712617638=for Pod::Functions square root function
1712717639
1712817640=begin original
1712917641
1713017642Return the positive square root of EXPR. If EXPR is omitted, uses
1713117643L<C<$_>|perlvar/$_>. Works only for non-negative operands unless you've
1713217644loaded the L<C<Math::Complex>|Math::Complex> module.
1713317645
1713417646=end original
1713517647
1713617648EXPR の正の平方根を返します。
1713717649EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1713817650L<C<Math::Complex>|Math::Complex> モジュールを使わない場合は、負の数の引数は
1713917651扱えません。
1714017652
1714117653 use Math::Complex;
1714217654 print sqrt(-4); # prints 2i
1714317655
1714417656=item srand EXPR
1714517657X<srand> X<seed> X<randseed>
1714617658
1714717659=item srand
1714817660
1714917661=for Pod::Functions seed the random number generator
1715017662
1715117663=begin original
1715217664
1715317665Sets and returns the random number seed for the L<C<rand>|/rand EXPR>
1715417666operator.
1715517667
1715617668=end original
1715717669
1715817670L<C<rand>|/rand EXPR> 演算子のためのシード値を設定して返します。
1715917671
1716017672=begin original
1716117673
1716217674The point of the function is to "seed" the L<C<rand>|/rand EXPR>
1716317675function so that L<C<rand>|/rand EXPR> can produce a different sequence
1716417676each time you run your program. When called with a parameter,
1716517677L<C<srand>|/srand EXPR> uses that for the seed; otherwise it
1716617678(semi-)randomly chooses a seed. In either case, starting with Perl 5.14,
1716717679it returns the seed. To signal that your code will work I<only> on Perls
1716817680of a recent vintage:
1716917681
1717017682=end original
1717117683
1717217684この関数のポイントは、プログラムを実行するごとに L<C<rand>|/rand EXPR> 関数が
1717317685異なる乱数列を生成できるように L<C<rand>|/rand EXPR> 関数の「種」を
1717417686設定することです。
1717517687L<C<srand>|/srand EXPR> を引数付きで呼び出すと、これを種として使います;
1717617688さもなければ(だいたい)ランダムに種を選びます。
1717717689どちらの場合でも、Perl 5.14 からは種を返します。
1717817690特定の時期の Perl I<でのみ> 動作することを知らせるには以下のようにします:
1717917691
1718017692 use 5.014; # so srand returns the seed
1718117693
1718217694=begin original
1718317695
1718417696If L<C<srand>|/srand EXPR> is not called explicitly, it is called
1718517697implicitly without a parameter at the first use of the
1718617698L<C<rand>|/rand EXPR> operator. However, there are a few situations
1718717699where programs are likely to want to call L<C<srand>|/srand EXPR>. One
1718817700is for generating predictable results, generally for testing or
1718917701debugging. There, you use C<srand($seed)>, with the same C<$seed> each
1719017702time. Another case is that you may want to call L<C<srand>|/srand EXPR>
1719117703after a L<C<fork>|/fork> to avoid child processes sharing the same seed
1719217704value as the parent (and consequently each other).
1719317705
1719417706=end original
1719517707
1719617708L<C<srand>|/srand EXPR> が明示的に呼び出されなかった場合、最初に
1719717709L<C<rand>|/rand EXPR> 演算子を使った時点で暗黙に引数なしで呼び出されます。
1719817710しかし、最近の Perl でプログラムが L<C<srand>|/srand EXPR> を
1719917711呼び出したいであろう状況がいくつかあります。
1720017712一つはテストやデバッグのために予測可能な結果を生成するためです。
1720117713この場合、C<srand($seed)> (C<$seed> は毎回同じ値を使う) を使います。
1720217714もう一つの場合としては、子プロセスが親や他の子プロセスと同じ種の値を
1720317715共有することを避けるために、L<C<fork>|/fork> の後に L<C<srand>|/srand EXPR> を
1720417716呼び出したいかもしれません。
1720517717
1720617718=begin original
1720717719
1720817720Do B<not> call C<srand()> (i.e., without an argument) more than once per
1720917721process. The internal state of the random number generator should
1721017722contain more entropy than can be provided by any seed, so calling
1721117723L<C<srand>|/srand EXPR> again actually I<loses> randomness.
1721217724
1721317725=end original
1721417726
1721517727L<C<srand>|/srand EXPR> (引数なし)をプロセス中で複数回
1721617728呼び出しては B<いけません>。
1721717729乱数生成器の内部状態はどのような種によって提供されるものよりも
1721817730高いエントロピーを持っているので、C<srand()> を再び呼び出すと
1721917731ランダム性が I<失われます>。
1722017732
1722117733=begin original
1722217734
1722317735Most implementations of L<C<srand>|/srand EXPR> take an integer and will
1722417736silently
1722517737truncate decimal numbers. This means C<srand(42)> will usually
1722617738produce the same results as C<srand(42.1)>. To be safe, always pass
1722717739L<C<srand>|/srand EXPR> an integer.
1722817740
1722917741=end original
1723017742
1723117743L<C<srand>|/srand EXPR> のほとんどの実装では整数を取り、小数を暗黙に
1723217744切り捨てます。
1723317745これは、C<srand(42)> は普通 C<srand(42.1)> と同じ結果になることを意味します。
1723417746安全のために、L<C<srand>|/srand EXPR> には常に整数を渡しましょう。
1723517747
1723617748=begin original
1723717749
1723817750A typical use of the returned seed is for a test program which has too many
1723917751combinations to test comprehensively in the time available to it each run. It
1724017752can test a random subset each time, and should there be a failure, log the seed
1724117753used for that run so that it can later be used to reproduce the same results.
1724217754
1724317755=end original
1724417756
1724517757返された種の典型的な利用法は、実行毎のテストを利用可能な時間内に完全に
1724617758行うには組み合わせが多すぎるテストプログラム用です。
1724717759毎回ランダムなサブセットをテストし、もし失敗したら、その実行で使った
1724817760種をログに出力することで、後で同じ結果を再現するために使えます。
1724917761
1725017762=begin original
1725117763
1725217764B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
1725317765on it in security-sensitive situations.> As of this writing, a
1725417766number of third-party CPAN modules offer random number generators
1725517767intended by their authors to be cryptographically secure,
1725617768including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1725717769and L<Math::TrulyRandom>.
1725817770
1725917771=end original
1726017772
1726117773B<L<C<rand>|/rand EXPR> は暗号学的に安全ではありません。
1726217774セキュリティ的に重要な状況でこれに頼るべきではありません。>
1726317775これを書いている時点で、いくつかのサードパーティ CPAN モジュールが
1726417776作者によって暗号学的に安全であることを目的とした乱数生成器を
1726517777提供しています: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
1726617778L<Math::TrulyRandom> などです。
1726717779
1726817780=item stat FILEHANDLE
1726917781X<stat> X<file, status> X<ctime>
1727017782
1727117783=item stat EXPR
1727217784
1727317785=item stat DIRHANDLE
1727417786
1727517787=item stat
1727617788
1727717789=for Pod::Functions get a file's status information
1727817790
1727917791=begin original
1728017792
1728117793Returns a 13-element list giving the status info for a file, either
1728217794the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
1728317795omitted, it stats L<C<$_>|perlvar/$_> (not C<_>!). Returns the empty
1728417796list if L<C<stat>|/stat FILEHANDLE> fails. Typically
1728517797used as follows:
1728617798
1728717799=end original
1728817800
1728917801FILEHANDLE か DIRHANDLE を通じてオープンされているファイルか、
1729017802EXPR で指定されるファイルの情報を与える、13 要素のリストを返します。
1729117803EXPR が省略されると、 L<C<$_>|perlvar/$_> が用いられます
1729217804(C<_> ではありません!)。
1729317805L<C<stat>|/stat FILEHANDLE> に失敗した場合には、空リストを返します。
1729417806普通は、以下のようにして使います:
1729517807
1729617808 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1729717809 $atime,$mtime,$ctime,$blksize,$blocks)
1729817810 = stat($filename);
1729917811
1730017812=begin original
1730117813
1730217814Not all fields are supported on all filesystem types. Here are the
1730317815meanings of the fields:
1730417816
1730517817=end original
1730617818
1730717819全てのファイルシステムで全てのフィールドに対応しているわけではありません。
1730817820フィールドの意味は以下の通りです。
1730917821
1731017822=begin original
1731117823
1731217824 0 dev device number of filesystem
1731317825 1 ino inode number
1731417826 2 mode file mode (type and permissions)
1731517827 3 nlink number of (hard) links to the file
1731617828 4 uid numeric user ID of file's owner
1731717829 5 gid numeric group ID of file's owner
1731817830 6 rdev the device identifier (special files only)
1731917831 7 size total size of file, in bytes
1732017832 8 atime last access time in seconds since the epoch
1732117833 9 mtime last modify time in seconds since the epoch
1732217834 10 ctime inode change time in seconds since the epoch (*)
1732317835 11 blksize preferred I/O size in bytes for interacting with the
1732417836 file (may vary from file to file)
1732517837 12 blocks actual number of system-specific blocks allocated
1732617838 on disk (often, but not always, 512 bytes each)
1732717839
1732817840=end original
1732917841
1733017842 0 dev ファイルシステムのデバイス番号
1733117843 1 ino inode 番号
1733217844 2 mode ファイルモード (タイプとパーミッション)
1733317845 3 nlink ファイルへの(ハード)リンクの数
1733417846 4 uid ファイル所有者のユーザー ID の数値
1733517847 5 gid ファイル所有者のグループ ID の数値
1733617848 6 rdev デバイス識別子(特殊ファイルのみ)
1733717849 7 size ファイルサイズ(バイト単位)
1733817850 8 atime 紀元から、最後にアクセスされた時刻までの秒数
1733917851 9 mtime 紀元から、最後に修正(modify)された時刻までの秒数
1734017852 10 ctime 紀元から、inode 変更(change)された時刻までの秒数 (*)
1734117853 11 blksize ファイルとの相互作用のために適した I/O バイト数
1734217854 (ファイルごとに異なるかもしれない)
1734317855 12 blocks ディスクに割り当てたシステム依存のブロック(常にでは
1734417856 ありませんがたいていはそれぞれ 512 バイト)の数
1734517857
1734617858=begin original
1734717859
1734817860(The epoch was at 00:00 January 1, 1970 GMT.)
1734917861
1735017862=end original
1735117863
1735217864(紀元は GMT で 1970/01/01 00:00:00。)
1735317865
1735417866=begin original
1735517867
1735617868(*) Not all fields are supported on all filesystem types. Notably, the
1735717869ctime field is non-portable. In particular, you cannot expect it to be a
1735817870"creation time"; see L<perlport/"Files and Filesystems"> for details.
1735917871
1736017872=end original
1736117873
1736217874(*) 全てのフィールドが全てのファイルシステムタイプで対応しているわけでは
1736317875ありません。
1736417876明らかに、ctime のフィールドは移植性がありません。
1736517877特に、これから「作成時刻」を想定することは出来ません;
1736617878詳細については L<perlport/"Files and Filesystems"> を参照してください。
1736717879
1736817880=begin original
1736917881
1737017882If L<C<stat>|/stat FILEHANDLE> is passed the special filehandle
1737117883consisting of an underline, no stat is done, but the current contents of
1737217884the stat structure from the last L<C<stat>|/stat FILEHANDLE>,
1737317885L<C<lstat>|/lstat FILEHANDLE>, or filetest are returned. Example:
1737417886
1737517887=end original
1737617888
1737717889下線だけの _ という特別なファイルハンドルを L<C<stat>|/stat FILEHANDLE> に
1737817890渡すと、実際には stat を行なわず、stat 構造体に残っている
1737917891前回の L<C<stat>|/stat FILEHANDLE>, L<C<lstat>|/lstat FILEHANDLE> や
1738017892ファイルテストの情報が返されます。
1738117893例:
1738217894
1738317895 if (-x $file && (($d) = stat(_)) && $d < 0) {
1738417896 print "$file is executable NFS file\n";
1738517897 }
1738617898
1738717899=begin original
1738817900
1738917901(This works on machines only for which the device number is negative
1739017902under NFS.)
1739117903
1739217904=end original
1739317905
1739417906(これは、NFS のもとでデバイス番号が負になるマシンでのみ動作します。)
1739517907
1739617908=begin original
1739717909
17910On some platforms inode numbers are of a type larger than perl knows how
17911to handle as integer numerical values. If necessary, an inode number will
17912be returned as a decimal string in order to preserve the entire value.
17913If used in a numeric context, this will be converted to a floating-point
17914numerical value, with rounding, a fate that is best avoided. Therefore,
17915you should prefer to compare inode numbers using C<eq> rather than C<==>.
17916C<eq> will work fine on inode numbers that are represented numerically,
17917as well as those represented as strings.
17918
17919=end original
17920
17921一部のプラットフォームでは、inode 番号は perl が整数値として
17922扱い方を知っているものよりも大きい型になっています。
17923もし必要なら、inode 番号は、値全体を保存するために 10 進文字列として
17924返されます。
17925数値コンテキストで使うと、これは丸めを伴う浮動小数点数に変換され、
17926できるだけ避けるべき結果になります。
17927従って、inode 番号の比較には C<==> ではなく C<eq> を使うべきです。
17928C<eq> は、inode 番号が数値で表現されていても、文字列で表現されていても
17929うまく動作します。
17930
17931=begin original
17932
1739817933Because the mode contains both the file type and its permissions, you
1739917934should mask off the file type portion and (s)printf using a C<"%o">
1740017935if you want to see the real permissions.
1740117936
1740217937=end original
1740317938
1740417939モードにはファイルタイプとその権限の両方が含まれているので、
1740517940本当の権限を見たい場合は、(s)printf で C<"%"> を使うことで
1740617941ファイルタイプをマスクするべきです。
1740717942
1740817943 my $mode = (stat($filename))[2];
1740917944 printf "Permissions are %04o\n", $mode & 07777;
1741017945
1741117946=begin original
1741217947
1741317948In scalar context, L<C<stat>|/stat FILEHANDLE> returns a boolean value
1741417949indicating success
1741517950or failure, and, if successful, sets the information associated with
1741617951the special filehandle C<_>.
1741717952
1741817953=end original
1741917954
1742017955スカラコンテキストでは、L<C<stat>|/stat FILEHANDLE> は成功か失敗を表す真偽値を
1742117956返し、成功した場合は、特別なファイルハンドル C<_> に結び付けられた
1742217957情報をセットします。
1742317958
1742417959=begin original
1742517960
1742617961The L<File::stat> module provides a convenient, by-name access mechanism:
1742717962
1742817963=end original
1742917964
1743017965L<File::stat> モジュールは、便利な名前によるアクセス機構を提供します。
1743117966
1743217967 use File::stat;
1743317968 my $sb = stat($filename);
1743417969 printf "File is %s, size is %s, perm %04o, mtime %s\n",
1743517970 $filename, $sb->size, $sb->mode & 07777,
1743617971 scalar localtime $sb->mtime;
1743717972
1743817973=begin original
1743917974
1744017975You can import symbolic mode constants (C<S_IF*>) and functions
1744117976(C<S_IS*>) from the L<Fcntl> module:
1744217977
1744317978=end original
1744417979
1744517980モード定数 (C<S_IF*>) と関数 (C<S_IS*>) を L<Fcntl> モジュールから
1744617981インポートできます。
1744717982
1744817983 use Fcntl ':mode';
1744917984
1745017985 my $mode = (stat($filename))[2];
1745117986
1745217987 my $user_rwx = ($mode & S_IRWXU) >> 6;
1745317988 my $group_read = ($mode & S_IRGRP) >> 3;
1745417989 my $other_execute = $mode & S_IXOTH;
1745517990
1745617991 printf "Permissions are %04o\n", S_IMODE($mode), "\n";
1745717992
1745817993 my $is_setuid = $mode & S_ISUID;
1745917994 my $is_directory = S_ISDIR($mode);
1746017995
1746117996=begin original
1746217997
1746317998You could write the last two using the C<-u> and C<-d> operators.
1746417999Commonly available C<S_IF*> constants are:
1746518000
1746618001=end original
1746718002
1746818003最後の二つは C<-u> と C<-d> 演算子を使っても書けます。
1746918004一般に利用可能な C<S_IF*> 定数は以下のものです。
1747018005
1747118006 # Permissions: read, write, execute, for user, group, others.
1747218007
1747318008 S_IRWXU S_IRUSR S_IWUSR S_IXUSR
1747418009 S_IRWXG S_IRGRP S_IWGRP S_IXGRP
1747518010 S_IRWXO S_IROTH S_IWOTH S_IXOTH
1747618011
1747718012 # Setuid/Setgid/Stickiness/SaveText.
1747818013 # Note that the exact meaning of these is system-dependent.
1747918014
1748018015 S_ISUID S_ISGID S_ISVTX S_ISTXT
1748118016
1748218017 # File types. Not all are necessarily available on
1748318018 # your system.
1748418019
1748518020 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR
1748618021 S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
1748718022
1748818023 # The following are compatibility aliases for S_IRUSR,
1748918024 # S_IWUSR, and S_IXUSR.
1749018025
1749118026 S_IREAD S_IWRITE S_IEXEC
1749218027
1749318028=begin original
1749418029
1749518030and the C<S_IF*> functions are
1749618031
1749718032=end original
1749818033
1749918034一般に利用可能な C<S_IF*> 関数は以下のものです。
1750018035
1750118036 S_IMODE($mode) the part of $mode containing the permission
1750218037 bits and the setuid/setgid/sticky bits
1750318038
1750418039 S_IFMT($mode) the part of $mode containing the file type
1750518040 which can be bit-anded with (for example)
1750618041 S_IFREG or with the following functions
1750718042
1750818043 # The operators -f, -d, -l, -b, -c, -p, and -S.
1750918044
1751018045 S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
1751118046 S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)
1751218047
1751318048 # No direct -X operator counterpart, but for the first one
1751418049 # the -g operator is often equivalent. The ENFMT stands for
1751518050 # record flocking enforcement, a platform-dependent feature.
1751618051
1751718052 S_ISENFMT($mode) S_ISWHT($mode)
1751818053
1751918054=begin original
1752018055
1752118056See your native L<chmod(2)> and L<stat(2)> documentation for more details
1752218057about the C<S_*> constants. To get status info for a symbolic link
1752318058instead of the target file behind the link, use the
1752418059L<C<lstat>|/lstat FILEHANDLE> function.
1752518060
1752618061=end original
1752718062
1752818063C<S_*> 定数に関する詳細についてはネイティブの L<chmod(2)> と L<stat(2)> の
1752918064ドキュメントを参照してください。
1753018065リンクの先にあるファイルではなく、シンボリックリンクそのものの情報を
1753118066得たい場合は、L<C<lstat>|/lstat FILEHANDLE> 関数を使ってください。
1753218067
1753318068=begin original
1753418069
1753518070Portability issues: L<perlport/stat>.
1753618071
1753718072=end original
1753818073
1753918074移植性の問題: L<perlport/stat>。
1754018075
1754118076=item state VARLIST
1754218077X<state>
1754318078
1754418079=item state TYPE VARLIST
1754518080
1754618081=item state VARLIST : ATTRS
1754718082
1754818083=item state TYPE VARLIST : ATTRS
1754918084
1755018085=for Pod::Functions +state declare and assign a persistent lexical variable
1755118086
1755218087=begin original
1755318088
1755418089L<C<state>|/state VARLIST> declares a lexically scoped variable, just
1755518090like L<C<my>|/my VARLIST>.
1755618091However, those variables will never be reinitialized, contrary to
1755718092lexical variables that are reinitialized each time their enclosing block
1755818093is entered.
1755918094See L<perlsub/"Persistent Private Variables"> for details.
1756018095
1756118096=end original
1756218097
1756318098L<C<state>|/state VARLIST> はちょうど L<C<my>|/my VARLIST> と同様に、
1756418099レキシカルなスコープの変数を宣言します。
1756518100しかし、レキシカル変数がブロックに入る毎に再初期化されるのと異なり、
1756618101この変数は決して再初期化されません。
1756718102詳しくは L<perlsub/"Persistent Private Variables"> を参照してください。
1756818103
1756918104=begin original
1757018105
1757118106If more than one variable is listed, the list must be placed in
1757218107parentheses. With a parenthesised list, L<C<undef>|/undef EXPR> can be
1757318108used as a
1757418109dummy placeholder. However, since initialization of state variables in
17575list context is currently not possible this would serve no purpose.
18110such lists is currently not possible this would serve no purpose.
1757618111
1757718112=end original
1757818113
1757918114複数の変数を指定する場合、かっこで囲まなければなりません。
1758018115かっこで囲まれたリストでは、L<C<undef>|/undef EXPR> はダミーの
1758118116プレースホルダとして使えます。
17582しかし、リストコンテキストでの state 変数の初期化は現在のところできないので、
18117しかし、そのようなリストでの state 変数の初期化は現在のところできないので、
1758318118これは無意味です。
1758418119
1758518120=begin original
1758618121
1758718122L<C<state>|/state VARLIST> is available only if the
1758818123L<C<"state"> feature|feature/The 'state' feature> is enabled or if it is
1758918124prefixed with C<CORE::>. The
1759018125L<C<"state"> feature|feature/The 'state' feature> is enabled
1759118126automatically with a C<use v5.10> (or higher) declaration in the current
1759218127scope.
1759318128
1759418129=end original
1759518130
1759618131L<C<state>|/state VARLIST> は
1759718132L<C<"state"> 機能|feature/The 'state' feature> が有効か C<CORE::> を
1759818133前置した場合にのみ利用可能です。
1759918134L<C<"state"> 機能|feature/The 'state' feature> は現在のスコープで
1760018135C<use v5.10> (またはそれ以上) を宣言した場合自動的に有効になります。
1760118136
1760218137=item study SCALAR
1760318138X<study>
1760418139
1760518140=item study
1760618141
1760718142=for Pod::Functions no-op, formerly optimized input data for repeated searches
1760818143
1760918144=begin original
1761018145
1761118146At this time, C<study> does nothing. This may change in the future.
1761218147
1761318148=end original
1761418149
1761518150現時点では、C<study> は何もしません。
1761618151これは将来変更されるかもしれません。
1761718152
1761818153=begin original
1761918154
1762018155Prior to Perl version 5.16, it would create an inverted index of all characters
1762118156that occurred in the given SCALAR (or L<C<$_>|perlvar/$_> if unspecified). When
1762218157matching a pattern, the rarest character from the pattern would be looked up in
1762318158this index. Rarity was based on some static frequency tables constructed from
1762418159some C programs and English text.
1762518160
1762618161=end original
1762718162
1762818163Perl バージョン 5.16 より前では、
1762918164与えられた SCALAR (または指定されていなかった場合は L<C<$_>|perlvar/$_>)に
1763018165現れた全ての文字の転置インデックスを作ります。
1763118166パターンにマッチングしたとき、
1763218167パターン中の最も頻度の少ない文字がこのインデックスから探されます。
1763318168頻度は、C プログラムと英語の文章から構築された静的頻度テーブルを
1763418169基にしています。
1763518170
1763618171=item sub NAME BLOCK
1763718172X<sub>
1763818173
1763918174=item sub NAME (PROTO) BLOCK
1764018175
1764118176=item sub NAME : ATTRS BLOCK
1764218177
1764318178=item sub NAME (PROTO) : ATTRS BLOCK
1764418179
1764518180=for Pod::Functions declare a subroutine, possibly anonymously
1764618181
1764718182=begin original
1764818183
1764918184This is subroutine definition, not a real function I<per se>. Without a
1765018185BLOCK it's just a forward declaration. Without a NAME, it's an anonymous
1765118186function declaration, so does return a value: the CODE ref of the closure
1765218187just created.
1765318188
1765418189=end original
1765518190
1765618191これはサブルーチン定義であり、I<本質的には> 実際の関数ではありません。
1765718192BLOCK なしの場合、これは単に前方宣言です。
1765818193NAME なしの場合は、無名関数定義であり、値(作成したブロックの
1765918194コードリファレンス)を返します: 単にクロージャの CODE リファレンスが
1766018195作成されます。
1766118196
1766218197=begin original
1766318198
1766418199See L<perlsub> and L<perlref> for details about subroutines and
1766518200references; see L<attributes> and L<Attribute::Handlers> for more
1766618201information about attributes.
1766718202
1766818203=end original
1766918204
1767018205サブルーチンとリファレンスに関する詳細については、L<perlsub> と
1767118206L<perlref> を参照してください; 属性に関する更なる情報については
1767218207L<attributes> と L<Attribute::Handlers> を参照してください。
1767318208
1767418209=item __SUB__
1767518210X<__SUB__>
1767618211
1767718212=for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine
1767818213
1767918214=begin original
1768018215
1768118216A special token that returns a reference to the current subroutine, or
1768218217L<C<undef>|/undef EXPR> outside of a subroutine.
1768318218
1768418219=end original
1768518220
1768618221現在のサブルーチンのリファレンスを返す特殊トークン; サブルーチンの外側では
1768718222L<C<undef>|/undef EXPR>。
1768818223
1768918224=begin original
1769018225
1769118226The behaviour of L<C<__SUB__>|/__SUB__> within a regex code block (such
1769218227as C</(?{...})/>) is subject to change.
1769318228
1769418229=end original
1769518230
1769618231(C</(?{...})/> のような) 正規表現コードブロックの中の
1769718232L<C<__SUB__>|/__SUB__> の振る舞いは変更される予定です。
1769818233
1769918234=begin original
1770018235
1770118236This token is only available under C<use v5.16> or the
1770218237L<C<"current_sub"> feature|feature/The 'current_sub' feature>.
1770318238See L<feature>.
1770418239
1770518240=end original
1770618241
1770718242このトークンは C<use v5.16> または
1770818243L<C<"current_sub"> 機能|feature/The 'current_sub' feature> でのみ
1770918244利用可能です。
1771018245L<feature> を参照してください。
1771118246
1771218247=item substr EXPR,OFFSET,LENGTH,REPLACEMENT
1771318248X<substr> X<substring> X<mid> X<left> X<right>
1771418249
1771518250=item substr EXPR,OFFSET,LENGTH
1771618251
1771718252=item substr EXPR,OFFSET
1771818253
1771918254=for Pod::Functions get or alter a portion of a string
1772018255
1772118256=begin original
1772218257
1772318258Extracts a substring out of EXPR and returns it. First character is at
1772418259offset zero. If OFFSET is negative, starts
1772518260that far back from the end of the string. If LENGTH is omitted, returns
1772618261everything through the end of the string. If LENGTH is negative, leaves that
1772718262many characters off the end of the string.
1772818263
1772918264=end original
1773018265
1773118266EXPR から、部分文字列を取り出して返します。
1773218267最初の文字がオフセット 0 となります。
1773318268OFFSET に負の値を設定すると、EXPR の終わりからのオフセットとなります。
1773418269LENGTH を省略すると、EXPR の最後まですべてが返されます。
1773518270LENGTH が負の値だと、文字列の最後から指定された数だけ文字を取り除きます。
1773618271
1773718272 my $s = "The black cat climbed the green tree";
1773818273 my $color = substr $s, 4, 5; # black
1773918274 my $middle = substr $s, 4, -11; # black cat climbed the
1774018275 my $end = substr $s, 14; # climbed the green tree
1774118276 my $tail = substr $s, -4; # tree
1774218277 my $z = substr $s, -4, 2; # tr
1774318278
1774418279=begin original
1774518280
1774618281You can use the L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT>
1774718282function as an lvalue, in which case EXPR
1774818283must itself be an lvalue. If you assign something shorter than LENGTH,
1774918284the string will shrink, and if you assign something longer than LENGTH,
1775018285the string will grow to accommodate it. To keep the string the same
1775118286length, you may need to pad or chop your value using
1775218287L<C<sprintf>|/sprintf FORMAT, LIST>.
1775318288
1775418289=end original
1775518290
1775618291L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として
1775718292使用することも可能で、その場合には、EXPR が自身左辺値でなければなりません。
1775818293LENGTH より短いものを代入したときには、
1775918294EXPR は短くなり、LENGTH より長いものを代入したときには、
1776018295EXPR はそれに合わせて伸びることになります。
1776118296EXPR の長さを一定に保つためには、L<C<sprintf>|/sprintf FORMAT, LIST> を
1776218297使って、代入する値の長さを調整することが、必要になるかもしれません。
1776318298
1776418299=begin original
1776518300
1776618301If OFFSET and LENGTH specify a substring that is partly outside the
1776718302string, only the part within the string is returned. If the substring
1776818303is beyond either end of the string,
1776918304L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> returns the undefined
1777018305value and produces a warning. When used as an lvalue, specifying a
1777118306substring that is entirely outside the string raises an exception.
1777218307Here's an example showing the behavior for boundary cases:
1777318308
1777418309=end original
1777518310
1777618311OFFSET と LENGTH として文字列の外側を含むような部分文字列が指定されると、
1777718312文字列の内側の部分だけが返されます。
1777818313部分文字列が文字列の両端の外側の場合、
1777918314L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> は未定義値を返し、
1778018315警告が出力されます。
1778118316左辺値として使った場合、文字列の完全に外側を部分文字列として指定すると
1778218317例外が発生します。
1778318318以下は境界条件の振る舞いを示す例です:
1778418319
1778518320 my $name = 'fred';
1778618321 substr($name, 4) = 'dy'; # $name is now 'freddy'
1778718322 my $null = substr $name, 6, 2; # returns "" (no warning)
1778818323 my $oops = substr $name, 7; # returns undef, with warning
1778918324 substr($name, 7) = 'gap'; # raises an exception
1779018325
1779118326=begin original
1779218327
1779318328An alternative to using
1779418329L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> as an lvalue is to
1779518330specify the
1779618331replacement string as the 4th argument. This allows you to replace
1779718332parts of the EXPR and return what was there before in one operation,
1779818333just as you can with
1779918334L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST>.
1780018335
1780118336=end original
1780218337
1780318338L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> を左辺値として使う
1780418339代わりの方法は、置き換える文字列を 4 番目の引数として指定することです。
1780518340これにより、EXPR の一部を置き換え、置き換える前が何であったかを返す、
1780618341ということを(L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> と同様)
17807183421 動作で行えます。
1780818343
1780918344 my $s = "The black cat climbed the green tree";
1781018345 my $z = substr $s, 14, 7, "jumped from"; # climbed
1781118346 # $s is now "The black cat jumped from the green tree"
1781218347
1781318348=begin original
1781418349
1781518350Note that the lvalue returned by the three-argument version of
1781618351L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> acts as
1781718352a 'magic bullet'; each time it is assigned to, it remembers which part
1781818353of the original string is being modified; for example:
1781918354
1782018355=end original
1782118356
17822183573 引数の L<C<substr>|/substr EXPR,OFFSET,LENGTH,REPLACEMENT> によって返された
1782318358左辺値は「魔法の弾丸」のように振舞うことに注意してください;
1782418359これが代入される毎に、元の文字列のどの部分が変更されたかが思い出されます;
1782518360例えば:
1782618361
1782718362 my $x = '1234';
1782818363 for (substr($x,1,2)) {
1782918364 $_ = 'a'; print $x,"\n"; # prints 1a4
1783018365 $_ = 'xyz'; print $x,"\n"; # prints 1xyz4
1783118366 $x = '56789';
1783218367 $_ = 'pq'; print $x,"\n"; # prints 5pq9
1783318368 }
1783418369
1783518370=begin original
1783618371
1783718372With negative offsets, it remembers its position from the end of the string
1783818373when the target string is modified:
1783918374
1784018375=end original
1784118376
1784218377負数のオフセットの場合、ターゲット文字列が修正されたときに文字列の末尾からの
1784318378位置を覚えます:
1784418379
1784518380 my $x = '1234';
1784618381 for (substr($x, -3, 2)) {
1784718382 $_ = 'a'; print $x,"\n"; # prints 1a4, as above
1784818383 $x = 'abcdefg';
1784918384 print $_,"\n"; # prints f
1785018385 }
1785118386
1785218387=begin original
1785318388
1785418389Prior to Perl version 5.10, the result of using an lvalue multiple times was
1785518390unspecified. Prior to 5.16, the result with negative offsets was
1785618391unspecified.
1785718392
1785818393=end original
1785918394
1786018395バージョン 5.10 より前の Perl では、複数回左辺値を使った場合の結果は
1786118396未定義でした。
17862183975.16 より前では、負のオフセットの結果は未定義です。
1786318398
1786418399=item symlink OLDFILE,NEWFILE
1786518400X<symlink> X<link> X<symbolic link> X<link, symbolic>
1786618401
1786718402=for Pod::Functions create a symbolic link to a file
1786818403
1786918404=begin original
1787018405
1787118406Creates a new filename symbolically linked to the old filename.
1787218407Returns C<1> for success, C<0> otherwise. On systems that don't support
1787318408symbolic links, raises an exception. To check for that,
1787418409use eval:
1787518410
1787618411=end original
1787718412
1787818413NEWFILE として、OLDFILE へのシンボリックリンクを生成します。
1787918414成功時には C<1> を返し、失敗時には C<0> を返します。
1788018415シンボリックリンクをサポートしていないシステムでは、
1788118416例外が発生します。
1788218417これをチェックするには、eval を使用します:
1788318418
1788418419 my $symlink_exists = eval { symlink("",""); 1 };
1788518420
1788618421=begin original
1788718422
1788818423Portability issues: L<perlport/symlink>.
1788918424
1789018425=end original
1789118426
1789218427移植性の問題: L<perlport/symlink>。
1789318428
1789418429=item syscall NUMBER, LIST
1789518430X<syscall> X<system call>
1789618431
1789718432=for Pod::Functions execute an arbitrary system call
1789818433
1789918434=begin original
1790018435
1790118436Calls the system call specified as the first element of the list,
1790218437passing the remaining elements as arguments to the system call. If
1790318438unimplemented, raises an exception. The arguments are interpreted
1790418439as follows: if a given argument is numeric, the argument is passed as
1790518440an int. If not, the pointer to the string value is passed. You are
1790618441responsible to make sure a string is pre-extended long enough to
1790718442receive any result that might be written into a string. You can't use a
1790818443string literal (or other read-only string) as an argument to
1790918444L<C<syscall>|/syscall NUMBER, LIST> because Perl has to assume that any
1791018445string pointer might be written through. If your
1791118446integer arguments are not literals and have never been interpreted in a
1791218447numeric context, you may need to add C<0> to them to force them to look
1791318448like numbers. This emulates the
1791418449L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> function (or
1791518450vice versa):
1791618451
1791718452=end original
1791818453
1791918454LIST の最初の要素で指定するシステムコールを、残りの要素をその
1792018455システムコールの引数として呼び出します。
1792118456実装されていない場合には、例外が発生します。
1792218457引数は、以下のように解釈されます: 引数が数字であれば、int として
1792318458引数を渡します。
1792418459そうでなければ、文字列値へのポインタが渡されます。
1792518460文字列に結果を受け取るときには、その結果を受け取るのに十分なくらいに、
1792618461文字列を予め伸ばしておく必要があります。
1792718462文字列リテラル(あるいはその他の読み込み専用の文字列)を
1792818463L<C<syscall>|/syscall NUMBER, LIST> の引数として使うことはできません;
1792918464Perl は全ての文字列ポインタは書き込まれると仮定しなければならないからです。
1793018465整数引数が、リテラルでなく、数値コンテキストで評価されたことのない
1793118466ものであれば、数値として解釈されるように、
1793218467C<0> を足しておく必要があるかもしれません。
1793318468以下は L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> 関数(あるいは
1793418469その逆)をエミュレートします。
1793518470
1793618471 require 'syscall.ph'; # may need to run h2ph
1793718472 my $s = "hi there\n";
1793818473 syscall(SYS_write(), fileno(STDOUT), $s, length $s);
1793918474
1794018475=begin original
1794118476
1794218477Note that Perl supports passing of up to only 14 arguments to your syscall,
1794318478which in practice should (usually) suffice.
1794418479
1794518480=end original
1794618481
1794718482Perl は、システムコールに最大 14 個の引数しか渡せませんが、
1794818483(普通は)実用上問題はないでしょう。
1794918484
1795018485=begin original
1795118486
1795218487Syscall returns whatever value returned by the system call it calls.
1795318488If the system call fails, L<C<syscall>|/syscall NUMBER, LIST> returns
1795418489C<-1> and sets L<C<$!>|perlvar/$!> (errno).
1795518490Note that some system calls I<can> legitimately return C<-1>. The proper
1795618491way to handle such calls is to assign C<$! = 0> before the call, then
1795718492check the value of L<C<$!>|perlvar/$!> if
1795818493L<C<syscall>|/syscall NUMBER, LIST> returns C<-1>.
1795918494
1796018495=end original
1796118496
1796218497syscall は、呼び出したシステムコールが返した値を返します。
1796318498システムコールが失敗すると、L<C<syscall>|/syscall NUMBER, LIST> は C<-1> を
1796418499返し、L<C<$!>|perlvar/$!>(errno) を設定します。
1796518500システムコールが正常に C<-1> を返す I<場合がある> ことに注意してください。
1796618501このようなシステムコールを正しく扱うには、
1796718502C<$! = 0> をシステムコールの前に実行し、それから
1796818503L<C<syscall>|/syscall NUMBER, LIST> が C<-1> を返した時には
1796918504L<C<$!>|perlvar/$!> の値を調べてください。
1797018505
1797118506=begin original
1797218507
1797318508There's a problem with C<syscall(SYS_pipe())>: it returns the file
1797418509number of the read end of the pipe it creates, but there is no way
1797518510to retrieve the file number of the other end. You can avoid this
1797618511problem by using L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> instead.
1797718512
1797818513=end original
1797918514
1798018515C<syscall(&SYS_pipe)> には問題があり、作ったパイプの、読み出し側の
1798118516ファイル番号を返しますが、もう一方のファイル番号を得る方法がありません。
1798218517この問題を避けるためには、代わりに L<C<pipe>|/pipe READHANDLE,WRITEHANDLE> を
1798318518使ってください。
1798418519
1798518520=begin original
1798618521
1798718522Portability issues: L<perlport/syscall>.
1798818523
1798918524=end original
1799018525
1799118526移植性の問題: L<perlport/syscall>。
1799218527
1799318528=item sysopen FILEHANDLE,FILENAME,MODE
1799418529X<sysopen>
1799518530
1799618531=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
1799718532
1799818533=for Pod::Functions +5.002 open a file, pipe, or descriptor
1799918534
1800018535=begin original
1800118536
1800218537Opens the file whose filename is given by FILENAME, and associates it with
1800318538FILEHANDLE. If FILEHANDLE is an expression, its value is used as the real
1800418539filehandle wanted; an undefined scalar will be suitably autovivified. This
1800518540function calls the underlying operating system's L<open(2)> function with the
1800618541parameters FILENAME, MODE, and PERMS.
1800718542
1800818543=end original
1800918544
1801018545FILENAME で与えられたファイル名のファイルをオープンし、
1801118546FILEHANDLE と結び付けます。
1801218547FILEHANDLE が式の場合、その値は実際の求めているファイルハンドルの名前として
1801318548扱われます; 未定義のスカラは適切に自動有効化されます。
1801418549この関数呼び出しはシステムの L<open(2)> 関数を FILENAME, MODE, PERMS の
1801518550引数で呼び出すことを基礎としています。
1801618551
1801718552=begin original
1801818553
1801918554Returns true on success and L<C<undef>|/undef EXPR> otherwise.
1802018555
1802118556=end original
1802218557
1802318558成功時は真を、さもなければ L<C<undef>|/undef EXPR> を返します。
1802418559
1802518560=begin original
1802618561
18562L<PerlIO> layers will be applied to the handle the same way they would in an
18563L<C<open>|/open FILEHANDLE,MODE,EXPR> call that does not specify layers. That is,
18564the current value of L<C<${^OPEN}>|perlvar/${^OPEN}> as set by the L<open>
18565pragma in a lexical scope, or the C<-C> commandline option or C<PERL_UNICODE>
18566environment variable in the main program scope, falling back to the platform
18567defaults as described in L<PerlIO/Defaults and how to override them>. If you
18568want to remove any layers that may transform the byte stream, use
18569L<C<binmode>|/binmode FILEHANDLE, LAYER> after opening it.
18570
18571=end original
18572
18573L<PerlIO> 層は、層を指定しない L<C<open>|/open FILEHANDLE,MODE,EXPR>
18574呼び出しでするのと同じ方法でハンドルに適用されます。
18575これは、レキシカルスコープの L<open> プラグマで設定された
18576L<C<${^OPEN}>|perlvar/${^OPEN}> の現在の値、
18577またはメインプログラムスコープの C<-C> コマンドラインオプションまたは
18578C<PERL_UNICODE> 環境変数、L<PerlIO/Defaults and how to override them> で
18579記述されているようにプラットフォームのデフォルトに
18580フォールバックしたものです。
18581バイトストリームを変換する全ての層を除去したい場合は、
18582それを開いた後に L<C<binmode>|/binmode FILEHANDLE, LAYER> を使ってください。
18583
18584=begin original
18585
1802718586The possible values and flag bits of the MODE parameter are
1802818587system-dependent; they are available via the standard module
1802918588L<C<Fcntl>|Fcntl>. See the documentation of your operating system's
1803018589L<open(2)> syscall to see
1803118590which values and flag bits are available. You may combine several flags
1803218591using the C<|>-operator.
1803318592
1803418593=end original
1803518594
1803618595MODE パラメータに指定できるフラグビットと値はシステム依存です;
1803718596これは標準モジュール L<C<Fcntl>|Fcntl> 経由で利用可能です。
1803818597どのようなフラグビットと値が利用可能であるかについては、
1803918598OS の L<open(2)> システムコールに関する文書を参照してください。
1804018599C<|> 演算子を使って複数のフラグを結合することができます。
1804118600
1804218601=begin original
1804318602
1804418603Some of the most common values are C<O_RDONLY> for opening the file in
1804518604read-only mode, C<O_WRONLY> for opening the file in write-only mode,
1804618605and C<O_RDWR> for opening the file in read-write mode.
1804718606X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1804818607
1804918608=end original
1805018609
1805118610もっともよく使われる値は、ファイルを読み込み専用で開く C<O_RDONLY>、
1805218611ファイルを書き込み専用で開く C<O_WRONLY>、
1805318612ファイルを読み書き両用で開く C<O_RDWR> です。
1805418613X<O_RDONLY> X<O_RDWR> X<O_WRONLY>
1805518614
1805618615=begin original
1805718616
1805818617For historical reasons, some values work on almost every system
1805918618supported by Perl: 0 means read-only, 1 means write-only, and 2
1806018619means read/write. We know that these values do I<not> work under
1806118620OS/390 and on the Macintosh; you probably don't want to
1806218621use them in new code.
1806318622
1806418623=end original
1806518624
1806618625歴史的な理由により、Perl が対応しているほとんどのシステムで使える値が
1806718626あります:0 は読み込み専用、1 は書き込み専用、2 は読み書き両用を意味します。
1806818627OS/390 と Macintosh では動作 I<しない> ことが分かっています;
1806918628新しく書くコードではこれらは使わないほうがよいでしょう。
1807018629
1807118630=begin original
1807218631
1807318632If the file named by FILENAME does not exist and the
18074L<C<open>|/open FILEHANDLE,EXPR> call creates
18633L<C<open>|/open FILEHANDLE,MODE,EXPR> call creates
1807518634it (typically because MODE includes the C<O_CREAT> flag), then the value of
1807618635PERMS specifies the permissions of the newly created file. If you omit
1807718636the PERMS argument to L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>,
1807818637Perl uses the octal value C<0666>.
1807918638These permission values need to be in octal, and are modified by your
1808018639process's current L<C<umask>|/umask EXPR>.
1808118640X<O_CREAT>
1808218641
1808318642=end original
1808418643
1808518644FILENAME という名前のファイルが存在せず、(典型的には MODE が
1808618645C<O_CREAT> フラグを含んでいたために)
18087L<C<open>|/open FILEHANDLE,EXPR> 呼び出しがそれを作った場合、
18646L<C<open>|/open FILEHANDLE,MODE,EXPR> 呼び出しがそれを作った場合、
1808818647PERMS の値は新しく作られたファイルの権限を指定します。
1808918648L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の PERMS 引数を省略した場合、
1809018649Perl は 8 進数 C<0666> を使います。
1809118650これらの権限は 8 進数である必要があり、プロセスの現在の
1809218651L<C<umask>|/umask EXPR> で修正されます。
1809318652X<O_CREAT>
1809418653
1809518654=begin original
1809618655
1809718656In many systems the C<O_EXCL> flag is available for opening files in
1809818657exclusive mode. This is B<not> locking: exclusiveness means here that
1809918658if the file already exists,
1810018659L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> fails. C<O_EXCL> may
1810118660not work
1810218661on network filesystems, and has no effect unless the C<O_CREAT> flag
1810318662is set as well. Setting C<O_CREAT|O_EXCL> prevents the file from
1810418663being opened if it is a symbolic link. It does not protect against
1810518664symbolic links in the file's path.
1810618665X<O_EXCL>
1810718666
1810818667=end original
1810918668
1811018669多くのシステムではファイルを排他モードで開くために C<O_EXCL> が
1811118670利用可能です。
1811218671これはロック B<ではありません>: 排他性というのは既にファイルが
1811318672存在していた場合、L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> が
1811418673失敗することを意味します。
1811518674C<O_EXCL> はネットワークファイルシステムでは動作せず、
1811618675またC<O_CREAT> フラグも有効でない限りは効果がありません。
1811718676C<O_CREAT|O_EXCL> をセットすると、これがシンボリックリンクだった場合は
1811818677ファイルを開くことを妨げます。
1811918678これはファイルパス中のシンボリックリンクは守りません。
1812018679X<O_EXCL>
1812118680
1812218681=begin original
1812318682
1812418683Sometimes you may want to truncate an already-existing file. This
1812518684can be done using the C<O_TRUNC> flag. The behavior of
1812618685C<O_TRUNC> with C<O_RDONLY> is undefined.
1812718686X<O_TRUNC>
1812818687
1812918688=end original
1813018689
1813118690既に存在しているファイルを切り詰めたい場合もあるかもしれません。
1813218691これは C<O_TRUNC> フラグを使うことで行えます。
1813318692C<O_RDONLY> と C<O_TRUNC> を同時に指定したときの振る舞いは未定義です。
1813418693X<O_TRUNC>
1813518694
1813618695=begin original
1813718696
1813818697You should seldom if ever use C<0644> as argument to
1813918698L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>, because
1814018699that takes away the user's option to have a more permissive umask.
1814118700Better to omit it. See L<C<umask>|/umask EXPR> for more on this.
1814218701
1814318702=end original
1814418703
1814518704めったなことでは L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> の引数に
1814618705C<0644> を指定するべきではないでしょう:
1814718706ユーザーがより寛大な umask を指定する選択肢を奪うからです。
1814818707省略した方がいいです。
1814918708これに関するさらなる情報については L<C<umask>|/umask EXPR> を
1815018709参照してください。
1815118710
1815218711=begin original
1815318712
18713This function has no direct relation to the usage of
18714L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
18715L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
18716or L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. A handle opened with
18717this function can be used with buffered IO just as one opened with
18718L<C<open>|/open FILEHANDLE,MODE,EXPR> can be used with unbuffered IO.
18719
18720=end original
18721
18722この関数は、
18723L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
18724L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
18725L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> の使用法と
18726直接の関係はありません。
18727この関数で開かれたハンドルがバッファリングされた IO で使えるのと同様、
18728L<C<open>|/open FILEHANDLE,MODE,EXPR> で開かれたものは
18729バッファリングされない IO で使えます。
18730
18731=begin original
18732
1815418733Note that under Perls older than 5.8.0,
1815518734L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> depends on the
1815618735L<fdopen(3)> C library function. On many Unix systems, L<fdopen(3)> is known
1815718736to fail when file descriptors exceed a certain value, typically 255. If
1815818737you need more file descriptors than that, consider using the
1815918738L<C<POSIX::open>|POSIX/C<open>> function. For Perls 5.8.0 and later,
1816018739PerlIO is (most often) the default.
1816118740
1816218741=end original
1816318742
18164187435.8.0 より古い Perl では、
1816518744L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> は
1816618745C の L<fdopen(3)> ライブラリ関数に依存していることに注意してください。
1816718746多くの Unix システムでは、L<fdopen(3)> はファイル記述子がある値(例えば 255)を
1816818747超えると失敗することが知られています。
1816918748これより多くのファイル記述子が必要な場合は、
1817018749L<C<POSIX::open>|POSIX/C<open>> 関数を使うことを検討してください。
1817118750Perl 5.8.0 以降では、(ほぼ確実に) PerlIO がデフォルトです。
1817218751
1817318752=begin original
1817418753
1817518754See L<perlopentut> for a kinder, gentler explanation of opening files.
1817618755
1817718756=end original
1817818757
1817918758ファイルを開くことに関するより親切な説明については L<perlopentut> を
1818018759参照してください。
1818118760
1818218761=begin original
1818318762
1818418763Portability issues: L<perlport/sysopen>.
1818518764
1818618765=end original
1818718766
1818818767移植性の問題: L<perlport/sysopen>。
1818918768
1819018769=item sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
1819118770X<sysread>
1819218771
1819318772=item sysread FILEHANDLE,SCALAR,LENGTH
1819418773
1819518774=for Pod::Functions fixed-length unbuffered input from a filehandle
1819618775
1819718776=begin original
1819818777
1819918778Attempts to read LENGTH bytes of data into variable SCALAR from the
18200specified FILEHANDLE, using L<read(2)>. It bypasses
18779specified FILEHANDLE, using L<read(2)>. It bypasses any L<PerlIO> layers
18201buffered IO, so mixing this with other kinds of reads,
18780including buffered IO (but is affected by the presence of the C<:utf8>
18781layer as described later), so mixing this with other kinds of reads,
1820218782L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1820318783L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1820418784L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> can cause
1820518785confusion because the
18206perlio or stdio layers usually buffer data. Returns the number of
18786C<:perlio> or C<:crlf> layers usually buffer data. Returns the number of
1820718787bytes actually read, C<0> at end of file, or undef if there was an
1820818788error (in the latter case L<C<$!>|perlvar/$!> is also set). SCALAR will
1820918789be grown or
1821018790shrunk so that the last byte actually read is the last byte of the
1821118791scalar after the read.
1821218792
1821318793=end original
1821418794
1821518795L<read(2)> を用いて、指定した FILEHANDLE から、変数 SCALAR へ、LENGTH バイトの
1821618796データの読み込みを試みます。
18217これは、バッファ付き IO ルーチンを通りませんか、他入力関数,
18797これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らない
18798(しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、
1821818799L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1821918800L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
1822018801L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、入力がおかしくなるかも
18221しれません; perlio 層や stdio 層は普通データをバッファリングするからです。
18802しれません;
18803C<:perlio> 層や C<:crlf> 層は普通データをバッファリングするからです。
1822218804ファイルの最後では C<0>が、エラー時には undef が、それ以外では実際に
1822318805読み込まれたデータの長さが返されます (後者の場合は L<C<$!>|perlvar/$!> も
1822418806セットされます)。
1822518807実際に読み込んだ最後のバイトが read した後の最後のバイトになるので、
1822618808SCALAR は伸び縮みします。
1822718809
1822818810=begin original
1822918811
1823018812An OFFSET may be specified to place the read data at some place in the
1823118813string other than the beginning. A negative OFFSET specifies
1823218814placement at that many characters counting backwards from the end of
1823318815the string. A positive OFFSET greater than the length of SCALAR
1823418816results in the string being padded to the required size with C<"\0">
1823518817bytes before the result of the read is appended.
1823618818
1823718819=end original
1823818820
1823918821OFFSET を指定すると、文字列の先頭以外の場所から読み込みを行なえます。
1824018822OFFSET に負の値を指定すると、文字列の最後から逆向きに何文字目かで
1824118823位置を指定します。
1824218824OFFSET が正の値で、SCALAR の長さよりも大きかった場合、文字列は読み込みの結果が
1824318825追加される前に、必要なサイズまで C<"\0"> のバイトでパッディングされます。
1824418826
1824518827=begin original
1824618828
1824718829There is no syseof() function, which is ok, since
1824818830L<C<eof>|/eof FILEHANDLE> doesn't work well on device files (like ttys)
1824918831anyway. Use L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> and
18250check for a return value for 0 to decide whether you're done.
18832check for a return value of 0 to decide whether you're done.
1825118833
1825218834=end original
1825318835
1825418836syseof() 関数はありませんが、問題ありません; どちらにしろ
1825518837L<C<eof>|/eof FILEHANDLE> は
1825618838(tty のような)デバイスファイルに対してはうまく動作しないからです。
1825718839L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> を使って、
1825818840返り値が 0 かどうかで最後まで読んだかを判断してください。
1825918841
1826018842=begin original
1826118843
18262Note that if the filehandle has been marked as C<:utf8>, Unicode
18844Note that if the filehandle has been marked as C<:utf8>, C<sysread> will
18263characters are read instead of bytes (the LENGTH, OFFSET, and the
18845throw an exception. The C<:encoding(...)> layer implicitly
18264return value of L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>
18265are in Unicode characters). The C<:encoding(...)> layer implicitly
1826618846introduces the C<:utf8> layer. See
1826718847L<C<binmode>|/binmode FILEHANDLE, LAYER>,
18268L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma.
18848L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma.
1826918849
1827018850=end original
1827118851
18272ファイルハンドルが C<:utf8> であるとマークが付けられると、バイトではなく
18852ファイルハンドルが C<:utf8> であるとマークが付けられていると、
18273Unicode 文字が読み込れま
18853C<sysread> は例外を投げます
18274(L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> の LENGTH, OFFSET
18275および返り値は Unicode 文字になります)。
1827618854C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
18277L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>,
18855L<C<binmode>|/binmode FILEHANDLE, LAYER>,
18278L<open> プラグマを参照してください。
18856L<C<open>|/open FILEHANDLE,MODE,EXPR>, L<open> プラグマを参照してください。
1827918857
1828018858=item sysseek FILEHANDLE,POSITION,WHENCE
1828118859X<sysseek> X<lseek>
1828218860
1828318861=for Pod::Functions +5.004 position I/O pointer on handle used with sysread and syswrite
1828418862
1828518863=begin original
1828618864
1828718865Sets FILEHANDLE's system position I<in bytes> using L<lseek(2)>. FILEHANDLE may
1828818866be an expression whose value gives the name of the filehandle. The values
18289for WHENCE are C<0> to set the new position to POSITION; C<1> to set the it
18867for WHENCE are C<0> to set the new position to POSITION; C<1> to set it
1829018868to the current position plus POSITION; and C<2> to set it to EOF plus
1829118869POSITION, typically negative.
1829218870
1829318871=end original
1829418872
1829518873FILEHANDLE のシステム位置を I<バイト単位> で L<lseek(2)> を使って設定します。
1829618874FILEHANDLE は、実際のファイルハンドル名を与える式でもかまいません。
1829718875WHENCE の値が、C<0> ならば、新しい位置を POSITION の位置へ設定します;
1829818876C<1> ならば、現在位置から POSITION 加えた位置へ設定します; C<2> ならば、
1829918877EOF から POSITION だけ(普通は負の数です)加えた位置へ、新しい位置を
1830018878設定します。
1830118879
1830218880=begin original
1830318881
1830418882Note the emphasis on bytes: even if the filehandle has been set to operate
1830518883on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
1830618884L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1830718885L<C<tell>|/tell FILEHANDLE>, and
1830818886L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
1830918887family of functions use byte offsets, not character offsets,
1831018888because seeking to a character offset would be very slow in a UTF-8 file.
1831118889
1831218890=end original
1831318891
1831418892バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
1831518893ファイルハンドルが文字単位で処理するように設定されていたとしても、
1831618894L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1831718895L<C<tell>|/tell FILEHANDLE>,
1831818896L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
1831918897文字オフセットではなくバイトオフセットを使います;
1832018898文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1832118899
1832218900=begin original
1832318901
1832418902L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> bypasses normal
1832518903buffered IO, so mixing it with reads other than
1832618904L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> (for example
1832718905L<C<readline>|/readline EXPR> or
1832818906L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>),
1832918907L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1833018908L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1833118909L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
1833218910confusion.
1833318911
1833418912=end original
1833518913
1833618914L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は普通のバッファ付き IO を
1833718915バイパスしますので、
1833818916L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET> 以外の (例えば
1833918917L<C<readline>|/readline EXPR> や
1834018918L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の)読み込み、
1834118919L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1834218920L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
1834318921L<C<eof>|/eof FILEHANDLE> と混ぜて使うと混乱を引き起こします。
1834418922
1834518923=begin original
1834618924
1834718925For WHENCE, you may also use the constants C<SEEK_SET>, C<SEEK_CUR>,
1834818926and C<SEEK_END> (start of the file, current position, end of the file)
1834918927from the L<Fcntl> module. Use of the constants is also more portable
1835018928than relying on 0, 1, and 2. For example to define a "systell" function:
1835118929
1835218930=end original
1835318931
1835418932WHENCE には、L<Fcntl> モジュールで使われている C<SEEK_SET>, C<SEEK_CUR>,
1835518933C<SEEK_END> (ファイルの先頭、現在位置、ファイルの最後)という定数を
1835618934使うこともできます。
1835718935定数の使用は 0, 1, 2 に依存するよりも移植性があります。
1835818936例えば "systell" 関数を定義するには:
1835918937
1836018938 use Fcntl 'SEEK_CUR';
1836118939 sub systell { sysseek($_[0], 0, SEEK_CUR) }
1836218940
1836318941=begin original
1836418942
1836518943Returns the new position, or the undefined value on failure. A position
1836618944of zero is returned as the string C<"0 but true">; thus
1836718945L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> returns
1836818946true on success and false on failure, yet you can still easily determine
1836918947the new position.
1837018948
1837118949=end original
1837218950
1837318951新しい位置を返します; 失敗したときは未定義値を返します。
1837418952位置がゼロの場合は、C<"0 but true"> の文字列として返されます; 従って
1837518953L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> は成功時に真を返し、
1837618954失敗時に偽を返しますが、簡単に新しい位置を判定できます。
1837718955
1837818956=item system LIST
1837918957X<system> X<shell>
1838018958
1838118959=item system PROGRAM LIST
1838218960
1838318961=for Pod::Functions run a separate program
1838418962
1838518963=begin original
1838618964
1838718965Does exactly the same thing as L<C<exec>|/exec LIST>, except that a fork is
1838818966done first and the parent process waits for the child process to
1838918967exit. Note that argument processing varies depending on the
1839018968number of arguments. If there is more than one argument in LIST,
1839118969or if LIST is an array with more than one value, starts the program
1839218970given by the first element of the list with arguments given by the
1839318971rest of the list. If there is only one scalar argument, the argument
1839418972is checked for shell metacharacters, and if there are any, the
1839518973entire argument is passed to the system's command shell for parsing
1839618974(this is C</bin/sh -c> on Unix platforms, but varies on other
1839718975platforms). If there are no shell metacharacters in the argument,
1839818976it is split into words and passed directly to C<execvp>, which is
1839918977more efficient. On Windows, only the C<system PROGRAM LIST> syntax will
1840018978reliably avoid using the shell; C<system LIST>, even with more than one
1840118979element, will fall back to the shell if the first spawn fails.
1840218980
1840318981=end original
1840418982
1840518983L<C<exec>|/exec LIST> とほとんど同じですが、まず fork を行ない、
1840618984親プロセスではチャイルドプロセスが終了するのを wait します。
1840718985exec の項で述べたように、引数の処理は、引数の数によって異なることに
1840818986注意してください。
1840918987LIST に複数の引数がある場合、または LIST が複数の要素からなる配列の場合、
1841018988リストの最初の要素で与えられるプログラムを、リストの残りの要素を引数として
1841118989起動します。
1841218990スカラの引数が一つだけの場合、引数はシェルのメタ文字をチェックされ、もし
1841318991あればパースのために引数全体がシステムコマンドシェル (これは
1841418992Unix プラットフォームでは C</bin/sh -c> ですが、他のプラットフォームでは
1841518993異なります)に渡されます。
1841618994シェルのメタ文字がなかった場合、引数は単語に分解されて直接 C<execvp> に
1841718995渡されます; この方がより効率的です。
1841818996Windows では、C<system PROGRAM LIST> 構文のみが安定してシェルの使用を
1841918997回避します; C<system LIST> は、2 要素以上でも、最初の spawn が失敗すると
1842018998シェルにフォールバックします。
1842118999
1842219000=begin original
1842319001
1842419002Perl will attempt to flush all files opened for
1842519003output before any operation that may do a fork, but this may not be
1842619004supported on some platforms (see L<perlport>). To be safe, you may need
1842719005to set L<C<$E<verbar>>|perlvar/$E<verbar>> (C<$AUTOFLUSH> in L<English>)
1842819006or call the C<autoflush> method of L<C<IO::Handle>|IO::Handle/METHODS>
1842919007on any open handles.
1843019008
1843119009=end original
1843219010
1843319011v5.6.0 から、Perl は書き込み用に開いている全てのファイルに対して
1843419012fork を行う前にフラッシュしようとしますが、これに対応していない
1843519013プラットフォームもあります(L<perlport> を参照してください)。
1843619014安全のために、L<C<$E<verbar>>|perlvar/$E<verbar>> (L<English> モジュールでは
1843719015C<$AUTOFLUSH>) をセットするか、全ての開いているハンドルに対して
1843819016L<C<IO::Handle>|IO::Handle/METHODS> の C<autoflush> メソッドを
1843919017呼び出す必要があるかもしれません。
1844019018
1844119019=begin original
1844219020
1844319021The return value is the exit status of the program as returned by the
1844419022L<C<wait>|/wait> call. To get the actual exit value, shift right by
1844519023eight (see below). See also L<C<exec>|/exec LIST>. This is I<not> what
1844619024you want to use to capture the output from a command; for that you
1844719025should use merely backticks or
1844819026L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>>, as described in
1844919027L<perlop/"`STRING`">. Return value of -1 indicates a failure to start
1845019028the program or an error of the L<wait(2)> system call (inspect
1845119029L<C<$!>|perlvar/$!> for the reason).
1845219030
1845319031=end original
1845419032
1845519033返り値は、L<C<wait>|/wait> が返すプログラムの exit 状態です。
1845619034実際の exit 値を得るには 右に 8 ビットシフトしてください(後述)。
1845719035L<C<exec>|/exec LIST> も参照してください。
1845819036これはコマンドからの出力を捕らえるために使うものI<ではありません>;
1845919037そのような用途には、L<perlop/"`STRING`"> に記述されている
1846019038逆クォートや L<C<qxE<sol>E<sol>>|/qxE<sol>STRINGE<sol>> を使用してください。
1846119039-1 の返り値はプログラムを開始させることに失敗したか、L<wait(2)>
1846219040システムコールがエラーを出したことを示します
1846319041(理由は L<C<$!>|perlvar/$!> を調べてください)。
1846419042
1846519043=begin original
1846619044
1846719045If you'd like to make L<C<system>|/system LIST> (and many other bits of
1846819046Perl) die on error, have a look at the L<autodie> pragma.
1846919047
1847019048=end original
1847119049
1847219050もし L<C<system>|/system LIST> (及び Perl のその他の多くの部分) でエラー時に
1847319051die したいなら、L<autodie> プラグマを見てみてください。
1847419052
1847519053=begin original
1847619054
1847719055Like L<C<exec>|/exec LIST>, L<C<system>|/system LIST> allows you to lie
1847819056to a program about its name if you use the C<system PROGRAM LIST>
1847919057syntax. Again, see L<C<exec>|/exec LIST>.
1848019058
1848119059=end original
1848219060
1848319061L<C<exec>|/exec LIST> と同様に、L<C<system>|/system LIST> でも
1848419062C<system PROGRAM LIST> の文法を使うことで、プログラムに対してその名前を
1848519063嘘をつくことができます。
1848619064再び、L<C<exec>|/exec LIST> を参照してください。
1848719065
1848819066=begin original
1848919067
1849019068Since C<SIGINT> and C<SIGQUIT> are ignored during the execution of
1849119069L<C<system>|/system LIST>, if you expect your program to terminate on
1849219070receipt of these signals you will need to arrange to do so yourself
1849319071based on the return value.
1849419072
1849519073=end original
1849619074
1849719075C<SIGINT> と C<SIGQUIT> は L<C<system>|/system LIST> の実行中は無視されるので、
1849819076これらのシグナルを受信して終了させることを想定したプログラムの場合、
1849919077返り値を利用するように変更する必要があります。
1850019078
1850119079 my @args = ("command", "arg1", "arg2");
1850219080 system(@args) == 0
1850319081 or die "system @args failed: $?";
1850419082
1850519083=begin original
1850619084
1850719085If you'd like to manually inspect L<C<system>|/system LIST>'s failure,
1850819086you can check all possible failure modes by inspecting
1850919087L<C<$?>|perlvar/$?> like this:
1851019088
1851119089=end original
1851219090
1851319091L<C<system>|/system LIST> の失敗を手動で検査したいなら、以下のように
1851419092L<C<$?>|perlvar/$?> を調べることで、全ての失敗の可能性をチェックできます:
1851519093
1851619094 if ($? == -1) {
1851719095 print "failed to execute: $!\n";
1851819096 }
1851919097 elsif ($? & 127) {
1852019098 printf "child died with signal %d, %s coredump\n",
1852119099 ($? & 127), ($? & 128) ? 'with' : 'without';
1852219100 }
1852319101 else {
1852419102 printf "child exited with value %d\n", $? >> 8;
1852519103 }
1852619104
1852719105=begin original
1852819106
1852919107Alternatively, you may inspect the value of
1853019108L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> with the
1853119109L<C<W*()>|POSIX/C<WIFEXITED>> calls from the L<POSIX> module.
1853219110
1853319111=end original
1853419112
1853519113または、L<POSIX> モジュールの L<C<W*()>|POSIX/C<WIFEXITED>> 呼び出しを使って
1853619114L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> の値を
1853719115調べることもできます。
1853819116
1853919117=begin original
1854019118
1854119119When L<C<system>|/system LIST>'s arguments are executed indirectly by
1854219120the shell, results and return codes are subject to its quirks.
1854319121See L<perlop/"`STRING`"> and L<C<exec>|/exec LIST> for details.
1854419122
1854519123=end original
1854619124
1854719125L<C<system>|/system LIST> の引数がシェルによって間接的に実行された場合、
1854819126結果と返り値はシェルの癖によって変更されることがあります。
1854919127詳細については L<perlop/"`STRING`"> と L<C<exec>|/exec LIST> を
1855019128参照してください。
1855119129
1855219130=begin original
1855319131
1855419132Since L<C<system>|/system LIST> does a L<C<fork>|/fork> and
1855519133L<C<wait>|/wait> it may affect a C<SIGCHLD> handler. See L<perlipc> for
1855619134details.
1855719135
1855819136=end original
1855919137
1856019138L<C<system>|/system LIST> は L<C<fork>|/fork> と L<C<wait>|/wait> を行うので、
1856119139C<SIGCHLD> ハンドラの影響を受けます。
1856219140詳しくは L<perlipc> を参照してください。
1856319141
1856419142=begin original
1856519143
1856619144Portability issues: L<perlport/system>.
1856719145
1856819146=end original
1856919147
1857019148移植性の問題: L<perlport/system>。
1857119149
1857219150=item syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
1857319151X<syswrite>
1857419152
1857519153=item syswrite FILEHANDLE,SCALAR,LENGTH
1857619154
1857719155=item syswrite FILEHANDLE,SCALAR
1857819156
1857919157=for Pod::Functions fixed-length unbuffered output to a filehandle
1858019158
1858119159=begin original
1858219160
1858319161Attempts to write LENGTH bytes of data from variable SCALAR to the
1858419162specified FILEHANDLE, using L<write(2)>. If LENGTH is
18585not specified, writes whole SCALAR. It bypasses buffered IO, so
19163not specified, writes whole SCALAR. It bypasses any L<PerlIO> layers
19164including buffered IO (but is affected by the presence of the C<:utf8>
19165layer as described later), so
1858619166mixing this with reads (other than C<sysread)>),
1858719167L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1858819168L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1858919169L<C<tell>|/tell FILEHANDLE>, or L<C<eof>|/eof FILEHANDLE> may cause
18590confusion because the perlio and stdio layers usually buffer data.
19170confusion because the C<:perlio> and C<:crlf> layers usually buffer data.
1859119171Returns the number of bytes actually written, or L<C<undef>|/undef EXPR>
1859219172if there was an error (in this case the errno variable
1859319173L<C<$!>|perlvar/$!> is also set). If the LENGTH is greater than the
1859419174data available in the SCALAR after the OFFSET, only as much data as is
1859519175available will be written.
1859619176
1859719177=end original
1859819178
1859919179L<write(2)> を使って、指定した FILEHANDLEへ、変数 SCALAR から、LENGTH バイトの
1860019180データの書き込みを試みます。
1860119181LENGTH が指定されなかった場合、 SCALAR 全体を書き込みます。
18602これは、バッファ付き IO ルーチンを通りませんか、他入力関数
19182これは、バッファ付き IO ルーチンを含むどの L<PerlIO> も通らない
18603(C<sysread> 以外),
19183(しかし、後述するように C<:utf8> の存在の影響を受けます)、他の入力関数、
19184他の入力関数 (C<sysread> 以外),
1860419185L<C<print>|/print FILEHANDLE LIST>, L<C<write>|/write FILEHANDLE>,
1860519186L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>, L<C<tell>|/tell FILEHANDLE>,
1860619187L<C<eof>|/eof FILEHANDLE> と混ぜて使うと、出力がおかしくなるかもしれません;
18607perlio 層と stdio 層は普通データをバッファリングするからです。
19188C<:perlio> 層と C<:crlf> 層は普通データをバッファリングするからです。
1860819189実際に読み込まれたデータの長さか、エラー時には L<C<undef>|/undef EXPR> が
1860919190返されます(この場合エラー変数 L<C<$!>|perlvar/$!> もセットされます)。
1861019191LENGTH が OFFSET 以降の SCALAR の利用可能なデータより大きかった場合、
1861119192利用可能なデータのみが書き込まれます。
1861219193
1861319194=begin original
1861419195
1861519196An OFFSET may be specified to write the data from some part of the
1861619197string other than the beginning. A negative OFFSET specifies writing
1861719198that many characters counting backwards from the end of the string.
1861819199If SCALAR is of length zero, you can only use an OFFSET of 0.
1861919200
1862019201=end original
1862119202
1862219203OFFSET を指定すると、SCALAR の先頭以外の場所から、
1862319204データを取り出して、書き込みを行なうことができます。
1862419205OFFSET に負の値を指定すると、文字列の最後から逆向きに数えて
1862519206何バイト目から書き込むかを示します。
1862619207SCALAR の長さが 0 の場合、OFFSET は 0 のみ使用できます。
1862719208
1862819209=begin original
1862919210
18630B<WARNING>: If the filehandle is marked C<:utf8>, Unicode characters
19211B<WARNING>: If the filehandle is marked C<:utf8>, C<syswrite> will raise an exception.
18631encoded in UTF-8 are written instead of bytes, and the LENGTH, OFFSET, and
18632return value of L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>
18633are in (UTF8-encoded Unicode) characters.
1863419212The C<:encoding(...)> layer implicitly introduces the C<:utf8> layer.
1863519213Alternately, if the handle is not marked with an encoding but you
1863619214attempt to write characters with code points over 255, raises an exception.
1863719215See L<C<binmode>|/binmode FILEHANDLE, LAYER>,
18638L<C<open>|/open FILEHANDLE,EXPR>, and the L<open> pragma.
19216L<C<open>|/open FILEHANDLE,MODE,EXPR>, and the L<open> pragma.
1863919217
1864019218=end original
1864119219
18642B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられると、
19220B<警告>: ファイルハンドルが C<:utf8> であるとマークが付けられていると、
18643バイトではなく UTF-8 エンコードされた Unicode 文字が読み込れ、
19221C<syswrite> は例外を投げす。
18644L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET> の LENGTH, OFFSET
18645および返り値は (UTF8 エンコードされた Unicode) 文字単位になります。
1864619222C<:encoding(...)> 層は暗黙のうちに C<:utf8> 層が導入されます。
1864719223または、もしハンドルにエンコーディングが記録されていない状態で
1864819224255 を超える符号位置の文字を書き込もうとすると、例外が発生します。
18649L<C<binmode>|/binmode FILEHANDLE, LAYER>, L<C<open>|/open FILEHANDLE,EXPR>,
19225L<C<binmode>|/binmode FILEHANDLE, LAYER>,
19226L<C<open>|/open FILEHANDLE,MODE,EXPR>,
1865019227L<open> プラグマを参照してください。
1865119228
1865219229=item tell FILEHANDLE
1865319230X<tell>
1865419231
1865519232=item tell
1865619233
1865719234=for Pod::Functions get current seekpointer on a filehandle
1865819235
1865919236=begin original
1866019237
1866119238Returns the current position I<in bytes> for FILEHANDLE, or -1 on
1866219239error. FILEHANDLE may be an expression whose value gives the name of
1866319240the actual filehandle. If FILEHANDLE is omitted, assumes the file
1866419241last read.
1866519242
1866619243=end original
1866719244
1866819245FILEHANDLE の現在の位置を I<バイト数で> 返します; エラーの場合は -1 を
1866919246返します。
1867019247FILEHANDLE は、実際のファイルハンドル名を示す式でもかまいません。
1867119248FILEHANDLE が省略された場合には、最後に読み込みを行なったファイルについて
1867219249調べます。
1867319250
1867419251=begin original
1867519252
1867619253Note the emphasis on bytes: even if the filehandle has been set to operate
1867719254on characters (for example using the C<:encoding(UTF-8)> I/O layer), the
1867819255L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1867919256L<C<tell>|/tell FILEHANDLE>, and
1868019257L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>
1868119258family of functions use byte offsets, not character offsets,
1868219259because seeking to a character offset would be very slow in a UTF-8 file.
1868319260
1868419261=end original
1868519262
1868619263バイト単位に対する注意: 例え(例えば C<:encoding(UTF-8)> I/O 層を使うなどして)
1868719264ファイルハンドルが文字単位で処理するように設定されていたとしても、
1868819265L<C<seek>|/seek FILEHANDLE,POSITION,WHENCE>,
1868919266L<C<tell>|/tell FILEHANDLE>,
1869019267L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> シリーズの関数は
1869119268文字オフセットではなくバイトオフセットを使います;
1869219269文字オフセットでシークするのは UTF-8 ファイルではとても遅いからです。
1869319270
1869419271=begin original
1869519272
1869619273The return value of L<C<tell>|/tell FILEHANDLE> for the standard streams
1869719274like the STDIN depends on the operating system: it may return -1 or
1869819275something else. L<C<tell>|/tell FILEHANDLE> on pipes, fifos, and
1869919276sockets usually returns -1.
1870019277
1870119278=end original
1870219279
1870319280STDIN のような標準ストリームに対する L<C<tell>|/tell FILEHANDLE> の返り値は
1870419281OS に依存します:
1870519282-1 やその他の値が返ってくるかもしれません。
1870619283パイプ、FIFO、ソケットに対して L<C<tell>|/tell FILEHANDLE> を使うと、普通は
1870719284-1 が返ります。
1870819285
1870919286=begin original
1871019287
1871119288There is no C<systell> function. Use
1871219289L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> for that.
1871319290
1871419291=end original
1871519292
1871619293C<systell> 関数はありません。
1871719294代わりに L<C<sysseek($fh, 0, 1)>|/sysseek FILEHANDLE,POSITION,WHENCE> を
1871819295使ってください。
1871919296
1872019297=begin original
1872119298
1872219299Do not use L<C<tell>|/tell FILEHANDLE> (or other buffered I/O
1872319300operations) on a filehandle that has been manipulated by
1872419301L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1872519302L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>, or
1872619303L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE>. Those functions
1872719304ignore the buffering, while L<C<tell>|/tell FILEHANDLE> does not.
1872819305
1872919306=end original
1873019307
1873119308L<C<sysread>|/sysread FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1873219309L<C<syswrite>|/syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET>,
1873319310L<C<sysseek>|/sysseek FILEHANDLE,POSITION,WHENCE> で操作された
1873419311ファイルハンドルに L<C<tell>|/tell FILEHANDLE>
1873519312(またはその他のバッファリング I/O 操作) を使わないでください。
1873619313これらの関数はバッファリングを無視しますが、L<C<tell>|/tell FILEHANDLE> は
1873719314違います。
1873819315
1873919316=item telldir DIRHANDLE
1874019317X<telldir>
1874119318
1874219319=for Pod::Functions get current seekpointer on a directory handle
1874319320
1874419321=begin original
1874519322
1874619323Returns the current position of the L<C<readdir>|/readdir DIRHANDLE>
1874719324routines on DIRHANDLE. Value may be given to
1874819325L<C<seekdir>|/seekdir DIRHANDLE,POS> to access a particular location in
1874919326a directory. L<C<telldir>|/telldir DIRHANDLE> has the same caveats
1875019327about possible directory compaction as the corresponding system library
1875119328routine.
1875219329
1875319330=end original
1875419331
1875519332DIRHANDLE 上の L<C<readdir>|/readdir DIRHANDLE> ルーチンに対する現在位置を
1875619333返します。
1875719334値は、そのディレクトリで特定の位置をアクセスするため、
1875819335L<C<seekdir>|/seekdir DIRHANDLE,POS> に渡すことができます。
1875919336L<C<telldir>|/telldir DIRHANDLE> は同名のシステムライブラリルーチンと同じく、
1876019337ディレクトリ縮小時の問題が考えられます。
1876119338
1876219339=item tie VARIABLE,CLASSNAME,LIST
1876319340X<tie>
1876419341
1876519342=for Pod::Functions +5.002 bind a variable to an object class
1876619343
1876719344=begin original
1876819345
1876919346This function binds a variable to a package class that will provide the
1877019347implementation for the variable. VARIABLE is the name of the variable
1877119348to be enchanted. CLASSNAME is the name of a class implementing objects
1877219349of correct type. Any additional arguments are passed to the
1877319350appropriate constructor
1877419351method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>,
1877519352or C<TIEHASH>). Typically these are arguments such as might be passed
1877619353to the L<dbm_open(3)> function of C. The object returned by the
1877719354constructor is also returned by the
1877819355L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function, which would be useful
1877919356if you want to access other methods in CLASSNAME.
1878019357
1878119358=end original
1878219359
1878319360この関数は、変数を、その変数の実装を行なうクラスと結び付けます。
1878419361VARIABLE は、魔法をかける変数の名前です。
1878519362CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。
1878619363他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます
1878719364(つまり C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>, C<TIEHASH>)。
1878819365通常、これらは、C の L<dbm_open(3)> などの関数に渡す引数となります。
1878919366コンストラクタで返されるオブジェクトはまた
1879019367L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数でも返されます;
1879119368これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。
1879219369
1879319370=begin original
1879419371
1879519372Note that functions such as L<C<keys>|/keys HASH> and
1879619373L<C<values>|/values HASH> may return huge lists when used on large
1879719374objects, like DBM files. You may prefer to use the L<C<each>|/each
1879819375HASH> function to iterate over such. Example:
1879919376
1880019377=end original
1880119378
1880219379DBM ファイルのような大きなオブジェクトでは、L<C<keys>|/keys HASH> や
1880319380L<C<values>|/values HASH> のような関数は、大きなリストを返す可能性があります。
1880419381そのような場合では、L<C<each>|/each HASH> 関数を使って繰り返しを行なった方が
1880519382よいかもしれません。
1880619383例:
1880719384
1880819385 # print out history file offsets
1880919386 use NDBM_File;
1881019387 tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
1881119388 while (my ($key,$val) = each %HIST) {
1881219389 print $key, ' = ', unpack('L', $val), "\n";
1881319390 }
1881419391
1881519392=begin original
1881619393
1881719394A class implementing a hash should have the following methods:
1881819395
1881919396=end original
1882019397
1882119398ハッシュを実装するクラスでは、次のようなメソッドを用意します:
1882219399
1882319400 TIEHASH classname, LIST
1882419401 FETCH this, key
1882519402 STORE this, key, value
1882619403 DELETE this, key
1882719404 CLEAR this
1882819405 EXISTS this, key
1882919406 FIRSTKEY this
1883019407 NEXTKEY this, lastkey
1883119408 SCALAR this
1883219409 DESTROY this
1883319410 UNTIE this
1883419411
1883519412=begin original
1883619413
1883719414A class implementing an ordinary array should have the following methods:
1883819415
1883919416=end original
1884019417
1884119418通常の配列を実装するクラスでは、次のようなメソッドを用意します:
1884219419
1884319420 TIEARRAY classname, LIST
1884419421 FETCH this, key
1884519422 STORE this, key, value
1884619423 FETCHSIZE this
1884719424 STORESIZE this, count
1884819425 CLEAR this
1884919426 PUSH this, LIST
1885019427 POP this
1885119428 SHIFT this
1885219429 UNSHIFT this, LIST
1885319430 SPLICE this, offset, length, LIST
1885419431 EXTEND this, count
1885519432 DELETE this, key
1885619433 EXISTS this, key
1885719434 DESTROY this
1885819435 UNTIE this
1885919436
1886019437=begin original
1886119438
1886219439A class implementing a filehandle should have the following methods:
1886319440
1886419441=end original
1886519442
1886619443ファイルハンドルを実装するクラスでは、次のようなメソッドを用意します:
1886719444
1886819445 TIEHANDLE classname, LIST
1886919446 READ this, scalar, length, offset
1887019447 READLINE this
1887119448 GETC this
1887219449 WRITE this, scalar, length, offset
1887319450 PRINT this, LIST
1887419451 PRINTF this, format, LIST
1887519452 BINMODE this
1887619453 EOF this
1887719454 FILENO this
1887819455 SEEK this, position, whence
1887919456 TELL this
1888019457 OPEN this, mode, LIST
1888119458 CLOSE this
1888219459 DESTROY this
1888319460 UNTIE this
1888419461
1888519462=begin original
1888619463
1888719464A class implementing a scalar should have the following methods:
1888819465
1888919466=end original
1889019467
1889119468スカラ変数を実装するクラスでは、次のようなメソッドを用意します:
1889219469
1889319470 TIESCALAR classname, LIST
1889419471 FETCH this,
1889519472 STORE this, value
1889619473 DESTROY this
1889719474 UNTIE this
1889819475
1889919476=begin original
1890019477
1890119478Not all methods indicated above need be implemented. See L<perltie>,
1890219479L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>, and L<Tie::Handle>.
1890319480
1890419481=end original
1890519482
1890619483上記の全てのメソッドを実装する必要はありません。
1890719484L<perltie>, L<Tie::Hash>, L<Tie::Array>, L<Tie::Scalar>,
1890819485L<Tie::Handle> を参照してください。
1890919486
1891019487=begin original
1891119488
1891219489Unlike L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK>, the
1891319490L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> function will not
1891419491L<C<use>|/use Module VERSION LIST> or L<C<require>|/require VERSION> a
1891519492module for you; you need to do that explicitly yourself. See L<DB_File>
1891619493or the L<Config> module for interesting
1891719494L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> implementations.
1891819495
1891919496=end original
1892019497
1892119498L<C<dbmopen>|/dbmopen HASH,DBNAME,MASK> と違い、
1892219499L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 関数はモジュールを
1892319500L<C<use>|/use Module VERSION LIST> したり
1892419501L<C<require>|/require VERSION> したりしません;
1892519502自分で明示的に行う必要があります。
1892619503L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> の興味深い実装については
1892719504L<DB_File> や L<Config> モジュールを参照してください。
1892819505
1892919506=begin original
1893019507
1893119508For further details see L<perltie>, L<C<tied>|/tied VARIABLE>.
1893219509
1893319510=end original
1893419511
1893519512更なる詳細については L<perltie> や L<C<tied>|/tied VARIABLE> を
1893619513参照してください。
1893719514
1893819515=item tied VARIABLE
1893919516X<tied>
1894019517
1894119518=for Pod::Functions get a reference to the object underlying a tied variable
1894219519
1894319520=begin original
1894419521
1894519522Returns a reference to the object underlying VARIABLE (the same value
1894619523that was originally returned by the
1894719524L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> call that bound the variable
1894819525to a package.) Returns the undefined value if VARIABLE isn't tied to a
1894919526package.
1895019527
1895119528=end original
1895219529
1895319530VARIABLE の基となるオブジェクトへのリファレンスを返します
1895419531(変数をパッケージに結びつけるために
1895519532L<C<tie>|/tie VARIABLE,CLASSNAME,LIST> 呼び出しをしたときの
1895619533返り値と同じものです)。
1895719534VARIABLE がパッケージと結び付けられていない場合は未定義値を返します。
1895819535
1895919536=item time
1896019537X<time> X<epoch>
1896119538
1896219539=for Pod::Functions return number of seconds since 1970
1896319540
1896419541=begin original
1896519542
1896619543Returns the number of non-leap seconds since whatever time the system
1896719544considers to be the epoch, suitable for feeding to
1896819545L<C<gmtime>|/gmtime EXPR> and L<C<localtime>|/localtime EXPR>. On most
1896919546systems the epoch is 00:00:00 UTC, January 1, 1970;
1897019547a prominent exception being Mac OS Classic which uses 00:00:00, January 1,
18971195481904 in the current local time zone for its epoch.
1897219549
1897319550=end original
1897419551
1897519552L<C<gmtime>|/gmtime EXPR> や L<C<localtime>|/localtime EXPR> への入力形式に
1897619553合っている、システムが紀元と考える時点からの連続秒数を返します。
1897719554ほとんどのシステムでは紀元は UTC 1970 年 1 月 1 日 00:00:00 です;
1897819555特徴的な例外としては、古い Mac OS ではローカルタイムゾーンの
18979195561904 年 1 月 1 日 00:00:00 を紀元として使います。
1898019557
1898119558=begin original
1898219559
1898319560For measuring time in better granularity than one second, use the
1898419561L<Time::HiRes> module from Perl 5.8 onwards (or from CPAN before then), or,
1898519562if you have L<gettimeofday(2)>, you may be able to use the
1898619563L<C<syscall>|/syscall NUMBER, LIST> interface of Perl. See L<perlfaq8>
1898719564for details.
1898819565
1898919566=end original
1899019567
18991195681 秒よりも細かい時間を計測するためには、Perl 5.8 以降(それ以前では
1899219569CPANから)の L<Time::HiRes> モジュールを使うか、
1899319570L<gettimeofday(2)> があるなら、Perl の
1899419571L<C<syscall>|/syscall NUMBER, LIST> インターフェースを使ってください。
1899519572詳しくは L<perlfaq8> を参照してください。
1899619573
1899719574=begin original
1899819575
1899919576For date and time processing look at the many related modules on CPAN.
1900019577For a comprehensive date and time representation look at the
1900119578L<DateTime> module.
1900219579
1900319580=end original
1900419581
1900519582日付と時刻の処理は、多くの関連するモジュールが CPAN にあります。
1900619583包括的な日付と時刻の表現については、CPAN の L<DateTime> モジュールを
1900719584参照してください。
1900819585
1900919586=item times
1901019587X<times>
1901119588
1901219589=for Pod::Functions return elapsed time for self and child processes
1901319590
1901419591=begin original
1901519592
1901619593Returns a four-element list giving the user and system times in
1901719594seconds for this process and any exited children of this process.
1901819595
1901919596=end original
1902019597
1902119598現プロセス及び終了したその子プロセスに対する、ユーザ時間とシステム時間を
1902219599秒で示した、4 要素のリスト値を返します。
1902319600
1902419601 my ($user,$system,$cuser,$csystem) = times;
1902519602
1902619603=begin original
1902719604
1902819605In scalar context, L<C<times>|/times> returns C<$user>.
1902919606
1903019607=end original
1903119608
1903219609スカラコンテキストでは、L<C<times>|/times> は C<$user> を返します。
1903319610
1903419611=begin original
1903519612
1903619613Children's times are only included for terminated children.
1903719614
1903819615=end original
1903919616
1904019617子プロセスに対する times は、終了した子プロセスのみ含められます。
1904119618
1904219619=begin original
1904319620
1904419621Portability issues: L<perlport/times>.
1904519622
1904619623=end original
1904719624
1904819625移植性の問題: L<perlport/times>。
1904919626
1905019627=item tr///
1905119628
1905219629=for Pod::Functions transliterate a string
1905319630
1905419631=begin original
1905519632
1905619633The transliteration operator. Same as
1905719634L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>>. See
1905819635L<perlop/"Quote-Like Operators">.
1905919636
1906019637=end original
1906119638
1906219639文字変換演算子です。
1906319640L<C<yE<sol>E<sol>E<sol>>|/yE<sol>E<sol>E<sol>> と同じです。
1906419641L<perlop/"Quote-Like Operators"> を参照してください。
1906519642
1906619643=item truncate FILEHANDLE,LENGTH
1906719644X<truncate>
1906819645
1906919646=item truncate EXPR,LENGTH
1907019647
1907119648=for Pod::Functions shorten a file
1907219649
1907319650=begin original
1907419651
1907519652Truncates the file opened on FILEHANDLE, or named by EXPR, to the
1907619653specified length. Raises an exception if truncate isn't implemented
1907719654on your system. Returns true if successful, L<C<undef>|/undef EXPR> on
1907819655error.
1907919656
1908019657=end original
1908119658
1908219659FILEHANDLE 上にオープンされたファイルか、EXPR で名前を表わしたファイルを、
1908319660指定した長さに切り詰めます。
1908419661システム上に truncate が実装されていなければ、例外が発生します。
1908519662成功すれば真を、エラー時には L<C<undef>|/undef EXPR> を返します。
1908619663
1908719664=begin original
1908819665
1908919666The behavior is undefined if LENGTH is greater than the length of the
1909019667file.
1909119668
1909219669=end original
1909319670
1909419671LENGTH がファイルの長さより大きい場合の振る舞いは未定義です。
1909519672
1909619673=begin original
1909719674
1909819675The position in the file of FILEHANDLE is left unchanged. You may want to
1909919676call L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> before writing to the
1910019677file.
1910119678
1910219679=end original
1910319680
1910419681FILEHANDLE のファイルの位置は変わりません。
1910519682ファイルに書き込む前に L<seek|/"seek FILEHANDLE,POSITION,WHENCE"> を
1910619683呼び出したいかもしれません。
1910719684
1910819685=begin original
1910919686
1911019687Portability issues: L<perlport/truncate>.
1911119688
1911219689=end original
1911319690
1911419691移植性の問題: L<perlport/truncate>。
1911519692
1911619693=item uc EXPR
1911719694X<uc> X<uppercase> X<toupper>
1911819695
1911919696=item uc
1912019697
1912119698=for Pod::Functions return upper-case version of a string
1912219699
1912319700=begin original
1912419701
1912519702Returns an uppercased version of EXPR. This is the internal function
1912619703implementing the C<\U> escape in double-quoted strings.
1912719704It does not attempt to do titlecase mapping on initial letters. See
1912819705L<C<ucfirst>|/ucfirst EXPR> for that.
1912919706
1913019707=end original
1913119708
1913219709EXPR を大文字に変換したものを返します。
1913319710これは、ダブルクォート文字列における、C<\U> エスケープを
1913419711実装する内部関数です。
1913519712先頭文字の タイトル文字マッピングは試みません。
1913619713このためには L<C<ucfirst>|/ucfirst EXPR> を参照してください。
1913719714
1913819715=begin original
1913919716
1914019717If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1914119718
1914219719=end original
1914319720
1914419721EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1914519722
1914619723=begin original
1914719724
1914819725This function behaves the same way under various pragmas, such as in a locale,
1914919726as L<C<lc>|/lc EXPR> does.
1915019727
1915119728=end original
1915219729
1915319730この関数は、ロケールのようなさまざまなプラグマの影響下では、
1915419731L<C<lc>|/lc EXPR> と同様に振る舞います。
1915519732
1915619733=item ucfirst EXPR
1915719734X<ucfirst> X<uppercase>
1915819735
1915919736=item ucfirst
1916019737
1916119738=for Pod::Functions return a string with just the next letter in upper case
1916219739
1916319740=begin original
1916419741
1916519742Returns the value of EXPR with the first character in uppercase
1916619743(titlecase in Unicode). This is the internal function implementing
1916719744the C<\u> escape in double-quoted strings.
1916819745
1916919746=end original
1917019747
1917119748最初の文字だけを大文字にした、EXPR を返します
1917219749(Unicode では titlecase)。
1917319750これは、ダブルクォート文字列における、C<\u> エスケープを
1917419751実装する内部関数です。
1917519752
1917619753=begin original
1917719754
1917819755If EXPR is omitted, uses L<C<$_>|perlvar/$_>.
1917919756
1918019757=end original
1918119758
1918219759EXPR が省略されると、L<C<$_>|perlvar/$_> を使います。
1918319760
1918419761=begin original
1918519762
1918619763This function behaves the same way under various pragmas, such as in a locale,
1918719764as L<C<lc>|/lc EXPR> does.
1918819765
1918919766=end original
1919019767
1919119768この関数は、ロケールのようなさまざまなプラグマの影響下では、
1919219769L<C<lc>|/lc EXPR> と同様に振る舞います。
1919319770
1919419771=item umask EXPR
1919519772X<umask>
1919619773
1919719774=item umask
1919819775
1919919776=for Pod::Functions set file creation mode mask
1920019777
1920119778=begin original
1920219779
1920319780Sets the umask for the process to EXPR and returns the previous value.
1920419781If EXPR is omitted, merely returns the current umask.
1920519782
1920619783=end original
1920719784
1920819785現在のプロセスの umask を EXPR に設定し、以前の値を返します。
1920919786EXPR が省略されると、単にその時点の umask の値を返します。
1921019787
1921119788=begin original
1921219789
1921319790The Unix permission C<rwxr-x---> is represented as three sets of three
1921419791bits, or three octal digits: C<0750> (the leading 0 indicates octal
1921519792and isn't one of the digits). The L<C<umask>|/umask EXPR> value is such
1921619793a number representing disabled permissions bits. The permission (or
19217"mode") values you pass L<C<mkdir>|/mkdir FILENAME,MASK> or
19794"mode") values you pass L<C<mkdir>|/mkdir FILENAME,MODE> or
1921819795L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> are modified by your
1921919796umask, so even if you tell
1922019797L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> to create a file with
1922119798permissions C<0777>, if your umask is C<0022>, then the file will
1922219799actually be created with permissions C<0755>. If your
1922319800L<C<umask>|/umask EXPR> were C<0027> (group can't write; others can't
1922419801read, write, or execute), then passing
1922519802L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> C<0666> would create a
1922619803file with mode C<0640> (because C<0666 &~ 027> is C<0640>).
1922719804
1922819805=end original
1922919806
1923019807Unix パーミッション C<rwxr-x---> は 3 ビットの三つの組、
1923119808または 3 桁の 8 進数として表現されます:
1923219809C<0750> (先頭の 0 は 8 進数を意味し、実際の値ではありません)。
1923319810L<C<umask>|/umask EXPR> の値は無効にするパーミッションビットのこのような
1923419811数値表現です。
19235L<C<mkdir>|/mkdir FILENAME,MASK> や
19812L<C<mkdir>|/mkdir FILENAME,MODE> や
1923619813L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で渡されたパーミッション
1923719814(または「モード」)の値は umask で修正され、たとえ
1923819815L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> で C<0777> のパーミッションで
1923919816ファイルを作るように指定しても、umask が C<0022> なら、
1924019817結果としてファイルは C<0755> のパーミッションで作成されます。
1924119818L<C<umask>|/umask EXPR> が C<0027> (グループは書き込めない; その他は読み込み、
1924219819書き込み、実行できない) のとき
1924319820L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> に C<0666> を渡すと、
1924419821ファイルはモード C<0640> (なぜなら C<0666 &~ 027> は C<0640>)で作成されます。
1924519822
1924619823=begin original
1924719824
1924819825Here's some advice: supply a creation mode of C<0666> for regular
1924919826files (in L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE>) and one of
19250C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MASK>) and
19827C<0777> for directories (in L<C<mkdir>|/mkdir FILENAME,MODE>) and
1925119828executable files. This gives users the freedom of
1925219829choice: if they want protected files, they might choose process umasks
1925319830of C<022>, C<027>, or even the particularly antisocial mask of C<077>.
1925419831Programs should rarely if ever make policy decisions better left to
1925519832the user. The exception to this is when writing files that should be
1925619833kept private: mail files, web browser cookies, F<.rhosts> files, and
1925719834so on.
1925819835
1925919836=end original
1926019837
1926119838以下は助言です: 作成モードとして、
1926219839(L<C<sysopen>|/sysopen FILEHANDLE,FILENAME,MODE> による)通常ファイルでは
19263C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MASK> による)ディレクトリでは
19840C<0666> を、(L<C<mkdir>|/mkdir FILENAME,MODE> による)ディレクトリでは
1926419841C<0777> を指定しましょう。
1926519842これにより、ユーザーに選択の自由を与えます: もしファイルを守りたいなら、
1926619843プロセスの umask として C<022>, C<027>, あるいは特に非社交的な
1926719844C<077> を選択できます。
1926819845プログラムがユーザーより適切なポリシー選択ができることは稀です。
1926919846例外は、プライベートに保つべきファイル(メール、ウェブブラウザのクッキー、
1927019847F<.rhosts> ファイルなど)を書く場合です。
1927119848
1927219849=begin original
1927319850
1927419851If L<umask(2)> is not implemented on your system and you are trying to
1927519852restrict access for I<yourself> (i.e., C<< (EXPR & 0700) > 0 >>),
1927619853raises an exception. If L<umask(2)> is not implemented and you are
1927719854not trying to restrict access for yourself, returns
1927819855L<C<undef>|/undef EXPR>.
1927919856
1928019857=end original
1928119858
1928219859L<umask(2)> が実装されていないシステムで、I<自分自身> へのアクセスを
1928319860制限しようとした(つまり C<< (EXPR & 0700) > 0 >>)場合、例外が発生します。
1928419861L<umask(2)> が実装されていないシステムで、自分自身へのアクセスは
1928519862制限しようとしなかった場合、L<C<undef>|/undef EXPR> を返します。
1928619863
1928719864=begin original
1928819865
1928919866Remember that a umask is a number, usually given in octal; it is I<not> a
1929019867string of octal digits. See also L<C<oct>|/oct EXPR>, if all you have
1929119868is a string.
1929219869
1929319870=end original
1929419871
1929519872umask は通常 8 進数で与えられる数値であることを忘れないでください; 8 進数の
1929619873文字列 I<ではありません>。
1929719874文字列しかない場合、 L<C<oct>|/oct EXPR> も参照してください。
1929819875
1929919876=begin original
1930019877
1930119878Portability issues: L<perlport/umask>.
1930219879
1930319880=end original
1930419881
1930519882移植性の問題: L<perlport/umask>。
1930619883
1930719884=item undef EXPR
1930819885X<undef> X<undefine>
1930919886
1931019887=item undef
1931119888
1931219889=for Pod::Functions remove a variable or function definition
1931319890
1931419891=begin original
1931519892
1931619893Undefines the value of EXPR, which must be an lvalue. Use only on a
1931719894scalar value, an array (using C<@>), a hash (using C<%>), a subroutine
1931819895(using C<&>), or a typeglob (using C<*>). Saying C<undef $hash{$key}>
1931919896will probably not do what you expect on most predefined variables or
1932019897DBM list values, so don't do that; see L<C<delete>|/delete EXPR>.
1932119898Always returns the undefined value.
1932219899You can omit the EXPR, in which case nothing is
1932319900undefined, but you still get an undefined value that you could, for
1932419901instance, return from a subroutine, assign to a variable, or pass as a
1932519902parameter. Examples:
1932619903
1932719904=end original
1932819905
1932919906左辺値である EXPR の値を未定義にします。
1933019907スカラ値、(C<@> を使った)配列、(C<%> を使った)ハッシュ、(C<&> を使った)
1933119908サブルーチン、(C<*> を使った)型グロブだけに使用します。
1933219909特殊変数や DBM リスト値に C<undef $hash{$key}> などとしても
1933319910おそらく期待通りの結果にはなりませんから、しないでください;
1933419911L<C<delete>|/delete EXPR> を参照してください。
1933519912常に未定義値を返します。
1933619913EXPR は省略することができ、その場合には何も未定義にされませんが
1933719914未定義値は返されますので、それをたとえば、
1933819915サブルーチンの返り値、変数への割り当て、引数などとして使うことができます。
1933919916例:
1934019917
1934119918 undef $foo;
1934219919 undef $bar{'blurfl'}; # Compare to: delete $bar{'blurfl'};
1934319920 undef @ary;
1934419921 undef %hash;
1934519922 undef &mysub;
1934619923 undef *xyz; # destroys $xyz, @xyz, %xyz, &xyz, etc.
1934719924 return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it;
1934819925 select undef, undef, undef, 0.25;
1934919926 my ($x, $y, undef, $z) = foo(); # Ignore third value returned
1935019927
1935119928=begin original
1935219929
1935319930Note that this is a unary operator, not a list operator.
1935419931
1935519932=end original
1935619933
1935719934これはリスト演算子ではなく、単項演算子であることに注意してください。
1935819935
1935919936=item unlink LIST
1936019937X<unlink> X<delete> X<remove> X<rm> X<del>
1936119938
1936219939=item unlink
1936319940
1936419941=for Pod::Functions remove one link to a file
1936519942
1936619943=begin original
1936719944
1936819945Deletes a list of files. On success, it returns the number of files
1936919946it successfully deleted. On failure, it returns false and sets
1937019947L<C<$!>|perlvar/$!> (errno):
1937119948
1937219949=end original
1937319950
1937419951LIST に含まれるファイルを削除します。
1937519952成功時は削除に成功したファイルの数を返します。
1937619953失敗時は偽を返して L<C<$!>|perlvar/$!> (error) をセットします:
1937719954
1937819955 my $unlinked = unlink 'a', 'b', 'c';
1937919956 unlink @goners;
1938019957 unlink glob "*.bak";
1938119958
1938219959=begin original
1938319960
1938419961On error, L<C<unlink>|/unlink LIST> will not tell you which files it
1938519962could not remove.
1938619963If you want to know which files you could not remove, try them one
1938719964at a time:
1938819965
1938919966=end original
1939019967
1939119968エラーの場合、L<C<unlink>|/unlink LIST> はどのファイルが削除できなかったかを
1939219969知らせません。
1939319970どのファイルが削除できなかったかを知りたい場合は、一つずつ削除してください:
1939419971
1939519972 foreach my $file ( @goners ) {
1939619973 unlink $file or warn "Could not unlink $file: $!";
1939719974 }
1939819975
1939919976=begin original
1940019977
1940119978Note: L<C<unlink>|/unlink LIST> will not attempt to delete directories
1940219979unless you are
1940319980superuser and the B<-U> flag is supplied to Perl. Even if these
1940419981conditions are met, be warned that unlinking a directory can inflict
1940519982damage on your filesystem. Finally, using L<C<unlink>|/unlink LIST> on
1940619983directories is not supported on many operating systems. Use
1940719984L<C<rmdir>|/rmdir FILENAME> instead.
1940819985
1940919986=end original
1941019987
1941119988注: スーパーユーザ権限で、Perl に B<-U> を付けて実行した場合でなければ、
1941219989L<C<unlink>|/unlink LIST> はディレクトリを削除しようとすることはありません。
1941319990この条件にあう場合にも、ディレクトリの削除は、
1941419991ファイルシステムに多大な損害を与える可能性があります。
1941519992最後に、L<C<unlink>|/unlink LIST> をディレクトリに使うのはほとんどの OS では
1941619993対応していません。
1941719994代わりに L<C<rmdir>|/rmdir FILENAME> を使ってください。
1941819995
1941919996=begin original
1942019997
1942119998If LIST is omitted, L<C<unlink>|/unlink LIST> uses L<C<$_>|perlvar/$_>.
1942219999
1942320000=end original
1942420001
1942520002LIST が省略されると、L<C<unlink>|/unlink LIST> は L<C<$_>|perlvar/$_> を
1942620003使います。
1942720004
1942820005=item unpack TEMPLATE,EXPR
1942920006X<unpack>
1943020007
1943120008=item unpack TEMPLATE
1943220009
1943320010=for Pod::Functions convert binary structure into normal perl variables
1943420011
1943520012=begin original
1943620013
1943720014L<C<unpack>|/unpack TEMPLATE,EXPR> does the reverse of
1943820015L<C<pack>|/pack TEMPLATE,LIST>: it takes a string
1943920016and expands it out into a list of values.
1944020017(In scalar context, it returns merely the first value produced.)
1944120018
1944220019=end original
1944320020
1944420021L<C<unpack>|/unpack TEMPLATE,EXPR> は L<C<pack>|/pack TEMPLATE,LIST> の逆を
1944520022行ないます: 構造体を表わす文字列をとり、
1944620023リスト値に展開し、その配列値を返します。
1944720024(スカラコンテキストでは、単に最初の値を返します。)
1944820025
1944920026=begin original
1945020027
1945120028If EXPR is omitted, unpacks the L<C<$_>|perlvar/$_> string.
1945220029See L<perlpacktut> for an introduction to this function.
1945320030
1945420031=end original
1945520032
1945620033EXPR が省略されると、L<C<$_>|perlvar/$_> の文字列を unpack します。
1945720034この関数の説明については L<perlpacktut> を参照してください。
1945820035
1945920036=begin original
1946020037
1946120038The string is broken into chunks described by the TEMPLATE. Each chunk
1946220039is converted separately to a value. Typically, either the string is a result
1946320040of L<C<pack>|/pack TEMPLATE,LIST>, or the characters of the string
1946420041represent a C structure of some kind.
1946520042
1946620043=end original
1946720044
1946820045文字列は TEMPLATE で示された固まりに分割されます。
1946920046それぞれの固まりは別々に値に変換されます。
1947020047典型的には、文字列は L<C<pack>|/pack TEMPLATE,LIST> の結果あるいはある種の
1947120048C の構造体の文字列表現の文字列です。
1947220049
1947320050=begin original
1947420051
1947520052The TEMPLATE has the same format as in the
1947620053L<C<pack>|/pack TEMPLATE,LIST> function.
1947720054Here's a subroutine that does substring:
1947820055
1947920056=end original
1948020057
1948120058TEMPLATE は、L<C<pack>|/pack TEMPLATE,LIST> 関数と同じフォーマットを使います。
1948220059部分文字列を取り出すうサブルーチンの例を示します:
1948320060
1948420061 sub substr {
1948520062 my ($what, $where, $howmuch) = @_;
1948620063 unpack("x$where a$howmuch", $what);
1948720064 }
1948820065
1948920066=begin original
1949020067
1949120068and then there's
1949220069
1949320070=end original
1949420071
1949520072これもそうです。
1949620073
1949720074 sub ordinal { unpack("W",$_[0]); } # same as ord()
1949820075
1949920076=begin original
1950020077
1950120078In addition to fields allowed in L<C<pack>|/pack TEMPLATE,LIST>, you may
1950220079prefix a field with a %<number> to indicate that
1950320080you want a <number>-bit checksum of the items instead of the items
1950420081themselves. Default is a 16-bit checksum. The checksum is calculated by
1950520082summing numeric values of expanded values (for string fields the sum of
1950620083C<ord($char)> is taken; for bit fields the sum of zeroes and ones).
1950720084
1950820085=end original
1950920086
1951020087L<C<pack>|/pack TEMPLATE,LIST> で利用可能なフィールドの他に、
1951120088フィールドの前に %<数値> というものを付けて、
1951220089項目自身の代わりに、その項目の <数値>-ビットのチェックサムを
1951320090計算させることができます。
1951420091デフォルトは、16-ビットチェックサムです。
1951520092チェックサムは展開された値の数値としての値の合計
1951620093(文字列フィールドの場合は C<ord($char)> の合計;
1951720094ビットフィールドの場合は 0 と 1 の合計) が用いられます。
1951820095
1951920096=begin original
1952020097
1952120098For example, the following
1952220099computes the same number as the System V sum program:
1952320100
1952420101=end original
1952520102
1952620103たとえば、以下のコードは
1952720104System V の sum プログラムと同じ値を計算します。
1952820105
1952920106 my $checksum = do {
1953020107 local $/; # slurp!
1953120108 unpack("%32W*", readline) % 65535;
1953220109 };
1953320110
1953420111=begin original
1953520112
1953620113The following efficiently counts the number of set bits in a bit vector:
1953720114
1953820115=end original
1953920116
1954020117以下は、効率的にビットベクターの設定されているビットを
1954120118数えるものです。
1954220119
1954320120 my $setbits = unpack("%32b*", $selectmask);
1954420121
1954520122=begin original
1954620123
1954720124The C<p> and C<P> formats should be used with care. Since Perl
1954820125has no way of checking whether the value passed to
1954920126L<C<unpack>|/unpack TEMPLATE,EXPR>
1955020127corresponds to a valid memory location, passing a pointer value that's
1955120128not known to be valid is likely to have disastrous consequences.
1955220129
1955320130=end original
1955420131
1955520132C<p> と C<P> は注意深く使うべきです。
1955620133Perl は L<C<unpack>|/unpack TEMPLATE,EXPR> に渡された値が有効なメモリ位置を
1955720134指しているかどうかを確認する方法がないので、有効かどうかわからない
1955820135ポインタ値を渡すと悲惨な結果を引き起こすかもしれません。
1955920136
1956020137=begin original
1956120138
1956220139If there are more pack codes or if the repeat count of a field or a group
1956320140is larger than what the remainder of the input string allows, the result
1956420141is not well defined: the repeat count may be decreased, or
1956520142L<C<unpack>|/unpack TEMPLATE,EXPR> may produce empty strings or zeros,
1956620143or it may raise an exception.
1956720144If the input string is longer than one described by the TEMPLATE,
1956820145the remainder of that input string is ignored.
1956920146
1957020147=end original
1957120148
1957220149多くの pack コードがある場合や、フィールドやグループの繰り返し回数が
1957320150入力文字列の残りより大きい場合、結果は未定義です:
1957420151繰り返し回数が減らされる場合もありますし、
1957520152L<C<unpack>|/unpack TEMPLATE,EXPR> が空文字列や 0 を
1957620153返すこともありますし、例外が発生します。
1957720154もし入力文字列が TEMPLATE で表現されているものより大きい場合、
1957820155入力文字列の残りは無視されます。
1957920156
1958020157=begin original
1958120158
1958220159See L<C<pack>|/pack TEMPLATE,LIST> for more examples and notes.
1958320160
1958420161=end original
1958520162
1958620163さらなる例と注意に関しては L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
1958720164
1958820165=item unshift ARRAY,LIST
1958920166X<unshift>
1959020167
1959120168=for Pod::Functions prepend more elements to the beginning of a list
1959220169
1959320170=begin original
1959420171
1959520172Does the opposite of a L<C<shift>|/shift ARRAY>. Or the opposite of a
1959620173L<C<push>|/push ARRAY,LIST>,
1959720174depending on how you look at it. Prepends list to the front of the
1959820175array and returns the new number of elements in the array.
1959920176
1960020177=end original
1960120178
1960220179L<C<shift>|/shift ARRAY> の逆操作を行ないます。
1960320180見方を変えれば、L<C<push>|/push ARRAY,LIST> の逆操作とも考えられます。
1960420181LIST を ARRAY の先頭に入れて、新しくできた配列の要素の数を返します。
1960520182
1960620183 unshift(@ARGV, '-e') unless $ARGV[0] =~ /^-/;
1960720184
1960820185=begin original
1960920186
1961020187Note the LIST is prepended whole, not one element at a time, so the
1961120188prepended elements stay in the same order. Use
1961220189L<C<reverse>|/reverse LIST> to do the reverse.
1961320190
1961420191=end original
1961520192
1961620193LIST は、はらばらにではなく、一度に登録されるので、順番はそのままです。
1961720194逆順に登録するには、L<C<reverse>|/reverse LIST> を使ってください。
1961820195
1961920196=begin original
1962020197
1962120198Starting with Perl 5.14, an experimental feature allowed
1962220199L<C<unshift>|/unshift ARRAY,LIST> to take
1962320200a scalar expression. This experiment has been deemed unsuccessful, and was
1962420201removed as of Perl 5.24.
1962520202
1962620203=end original
1962720204
1962820205Perl 5.14 から、L<C<unshift>|/unshift ARRAY,LIST> がスカラ式を
1962920206取ることが出来るという実験的機能がありました。
1963020207この実験は失敗と見なされ、Perl 5.24 で削除されました。
1963120208
1963220209=item untie VARIABLE
1963320210X<untie>
1963420211
1963520212=for Pod::Functions break a tie binding to a variable
1963620213
1963720214=begin original
1963820215
1963920216Breaks the binding between a variable and a package.
1964020217(See L<tie|/tie VARIABLE,CLASSNAME,LIST>.)
1964120218Has no effect if the variable is not tied.
1964220219
1964320220=end original
1964420221
1964520222変数とパッケージの間の結合を解きます。
1964620223(L<tie|/tie VARIABLE,CLASSNAME,LIST> を参照してください。)
1964720224結合されていない場合は何も起きません。
1964820225
1964920226=item use Module VERSION LIST
1965020227X<use> X<module> X<import>
1965120228
1965220229=item use Module VERSION
1965320230
1965420231=item use Module LIST
1965520232
1965620233=item use Module
1965720234
1965820235=item use VERSION
1965920236
1966020237=for Pod::Functions load in a module at compile time and import its namespace
1966120238
1966220239=begin original
1966320240
1966420241Imports some semantics into the current package from the named module,
1966520242generally by aliasing certain subroutine or variable names into your
1966620243package. It is exactly equivalent to
1966720244
1966820245=end original
1966920246
1967020247指定したモジュールから、現在のパッケージにさまざまな内容をインポートします;
1967120248多くは、パッケージのサブルーチン名や、変数名に別名を付けることで、
1967220249実現されています。
1967320250これは、以下は等価ですが:
1967420251
1967520252 BEGIN { require Module; Module->import( LIST ); }
1967620253
1967720254=begin original
1967820255
1967920256except that Module I<must> be a bareword.
1968020257The importation can be made conditional by using the L<if> module.
1968120258
1968220259=end original
1968320260
1968420261Module が I<裸の単語でなければならない> ことを除けば、です。
1968520262インポートは、L<if> を使って条件付きで行うことができます。
1968620263
1968720264=begin original
1968820265
19689In the peculiar C<use VERSION> form, VERSION may be either a positive
20266In the C<use VERSION> form, VERSION may be either a v-string such as
19690decimal fraction such as 5.006, which will be compared to
20267v5.24.1, which will be compared to L<C<$^V>|perlvar/$^V> (aka
19691L<C<$]>|perlvar/$]>, or a v-string of the form v5.6.1, which will be
20268$PERL_VERSION), or a numeric argument of the form 5.024001, which will
19692compared to L<C<$^V>|perlvar/$^V> (aka $PERL_VERSION). An
20269be compared to L<C<$]>|perlvar/$]>. An exception is raised if VERSION
19693exception is raised if VERSION is greater than the version of the
20270is greater than the version of the current Perl interpreter; Perl will
19694current Perl interpreter; Perl will not attempt to parse the rest of the
20271not attempt to parse the rest of the file. Compare with
19695file. Compare with L<C<require>|/require VERSION>, which can do a
20272L<C<require>|/require VERSION>, which can do a similar check at run
19696similar check at run time.
20273time. Symmetrically, C<no VERSION> allows you to specify that you
19697Symmetrically, C<no VERSION> allows you to specify that you want a version
20274want a version of Perl older than the specified one.
19698of Perl older than the specified one.
1969920275
1970020276=end original
1970120277
19702特に C<use VERSION> の形式では、VERSION は 5.006 のような正の 10 進小数
20278C<use VERSION> の形式では、VERSION は v5.24.1 のような v-文字列
19703(L<C<$]>|perlvar/$]> と比較されます)か、v5.6.1 の形
20279(L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます)
19704(L<C<$^V>|perlvar/$^V> (またの名を $PERL_VERSION) と比較されます)
20280か、5.024001 の形の数値形式 (L<C<$]>|perlvar/$]> と比較されます)
19705v-文字列で指定します。
20281指定します。
1970620282VERSION が Perl の現在のバージョンより大きいと、例外が発生します;
1970720283Perl はファイルの残りを読み込みません。
19708L<C<require>|/require VERSION> と似ていますが、これは実行時にチェックされます。
20284L<C<require>|/require VERSION> と似ていますが、これは実行時に
20285チェックされます。
1970920286対称的に、C<no VERSION> は指定されたバージョンより古いバージョンの Perl で
1971020287動作させたいことを意味します。
1971120288
1971220289=begin original
1971320290
19714Specifying VERSION as a literal of the form v5.6.1 should generally be
20291Specifying VERSION as a numeric argument of the form 5.024001 should
19715avoided, because it leads to misleading error messages under earlier
20292generally be avoided as older less readable syntax compared to
19716versions of Perl (that is, prior to 5.6.0) that do not support this
20293v5.24.1. Before perl 5.8.0 released in 2002 the more verbose numeric
19717syntax. The equivalent numeric version should be used instead.
20294form was the only supported syntax, which is why you might see it in
1971820295
1971920296=end original
1972020297
19721VERSION に v5.6.1 の形のリテラルを指定することは一般的には避けるべきです;
20298VERSION に 5.024001 の形の数値引数を指定することは一般的には避けるべきです;
19722なぜなら、この文法対応していない Perl の初期のバージョン
20299v5.24.1 比べより古く読みにく文法だからです。
19723(つまり、 5.6.0 ) では誤解させるエラーメッセージが出るからです。
20300(2002 年にリリースされた) perl 5.8.0 より前ではり冗長
19724代わりに等価な数値表現を使うべきす。
20301数値形式が唯一対応している文法した; これが古いコードでこれを
20302見るかも知れない理由です。
1972520303
19726 use v5.6.1; # compile time version check
20304=begin original
19727 use 5.6.1; # ditto
19728 use 5.006_001; # ditto; preferred for backwards compatibility
1972920305
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
1973020316=begin original
1973120317
1973220318This is often useful if you need to check the current Perl version before
1973320319L<C<use>|/use Module VERSION LIST>ing library modules that won't work
1973420320with older versions of Perl.
1973520321(We try not to do this more than we have to.)
1973620322
1973720323=end original
1973820324
1973920325これは古いバージョンの Perl で動かなくなったライブラリモジュールを
1974020326L<C<use>|/use Module VERSION LIST> する前に、現在の Perl のバージョンを
1974120327調べたい場合に有用です。
1974220328(我々は必要な場合以外にそのようなことがないように努力していますが。)
1974320329
1974420330=begin original
1974520331
1974620332C<use VERSION> also lexically enables all features available in the requested
1974720333version as defined by the L<feature> pragma, disabling any features
1974820334not in the requested version's feature bundle. See L<feature>.
1974920335Similarly, if the specified Perl version is greater than or equal to
19750203365.12.0, strictures are enabled lexically as
1975120337with L<C<use strict>|strict>. Any explicit use of
1975220338C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes
1975320339before it. Later use of C<use VERSION>
1975420340will override all behavior of a previous
1975520341C<use VERSION>, possibly removing the C<strict> and C<feature> added by
1975620342C<use VERSION>. C<use VERSION> does not
1975720343load the F<feature.pm> or F<strict.pm>
1975820344files.
1975920345
1976020346=end original
1976120347
1976220348C<use VERSION> は、L<feature> プラグマで定義されたように、指定された
1976320349バージョンで利用可能な全ての機能を有効にし、指定されたバージョンの機能の
1976420350束にない機能をレキシカルに無効にします。
1976520351L<feature> を参照してください。
1976620352同様に、指定された Perl のバージョンが 5.12.0 以上の場合、
1976720353制限は L<C<use strict>|strict> と同様にレキシカルに有効になります。
1976820354明示的に C<use strict> や C<no strict> を使うと、例え先に
1976920355指定されていたとしても、C<use VERSION> を上書きします。
1977020356後から使った C<use VERSION> は先の
1977120357C<use VERSION> の全ての振る舞いを上書きするので、
1977220358C<use VERSION> によって追加された C<strict> と C<feature> を
1977320359削除することがあります。
1977420360C<use VERSION> は F<feature.pm> と F<strict.pm> ファイルは読み込みません。
1977520361
1977620362=begin original
1977720363
1977820364The C<BEGIN> forces the L<C<require>|/require VERSION> and
1977920365L<C<import>|/import LIST> to happen at compile time. The
1978020366L<C<require>|/require VERSION> makes sure the module is loaded into
1978120367memory if it hasn't been yet. The L<C<import>|/import LIST> is not a
1978220368builtin; it's just an ordinary static method
1978320369call into the C<Module> package to tell the module to import the list of
1978420370features back into the current package. The module can implement its
1978520371L<C<import>|/import LIST> method any way it likes, though most modules
1978620372just choose to derive their L<C<import>|/import LIST> method via
1978720373inheritance from the C<Exporter> class that is defined in the
1978820374L<C<Exporter>|Exporter> module. See L<Exporter>. If no
1978920375L<C<import>|/import LIST> method can be found, then the call is skipped,
1979020376even if there is an AUTOLOAD method.
1979120377
1979220378=end original
1979320379
1979420380C<BEGIN> によって、L<C<require>|/require VERSION> や
1979520381L<C<import>|/import LIST> は、コンパイル時に
1979620382実行されることになります。
1979720383L<C<require>|/require VERSION> は、モジュールがまだメモリに
1979820384ロードされていなければ、ロードします。
1979920385L<C<import>|/import LIST> は、組込みの関数ではありません; さまざまな機能を
1980020386現在のパッケージにインポートするように C<Module> パッケージに伝えるために
1980120387呼ばれる、通常の静的メソッドです。
1980220388モジュール側では、L<C<import>|/import LIST> メソッドをどのようにでも
1980320389実装することができますが、多くのモジュールでは、
1980420390L<C<Exporter>|Exporter> モジュールで定義された、
1980520391C<Exporter> クラスからの継承によって、L<C<import>|/import LIST> メソッドを
1980620392行なうようにしています。
1980720393L<Exporter>モジュールを参照してください。
1980820394L<C<import>|/import LIST>メソッドが見つからなかった場合、AUTOLOAD メソッドが
1980920395あったとしても呼び出しはスキップされます。
1981020396
1981120397=begin original
1981220398
1981320399If you do not want to call the package's L<C<import>|/import LIST>
1981420400method (for instance,
1981520401to stop your namespace from being altered), explicitly supply the empty list:
1981620402
1981720403=end original
1981820404
1981920405パッケージの L<C<import>|/import LIST> メソッドを呼び出したくない場合(例えば、
1982020406名前空間を変更したくない場合など)は、明示的に空リストを指定してください:
1982120407
1982220408 use Module ();
1982320409
1982420410=begin original
1982520411
1982620412That is exactly equivalent to
1982720413
1982820414=end original
1982920415
1983020416これは以下と完全に等価です:
1983120417
1983220418 BEGIN { require Module }
1983320419
1983420420=begin original
1983520421
1983620422If the VERSION argument is present between Module and LIST, then the
1983720423L<C<use>|/use Module VERSION LIST> will call the C<VERSION> method in
1983820424class Module with the given version as an argument:
1983920425
1984020426=end original
1984120427
1984220428Module と LIST の間に VERSION 引数がある場合、
1984320429L<C<use>|/use Module VERSION LIST> は Module クラスの
1984420430C<VERSION> メソッドを、与えられたバージョンを引数として呼び出します:
1984520431
1984620432 use Module 12.34;
1984720433
1984820434=begin original
1984920435
1985020436is equivalent to:
1985120437
1985220438=end original
1985320439
1985420440は以下と等価です:
1985520441
1985620442 BEGIN { require Module; Module->VERSION(12.34) }
1985720443
1985820444=begin original
1985920445
1986020446The L<default C<VERSION> method|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>>,
1986120447inherited from the L<C<UNIVERSAL>|UNIVERSAL> class, croaks if the given
1986220448version is larger than the value of the variable C<$Module::VERSION>.
1986320449
1986420450=end original
1986520451
1986620452デフォルトの
1986720453L<default C<VERSION> メソッド|UNIVERSAL/C<VERSION ( [ REQUIRE ] )>> は、
1986820454L<C<UNIVERSAL>|UNIVERSAL> クラスから継承したもので、
1986920455与えられたバージョンが 変数 C<$Module::VERSION> の値より大きい場合に
1987020456警告を出します。
1987120457
1987220458=begin original
1987320459
20460The VERSION argument cannot be an arbitrary expression. It only counts
20461as a VERSION argument if it is a version number literal, starting with
20462either a digit or C<v> followed by a digit. Anything that doesn't
20463look like a version literal will be parsed as the start of the LIST.
20464Nevertheless, many attempts to use an arbitrary expression as a VERSION
20465argument will appear to work, because L<Exporter>'s C<import> method
20466handles numeric arguments specially, performing version checks rather
20467than treating them as things to export.
20468
20469=end original
20470
20471VERSION 引数は任意の式ではありません。
20472VERSION 引数が数値または C<v> に引き続いて数値であるバージョン番号リテラルの
20473場合にのみ扱われます。
20474バージョンリテラルのように見えないものは LIST の開始としてパースされます。
20475それにも関わらず、VERSION 引数として任意の式を使おうとする
20476多くの試みは動作しているように見えます; なぜなら
20477L<Exporter> の C<import> メソッドは数値引数を特別に扱い、
20478それらをエクスポートするべきものと扱わずにバージョンチェックを
20479実行するからです。
20480
20481=begin original
20482
1987420483Again, there is a distinction between omitting LIST (L<C<import>|/import
1987520484LIST> called with no arguments) and an explicit empty LIST C<()>
1987620485(L<C<import>|/import LIST> not called). Note that there is no comma
1987720486after VERSION!
1987820487
1987920488=end original
1988020489
1988120490繰り返すと、LIST を省略する(L<C<import>|/import LIST> が引数なしで
1988220491呼び出される)ことと明示的に空の LIST C<()> を指定する
1988320492(L<C<import>|/import LIST> は呼び出されない)ことは違います。
1988420493VERSION の後ろにカンマが不要なことに注意してください!
1988520494
1988620495=begin original
1988720496
1988820497Because this is a wide-open interface, pragmas (compiler directives)
1988920498are also implemented this way. Some of the currently implemented
1989020499pragmas are:
1989120500
1989220501=end original
1989320502
1989420503これは、広く公開されているインタフェースですので、
1989520504プラグマ (コンパイラディレクティブ) も、この方法で実装されています。
1989620505現在実装されているプラグマには、以下のようなものがあります:
1989720506
1989820507 use constant;
1989920508 use diagnostics;
1990020509 use integer;
1990120510 use sigtrap qw(SEGV BUS);
1990220511 use strict qw(subs vars refs);
1990320512 use subs qw(afunc blurfl);
1990420513 use warnings qw(all);
19905 use sort qw(stable _quicksort _mergesort);
20514 use sort qw(stable);
1990620515
1990720516=begin original
1990820517
1990920518Some of these pseudo-modules import semantics into the current
1991020519block scope (like L<C<strict>|strict> or L<C<integer>|integer>, unlike
1991120520ordinary modules, which import symbols into the current package (which
1991220521are effective through the end of the file).
1991320522
1991420523=end original
1991520524
1991620525通常のモジュールが、現在のパッケージにシンボルをインポートする
1991720526(これは、ファイルの終わりまで有効です) のに対して、これらの擬似モジュールの
1991820527一部(L<C<strict>|strict> や L<C<integer>|integer> など)は、現在の
1991920528ブロックスコープにインポートを行ないます。
1992020529
1992120530=begin original
1992220531
1992320532Because L<C<use>|/use Module VERSION LIST> takes effect at compile time,
1992420533it doesn't respect the ordinary flow control of the code being compiled.
1992520534In particular, putting a L<C<use>|/use Module VERSION LIST> inside the
1992620535false branch of a conditional doesn't prevent it
1992720536from being processed. If a module or pragma only needs to be loaded
1992820537conditionally, this can be done using the L<if> pragma:
1992920538
1993020539=end original
1993120540
1993220541L<C<use>|/use Module VERSION LIST> はコンパイル時に有効なので、コードが
1993320542コンパイルされる際の通常の流れ制御には従いません。
1993420543特に、条件文のうち成立しない側の中に L<C<use>|/use Module VERSION LIST> を
1993520544書いても、処理を妨げられません。
1993620545モジュールやプラグマを条件付きでのみ読み込みたい場合、
1993720546L<if> プラグマを使って実現できます:
1993820547
1993920548 use if $] < 5.008, "utf8";
1994020549 use if WANT_WARNINGS, warnings => qw(all);
1994120550
1994220551=begin original
1994320552
1994420553There's a corresponding L<C<no>|/no MODULE VERSION LIST> declaration
1994520554that unimports meanings imported by L<C<use>|/use Module VERSION LIST>,
1994620555i.e., it calls C<< Module->unimport(LIST) >> instead of
1994720556L<C<import>|/import LIST>. It behaves just as L<C<import>|/import LIST>
1994820557does with VERSION, an omitted or empty LIST,
1994920558or no unimport method being found.
1995020559
1995120560=end original
1995220561
1995320562これに対して、L<C<no>|/no MODULE VERSION LIST> 宣言という、
1995420563L<C<use>|/use Module VERSION LIST> によってインポートされたものを、
1995520564インポートされていないことにするものがあります; つまり、
1995620565L<C<import>|/import LIST> の代わりに
1995720566C<< Module->unimport(LIST) >> を呼び出します。
1995820567これは VERSION、省略された LIST、空の LIST、unimport メソッドが見つからない
1995920568場合などの観点では、L<C<import>|/import LIST> と同様に振る舞います。
1996020569
1996120570 no integer;
1996220571 no strict 'refs';
1996320572 no warnings;
1996420573
1996520574=begin original
1996620575
1996720576Care should be taken when using the C<no VERSION> form of L<C<no>|/no
1996820577MODULE VERSION LIST>. It is
1996920578I<only> meant to be used to assert that the running Perl is of a earlier
1997020579version than its argument and I<not> to undo the feature-enabling side effects
1997120580of C<use VERSION>.
1997220581
1997320582=end original
1997420583
1997520584L<C<no>|/no MODULE VERSION LIST> の C<no VERSION> 形式を使うときには
1997620585注意を払うべきです。
1997720586これは引数で指定されたバージョンよりも前の Perl で実行されたときに
1997820587アサートされることを意味する I<だけ> で、C<use VERSION> によって
1997920588有効にされた副作用をなかったことにするもの I<ではありません>。
1998020589
1998120590=begin original
1998220591
19983See L<perlmodlib> for a list of standard modules and pragmas. See L<perlrun>
20592See L<perlmodlib> for a list of standard modules and pragmas. See
19984for the C<-M> and C<-m> command-line options to Perl that give
20593L<perlrun|perlrun/-m[-]module> for the C<-M> and C<-m> command-line
19985L<C<use>|/use Module VERSION LIST> functionality from the command-line.
20594options to Perl that give L<C<use>|/use Module VERSION LIST>
20595functionality from the command-line.
1998620596
1998720597=end original
1998820598
1998920599標準モジュールやプラグマの一覧は、L<perlmodlib> を参照してください。
1999020600コマンドラインから L<C<use>|/use Module VERSION LIST> 機能を
1999120601指定するための C<-M> と C<-m> の
19992コマンドラインオプションについては L<perlrun> を参照してください。
20602コマンドラインオプションについては
20603L<perlrun|perlrun/-m[-]module> を参照してください。
1999320604
1999420605=item utime LIST
1999520606X<utime>
1999620607
1999720608=for Pod::Functions set a file's last access and modify times
1999820609
1999920610=begin original
2000020611
2000120612Changes the access and modification times on each file of a list of
2000220613files. The first two elements of the list must be the NUMERIC access
2000320614and modification times, in that order. Returns the number of files
2000420615successfully changed. The inode change time of each file is set
2000520616to the current time. For example, this code has the same effect as the
2000620617Unix L<touch(1)> command when the files I<already exist> and belong to
2000720618the user running the program:
2000820619
2000920620=end original
2001020621
2001120622ファイルのアクセス時刻と修正(modification) 時刻を変更します。
2001220623LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を
2001320624順に指定します。
2001420625変更に成功したファイルの数を返します。
2001520626各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。
2001620627例えば、このコードはファイルが I<既に存在して> いて、ユーザーが
2001720628実行しているプログラムに従っているなら、
2001820629Unix の L<touch(1)> コマンドと同じ効果があります。
2001920630
2002020631 #!/usr/bin/perl
2002120632 my $atime = my $mtime = time;
2002220633 utime $atime, $mtime, @ARGV;
2002320634
2002420635=begin original
2002520636
2002620637Since Perl 5.8.0, if the first two elements of the list are
2002720638L<C<undef>|/undef EXPR>,
2002820639the L<utime(2)> syscall from your C library is called with a null second
2002920640argument. On most systems, this will set the file's access and
2003020641modification times to the current time (i.e., equivalent to the example
2003120642above) and will work even on files you don't own provided you have write
2003220643permission:
2003320644
2003420645=end original
2003520646
2003620647Perl 5.8.0 から、リストの最初の二つの要素が L<C<undef>|/undef EXPR> である
2003720648場合、C ライブラリの L<utime(2)> システムコールを、秒の引数を null として
2003820649呼び出します。
2003920650ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を
2004020651現在の時刻にセットし(つまり、上記の例と等価です)、
2004120652書き込み権限があれば他のユーザーのファイルに対しても動作します。
2004220653
2004320654 for my $file (@ARGV) {
2004420655 utime(undef, undef, $file)
2004520656 || warn "Couldn't touch $file: $!";
2004620657 }
2004720658
2004820659=begin original
2004920660
2005020661Under NFS this will use the time of the NFS server, not the time of
2005120662the local machine. If there is a time synchronization problem, the
2005220663NFS server and local machine will have different times. The Unix
2005320664L<touch(1)> command will in fact normally use this form instead of the
2005420665one shown in the first example.
2005520666
2005620667=end original
2005720668
2005820669NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が
2005920670使われます。
2006020671時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に
2006120672なっている場合があります。
2006220673実際のところ、Unix の L<touch(1)> コマンドは普通、最初の例ではなく、
2006320674この形を使います。
2006420675
2006520676=begin original
2006620677
2006720678Passing only one of the first two elements as L<C<undef>|/undef EXPR> is
2006820679equivalent to passing a 0 and will not have the effect described when
2006920680both are L<C<undef>|/undef EXPR>. This also triggers an
2007020681uninitialized warning.
2007120682
2007220683=end original
2007320684
2007420685最初の二つの要素のうち、一つだけに L<C<undef>|/undef EXPR> を渡すと、その
2007520686要素は 0 を渡すのと等価となり、上述の、両方に L<C<undef>|/undef EXPR> を
2007620687渡した時と同じ効果ではありません。
2007720688この場合は、未初期化の警告が出ます。
2007820689
2007920690=begin original
2008020691
2008120692On systems that support L<futimes(2)>, you may pass filehandles among the
2008220693files. On systems that don't support L<futimes(2)>, passing filehandles raises
2008320694an exception. Filehandles must be passed as globs or glob references to be
2008420695recognized; barewords are considered filenames.
2008520696
2008620697=end original
2008720698
2008820699L<futimes(2)> に対応しているシステムでは、ファイルハンドルを引数として
2008920700渡せます。
2009020701L<futimes(2)> に対応していないシステムでは、ファイルハンドルを渡すと
2009120702例外が発生します。
2009220703ファイルハンドルを認識させるためには、グロブまたはリファレンスとして
2009320704渡されなければなりません; 裸の単語はファイル名として扱われます。
2009420705
2009520706=begin original
2009620707
2009720708Portability issues: L<perlport/utime>.
2009820709
2009920710=end original
2010020711
2010120712移植性の問題: L<perlport/utime>。
2010220713
2010320714=item values HASH
2010420715X<values>
2010520716
2010620717=item values ARRAY
2010720718
2010820719=for Pod::Functions return a list of the values in a hash
2010920720
2011020721=begin original
2011120722
2011220723In list context, returns a list consisting of all the values of the named
2011320724hash. In Perl 5.12 or later only, will also return a list of the values of
2011420725an array; prior to that release, attempting to use an array argument will
2011520726produce a syntax error. In scalar context, returns the number of values.
2011620727
2011720728=end original
2011820729
2011920730リストコンテキストでは、指定したハッシュのすべての値を返します。
2012020731Perl 5.12 以降でのみ、配列の全ての値からなるリストも返します;
2012120732このリリースの前では、配列要素に使おうとすると文法エラーが発生します。
2012220733スカラコンテキストでは、値の数を返します。
2012320734
2012420735=begin original
2012520736
2012620737Hash entries are returned in an apparently random order. The actual random
2012720738order is specific to a given hash; the exact same series of operations
2012820739on two hashes may result in a different order for each hash. Any insertion
2012920740into the hash may change the order, as will any deletion, with the exception
2013020741that the most recent key returned by L<C<each>|/each HASH> or
2013120742L<C<keys>|/keys HASH> may be deleted without changing the order. So
2013220743long as a given hash is unmodified you may rely on
2013320744L<C<keys>|/keys HASH>, L<C<values>|/values HASH> and
2013420745L<C<each>|/each HASH> to repeatedly return the same order
2013520746as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
2013620747details on why hash order is randomized. Aside from the guarantees
2013720748provided here the exact details of Perl's hash algorithm and the hash
2013820749traversal order are subject to change in any release of Perl. Tied hashes
2013920750may behave differently to Perl's hashes with respect to changes in order on
2014020751insertion and deletion of items.
2014120752
2014220753=end original
2014320754
2014420755ハッシュ要素は見かけ上、ランダムな順序で返されます。
2014520756実際のランダムな順序はハッシュに固有です; 二つのハッシュに全く同じ一連の
2014620757操作を行っても、ハッシュによって異なった順序になります。
2014720758ハッシュへの挿入によって順序が変わることがあります; 削除も同様ですが、
2014820759L<C<each>|/each HASH> または L<C<keys>|/keys HASH> によって返されたもっとも
2014920760最近のキーは順序を変えることなく削除できます。
2015020761ハッシュが変更されない限り、L<C<keys>|/keys HASH>, L<C<values>|/values HASH>,
2015120762L<C<each>|/each HASH> が繰り返し同じ順序で返すことに依存してもかまいません。
2015220763なぜハッシュの順序がランダム化されているかの詳細については
2015320764L<perlsec/"Algorithmic Complexity Attacks"> を参照してください。
2015420765ここで保証したことを除いて、Perl のハッシュアルゴリズムとハッシュ横断順序の
2015520766正確な詳細は Perl のリリースによって変更される可能性があります。
2015620767tie されたハッシュは、アイテムの挿入と削除の順序に関して Perl のハッシュと
2015720768異なった振る舞いをします。
2015820769
2015920770=begin original
2016020771
2016120772As a side effect, calling L<C<values>|/values HASH> resets the HASH or
20162ARRAY's internal iterator, see L<C<each>|/each HASH>. (In particular,
20773ARRAY's internal iterator (see L<C<each>|/each HASH>) before yielding the
20774values. In particular,
2016320775calling L<C<values>|/values HASH> in void context resets the iterator
20164with no other overhead. Apart from resetting the iterator,
20776with no other overhead.
20777
20778=end original
20779
20780副作用として、L<C<values>|/values HASH> を呼び出すと、
20781値を取り出す前に HASH や ARRAY の
20782内部反復子(L<C<each>|/each HASH> 参照)をリセットします。
20783特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の
20784オーバーヘッドなしで反復子をリセットします。
20785
20786=begin original
20787
20788Apart from resetting the iterator,
2016520789C<values @array> in list context is the same as plain C<@array>.
2016620790(We recommend that you use void context C<keys @array> for this, but
2016720791reasoned that taking C<values @array> out would require more
2016820792documentation than leaving it in.)
2016920793
2017020794=end original
2017120795
20172副作用として、L<C<values>|/values HASH> を呼び出すと HASH や ARRAY の
20173内部反復子をリセットします; L<C<each>|/each HASH> を参照してください。
20174(特に、L<C<values>|/values HASH> を無効コンテキストで呼び出すとその他の
20175オーバーヘッドなしで反復子をリセットします。
2017620796反復子をリセットするということを除けば、
2017720797リストコンテキストでの C<values @array> は単なる C<@array> と同じです。
2017820798この目的のためには無効コンテキストで C<keys @array> を使うことを
2017920799お勧めしますが、C<values @array> を取り出すにはそのままにするよりも
2018020800より多くの文書が必要だと判断しました。)
2018120801
2018220802=begin original
2018320803
2018420804Note that the values are not copied, which means modifying them will
2018520805modify the contents of the hash:
2018620806
2018720807=end original
2018820808
2018920809値はコピーされないので、返されたリストを変更すると
2019020810ハッシュの中身が変更されることに注意してください。
2019120811
2019220812 for (values %hash) { s/foo/bar/g } # modifies %hash values
2019320813 for (@hash{keys %hash}) { s/foo/bar/g } # same
2019420814
2019520815=begin original
2019620816
2019720817Starting with Perl 5.14, an experimental feature allowed
2019820818L<C<values>|/values HASH> to take a
2019920819scalar expression. This experiment has been deemed unsuccessful, and was
2020020820removed as of Perl 5.24.
2020120821
2020220822=end original
2020320823
2020420824Perl 5.14 から、L<C<values>|/values HASH> がスカラ式を取ることが出来るという
2020520825実験的機能がありました。
2020620826この実験は失敗と見なされ、Perl 5.24 で削除されました。
2020720827
2020820828=begin original
2020920829
2021020830To avoid confusing would-be users of your code who are running earlier
2021120831versions of Perl with mysterious syntax errors, put this sort of thing at
2021220832the top of your file to signal that your code will work I<only> on Perls of
2021320833a recent vintage:
2021420834
2021520835=end original
2021620836
2021720837あなたのコードを以前のバージョンの Perl で実行したユーザーが不思議な
2021820838文法エラーで混乱することを避けるために、コードが最近のバージョンの Perl で
2021920839I<のみ> 動作することを示すためにファイルの先頭に以下のようなことを
2022020840書いてください:
2022120841
2022220842 use 5.012; # so keys/values/each work on arrays
2022320843
2022420844=begin original
2022520845
2022620846See also L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, and
2022720847L<C<sort>|/sort SUBNAME LIST>.
2022820848
2022920849=end original
2023020850
2023120851L<C<keys>|/keys HASH>, L<C<each>|/each HASH>, L<C<sort>|/sort SUBNAME LIST> も
2023220852参照してください。
2023320853
2023420854=item vec EXPR,OFFSET,BITS
2023520855X<vec> X<bit> X<bit vector>
2023620856
2023720857=for Pod::Functions test or set particular bits in a string
2023820858
2023920859=begin original
2024020860
2024120861Treats the string in EXPR as a bit vector made up of elements of
2024220862width BITS and returns the value of the element specified by OFFSET
2024320863as an unsigned integer. BITS therefore specifies the number of bits
2024420864that are reserved for each element in the bit vector. This must
2024520865be a power of two from 1 to 32 (or 64, if your platform supports
2024620866that).
2024720867
2024820868=end original
2024920869
2025020870文字列 EXPR を BITS 幅の要素からなるビットベクターとして扱い、
2025120871OFFSET で指定された要素を符号なし整数として返します。
2025220872従って、 BITS はビットベクターの中の各要素について予約されるビット数です。
2025320873BIT は、1 から 32 まで(プラットホームが
2025420874対応していれば 64 まで) の 2 のべき乗でなければなりません。
2025520875
2025620876=begin original
2025720877
2025820878If BITS is 8, "elements" coincide with bytes of the input string.
2025920879
2026020880=end original
2026120881
2026220882BITS が 8 の場合、「要素」は入力文字列の各バイトと一致します。
2026320883
2026420884=begin original
2026520885
2026620886If BITS is 16 or more, bytes of the input string are grouped into chunks
2026720887of size BITS/8, and each group is converted to a number as with
2026820888L<C<pack>|/pack TEMPLATE,LIST>/L<C<unpack>|/unpack TEMPLATE,EXPR> with
2026920889big-endian formats C<n>/C<N> (and analogously for BITS==64). See
2027020890L<C<pack>|/pack TEMPLATE,LIST> for details.
2027120891
2027220892=end original
2027320893
2027420894BITS が 16 以上の場合、入力のバイト列は BITS/8 のサイズの固まりに
2027520895グループ化され、各グループは L<C<pack>|/pack TEMPLATE,LIST>/
2027620896L<C<unpack>|/unpack TEMPLATE,EXPR> のビッグエンディアン
2027720897フォーマット C<n>/C<N> を用いて(BITS==64 の類似として)数値に変換されます。
2027820898詳細は L<C<pack>|/pack TEMPLATE,LIST> を参照してください。
2027920899
2028020900=begin original
2028120901
2028220902If bits is 4 or less, the string is broken into bytes, then the bits
2028320903of each byte are broken into 8/BITS groups. Bits of a byte are
2028420904numbered in a little-endian-ish way, as in C<0x01>, C<0x02>,
2028520905C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. For example,
2028620906breaking the single input byte C<chr(0x36)> into two groups gives a list
2028720907C<(0x6, 0x3)>; breaking it into 4 groups gives C<(0x2, 0x1, 0x3, 0x0)>.
2028820908
2028920909=end original
2029020910
2029120911BITS が 4 以下の場合、文字列はバイトに分解され、バイトの各ビットは
20292209128/BITS 個のグループに分割されます。
2029320913ビットはリトルエンディアン風に、C<0x01>, C<0x02>,
2029420914C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80> の順になります。
2029520915例えば、入力バイト C<chr(0x36)> を二つのグループに分割すると、
2029620916C<(0x6, 0x3)> になります; 4 つに分割すると C<(0x2, 0x1, 0x3, 0x0)> に
2029720917なります。
2029820918
2029920919=begin original
2030020920
2030120921L<C<vec>|/vec EXPR,OFFSET,BITS> may also be assigned to, in which case
2030220922parentheses are needed
2030320923to give the expression the correct precedence as in
2030420924
2030520925=end original
2030620926
2030720927L<C<vec>|/vec EXPR,OFFSET,BITS> は左辺値として、代入の
2030820928対象にすることもできます; この場合、式を正しく
2030920929先行させるために以下のように括弧が必要です:
2031020930
2031120931 vec($image, $max_x * $x + $y, 8) = 3;
2031220932
2031320933=begin original
2031420934
2031520935If the selected element is outside the string, the value 0 is returned.
2031620936If an element off the end of the string is written to, Perl will first
2031720937extend the string with sufficiently many zero bytes. It is an error
2031820938to try to write off the beginning of the string (i.e., negative OFFSET).
2031920939
2032020940=end original
2032120941
2032220942選択された要素が文字列の外側だった場合、値 0 が返されます。
2032320943文字列の最後よりも後ろの要素に書き込もうとした場合、
2032420944Perl はまず文字列を必要な分だけ 0 のバイトで拡張します。
2032520945文字列の先頭より前に書き込もうとした(つまり OFFSET が負の数だった)
2032620946場合はエラーとなります。
2032720947
2032820948=begin original
2032920949
2033020950If the string happens to be encoded as UTF-8 internally (and thus has
2033120951the UTF8 flag set), L<C<vec>|/vec EXPR,OFFSET,BITS> tries to convert it
2033220952to use a one-byte-per-character internal representation. However, if the
20333string contains characters with values of 256 or higher, that conversion
20953string contains characters with values of 256 or higher, a fatal error
20334will fail. In that situation, C<vec> will operate on the underlying buffer
20954will occur.
20335regardless, in its internal UTF-8 representation.
2033620955
2033720956=end original
2033820957
20339文字列がなぜか内部で UTF-8 でエンコードされている場合(したがって UTF8 フラグが
20958文字列がたまたま内部で UTF-8 でエンコードされている場合(したがって
20340セットされている場合)、
20959UTF8 フラグがセットされている場合)、
2034120960L<C<vec>|/vec EXPR,OFFSET,BITS> はこれを単一バイト文字内部表現に
2034220961変換しようとします。
2034320962しかし、この文字列に値が 256 以上の文字が含まれている場合、
20344変換は失敗します。
20963致命的エラーが発生します。
20345この場合、C<vec> は内部の UTF-8 表現を気にせず、
20346基となっているバッファに対して操作します。
2034720964
2034820965=begin original
2034920966
2035020967Strings created with L<C<vec>|/vec EXPR,OFFSET,BITS> can also be
2035120968manipulated with the logical
2035220969operators C<|>, C<&>, C<^>, and C<~>. These operators will assume a bit
2035320970vector operation is desired when both operands are strings.
2035420971See L<perlop/"Bitwise String Operators">.
2035520972
2035620973=end original
2035720974
2035820975L<C<vec>|/vec EXPR,OFFSET,BITS> で作られた文字列は、論理演算子 C<|>、C<&>、
2035920976C<^>, C<~> で扱うこともできます。
2036020977これらの演算子は、両方の被演算子に文字列を使うと、
2036120978ビットベクター演算を行ないます。
2036220979L<perlop/"Bitwise String Operators"> を参照してください。
2036320980
2036420981=begin original
2036520982
2036620983The following code will build up an ASCII string saying C<'PerlPerlPerl'>.
2036720984The comments show the string after each step. Note that this code works
2036820985in the same way on big-endian or little-endian machines.
2036920986
2037020987=end original
2037120988
2037220989次のコードは C<'PerlPerlPerl'> という ASCII 文字列を作成します。
2037320990コメントは各行の実行後の文字列を示します。
2037420991このコードはビッグエンディアンでもリトルエンディアンでも同じように
2037520992動作することに注意してください。
2037620993
2037720994 my $foo = '';
2037820995 vec($foo, 0, 32) = 0x5065726C; # 'Perl'
2037920996
2038020997 # $foo eq "Perl" eq "\x50\x65\x72\x6C", 32 bits
2038120998 print vec($foo, 0, 8); # prints 80 == 0x50 == ord('P')
2038220999
2038321000 vec($foo, 2, 16) = 0x5065; # 'PerlPe'
2038421001 vec($foo, 3, 16) = 0x726C; # 'PerlPerl'
2038521002 vec($foo, 8, 8) = 0x50; # 'PerlPerlP'
2038621003 vec($foo, 9, 8) = 0x65; # 'PerlPerlPe'
2038721004 vec($foo, 20, 4) = 2; # 'PerlPerlPe' . "\x02"
2038821005 vec($foo, 21, 4) = 7; # 'PerlPerlPer'
2038921006 # 'r' is "\x72"
2039021007 vec($foo, 45, 2) = 3; # 'PerlPerlPer' . "\x0c"
2039121008 vec($foo, 93, 1) = 1; # 'PerlPerlPer' . "\x2c"
2039221009 vec($foo, 94, 1) = 1; # 'PerlPerlPerl'
2039321010 # 'l' is "\x6c"
2039421011
2039521012=begin original
2039621013
2039721014To transform a bit vector into a string or list of 0's and 1's, use these:
2039821015
2039921016=end original
2040021017
2040121018ビットベクターを、0 と 1 の文字列や配列に変換するには、
2040221019以下のようにします。
2040321020
2040421021 my $bits = unpack("b*", $vector);
2040521022 my @bits = split(//, unpack("b*", $vector));
2040621023
2040721024=begin original
2040821025
2040921026If you know the exact length in bits, it can be used in place of the C<*>.
2041021027
2041121028=end original
2041221029
2041321030ビット長が分かっていれば、C<*> の代わりにその長さを使うことができます。
2041421031
2041521032=begin original
2041621033
2041721034Here is an example to illustrate how the bits actually fall in place:
2041821035
2041921036=end original
2042021037
2042121038これはビットが実際にどのような位置に入るかを図示する例です。
2042221039
2042321040 #!/usr/bin/perl -wl
2042421041
2042521042 print <<'EOT';
2042621043 0 1 2 3
2042721044 unpack("V",$_) 01234567890123456789012345678901
2042821045 ------------------------------------------------------------------
2042921046 EOT
2043021047
2043121048 for $w (0..3) {
2043221049 $width = 2**$w;
2043321050 for ($shift=0; $shift < $width; ++$shift) {
2043421051 for ($off=0; $off < 32/$width; ++$off) {
2043521052 $str = pack("B*", "0"x32);
2043621053 $bits = (1<<$shift);
2043721054 vec($str, $off, $width) = $bits;
2043821055 $res = unpack("b*",$str);
2043921056 $val = unpack("V", $str);
2044021057 write;
2044121058 }
2044221059 }
2044321060 }
2044421061
2044521062 format STDOUT =
2044621063 vec($_,@#,@#) = @<< == @######### @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2044721064 $off, $width, $bits, $val, $res
2044821065 .
2044921066 __END__
2045021067
2045121068=begin original
2045221069
2045321070Regardless of the machine architecture on which it runs, the
2045421071example above should print the following table:
2045521072
2045621073=end original
2045721074
2045821075実行するマシンのアーキテクチャに関わらず、
2045921076上記の例は以下の表を出力します。
2046021077
2046121078 0 1 2 3
2046221079 unpack("V",$_) 01234567890123456789012345678901
2046321080 ------------------------------------------------------------------
2046421081 vec($_, 0, 1) = 1 == 1 10000000000000000000000000000000
2046521082 vec($_, 1, 1) = 1 == 2 01000000000000000000000000000000
2046621083 vec($_, 2, 1) = 1 == 4 00100000000000000000000000000000
2046721084 vec($_, 3, 1) = 1 == 8 00010000000000000000000000000000
2046821085 vec($_, 4, 1) = 1 == 16 00001000000000000000000000000000
2046921086 vec($_, 5, 1) = 1 == 32 00000100000000000000000000000000
2047021087 vec($_, 6, 1) = 1 == 64 00000010000000000000000000000000
2047121088 vec($_, 7, 1) = 1 == 128 00000001000000000000000000000000
2047221089 vec($_, 8, 1) = 1 == 256 00000000100000000000000000000000
2047321090 vec($_, 9, 1) = 1 == 512 00000000010000000000000000000000
2047421091 vec($_,10, 1) = 1 == 1024 00000000001000000000000000000000
2047521092 vec($_,11, 1) = 1 == 2048 00000000000100000000000000000000
2047621093 vec($_,12, 1) = 1 == 4096 00000000000010000000000000000000
2047721094 vec($_,13, 1) = 1 == 8192 00000000000001000000000000000000
2047821095 vec($_,14, 1) = 1 == 16384 00000000000000100000000000000000
2047921096 vec($_,15, 1) = 1 == 32768 00000000000000010000000000000000
2048021097 vec($_,16, 1) = 1 == 65536 00000000000000001000000000000000
2048121098 vec($_,17, 1) = 1 == 131072 00000000000000000100000000000000
2048221099 vec($_,18, 1) = 1 == 262144 00000000000000000010000000000000
2048321100 vec($_,19, 1) = 1 == 524288 00000000000000000001000000000000
2048421101 vec($_,20, 1) = 1 == 1048576 00000000000000000000100000000000
2048521102 vec($_,21, 1) = 1 == 2097152 00000000000000000000010000000000
2048621103 vec($_,22, 1) = 1 == 4194304 00000000000000000000001000000000
2048721104 vec($_,23, 1) = 1 == 8388608 00000000000000000000000100000000
2048821105 vec($_,24, 1) = 1 == 16777216 00000000000000000000000010000000
2048921106 vec($_,25, 1) = 1 == 33554432 00000000000000000000000001000000
2049021107 vec($_,26, 1) = 1 == 67108864 00000000000000000000000000100000
2049121108 vec($_,27, 1) = 1 == 134217728 00000000000000000000000000010000
2049221109 vec($_,28, 1) = 1 == 268435456 00000000000000000000000000001000
2049321110 vec($_,29, 1) = 1 == 536870912 00000000000000000000000000000100
2049421111 vec($_,30, 1) = 1 == 1073741824 00000000000000000000000000000010
2049521112 vec($_,31, 1) = 1 == 2147483648 00000000000000000000000000000001
2049621113 vec($_, 0, 2) = 1 == 1 10000000000000000000000000000000
2049721114 vec($_, 1, 2) = 1 == 4 00100000000000000000000000000000
2049821115 vec($_, 2, 2) = 1 == 16 00001000000000000000000000000000
2049921116 vec($_, 3, 2) = 1 == 64 00000010000000000000000000000000
2050021117 vec($_, 4, 2) = 1 == 256 00000000100000000000000000000000
2050121118 vec($_, 5, 2) = 1 == 1024 00000000001000000000000000000000
2050221119 vec($_, 6, 2) = 1 == 4096 00000000000010000000000000000000
2050321120 vec($_, 7, 2) = 1 == 16384 00000000000000100000000000000000
2050421121 vec($_, 8, 2) = 1 == 65536 00000000000000001000000000000000
2050521122 vec($_, 9, 2) = 1 == 262144 00000000000000000010000000000000
2050621123 vec($_,10, 2) = 1 == 1048576 00000000000000000000100000000000
2050721124 vec($_,11, 2) = 1 == 4194304 00000000000000000000001000000000
2050821125 vec($_,12, 2) = 1 == 16777216 00000000000000000000000010000000
2050921126 vec($_,13, 2) = 1 == 67108864 00000000000000000000000000100000
2051021127 vec($_,14, 2) = 1 == 268435456 00000000000000000000000000001000
2051121128 vec($_,15, 2) = 1 == 1073741824 00000000000000000000000000000010
2051221129 vec($_, 0, 2) = 2 == 2 01000000000000000000000000000000
2051321130 vec($_, 1, 2) = 2 == 8 00010000000000000000000000000000
2051421131 vec($_, 2, 2) = 2 == 32 00000100000000000000000000000000
2051521132 vec($_, 3, 2) = 2 == 128 00000001000000000000000000000000
2051621133 vec($_, 4, 2) = 2 == 512 00000000010000000000000000000000
2051721134 vec($_, 5, 2) = 2 == 2048 00000000000100000000000000000000
2051821135 vec($_, 6, 2) = 2 == 8192 00000000000001000000000000000000
2051921136 vec($_, 7, 2) = 2 == 32768 00000000000000010000000000000000
2052021137 vec($_, 8, 2) = 2 == 131072 00000000000000000100000000000000
2052121138 vec($_, 9, 2) = 2 == 524288 00000000000000000001000000000000
2052221139 vec($_,10, 2) = 2 == 2097152 00000000000000000000010000000000
2052321140 vec($_,11, 2) = 2 == 8388608 00000000000000000000000100000000
2052421141 vec($_,12, 2) = 2 == 33554432 00000000000000000000000001000000
2052521142 vec($_,13, 2) = 2 == 134217728 00000000000000000000000000010000
2052621143 vec($_,14, 2) = 2 == 536870912 00000000000000000000000000000100
2052721144 vec($_,15, 2) = 2 == 2147483648 00000000000000000000000000000001
2052821145 vec($_, 0, 4) = 1 == 1 10000000000000000000000000000000
2052921146 vec($_, 1, 4) = 1 == 16 00001000000000000000000000000000
2053021147 vec($_, 2, 4) = 1 == 256 00000000100000000000000000000000
2053121148 vec($_, 3, 4) = 1 == 4096 00000000000010000000000000000000
2053221149 vec($_, 4, 4) = 1 == 65536 00000000000000001000000000000000
2053321150 vec($_, 5, 4) = 1 == 1048576 00000000000000000000100000000000
2053421151 vec($_, 6, 4) = 1 == 16777216 00000000000000000000000010000000
2053521152 vec($_, 7, 4) = 1 == 268435456 00000000000000000000000000001000
2053621153 vec($_, 0, 4) = 2 == 2 01000000000000000000000000000000
2053721154 vec($_, 1, 4) = 2 == 32 00000100000000000000000000000000
2053821155 vec($_, 2, 4) = 2 == 512 00000000010000000000000000000000
2053921156 vec($_, 3, 4) = 2 == 8192 00000000000001000000000000000000
2054021157 vec($_, 4, 4) = 2 == 131072 00000000000000000100000000000000
2054121158 vec($_, 5, 4) = 2 == 2097152 00000000000000000000010000000000
2054221159 vec($_, 6, 4) = 2 == 33554432 00000000000000000000000001000000
2054321160 vec($_, 7, 4) = 2 == 536870912 00000000000000000000000000000100
2054421161 vec($_, 0, 4) = 4 == 4 00100000000000000000000000000000
2054521162 vec($_, 1, 4) = 4 == 64 00000010000000000000000000000000
2054621163 vec($_, 2, 4) = 4 == 1024 00000000001000000000000000000000
2054721164 vec($_, 3, 4) = 4 == 16384 00000000000000100000000000000000
2054821165 vec($_, 4, 4) = 4 == 262144 00000000000000000010000000000000
2054921166 vec($_, 5, 4) = 4 == 4194304 00000000000000000000001000000000
2055021167 vec($_, 6, 4) = 4 == 67108864 00000000000000000000000000100000
2055121168 vec($_, 7, 4) = 4 == 1073741824 00000000000000000000000000000010
2055221169 vec($_, 0, 4) = 8 == 8 00010000000000000000000000000000
2055321170 vec($_, 1, 4) = 8 == 128 00000001000000000000000000000000
2055421171 vec($_, 2, 4) = 8 == 2048 00000000000100000000000000000000
2055521172 vec($_, 3, 4) = 8 == 32768 00000000000000010000000000000000
2055621173 vec($_, 4, 4) = 8 == 524288 00000000000000000001000000000000
2055721174 vec($_, 5, 4) = 8 == 8388608 00000000000000000000000100000000
2055821175 vec($_, 6, 4) = 8 == 134217728 00000000000000000000000000010000
2055921176 vec($_, 7, 4) = 8 == 2147483648 00000000000000000000000000000001
2056021177 vec($_, 0, 8) = 1 == 1 10000000000000000000000000000000
2056121178 vec($_, 1, 8) = 1 == 256 00000000100000000000000000000000
2056221179 vec($_, 2, 8) = 1 == 65536 00000000000000001000000000000000
2056321180 vec($_, 3, 8) = 1 == 16777216 00000000000000000000000010000000
2056421181 vec($_, 0, 8) = 2 == 2 01000000000000000000000000000000
2056521182 vec($_, 1, 8) = 2 == 512 00000000010000000000000000000000
2056621183 vec($_, 2, 8) = 2 == 131072 00000000000000000100000000000000
2056721184 vec($_, 3, 8) = 2 == 33554432 00000000000000000000000001000000
2056821185 vec($_, 0, 8) = 4 == 4 00100000000000000000000000000000
2056921186 vec($_, 1, 8) = 4 == 1024 00000000001000000000000000000000
2057021187 vec($_, 2, 8) = 4 == 262144 00000000000000000010000000000000
2057121188 vec($_, 3, 8) = 4 == 67108864 00000000000000000000000000100000
2057221189 vec($_, 0, 8) = 8 == 8 00010000000000000000000000000000
2057321190 vec($_, 1, 8) = 8 == 2048 00000000000100000000000000000000
2057421191 vec($_, 2, 8) = 8 == 524288 00000000000000000001000000000000
2057521192 vec($_, 3, 8) = 8 == 134217728 00000000000000000000000000010000
2057621193 vec($_, 0, 8) = 16 == 16 00001000000000000000000000000000
2057721194 vec($_, 1, 8) = 16 == 4096 00000000000010000000000000000000
2057821195 vec($_, 2, 8) = 16 == 1048576 00000000000000000000100000000000
2057921196 vec($_, 3, 8) = 16 == 268435456 00000000000000000000000000001000
2058021197 vec($_, 0, 8) = 32 == 32 00000100000000000000000000000000
2058121198 vec($_, 1, 8) = 32 == 8192 00000000000001000000000000000000
2058221199 vec($_, 2, 8) = 32 == 2097152 00000000000000000000010000000000
2058321200 vec($_, 3, 8) = 32 == 536870912 00000000000000000000000000000100
2058421201 vec($_, 0, 8) = 64 == 64 00000010000000000000000000000000
2058521202 vec($_, 1, 8) = 64 == 16384 00000000000000100000000000000000
2058621203 vec($_, 2, 8) = 64 == 4194304 00000000000000000000001000000000
2058721204 vec($_, 3, 8) = 64 == 1073741824 00000000000000000000000000000010
2058821205 vec($_, 0, 8) = 128 == 128 00000001000000000000000000000000
2058921206 vec($_, 1, 8) = 128 == 32768 00000000000000010000000000000000
2059021207 vec($_, 2, 8) = 128 == 8388608 00000000000000000000000100000000
2059121208 vec($_, 3, 8) = 128 == 2147483648 00000000000000000000000000000001
2059221209
2059321210=item wait
2059421211X<wait>
2059521212
2059621213=for Pod::Functions wait for any child process to die
2059721214
2059821215=begin original
2059921216
2060021217Behaves like L<wait(2)> on your system: it waits for a child
2060121218process to terminate and returns the pid of the deceased process, or
2060221219C<-1> if there are no child processes. The status is returned in
2060321220L<C<$?>|perlvar/$?> and
2060421221L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
2060521222Note that a return value of C<-1> could mean that child processes are
2060621223being automatically reaped, as described in L<perlipc>.
2060721224
2060821225=end original
2060921226
2061021227L<wait(2)> と同様に振る舞います: チャイルドプロセスが終了するのを待ち、
2061121228消滅したプロセスの pid を返します; チャイルドプロセスが存在しないときには、
2061221229C<-1> を返します。
2061321230ステータスは L<C<$?>|perlvar/$?> と
2061421231L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
2061521232L<perlipc> に書いているように、返り値が C<-1> の場合は子プロセスが
2061621233自動的に刈り取られたことを意味するかもしれないことに注意してください。
2061721234
2061821235=begin original
2061921236
2062021237If you use L<C<wait>|/wait> in your handler for
2062121238L<C<$SIG{CHLD}>|perlvar/%SIG>, it may accidentally wait for the child
2062221239created by L<C<qx>|/qxE<sol>STRINGE<sol>> or L<C<system>|/system LIST>.
2062321240See L<perlipc> for details.
2062421241
2062521242=end original
2062621243
2062721244L<C<wait>|/wait> を L<C<$SIG{CHLD}>|perlvar/%SIG> のハンドラで使うと、誤って
2062821245L<C<qx>|/qxE<sol>STRINGE<sol>> や L<C<system>|/system LIST> によって
2062921246作られた子を待つことになるかも知れません。
2063021247詳しくは L<perlipc> を参照してください。
2063121248
2063221249=begin original
2063321250
2063421251Portability issues: L<perlport/wait>.
2063521252
2063621253=end original
2063721254
2063821255移植性の問題: L<perlport/wait>。
2063921256
2064021257=item waitpid PID,FLAGS
2064121258X<waitpid>
2064221259
2064321260=for Pod::Functions wait for a particular child process to die
2064421261
2064521262=begin original
2064621263
2064721264Waits for a particular child process to terminate and returns the pid of
2064821265the deceased process, or C<-1> if there is no such child process. A
2064921266non-blocking wait (with L<WNOHANG|POSIX/C<WNOHANG>> in FLAGS) can return 0 if
2065021267there are child processes matching PID but none have terminated yet.
2065121268The status is returned in L<C<$?>|perlvar/$?> and
2065221269L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}>.
2065321270
2065421271=end original
2065521272
2065621273特定の子プロセスが終了するのを待ち、消滅したプロセスの pid を
2065721274返します; 指定した子プロセスが存在しないときには、C<-1> を返します。
2065821275(FLAGS に L<WNOHANG|POSIX/C<WNOHANG>> を指定した) 非ブロッキング wait は、
2065921276PID がマッチングする子プロセスがいてもまだ終了していない場合に 0 を
2066021277返すことがあります。
2066121278ステータスは L<C<$?>|perlvar/$?> と
2066221279L<C<${^CHILD_ERROR_NATIVE}>|perlvar/${^CHILD_ERROR_NATIVE}> に返されます。
2066321280
2066421281=begin original
2066521282
2066621283A PID of C<0> indicates to wait for any child process whose process group ID is
2066721284equal to that of the current process. A PID of less than C<-1> indicates to
2066821285wait for any child process whose process group ID is equal to -PID. A PID of
2066921286C<-1> indicates to wait for any child process.
2067021287
2067121288=end original
2067221289
2067321290PID に C<0> を指定すると、プロセスグループ ID が現在のプロセスと同じである
2067421291任意の子プロセスを wait します。
2067521292PID に C<-1> 以下を指定すると、プロセスグループ ID が -PID に等しい
2067621293任意の子プロセスを wait します。
2067721294PID に C<-1> を指定すると任意の子プロセスを wait します。
2067821295
2067921296=begin original
2068021297
2068121298If you say
2068221299
2068321300=end original
2068421301
2068521302以下のようにするか
2068621303
2068721304 use POSIX ":sys_wait_h";
2068821305
2068921306 my $kid;
2069021307 do {
2069121308 $kid = waitpid(-1, WNOHANG);
2069221309 } while $kid > 0;
2069321310
2069421311=begin original
2069521312
2069621313or
2069721314
2069821315=end original
2069921316
2070021317または
2070121318
2070221319 1 while waitpid(-1, WNOHANG) > 0;
2070321320
2070421321=begin original
2070521322
2070621323then you can do a non-blocking wait for all pending zombie processes (see
2070721324L<POSIX/WAIT>).
2070821325Non-blocking wait is available on machines supporting either the
2070921326L<waitpid(2)> or L<wait4(2)> syscalls. However, waiting for a particular
2071021327pid with FLAGS of C<0> is implemented everywhere. (Perl emulates the
2071121328system call by remembering the status values of processes that have
2071221329exited but have not been harvested by the Perl script yet.)
2071321330
2071421331=end original
2071521332
2071621333とすると、ブロックが起こらないようにして、全ての待機中ゾンビプロセスを
2071721334wait します (L<POSIX/WAIT> を参照してください)。
2071821335ブロックなしの wait は、システムコール L<wait_pid(2)> か、
2071921336システムコール L<wait4(2)> をサポートしているマシンで利用可能です。
2072021337しかしながら、特定の pid を C<0> の FLAGS での wait はどこでも
2072121338実装されています。
2072221339(exit したプロセスのステータス値を覚えておいて、Perl がシステムコールを
2072321340エミュレートしますが、Perl スクリプトには取り入れられていません。)
2072421341
2072521342=begin original
2072621343
2072721344Note that on some systems, a return value of C<-1> could mean that child
2072821345processes are being automatically reaped. See L<perlipc> for details,
2072921346and for other examples.
2073021347
2073121348=end original
2073221349
2073321350システムによっては、返り値が C<-1> の場合は子プロセスが自動的に
2073421351刈り取られたことを意味するかもしれないことに注意してください。
2073521352詳細やその他の例については L<perlipc> を参照してください。
2073621353
2073721354=begin original
2073821355
2073921356Portability issues: L<perlport/waitpid>.
2074021357
2074121358=end original
2074221359
2074321360移植性の問題: L<perlport/waitpid>。
2074421361
2074521362=item wantarray
2074621363X<wantarray> X<context>
2074721364
2074821365=for Pod::Functions get void vs scalar vs list context of current subroutine call
2074921366
2075021367=begin original
2075121368
2075221369Returns true if the context of the currently executing subroutine or
2075321370L<C<eval>|/eval EXPR> is looking for a list value. Returns false if the
2075421371context is
2075521372looking for a scalar. Returns the undefined value if the context is
2075621373looking for no value (void context).
2075721374
2075821375=end original
2075921376
2076021377現在実行中のサブルーチンか L<C<eval>|/eval EXPR> ブロックのコンテキストが、
2076121378リスト値を要求するものであれば、真を返します。
2076221379スカラを要求するコンテキストであれば、偽を返します。
2076321380何も値を要求しない(無効コンテキスト)場合は未定義値を返します。
2076421381
2076521382 return unless defined wantarray; # don't bother doing more
2076621383 my @a = complex_calculation();
2076721384 return wantarray ? @a : "@a";
2076821385
2076921386=begin original
2077021387
2077121388L<C<wantarray>|/wantarray>'s result is unspecified in the top level of a file,
2077221389in a C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT> or C<END> block, or
2077321390in a C<DESTROY> method.
2077421391
2077521392=end original
2077621393
2077721394ファイルのトップレベル、C<BEGIN>, C<UNITCHECK>, C<CHECK>, C<INIT>, C<END>
2077821395ブロック内、C<DESTROY> メソッド内では L<C<wantarray>|/wantarray> の結果は
2077921396未定義です。
2078021397
2078121398=begin original
2078221399
2078321400This function should have been named wantlist() instead.
2078421401
2078521402=end original
2078621403
2078721404この関数は wantlist() という名前にするべきでした。
2078821405
2078921406=item warn LIST
2079021407X<warn> X<warning> X<STDERR>
2079121408
2079221409=for Pod::Functions print debugging info
2079321410
2079421411=begin original
2079521412
20796Prints the value of LIST to STDERR. If the last element of LIST does
21413Emits a warning, usually by printing it to C<STDERR>. C<warn> interprets
20797not end in a newline, it appends the same file/line number text as
21414its operand LIST in the same way as C<die>, but is slightly different
20798L<C<die>|/die LIST> does.
21415in what it defaults to when LIST is empty or makes an empty string.
21416If it is empty and L<C<$@>|perlvar/$@> already contains an exception
21417value then that value is used after appending C<"\t...caught">. If it
21418is empty and C<$@> is also empty then the string C<"Warning: Something's
21419wrong"> is used.
2079921420
2080021421=end original
2080121422
20802LIST の値を STDERR に出力します。
21423(通常は C<STDERR>表示することで) 警告を出力します。
20803LIST の最後の要素が改行で終わっていない場合、L<C<die>|/die LIST> が行うの
21424C<warn> はそのオペランド LIST C<die> と同様に解釈しますが、
20804同様のァイ/行番号のテキストが追加されます。
21425LIST が空や空文字列を作る時に何をデルトとするか少し異なります。
21426それが空かつ、L<C<$@>|perlvar/$@> に既に
20806=begin original
21427例外値が入っている場合、C<"\t...caught"> を追加した値が
20807
20808If the output is empty and L<C<$@>|perlvar/$@> already contains a value
20809(typically from a previous eval) that value is used after appending
20810C<"\t...caught"> to L<C<$@>|perlvar/$@>. This is useful for staying
20811almost, but not entirely similar to L<C<die>|/die LIST>.
20812
20813=end original
20814
20815出力が空かつ、(典型的には以前の eval によって) L<C<$@>|perlvar/$@> に既に値が
20816入っている場合、L<C<$@>|perlvar/$@> に C<"\t...caught"> を追加した値が
2081721428用いられます。
20818これはほとんどそのままにするときに便利ですが、
21429もしこれが空で C<$@> も空の場合はC<"Warning: Something's wrong"> という
20819L<C<die>|/die LIST> と全体的に似ているわけではありません。
20820
20821=begin original
20822
20823If L<C<$@>|perlvar/$@> is empty, then the string
20824C<"Warning: Something's wrong"> is used.
20825
20826=end original
20827
20828L<C<$@>|perlvar/$@> が空の場合は、C<"Warning: Something's wrong"> という
2082921430文字列が使われます。
2083021431
2083121432=begin original
2083221433
20833No message is printed if there is a L<C<$SIG{__WARN__}>|perlvar/%SIG>
21434By default, the exception derived from the operand LIST is stringified
20834handler
21435and printed to C<STDERR>. This behaviour can be altered by installing
20835installed. It is the handler's responsibility to deal with the message
21436a L<C<$SIG{__WARN__}>|perlvar/%SIG> handler. If there is such a
21437handler then no message is automatically printed; it is the handler's
21438responsibility to deal with the exception
2083621439as it sees fit (like, for instance, converting it into a
2083721440L<C<die>|/die LIST>). Most
2083821441handlers must therefore arrange to actually display the
2083921442warnings that they are not prepared to deal with, by calling
2084021443L<C<warn>|/warn LIST>
2084121444again in the handler. Note that this is quite safe and will not
2084221445produce an endless loop, since C<__WARN__> hooks are not called from
2084321446inside one.
2084421447
2084521448=end original
2084621449
20847L<C<$SIG{__WARN__}>|perlvar/%SIG> ンドラが設定されている場合何の
21450デフォルトでは、LIST オペランドから生成された例外
20848メッセージも表示されません
21451文字列化されて C<STDERR> に表示されま
20849メッセージをどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラ
21452この振る舞いは、L<C<$SIG{__WARN__}>|perlvar/%SIG> ハンドラを設定することで
21453置き換えられます。
21454このようなハンドラが設定されている場合は何の
21455メッセージも自動的には表示されません;
21456例外をどう扱うか(例えば L<C<die>|/die LIST> に変換するか)はハンドラの
2085021457責任ということです。
2085121458従ってほとんどのハンドラは、扱おうと準備していない警告を表示するために、
2085221459ハンドラの中で L<C<warn>|/warn LIST> を再び呼び出します。
2085321460C<__WARN__> フックはハンドラ内では呼び出されないので、これは十分安全で、
2085421461無限ループを引き起こすことはないということに注意してください。
2085521462
2085621463=begin original
2085721464
2085821465You will find this behavior is slightly different from that of
2085921466L<C<$SIG{__DIE__}>|perlvar/%SIG> handlers (which don't suppress the
2086021467error text, but can instead call L<C<die>|/die LIST> again to change
2086121468it).
2086221469
2086321470=end original
2086421471
2086521472この振る舞いは L<C<$SIG{__DIE__}>|perlvar/%SIG> ハンドラ(エラーテキストは
2086621473削除しませんが、代わりに L<C<die>|/die LIST> をもう一度呼び出すことで
2086721474変更できます)とは少し違うことに気付くことでしょう。
2086821475
2086921476=begin original
2087021477
2087121478Using a C<__WARN__> handler provides a powerful way to silence all
2087221479warnings (even the so-called mandatory ones). An example:
2087321480
2087421481=end original
2087521482
2087621483C<__WARN__> ハンドラを使うと、(いわゆる必須のものを含む)全ての
2087721484警告を黙らせる強力な手段となります。
2087821485例:
2087921486
2088021487 # wipe out *all* compile-time warnings
2088121488 BEGIN { $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN } }
2088221489 my $foo = 10;
2088321490 my $foo = 20; # no warning about duplicate my $foo,
2088421491 # but hey, you asked for it!
2088521492 # no compile-time or run-time warnings before here
2088621493 $DOWARN = 1;
2088721494
2088821495 # run-time warnings enabled after here
2088921496 warn "\$foo is alive and $foo!"; # does show up
2089021497
2089121498=begin original
2089221499
2089321500See L<perlvar> for details on setting L<C<%SIG>|perlvar/%SIG> entries
2089421501and for more
2089521502examples. See the L<Carp> module for other kinds of warnings using its
2089621503C<carp> and C<cluck> functions.
2089721504
2089821505=end original
2089921506
2090021507L<C<%SIG>|perlvar/%SIG> エントリのセットに関する詳細とさらなる例に関しては
2090121508L<perlvar> を参照してください。
2090221509C<carp> 関数と C<cluck> 関数を用いた警告の方法に関しては
2090321510L<Carp> モジュールを参照してください。
2090421511
2090521512=item write FILEHANDLE
2090621513X<write>
2090721514
2090821515=item write EXPR
2090921516
2091021517=item write
2091121518
2091221519=for Pod::Functions print a picture record
2091321520
2091421521=begin original
2091521522
2091621523Writes a formatted record (possibly multi-line) to the specified FILEHANDLE,
2091721524using the format associated with that file. By default the format for
2091821525a file is the one having the same name as the filehandle, but the
2091921526format for the current output channel (see the
2092021527L<C<select>|/select FILEHANDLE> function) may be set explicitly by
2092121528assigning the name of the format to the L<C<$~>|perlvar/$~> variable.
2092221529
2092321530=end original
2092421531
2092521532指定された FILEHANDLE に対して、そのファイルに対応させた
2092621533フォーマットを使って、(複数行の場合もある) 整形された
2092721534レコードを書き出します。
2092821535デフォルトでは、ファイルに対応するフォーマットは、ファイルハンドルと
2092921536同じ名前のものですが、その時点の出力チャネル
2093021537(L<C<select>|/select FILEHANDLE> 関数の項を
2093121538参照してください) のフォーマットは、その名前を明示的に変数
2093221539L<C<$~>|perlvar/$~> に代入することで、変更が可能です。
2093321540
2093421541=begin original
2093521542
2093621543Top of form processing is handled automatically: if there is insufficient
2093721544room on the current page for the formatted record, the page is advanced by
2093821545writing a form feed and a special top-of-page
2093921546format is used to format the new
2094021547page header before the record is written. By default, the top-of-page
2094121548format is the name of the filehandle with C<_TOP> appended, or C<top>
2094221549in the current package if the former does not exist. This would be a
2094321550problem with autovivified filehandles, but it may be dynamically set to the
2094421551format of your choice by assigning the name to the L<C<$^>|perlvar/$^>
2094521552variable while that filehandle is selected. The number of lines
2094621553remaining on the current page is in variable L<C<$->|perlvar/$->, which
2094721554can be set to C<0> to force a new page.
2094821555
2094921556=end original
2095021557
2095121558ページの先頭の処理は、自動的に行なわれます: 現在のページに整形された
2095221559レコードを出力するだけのスペースがない場合には、改ページを行なってページを
2095321560進め、新しいページヘッダを整形するため、ページ先頭フォーマットが使われ、
2095421561その後でレコードが書かれます。
2095521562デフォルトでは、ページ先頭フォーマットは、ファイルハンドルの名前に
2095621563C<_TOP> をつなげたものか、前者が存在しないなら、現在のパッケージの
2095721564C<top> です。
2095821565これは自動有効化されたファイルハンドルで問題になる可能性がありますが、
2095921566ファイルハンドルが選択されている間に、
2096021567変数 L<C<$^>|perlvar/$^> に名前を設定すれば、動的にフォーマットを
2096121568変更することができます。
2096221569そのページの残り行数は、変数 L<C<$->|perlvar/$-> に入っており、この変数を
2096321570C<0> に設定することで、強制的に改ページを行なうことができます。
2096421571
2096521572=begin original
2096621573
2096721574If FILEHANDLE is unspecified, output goes to the current default output
2096821575channel, which starts out as STDOUT but may be changed by the
2096921576L<C<select>|/select FILEHANDLE> operator. If the FILEHANDLE is an EXPR,
2097021577then the expression
2097121578is evaluated and the resulting string is used to look up the name of
2097221579the FILEHANDLE at run time. For more on formats, see L<perlform>.
2097321580
2097421581=end original
2097521582
2097621583FILEHANDLE を指定しないと、出力はその時点のデフォルト出力チャネルに対して
2097721584行なわれます; これは、スクリプトの開始時点では STDOUT ですが、
2097821585L<C<select>|/select FILEHANDLE> 演算子で変更することができます。
2097921586FILEHANDLE が EXPR ならば、式が評価され、その結果の文字列が
2098021587実行時に FILEHANDLE の名前として見られます。
2098121588フォーマットについて、さらには、L<perlform> を参照してください。
2098221589
2098321590=begin original
2098421591
2098521592Note that write is I<not> the opposite of
2098621593L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET>. Unfortunately.
2098721594
2098821595=end original
2098921596
2099021597write は L<C<read>|/read FILEHANDLE,SCALAR,LENGTH,OFFSET> の
2099121598反対のことをするもの I<ではありません>。
2099221599残念ながら。
2099321600
2099421601=item y///
2099521602
2099621603=for Pod::Functions transliterate a string
2099721604
2099821605=begin original
2099921606
2100021607The transliteration operator. Same as
2100121608L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>>. See
2100221609L<perlop/"Quote-Like Operators">.
2100321610
2100421611=end original
2100521612
2100621613文字変換演算子です。
2100721614L<C<trE<sol>E<sol>E<sol>>|/trE<sol>E<sol>E<sol>> と同じです。
2100821615L<perlop/"Quote-Like Operators"> を参照してください。
2100921616
2101021617=back
2101121618
2101221619=head2 Non-function Keywords by Cross-reference
2101321620
2101421621=head3 perldata
2101521622
2101621623=over
2101721624
2101821625=item __DATA__
2101921626
2102021627=item __END__
2102121628
2102221629=begin original
2102321630
2102421631These keywords are documented in L<perldata/"Special Literals">.
2102521632
2102621633=end original
2102721634
2102821635これらのキーワードは L<perldata/"Special Literals"> で文書化されています。
2102921636
2103021637=back
2103121638
2103221639=head3 perlmod
2103321640
2103421641=over
2103521642
2103621643=item BEGIN
2103721644
2103821645=item CHECK
2103921646
2104021647=item END
2104121648
2104221649=item INIT
2104321650
2104421651=item UNITCHECK
2104521652
2104621653=begin original
2104721654
2104821655These compile phase keywords are documented in L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END">.
2104921656
2105021657=end original
2105121658
2105221659これらのコンパイルフェーズキーワードは
2105321660L<perlmod/"BEGIN, UNITCHECK, CHECK, INIT and END"> で文書化されています。
2105421661
2105521662=back
2105621663
2105721664=head3 perlobj
2105821665
2105921666=over
2106021667
2106121668=item DESTROY
2106221669
2106321670=begin original
2106421671
2106521672This method keyword is documented in L<perlobj/"Destructors">.
2106621673
2106721674=end original
2106821675
2106921676このメソッドキーワードは L<perlobj/"Destructors"> で文書化されています。
2107021677
2107121678=back
2107221679
2107321680=head3 perlop
2107421681
2107521682=over
2107621683
2107721684=item and
2107821685
2107921686=item cmp
2108021687
2108121688=item eq
2108221689
2108321690=item ge
2108421691
2108521692=item gt
2108621693
2108721694=item le
2108821695
2108921696=item lt
2109021697
2109121698=item ne
2109221699
2109321700=item not
2109421701
2109521702=item or
2109621703
2109721704=item x
2109821705
2109921706=item xor
2110021707
2110121708=begin original
2110221709
2110321710These operators are documented in L<perlop>.
2110421711
2110521712=end original
2110621713
2110721714これらの演算子は L<perlop> で文書化されています。
2110821715
2110921716=back
2111021717
2111121718=head3 perlsub
2111221719
2111321720=over
2111421721
2111521722=item AUTOLOAD
2111621723
2111721724=begin original
2111821725
2111921726This keyword is documented in L<perlsub/"Autoloading">.
2112021727
2112121728=end original
2112221729
2112321730このキーワードは L<perlsub/"Autoloading"> で文書化されています。
2112421731
2112521732=back
2112621733
2112721734=head3 perlsyn
2112821735
2112921736=over
2113021737
2113121738=item else
2113221739
2113321740=item elsif
2113421741
2113521742=item for
2113621743
2113721744=item foreach
2113821745
2113921746=item if
2114021747
2114121748=item unless
2114221749
2114321750=item until
2114421751
2114521752=item while
2114621753
2114721754=begin original
2114821755
2114921756These flow-control keywords are documented in L<perlsyn/"Compound Statements">.
2115021757
2115121758=end original
2115221759
2115321760これらのフロー制御キーワードは L<perlsyn/"Compound Statements"> で
2115421761文書化されています。
2115521762
2115621763=item elseif
2115721764
2115821765=begin original
2115921766
2116021767The "else if" keyword is spelled C<elsif> in Perl. There's no C<elif>
2116121768or C<else if> either. It does parse C<elseif>, but only to warn you
2116221769about not using it.
2116321770
2116421771=end original
2116521772
2116621773"else if" キーワードは Perl では C<elsif> と綴ります。
2116721774C<elif> や C<else if> はありません。
2116821775C<elseif> はパースされますが、使わないように警告するためだけです。
2116921776
2117021777=begin original
2117121778
2117221779See the documentation for flow-control keywords in L<perlsyn/"Compound
2117321780Statements">.
2117421781
2117521782=end original
2117621783
2117721784L<perlsyn/"Compound Statements"> のフロー制御キーワードに関する文章を
2117821785参照してください。
2117921786
2118021787=back
2118121788
2118221789=over
2118321790
2118421791=item default
2118521792
2118621793=item given
2118721794
2118821795=item when
2118921796
2119021797=begin original
2119121798
2119221799These flow-control keywords related to the experimental switch feature are
2119321800documented in L<perlsyn/"Switch Statements">.
2119421801
2119521802=end original
2119621803
2119721804これらの実験的な switch 機能に関連するフロー制御キーワードは
2119821805L<perlsyn/"Switch Statements"> で文書化されています。
2119921806
2120021807=back
2120121808
2120221809=cut
2120321810
2120421811=begin meta
2120521812
2120621813Translate: 吉村 寿人 <JAE00534@niftyserve.or.jp>
2120721814Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.6.1-)
2120821815Status: completed
2120921816
2121021817=end meta